test(core): add e2e test for share page copy function (#11555)

related pr https://github.com/toeverything/AFFiNE/pull/11538
To close [BS-1915](https://linear.app/affine-design/issue/BS-1915/public-page-页面应该允许选中和复制内容)
This commit is contained in:
donteatfriedrice
2025-04-10 06:34:15 +00:00
parent e376aa57c5
commit dbb8451adb
3 changed files with 81 additions and 23 deletions

View File

@@ -1,5 +1,8 @@
import type * as BlocksuiteEffects from '@blocksuite/affine/effects';
import type { IVec, XYWH } from '@blocksuite/affine/global/gfx';
import type { CodeBlockComponent } from '@blocksuite/affine-block-code';
import type { ParagraphBlockComponent } from '@blocksuite/affine-block-paragraph';
import type { BlockComponent } from '@blocksuite/std';
import { expect, type Locator, type Page } from '@playwright/test';
declare type _GLOBAL_ = typeof BlocksuiteEffects;
@@ -11,6 +14,9 @@ export function inlineEditorInnerTextToString(innerText: string): string {
return innerText.replace(ZERO_WIDTH_SPACE, '').trim();
}
const PARAGRAPH_BLOCK_LOCATOR = 'affine-paragraph';
const CODE_BLOCK_LOCATOR = 'affine-code';
export function locateModeSwitchButton(
page: Page,
mode: 'page' | 'edgeless',
@@ -475,3 +481,25 @@ export async function createEdgelessNoteBlock(
await clickView(page, position, editorIndex);
}
}
// Helper function to get block ids
export async function getBlockIds<T extends BlockComponent>(
page: Page,
selector: string
) {
const blocks = page.locator(selector);
const blockIds = await blocks.evaluateAll((blocks: T[]) =>
blocks.map(block => block.model.id)
);
return { blockIds };
}
// Helper functions using the generic getBlockIds
export async function getParagraphIds(page: Page) {
return getBlockIds<ParagraphBlockComponent>(page, PARAGRAPH_BLOCK_LOCATOR);
}
// Helper functions using the generic getBlockIds
export async function getCodeBlockIds(page: Page) {
return getBlockIds<CodeBlockComponent>(page, CODE_BLOCK_LOCATOR);
}