refactor: workspace loading logic (#1966)

This commit is contained in:
Himself65
2023-04-16 16:02:41 -05:00
committed by GitHub
parent caa292e097
commit 7bbe67af43
88 changed files with 2684 additions and 2268 deletions

View File

@@ -1,61 +1,55 @@
import { resolve } from 'node:path';
import { expect } from '@playwright/test';
import { openHomePage } from '../libs/load-page';
import { waitMarkdownImported } from '../libs/page-logic';
import { test } from '../libs/playwright';
import { testResultDir } from '../libs/utils';
test.describe('Change Theme', () => {
// default could be anything according to the system
test('default white', async ({ browser }) => {
const context = await browser.newContext({
colorScheme: 'light',
});
const page = await context.newPage();
await openHomePage(page);
await waitMarkdownImported(page);
await page.waitForSelector('html');
const root = page.locator('html');
const themeMode = await root.evaluate(element =>
element.getAttribute('data-theme')
);
expect(themeMode).toBe('light');
await page.waitForTimeout(50);
const rightMenu = page.getByTestId('editor-option-menu');
const rightMenuBox = await rightMenu.boundingBox();
const lightButton = page.getByTestId('change-theme-light');
const lightButtonBox = await lightButton.boundingBox();
const darkButton = page.getByTestId('change-theme-dark');
const darkButtonBox = await darkButton.boundingBox();
if (!rightMenuBox || !lightButtonBox || !darkButtonBox) {
throw new Error('rightMenuBox or lightButtonBox or darkButtonBox is nil');
}
expect(darkButtonBox.x).toBeLessThan(rightMenuBox.x);
expect(darkButtonBox.y).toBeGreaterThan(rightMenuBox.y);
expect(lightButtonBox.y).toBeCloseTo(rightMenuBox.y);
expect(lightButtonBox.x).toBeCloseTo(darkButtonBox.x);
// default could be anything according to the system
test('default white', async ({ browser }) => {
const context = await browser.newContext({
colorScheme: 'light',
});
// 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();
//
// await page.mouse.move((box?.x ?? 0) + 5, (box?.y ?? 0) + 5);
// await page.waitForTimeout(1000);
// const darkButton = page.locator('[data-testid=change-theme-dark]');
// const darkButtonPositionTop = await darkButton.evaluate(
// element => element.getBoundingClientRect().y
// );
// expect(darkButtonPositionTop).toBe(box?.y);
//
// await page.mouse.click((box?.x ?? 0) + 5, (box?.y ?? 0) + 5);
// const root = page.locator('html');
// const themeMode = await root.evaluate(element =>
// element.getAttribute('data-theme')
// );
// expect(themeMode).toBe('dark');
// });
const page = await context.newPage();
await openHomePage(page);
await waitMarkdownImported(page);
const root = page.locator('html');
const themeMode = await root.evaluate(element =>
element.getAttribute('data-theme')
);
expect(themeMode).toBe('light');
const prev = await page.screenshot({
path: resolve(testResultDir, 'affine-light-theme.png'),
});
await page.getByTestId('change-theme-dark').click();
await page.waitForTimeout(50);
const after = await page.screenshot({
path: resolve(testResultDir, 'affine-dark-theme.png'),
});
expect(prev).not.toEqual(after);
});
// 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();
//
// await page.mouse.move((box?.x ?? 0) + 5, (box?.y ?? 0) + 5);
// await page.waitForTimeout(1000);
// const darkButton = page.locator('[data-testid=change-theme-dark]');
// const darkButtonPositionTop = await darkButton.evaluate(
// element => element.getBoundingClientRect().y
// );
// expect(darkButtonPositionTop).toBe(box?.y);
//
// await page.mouse.click((box?.x ?? 0) + 5, (box?.y ?? 0) + 5);
// const root = page.locator('html');
// const themeMode = await root.evaluate(element =>
// element.getAttribute('data-theme')
// );
// expect(themeMode).toBe('dark');
// });