dev1/tests/e2e/08-logout.guard.spec.mjs

29 lines
1.2 KiB
JavaScript

// @ts-check
import { test, expect } from '@playwright/test';
import { loadTestUser } from '../utils/testUser.js';
test.describe('@p0 Logout + guard', () => {
test.setTimeout(10000);
test('logout clears session; protected routes redirect to /signin', async ({ page }) => {
const user = loadTestUser();
// Sign in
await page.context().clearCookies();
await page.goto('/signin', { waitUntil: 'networkidle' });
await page.getByPlaceholder('Username', { exact: true }).fill(user.username);
await page.getByPlaceholder('Password', { exact: true }).fill(user.password);
await page.getByRole('button', { name: /^Sign In$/ }).click();
await page.waitForURL('**/signin-landing**', { timeout: 15000 });
// Click Logout in top nav (link or button)
const logout = page.getByRole('link', { name: /Logout/i }).or(page.getByRole('button', { name: /Logout/i }));
await expect(logout).toBeVisible({ timeout: 5000 });
await logout.click();
// Hitting a protected route should bounce to /signin
await page.goto('/career-explorer', { waitUntil: 'networkidle' });
await expect(page).toHaveURL(/\/signin(\?|$)/, { timeout: 10000 });
});
});