Files
cms-client/tests/e2e/auth.spec.ts
Noa Virellia a01c75a2ca chore: rename app to NixCN CMS and add browser title
Corrects misspelling "Nix CN CMS" → "NixCN CMS" across all source files,
docs, and tests; adds <title>NixCN CMS</title> to the root layout; documents
the correct spelling in CLAUDE.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-18 17:29:37 +08:00

59 lines
2.1 KiB
TypeScript

import { test, expect } from './helpers/fixtures';
import { mock } from './helpers/mock';
test('anonymous user is redirected from /app/ to /app/authorize', async ({ page }) => {
// hooks.server.ts skips getUserInfo when no access_token cookie is present,
// so this path makes zero backend calls — no overrides needed.
await page.goto('/app/');
await expect(page).toHaveURL(/\/app\/authorize/);
await expect(page.getByRole('heading', { name: /NixCN CMS/ })).toBeVisible();
});
test('full magic-link → token → dashboard flow against mock', async ({ page }) => {
// The dev-mode auto-follow path: /auth/magic returns a uri that the form
// action redirects to → /token exchanges code for tokens → cookies set →
// hooks.server.ts loads the user → dashboard renders.
await mock.override('POST', '/auth/magic', {
status: 200,
body: { status: 200, data: { uri: '/app/token?code=test-code' } }
});
await mock.override('POST', '/auth/token', {
status: 200,
body: {
status: 200,
data: { access_token: 'test-access', refresh_token: 'test-refresh' }
}
});
await mock.override('GET', '/user/info', {
status: 200,
body: {
status: 200,
data: {
user_id: '1',
email: 'edolstra@gmail.com',
username: 'edolstra',
nickname: 'E',
permission_level: 10,
allow_public: true
}
}
});
// Dashboard (/) loads the event list; override so the page renders instead of 500ing.
await mock.override('GET', '/event/list', {
status: 200,
body: { status: 200, data: [] }
});
await page.goto('/app/authorize');
await page.getByPlaceholder('edolstra@gmail.com').fill('edolstra@gmail.com');
await page.getByRole('button', { name: /发送登录链接/ }).click();
await page.waitForLoadState('networkidle');
await expect(page).toHaveURL(/\/app\/?$/);
// Avatar dropdown trigger is always visible; the email lives inside the
// dropdown content which is CSS-hidden until interaction. Open it first.
await page.getByRole('button', { name: 'user menu' }).click();
// The email appears in the menu-title li inside the dropdown.
await expect(page.locator('li.menu-title').getByText('edolstra@gmail.com')).toBeVisible();
});