Files
carmanagement/apps/homepage/tests/browser/theme-csp.spec.ts
T
root 781512399b
Build & Deploy / Build & Push Docker Image (push) Successful in 2m51s
Test / Type Check (all packages) (push) Successful in 52s
Build & Deploy / Deploy to VPS (push) Successful in 4s
Test / API Unit Tests (push) Successful in 49s
Test / Homepage Unit Tests (push) Successful in 44s
Test / Storefront Unit Tests (push) Successful in 39s
Test / Admin Unit Tests (push) Successful in 40s
Test / Dashboard Unit Tests (push) Successful in 40s
Test / API Integration Tests (push) Successful in 1m0s
Update homepage routes to include language and mode
2026-07-02 14:10:17 -04:00

61 lines
2.4 KiB
TypeScript

import { expect, test } from '@playwright/test';
test('explicit dark theme is present on the server-rendered root', async ({ browser, baseURL }) => {
const origin = new URL(baseURL ?? 'http://127.0.0.1:3000');
const context = await browser.newContext();
await context.addCookies([
{
name: 'hpc-theme',
value: 'dark',
domain: origin.hostname,
path: '/',
secure: false,
sameSite: 'Lax',
},
]);
const page = await context.newPage();
const response = await page.goto('/en/dark');
await expect(page.locator('html')).toHaveAttribute('data-theme-preference', 'dark');
await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark');
const csp = response?.headers()['content-security-policy'] ?? '';
const nonce = await page.locator('#theme-bootstrap').getAttribute('nonce');
expect(nonce).toBeTruthy();
expect(csp).toContain("'unsafe-inline'");
expect(csp).not.toContain("'strict-dynamic'");
await context.close();
});
test('system preference resolves before interaction', async ({ browser }) => {
const context = await browser.newContext({ colorScheme: 'dark' });
const page = await context.newPage();
await page.goto('/en/system');
await expect(page.locator('html')).toHaveAttribute('data-theme-preference', 'system');
await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark');
await context.close();
});
test('system follows operating-system changes while explicit preferences ignore them', async ({
page,
}) => {
await page.goto('/en/system');
const selector = page.getByLabel('Theme').first();
await selector.selectOption('system');
await page.emulateMedia({ colorScheme: 'dark' });
await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark');
await page.emulateMedia({ colorScheme: 'light' });
await expect(page.locator('html')).toHaveAttribute('data-theme', 'light');
await selector.selectOption('dark');
await expect(page).toHaveURL('/en/dark');
await page.emulateMedia({ colorScheme: 'light' });
await expect(page.locator('html')).toHaveAttribute('data-theme-preference', 'dark');
await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark');
expect(await page.evaluate(() => window.localStorage.getItem('hpc.theme.preference'))).toBe(
'dark',
);
expect(await page.context().cookies()).toEqual(
expect.arrayContaining([expect.objectContaining({ name: 'hpc-theme', value: 'dark' })]),
);
});