// @ts-check import { test, expect } from '@playwright/test'; import { loadTestUser } from '../utils/testUser.js'; test.describe('@p0 Logout — clears client caches & redirects', () => { test.setTimeout(10000); test('logout nukes cached keys and lands on /signin', async ({ page }) => { const u = loadTestUser(); // Sign in await page.context().clearCookies(); await page.goto('/signin', { waitUntil: 'networkidle' }); await page.getByPlaceholder('Username', { exact: true }).fill(u.username); await page.getByPlaceholder('Password', { exact: true }).fill(u.password); await page.getByRole('button', { name: /^Sign In$/ }).click(); await page.waitForURL('**/signin-landing**', { timeout: 15000 }); // Seed the keys that App.clearMany() clears during logout await page.evaluate(() => { localStorage.setItem('id', '123'); localStorage.setItem('careerSuggestionsCache', '["demo"]'); localStorage.setItem('lastSelectedCareerProfileId', 'abc'); localStorage.setItem('selectedCareer', '{"title":"Test"}'); localStorage.setItem('aiClickCount', '1'); localStorage.setItem('aiClickDate', '2024-01-01'); localStorage.setItem('aiRecommendations', '[]'); localStorage.setItem('premiumOnboardingState', '{"step":1}'); localStorage.setItem('premiumOnboardingPointer', 'wizard://step/2'); localStorage.setItem('financialProfile', '{"ok":true}'); localStorage.setItem('selectedScenario', 'foo'); }); // Click Logout const logout = page.getByRole('button', { name: /^Logout$/i }).or(page.getByText(/^Logout$/i)); await expect(logout).toBeVisible({ timeout: 5000 }); await logout.click(); // Redirected to /signin await expect(page).toHaveURL(/\/signin(\?|$)/, { timeout: 8000 }); // All keys cleared const cleared = await page.evaluate(() => ([ 'id', 'careerSuggestionsCache', 'lastSelectedCareerProfileId', 'selectedCareer', 'aiClickCount', 'aiClickDate', 'aiRecommendations', 'premiumOnboardingState', 'premiumOnboardingPointer', 'financialProfile', 'selectedScenario', ].every(k => localStorage.getItem(k) === null))); expect(cleared).toBeTruthy(); }); });