2023-10-27 12:06:59 +03:00
|
|
|
import type { Locator, Page } from '@playwright/test';
|
2023-05-18 08:18:40 +03:00
|
|
|
import { expect } from '@playwright/test';
|
2023-01-03 16:57:33 +03:00
|
|
|
|
2023-09-02 06:31:07 +03:00
|
|
|
export async function waitForEditorLoad(page: Page) {
|
2023-06-07 12:31:54 +03:00
|
|
|
await page.waitForSelector('v-line', {
|
2023-09-13 19:54:02 +03:00
|
|
|
timeout: 20000,
|
2023-06-07 12:31:54 +03:00
|
|
|
});
|
2023-03-28 08:25:16 +03:00
|
|
|
}
|
|
|
|
|
2023-08-11 09:59:06 +03:00
|
|
|
export async function waitForAllPagesLoad(page: Page) {
|
|
|
|
// if filters tag is rendered, we believe all_pages is ready
|
|
|
|
await page.waitForSelector('[data-testid="create-first-filter"]', {
|
2024-07-30 16:22:16 +03:00
|
|
|
timeout: 20000,
|
2023-08-11 09:59:06 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-08-02 05:02:03 +03:00
|
|
|
export async function clickNewPageButton(page: Page, title?: string) {
|
|
|
|
// FiXME: when the page is in edgeless mode, clickNewPageButton will create a new edgeless page
|
2024-02-21 15:57:18 +03:00
|
|
|
const edgelessPage = page.locator('edgeless-editor');
|
|
|
|
if (await edgelessPage.isVisible()) {
|
|
|
|
await page.getByTestId('switch-page-mode-button').click({
|
|
|
|
delay: 100,
|
|
|
|
});
|
|
|
|
}
|
2023-03-01 10:40:01 +03:00
|
|
|
// fixme(himself65): if too fast, the page will crash
|
2023-12-18 16:36:56 +03:00
|
|
|
await page.getByTestId('sidebar-new-page-button').click({
|
2023-03-01 10:40:01 +03:00
|
|
|
delay: 100,
|
|
|
|
});
|
2024-02-06 06:20:54 +03:00
|
|
|
await waitForEmptyEditor(page);
|
2024-08-02 05:02:03 +03:00
|
|
|
if (title) {
|
|
|
|
await getBlockSuiteEditorTitle(page).fill(title);
|
|
|
|
}
|
2024-02-06 06:20:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function waitForEmptyEditor(page: Page) {
|
|
|
|
await expect(page.locator('.doc-title-container-empty')).toBeVisible();
|
2023-03-02 20:38:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getBlockSuiteEditorTitle(page: Page) {
|
2024-01-03 05:10:19 +03:00
|
|
|
return page.locator('doc-title .inline-editor').nth(0);
|
2022-12-30 21:32:59 +03:00
|
|
|
}
|
|
|
|
|
2023-05-18 08:18:40 +03:00
|
|
|
export async function type(page: Page, content: string, delay = 50) {
|
|
|
|
await page.keyboard.type(content, { delay });
|
|
|
|
}
|
|
|
|
|
|
|
|
export const createLinkedPage = async (page: Page, pageName?: string) => {
|
2024-09-24 04:54:09 +03:00
|
|
|
// fixme: workaround for @ popover not showing up when editor is not ready
|
|
|
|
await page.waitForTimeout(500);
|
2023-05-18 08:18:40 +03:00
|
|
|
await page.keyboard.type('@', { delay: 50 });
|
2024-01-18 12:26:31 +03:00
|
|
|
const linkedPagePopover = page.locator('.linked-doc-popover');
|
2023-05-18 08:18:40 +03:00
|
|
|
await expect(linkedPagePopover).toBeVisible();
|
2024-05-31 13:28:42 +03:00
|
|
|
await type(page, pageName || 'Untitled');
|
2023-05-18 08:18:40 +03:00
|
|
|
|
|
|
|
await page.keyboard.press('ArrowUp');
|
|
|
|
await page.keyboard.press('ArrowUp');
|
|
|
|
await page.keyboard.press('Enter', { delay: 50 });
|
|
|
|
};
|
|
|
|
|
2023-01-03 16:57:33 +03:00
|
|
|
export async function clickPageMoreActions(page: Page) {
|
2022-12-30 21:32:59 +03:00
|
|
|
return page
|
2023-08-11 23:27:24 +03:00
|
|
|
.getByTestId('header')
|
2023-08-08 20:14:24 +03:00
|
|
|
.getByTestId('header-dropDownButton')
|
2022-12-30 21:32:59 +03:00
|
|
|
.click();
|
|
|
|
}
|
2023-10-27 12:06:59 +03:00
|
|
|
|
|
|
|
export const getPageOperationButton = (page: Page, id: string) => {
|
|
|
|
return getPageItem(page, id).getByTestId('page-list-operation-button');
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getPageItem = (page: Page, id: string) => {
|
|
|
|
return page.locator(`[data-page-id="${id}"][data-testid="page-list-item"]`);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getPageByTitle = (page: Page, title: string) => {
|
|
|
|
return page.getByTestId('page-list-item').getByText(title);
|
|
|
|
};
|
|
|
|
|
2024-07-26 07:35:31 +03:00
|
|
|
export const dragTo = async (
|
|
|
|
page: Page,
|
|
|
|
locator: Locator,
|
|
|
|
target: Locator,
|
2024-08-02 05:02:03 +03:00
|
|
|
location:
|
|
|
|
| 'top-left'
|
|
|
|
| 'top'
|
|
|
|
| 'bottom'
|
|
|
|
| 'center'
|
|
|
|
| 'left'
|
|
|
|
| 'right' = 'center'
|
2024-07-26 07:35:31 +03:00
|
|
|
) => {
|
2023-10-27 12:06:59 +03:00
|
|
|
await locator.hover();
|
|
|
|
await page.mouse.down();
|
2024-07-26 07:35:31 +03:00
|
|
|
await page.mouse.move(1, 1);
|
|
|
|
|
2023-10-27 12:06:59 +03:00
|
|
|
const targetElement = await target.boundingBox();
|
|
|
|
if (!targetElement) {
|
|
|
|
throw new Error('target element not found');
|
|
|
|
}
|
2024-08-02 05:02:03 +03:00
|
|
|
const position = (() => {
|
|
|
|
switch (location) {
|
|
|
|
case 'center':
|
|
|
|
return {
|
2024-07-26 07:35:31 +03:00
|
|
|
x: targetElement.width / 2,
|
|
|
|
y: targetElement.height / 2,
|
2024-08-02 05:02:03 +03:00
|
|
|
};
|
|
|
|
case 'top':
|
|
|
|
return { x: targetElement.width / 2, y: 1 };
|
|
|
|
case 'bottom':
|
|
|
|
return { x: targetElement.width / 2, y: targetElement.height - 1 };
|
|
|
|
|
|
|
|
case 'left':
|
|
|
|
return { x: 1, y: targetElement.height / 2 };
|
|
|
|
|
|
|
|
case 'right':
|
|
|
|
return { x: targetElement.width - 1, y: targetElement.height / 2 };
|
|
|
|
|
|
|
|
case 'top-left':
|
|
|
|
default:
|
|
|
|
return { x: 1, y: 1 };
|
|
|
|
}
|
|
|
|
})();
|
2024-07-26 07:35:31 +03:00
|
|
|
await target.hover({
|
|
|
|
position: position,
|
|
|
|
});
|
2023-10-27 12:06:59 +03:00
|
|
|
await page.mouse.up();
|
|
|
|
};
|
2024-03-25 05:46:31 +03:00
|
|
|
|
|
|
|
// sometimes editor loses focus, this function is to focus the editor
|
|
|
|
export const focusInlineEditor = async (page: Page) => {
|
|
|
|
await page
|
|
|
|
.locator(
|
|
|
|
`.affine-paragraph-rich-text-wrapper:has(.visible):has-text("Type '/' for commands")`
|
|
|
|
)
|
|
|
|
.locator('.inline-editor')
|
|
|
|
.focus();
|
|
|
|
};
|