2023-02-05 13:41:18 +03:00
|
|
|
import { expect } from '@playwright/test';
|
2023-02-17 05:43:52 +03:00
|
|
|
import { test } from './libs/playwright';
|
|
|
|
import { loadPage } from './libs/load-page';
|
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
|
|
|
|
2023-02-05 12:53:14 +03:00
|
|
|
test.describe('Change Theme', () => {
|
2022-11-10 15:51:06 +03:00
|
|
|
test('default white', async ({ page }) => {
|
2022-12-30 16:40:15 +03:00
|
|
|
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')
|
|
|
|
);
|
2022-12-30 16:40:15 +03:00
|
|
|
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
|
|
|
|
);
|
2022-12-30 16:40:15 +03:00
|
|
|
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();
|
2022-12-30 16:40:15 +03:00
|
|
|
expect(box?.x).not.toBeUndefined();
|
2022-11-10 15:51:06 +03:00
|
|
|
|
2022-12-30 16:40:15 +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
|
|
|
|
);
|
2022-12-30 16:40:15 +03:00
|
|
|
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')
|
|
|
|
);
|
2022-12-30 16:40:15 +03:00
|
|
|
expect(themeMode).toBe('dark');
|
2022-11-10 15:51:06 +03:00
|
|
|
});
|
|
|
|
});
|