Files
AFFiNE-Mirror/tests/kit/utils/page-logic.ts
T
pengx17 4b6c4ed546 feat(core): doc database properties (#8520)
fix AF-1454

1. move inline tags editor to components
2. add progress component
3. adjust doc properties styles for desktop
4. subscribe bs database links and display in doc info
5. move update/create dates to doc info
6. a trivial e2e test

<div class='graphite__hidden'>
          <div>🎥 Video uploaded on Graphite:</div>
            <a href="https://app.graphite.dev/media/video/T2klNLEk0wxLh4NRDzhk/eed266c1-fdac-4f0e-baa9-4aa00d14a2e8.mp4">
              <img src="https://app.graphite.dev/api/v1/graphite/video/thumbnail/T2klNLEk0wxLh4NRDzhk/eed266c1-fdac-4f0e-baa9-4aa00d14a2e8.mp4">
            </a>
          </div>
<video src="https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/T2klNLEk0wxLh4NRDzhk/eed266c1-fdac-4f0e-baa9-4aa00d14a2e8.mp4">10月23日.mp4</video>
2024-10-24 07:38:45 +00:00

161 lines
4.6 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, title?: string) {
// 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);
if (title) {
await getBlockSuiteEditorTitle(page).fill(title);
}
}
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) => {
// fixme: workaround for @ popover not showing up when editor is not ready
await page.waitForTimeout(500);
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'
| 'left'
| 'right' = '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 = (() => {
switch (location) {
case 'center':
return {
x: targetElement.width / 2,
y: targetElement.height / 2,
};
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 };
}
})();
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();
};
export const addDatabase = async (page: Page, title?: string) => {
await page.keyboard.press('/');
await expect(page.locator('affine-slash-menu .slash-menu')).toBeVisible();
await page.keyboard.type('database');
await page.getByTestId('Table View').click();
if (title) {
await page.locator('affine-database-title').click();
await page
.locator('affine-database-title rich-text [contenteditable]')
.fill(title);
await page
.locator('affine-database-title rich-text [contenteditable]')
.blur();
}
};
export const addDatabaseRow = async (page: Page, databaseTitle: string) => {
const db = page.locator(`affine-database-table`, {
has: page.locator(`affine-database-title:has-text("${databaseTitle}")`),
});
await db.locator('.data-view-table-group-add-row-button').click();
};