2023-09-17 23:26:06 +03:00
|
|
|
import { test } from '@affine-test/kit/electron';
|
2023-10-16 15:27:06 +03:00
|
|
|
import { withCtrlOrMeta } from '@affine-test/kit/utils/keyboard';
|
2024-02-21 15:57:18 +03:00
|
|
|
import {
|
|
|
|
clickNewPageButton,
|
2024-03-18 10:04:06 +03:00
|
|
|
createLinkedPage,
|
2024-02-21 15:57:18 +03:00
|
|
|
getBlockSuiteEditorTitle,
|
2024-03-18 10:04:06 +03:00
|
|
|
waitForEmptyEditor,
|
2024-02-21 15:57:18 +03:00
|
|
|
} 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') => {
|
|
|
|
await withCtrlOrMeta(page, () =>
|
|
|
|
page.keyboard.press(command === 'goBack' ? '[' : ']', { delay: 50 })
|
|
|
|
);
|
|
|
|
};
|
2023-04-28 09:40:44 +03:00
|
|
|
|
2023-05-09 10:30:01 +03:00
|
|
|
test('new page', async ({ page, workspace }) => {
|
2023-12-18 16:36:56 +03:00
|
|
|
await page.getByTestId('sidebar-new-page-button').click({
|
2023-04-25 02:53:36 +03:00
|
|
|
delay: 100,
|
|
|
|
});
|
|
|
|
await page.waitForSelector('v-line');
|
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 }) => {
|
|
|
|
{
|
|
|
|
// create pages
|
|
|
|
await page.waitForTimeout(500);
|
2024-02-21 15:57:18 +03:00
|
|
|
await clickNewPageButton(page);
|
2023-10-16 15:27:06 +03:00
|
|
|
await page.waitForSelector('v-line');
|
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
|
|
|
await title.focus();
|
|
|
|
await title.pressSequentially('test1', {
|
|
|
|
delay: 100,
|
|
|
|
});
|
|
|
|
await page.waitForTimeout(500);
|
2023-12-18 16:36:56 +03:00
|
|
|
await page.getByTestId('sidebar-new-page-button').click({
|
2023-10-16 15:27:06 +03:00
|
|
|
delay: 100,
|
|
|
|
});
|
|
|
|
await page.waitForSelector('v-line');
|
2023-10-11 09:05:06 +03:00
|
|
|
|
2023-10-16 15:27:06 +03:00
|
|
|
await title.focus();
|
|
|
|
await title.pressSequentially('test2', {
|
|
|
|
delay: 100,
|
|
|
|
});
|
|
|
|
await page.waitForTimeout(500);
|
2023-12-18 16:36:56 +03:00
|
|
|
await page.getByTestId('sidebar-new-page-button').click({
|
2023-10-16 15:27:06 +03:00
|
|
|
delay: 100,
|
|
|
|
});
|
|
|
|
await page.waitForSelector('v-line');
|
|
|
|
await title.focus();
|
|
|
|
await title.pressSequentially('test3', {
|
|
|
|
delay: 100,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
{
|
2024-01-03 05:10:19 +03:00
|
|
|
await expect(getBlockSuiteEditorTitle(page)).toHaveText('test3');
|
2023-10-16 15:27:06 +03:00
|
|
|
}
|
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"]');
|
2023-10-16 15:27:06 +03:00
|
|
|
{
|
2024-01-03 05:10:19 +03:00
|
|
|
await expect(getBlockSuiteEditorTitle(page)).toHaveText('test1');
|
2023-10-16 15:27:06 +03:00
|
|
|
}
|
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"]');
|
2023-10-16 15:27:06 +03:00
|
|
|
{
|
2024-01-03 05:10:19 +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-01-03 05:10:19 +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-01-03 05:10:19 +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 }) => {
|
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();
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
expect(await page.getByTestId('workspace-name').textContent()).toBe(
|
|
|
|
'Demo Workspace'
|
|
|
|
);
|
|
|
|
});
|
2024-03-18 10:04:06 +03:00
|
|
|
|
|
|
|
// temporary way to enable split view
|
|
|
|
async function enableSplitView(page: Page) {
|
|
|
|
await page.evaluate(() => {
|
|
|
|
const settingKey = 'affine-settings';
|
|
|
|
window.localStorage.setItem(
|
|
|
|
settingKey,
|
|
|
|
JSON.stringify({
|
|
|
|
clientBorder: false,
|
|
|
|
fullWidthLayout: false,
|
|
|
|
windowFrameStyle: 'frameless',
|
|
|
|
fontStyle: 'Serif',
|
|
|
|
dateFormat: 'MM/dd/YYYY',
|
|
|
|
startWeekOnMonday: false,
|
|
|
|
enableBlurBackground: true,
|
|
|
|
enableNoisyBackground: true,
|
|
|
|
autoCheckUpdate: true,
|
|
|
|
autoDownloadUpdate: true,
|
|
|
|
enableMultiView: true,
|
|
|
|
editorFlags: {},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
await page.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
test('open split view', async ({ page }) => {
|
|
|
|
await enableSplitView(page);
|
|
|
|
await page.getByTestId('sidebar-new-page-button').click({
|
|
|
|
delay: 100,
|
|
|
|
});
|
|
|
|
await waitForEmptyEditor(page);
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
await page.keyboard.press('Enter');
|
|
|
|
await createLinkedPage(page, 'hi from another page');
|
|
|
|
await page
|
|
|
|
.locator('.affine-reference-title:has-text("hi from another page")')
|
|
|
|
.click({
|
|
|
|
modifiers: [process.platform === 'darwin' ? 'Meta' : 'Control'],
|
|
|
|
});
|
|
|
|
await expect(page.locator('.doc-title-container')).toHaveCount(2);
|
|
|
|
});
|