import { test, expect } from '@playwright/test' test('availability toggle should not log out the admin (with network capture)', async ({ page }) => { const networkLogs: string[] = [] page.on('request', req => { const url = req.url() if (url.includes('/api/availability/blocked') || url.includes('/_next/image') || url.includes('/_next/data')) { networkLogs.push(`REQ -> ${req.method()} ${url} | headers: ${JSON.stringify(req.headers())}`) } }) page.on('response', async res => { const url = res.url() if (url.includes('/api/availability/blocked') || url.includes('/_next/image') || url.includes('/_next/data')) { let body = '' try { body = await res.text() } catch (e) { body = `` } networkLogs.push(`RES <- ${res.status()} ${url} | headers: ${JSON.stringify(res.headers())} | body: ${body.substring(0, 200)}`) } }) // Go to login and sign in await page.goto('/login') await page.fill('#username', 'brotha') await page.fill('#password', 'makefood1') await Promise.all([ page.waitForNavigation({ url: '**/admin', waitUntil: 'load' }), page.click('button:has-text("Log ind")'), ]) // Confirm cookie set const cookiesBefore = await page.context().cookies() const hasAuthBefore = cookiesBefore.some(c => c.name === 'authToken') expect(hasAuthBefore).toBeTruthy() // Navigate to availability await page.goto('/admin/availability') await expect(page).toHaveURL(/\/admin\/availability/) // Try to toggle: prefer existing "Åbn dag" button if present (safer), otherwise click first available day in calendar const openButton = page.locator('button:has-text("Åbn dag")').first() if (await openButton.count() > 0) { await openButton.click() } else { // Fallback: click first clickable day in the calendar const dayButton = page.locator('main button:not([disabled])').first() await dayButton.click() } // Wait for any network activity to settle await page.waitForTimeout(1000) // Dump network logs for debugging console.log('\n--- NETWORK LOGS ---') for (const l of networkLogs) console.log(l) console.log('--- END NETWORK LOGS ---\n') // Ensure we are still on the admin availability page (not redirected to /login) const current = page.url() expect(current).toContain('/admin/availability') // Confirm auth cookie still exists after the toggle const cookiesAfter = await page.context().cookies() const hasAuthAfter = cookiesAfter.some(c => c.name === 'authToken') expect(hasAuthAfter).toBeTruthy() })