AFFiNE/tests/theme.spec.ts

46 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-02-05 13:41:18 +03:00
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
2023-01-09 07:20:53 +03:00
import { loadPage } from './libs/load-page.js';
2022-11-10 15:51:06 +03:00
2022-11-28 16:17:34 +03:00
loadPage();
2022-11-10 15:51:06 +03:00
test.describe('Change Theme', () => {
2022-11-10 15:51:06 +03:00
test('default white', async ({ page }) => {
await page.waitForSelector('html');
2022-11-10 15:51:06 +03:00
const root = page.locator('html');
const themeMode = await root.evaluate(element =>
window.getComputedStyle(element).getPropertyValue('--affine-theme-mode')
);
expect(themeMode).toBe('light');
2022-11-10 15:51:06 +03:00
const lightButton = page.locator('[data-testid=change-theme-light]');
const buttonPositionTop = await lightButton.evaluate(
element => window.getComputedStyle(element).top
);
expect(buttonPositionTop).toBe('0px');
2022-11-10 15:51:06 +03:00
});
test('change theme to dark', async ({ page }) => {
const changeThemeContainer = page.locator(
'[data-testid=change-theme-container]'
);
const box = await changeThemeContainer.boundingBox();
expect(box?.x).not.toBeUndefined();
2022-11-10 15:51:06 +03:00
await page.mouse.move((box?.x ?? 0) + 5, (box?.y ?? 0) + 5);
2022-11-28 16:17:34 +03:00
await page.waitForTimeout(1000);
2022-11-10 15:51:06 +03:00
const darkButton = page.locator('[data-testid=change-theme-dark]');
const darkButtonPositionTop = await darkButton.evaluate(
element => element.getBoundingClientRect().y
);
expect(darkButtonPositionTop).toBe(box?.y);
2022-11-10 15:51:06 +03:00
await page.mouse.click((box?.x ?? 0) + 5, (box?.y ?? 0) + 5);
const root = page.locator('html');
const themeMode = await root.evaluate(element =>
window.getComputedStyle(element).getPropertyValue('--affine-theme-mode')
);
expect(themeMode).toBe('dark');
2022-11-10 15:51:06 +03:00
});
});