mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-22 20:41:53 +03:00
ab92efcfc0
move @affine/core/utils/mixpanel -> @affine/core/mixpanel now you can debug mixpanel on browser devtool ![CleanShot 2024-07-30 at 17.32.48@2x.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/g3jz87HxbjOJpXV3FPT7/083c1286-39fd-4569-b4d2-e6e84cf2e797.png)
116 lines
3.4 KiB
TypeScript
116 lines
3.4 KiB
TypeScript
import type { Locator, Page } from '@playwright/test';
|
|
import { expect } from '@playwright/test';
|
|
|
|
export async function waitForEditorLoad(page: Page) {
|
|
await page.waitForSelector('v-line', {
|
|
timeout: 20000,
|
|
});
|
|
}
|
|
|
|
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"]', {
|
|
timeout: 20000,
|
|
});
|
|
}
|
|
|
|
export async function clickNewPageButton(page: Page) {
|
|
//FiXME: when the page is in edgeless mode, clickNewPageButton will create a new edgeless page
|
|
const edgelessPage = page.locator('edgeless-editor');
|
|
if (await edgelessPage.isVisible()) {
|
|
await page.getByTestId('switch-page-mode-button').click({
|
|
delay: 100,
|
|
});
|
|
}
|
|
// fixme(himself65): if too fast, the page will crash
|
|
await page.getByTestId('sidebar-new-page-button').click({
|
|
delay: 100,
|
|
});
|
|
await waitForEmptyEditor(page);
|
|
}
|
|
|
|
export async function waitForEmptyEditor(page: Page) {
|
|
await expect(page.locator('.doc-title-container-empty')).toBeVisible();
|
|
}
|
|
|
|
export function getBlockSuiteEditorTitle(page: Page) {
|
|
return page.locator('doc-title .inline-editor').nth(0);
|
|
}
|
|
|
|
export async function type(page: Page, content: string, delay = 50) {
|
|
await page.keyboard.type(content, { delay });
|
|
}
|
|
|
|
export const createLinkedPage = async (page: Page, pageName?: string) => {
|
|
await page.keyboard.type('@', { delay: 50 });
|
|
const linkedPagePopover = page.locator('.linked-doc-popover');
|
|
await expect(linkedPagePopover).toBeVisible();
|
|
await type(page, pageName || 'Untitled');
|
|
|
|
await page.keyboard.press('ArrowUp');
|
|
await page.keyboard.press('ArrowUp');
|
|
await page.keyboard.press('Enter', { delay: 50 });
|
|
};
|
|
|
|
export async function clickPageMoreActions(page: Page) {
|
|
return page
|
|
.getByTestId('header')
|
|
.getByTestId('header-dropDownButton')
|
|
.click();
|
|
}
|
|
|
|
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);
|
|
};
|
|
|
|
export const dragTo = async (
|
|
page: Page,
|
|
locator: Locator,
|
|
target: Locator,
|
|
location: 'top-left' | 'top' | 'bottom' | 'center' = 'center'
|
|
) => {
|
|
await locator.hover();
|
|
await page.mouse.down();
|
|
await page.mouse.move(1, 1);
|
|
|
|
const targetElement = await target.boundingBox();
|
|
if (!targetElement) {
|
|
throw new Error('target element not found');
|
|
}
|
|
const position =
|
|
location === 'center'
|
|
? {
|
|
x: targetElement.width / 2,
|
|
y: targetElement.height / 2,
|
|
}
|
|
: location === 'top-left'
|
|
? { x: 1, y: 1 }
|
|
: location === 'top'
|
|
? { x: targetElement.width / 2, y: 1 }
|
|
: location === 'bottom'
|
|
? { x: targetElement.width / 2, y: targetElement.height - 1 }
|
|
: { x: 1, y: 1 };
|
|
await target.hover({
|
|
position: position,
|
|
});
|
|
await page.mouse.up();
|
|
};
|
|
|
|
// 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();
|
|
};
|