POST /app/theme sets the theme cookie and redirects back. Sun/Moon button in the app navbar submits the form. E2E tests verify SSR cookie-driven theme switching. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { test, expect } from './helpers/fixtures';
|
|
import { mock } from './helpers/mock';
|
|
|
|
test('default data-theme is dark', async ({ page }) => {
|
|
await page.goto('/app/authorize');
|
|
await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark');
|
|
});
|
|
|
|
test('theme cookie set to light makes data-theme light', async ({ page }) => {
|
|
await page.context().addCookies([
|
|
{
|
|
name: 'theme',
|
|
value: 'light',
|
|
domain: 'localhost',
|
|
path: '/app',
|
|
sameSite: 'Lax'
|
|
}
|
|
]);
|
|
await page.goto('/app/authorize');
|
|
await expect(page.locator('html')).toHaveAttribute('data-theme', 'light');
|
|
});
|
|
|
|
test('theme toggle button switches dark to light', async ({ page, loggedInUser }) => {
|
|
void loggedInUser;
|
|
await mock.override('GET', '/event/list', {
|
|
status: 200,
|
|
body: { status: 200, data: { items: [] } }
|
|
});
|
|
await page.goto('/app/');
|
|
await page.waitForLoadState('networkidle');
|
|
await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark');
|
|
await page.getByRole('button', { name: '切换主题' }).click();
|
|
await page.waitForLoadState('networkidle');
|
|
await expect(page.locator('html')).toHaveAttribute('data-theme', 'light');
|
|
});
|