2023-09-17 23:26:06 +03:00
|
|
|
import { test } from '@affine-test/kit/electron';
|
2024-02-21 15:57:18 +03:00
|
|
|
import {
|
|
|
|
clickNewPageButton,
|
|
|
|
getBlockSuiteEditorTitle,
|
|
|
|
} from '@affine-test/kit/utils/page-logic';
|
2023-10-16 11:44:09 +03:00
|
|
|
import {
|
|
|
|
clickSideBarCurrentWorkspaceBanner,
|
|
|
|
clickSideBarSettingButton,
|
|
|
|
} from '@affine-test/kit/utils/sidebar';
|
2024-03-25 06:55:32 +03:00
|
|
|
import type { Page } from '@playwright/test';
|
|
|
|
import { expect } from '@playwright/test';
|
2023-10-16 15:27:06 +03:00
|
|
|
|
|
|
|
const historyShortcut = async (page: Page, command: 'goBack' | 'goForward') => {
|
2024-07-29 14:05:22 +03:00
|
|
|
await page.keyboard.press(
|
|
|
|
command === 'goBack' ? 'ControlOrMeta+[' : 'ControlOrMeta+]'
|
2023-10-16 15:27:06 +03:00
|
|
|
);
|
|
|
|
};
|
2023-04-28 09:40:44 +03:00
|
|
|
|
2023-05-09 10:30:01 +03:00
|
|
|
test('new page', async ({ page, workspace }) => {
|
2024-07-29 14:05:22 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-12-15 10:20:50 +03:00
|
|
|
const flavour = (await workspace.current()).meta.flavour;
|
2023-04-25 02:53:36 +03:00
|
|
|
expect(flavour).toBe('local');
|
|
|
|
});
|
2023-04-28 09:26:14 +03:00
|
|
|
|
2023-10-16 15:27:06 +03:00
|
|
|
test('app sidebar router forward/back', async ({ page }) => {
|
2024-07-29 14:05:22 +03:00
|
|
|
// create pages
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
await clickNewPageButton(page);
|
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
|
|
|
await title.focus();
|
|
|
|
await title.pressSequentially('test1', {
|
|
|
|
delay: 100,
|
|
|
|
});
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
await clickNewPageButton(page);
|
2023-10-11 09:05:06 +03:00
|
|
|
|
2024-07-29 14:05:22 +03:00
|
|
|
await title.focus();
|
|
|
|
await title.pressSequentially('test2', {
|
|
|
|
delay: 100,
|
|
|
|
});
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
await clickNewPageButton(page);
|
|
|
|
await title.focus();
|
|
|
|
await title.pressSequentially('test3', {
|
|
|
|
delay: 100,
|
|
|
|
});
|
|
|
|
await expect(getBlockSuiteEditorTitle(page)).toHaveText('test3');
|
2023-05-15 09:13:30 +03:00
|
|
|
|
2024-03-05 10:01:24 +03:00
|
|
|
await page.click('[data-testid="app-navigation-button-back"]');
|
|
|
|
await page.click('[data-testid="app-navigation-button-back"]');
|
2024-07-29 14:05:22 +03:00
|
|
|
await expect(getBlockSuiteEditorTitle(page)).toHaveText('test1');
|
2024-03-05 10:01:24 +03:00
|
|
|
await page.click('[data-testid="app-navigation-button-forward"]');
|
|
|
|
await page.click('[data-testid="app-navigation-button-forward"]');
|
2024-07-29 14:05:22 +03:00
|
|
|
await expect(getBlockSuiteEditorTitle(page)).toHaveText('test3');
|
2023-10-16 15:27:06 +03:00
|
|
|
await historyShortcut(page, 'goBack');
|
|
|
|
await historyShortcut(page, 'goBack');
|
2024-07-29 14:05:22 +03:00
|
|
|
await expect(getBlockSuiteEditorTitle(page)).toHaveText('test1');
|
2023-10-16 15:27:06 +03:00
|
|
|
await historyShortcut(page, 'goForward');
|
|
|
|
await historyShortcut(page, 'goForward');
|
2024-07-29 14:05:22 +03:00
|
|
|
await expect(getBlockSuiteEditorTitle(page)).toHaveText('test3');
|
2023-10-16 15:27:06 +03:00
|
|
|
});
|
2023-05-15 09:13:30 +03:00
|
|
|
|
2023-08-26 23:26:48 +03:00
|
|
|
test('clientBorder value should disable by default on window', async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
await clickSideBarSettingButton(page);
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
const settingItem = page.locator(
|
|
|
|
'[data-testid="client-border-style-trigger"]'
|
|
|
|
);
|
|
|
|
expect(await settingItem.locator('input').inputValue()).toEqual(
|
|
|
|
process.platform === 'win32' ? 'off' : 'on'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-05-09 10:30:01 +03:00
|
|
|
test('app theme', async ({ page, electronApp }) => {
|
2023-04-28 09:40:44 +03:00
|
|
|
const root = page.locator('html');
|
|
|
|
{
|
2023-11-29 07:43:35 +03:00
|
|
|
const themeMode = await root.evaluate(element => element.dataset.theme);
|
2023-04-28 09:40:44 +03:00
|
|
|
expect(themeMode).toBe('light');
|
2023-05-09 10:30:01 +03:00
|
|
|
|
2023-05-10 06:04:36 +03:00
|
|
|
const theme = await electronApp.evaluate(({ nativeTheme }) => {
|
|
|
|
return nativeTheme.shouldUseDarkColors ? 'dark' : 'light';
|
2023-05-09 10:30:01 +03:00
|
|
|
});
|
|
|
|
|
2023-05-10 06:04:36 +03:00
|
|
|
expect(theme).toBe('light');
|
2023-04-28 09:40:44 +03:00
|
|
|
}
|
2023-05-09 10:30:01 +03:00
|
|
|
|
2023-04-28 09:40:44 +03:00
|
|
|
{
|
2023-07-31 10:56:51 +03:00
|
|
|
await page.getByTestId('settings-modal-trigger').click();
|
|
|
|
await page.getByTestId('appearance-panel-trigger').click();
|
2023-05-09 10:30:01 +03:00
|
|
|
await page.waitForTimeout(50);
|
2023-07-31 10:56:51 +03:00
|
|
|
await page.getByTestId('dark-theme-trigger').click();
|
2023-11-29 07:43:35 +03:00
|
|
|
const themeMode = await root.evaluate(element => element.dataset.theme);
|
2023-05-10 06:04:36 +03:00
|
|
|
expect(themeMode).toBe('dark');
|
|
|
|
const theme = await electronApp.evaluate(({ nativeTheme }) => {
|
|
|
|
return nativeTheme.shouldUseDarkColors ? 'dark' : 'light';
|
2023-05-09 10:30:01 +03:00
|
|
|
});
|
2023-05-10 06:04:36 +03:00
|
|
|
expect(theme).toBe('dark');
|
2023-04-28 09:40:44 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-06-29 19:15:44 +03:00
|
|
|
test('windows only check', async ({ page }) => {
|
|
|
|
const windowOnlyUI = page.locator('[data-platform-target=win32]');
|
|
|
|
if (process.platform === 'win32') {
|
2023-12-08 04:03:47 +03:00
|
|
|
await expect(windowOnlyUI.first()).toBeVisible();
|
2023-06-29 19:15:44 +03:00
|
|
|
} else {
|
2023-12-08 04:03:47 +03:00
|
|
|
await expect(windowOnlyUI.first()).not.toBeVisible();
|
2023-06-29 19:15:44 +03:00
|
|
|
}
|
|
|
|
});
|
2023-07-11 07:37:47 +03:00
|
|
|
|
|
|
|
test('delete workspace', async ({ page }) => {
|
2024-07-29 14:05:22 +03:00
|
|
|
await clickNewPageButton(page);
|
|
|
|
|
2023-10-16 11:44:09 +03:00
|
|
|
await clickSideBarCurrentWorkspaceBanner(page);
|
2023-07-11 07:37:47 +03:00
|
|
|
await page.getByTestId('new-workspace').click();
|
2023-12-15 10:20:50 +03:00
|
|
|
await page.getByTestId('create-workspace-input').fill('Delete Me');
|
|
|
|
await page.getByTestId('create-workspace-create-button').click();
|
2023-09-26 17:11:04 +03:00
|
|
|
// await page.getByTestId('create-workspace-continue-button').click({
|
|
|
|
// delay: 100,
|
|
|
|
// });
|
2023-08-17 07:20:27 +03:00
|
|
|
await page.waitForTimeout(1000);
|
2023-08-29 13:07:05 +03:00
|
|
|
await clickSideBarSettingButton(page);
|
2023-07-11 07:37:47 +03:00
|
|
|
await page.getByTestId('current-workspace-label').click();
|
2023-12-18 15:24:48 +03:00
|
|
|
await expect(page.getByTestId('workspace-name-input')).toHaveValue(
|
2023-07-11 07:37:47 +03:00
|
|
|
'Delete Me'
|
|
|
|
);
|
2023-10-11 09:05:06 +03:00
|
|
|
const contentElement = page.getByTestId('setting-modal-content');
|
2023-07-11 07:37:47 +03:00
|
|
|
const boundingBox = await contentElement.boundingBox();
|
|
|
|
if (!boundingBox) {
|
|
|
|
throw new Error('boundingBox is null');
|
|
|
|
}
|
|
|
|
await page.mouse.move(
|
|
|
|
boundingBox.x + boundingBox.width / 2,
|
|
|
|
boundingBox.y + boundingBox.height / 2
|
|
|
|
);
|
|
|
|
await page.mouse.wheel(0, 500);
|
|
|
|
await page.getByTestId('delete-workspace-button').click();
|
2023-12-15 10:20:50 +03:00
|
|
|
await page.getByTestId('delete-workspace-input').fill('Delete Me');
|
2023-07-11 07:37:47 +03:00
|
|
|
await page.getByTestId('delete-workspace-confirm-button').click();
|
2024-07-29 14:05:22 +03:00
|
|
|
await expect(page.getByTestId('workspace-name')).toContainText(
|
2023-07-11 07:37:47 +03:00
|
|
|
'Demo Workspace'
|
|
|
|
);
|
|
|
|
});
|