style: 全站接入深色主题,按新规则整改界面取值
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('深色模式', () => {
|
||||
test('没有手动选择时跟随系统', async ({ page }) => {
|
||||
await page.emulateMedia({ colorScheme: 'dark' });
|
||||
await page.goto('/login');
|
||||
await expect(page.locator('html')).toHaveClass(/dark/);
|
||||
const solid = await page.getByRole('button', { name: '进入系统' }).evaluate((node) => {
|
||||
const style = getComputedStyle(node);
|
||||
return { background: style.backgroundColor, color: style.color };
|
||||
});
|
||||
expect(solid.background).toBe('rgb(127, 216, 180)');
|
||||
expect(solid.color).toBe('rgb(17, 26, 22)');
|
||||
await page.emulateMedia({ colorScheme: 'light' });
|
||||
await expect(page.locator('html')).not.toHaveClass(/dark/);
|
||||
});
|
||||
|
||||
test('手动切换覆盖系统并在刷新后保持', async ({ page }) => {
|
||||
await page.emulateMedia({ colorScheme: 'dark' });
|
||||
await page.goto('/login');
|
||||
await expect(page.locator('html')).toHaveClass(/dark/);
|
||||
await page.getByRole('button', { name: '切到浅色' }).click();
|
||||
await expect(page.locator('html')).not.toHaveClass(/dark/);
|
||||
expect(await page.evaluate(() => localStorage.getItem('theme'))).toBe('light');
|
||||
await page.reload();
|
||||
await expect(page.locator('html')).not.toHaveClass(/dark/);
|
||||
await expect(page.getByRole('button', { name: '切到深色' })).toBeVisible();
|
||||
});
|
||||
|
||||
test('手动选择后不再跟随系统变化', async ({ page }) => {
|
||||
await page.emulateMedia({ colorScheme: 'light' });
|
||||
await page.goto('/login');
|
||||
await page.getByRole('button', { name: '切到深色' }).click();
|
||||
await expect(page.locator('html')).toHaveClass(/dark/);
|
||||
await page.emulateMedia({ colorScheme: 'light' });
|
||||
await expect(page.locator('html')).toHaveClass(/dark/);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user