mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
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:
@@ -5,13 +5,18 @@ import {
|
||||
enableShare,
|
||||
loginUser,
|
||||
} from '@affine-test/kit/utils/cloud';
|
||||
import { clickEdgelessModeButton } from '@affine-test/kit/utils/editor';
|
||||
import {
|
||||
clickEdgelessModeButton,
|
||||
getParagraphIds,
|
||||
} from '@affine-test/kit/utils/editor';
|
||||
import { importImage } from '@affine-test/kit/utils/image';
|
||||
import { copyByKeyboard } from '@affine-test/kit/utils/keyboard';
|
||||
import {
|
||||
clickNewPageButton,
|
||||
getBlockSuiteEditorTitle,
|
||||
waitForEditorLoad,
|
||||
} from '@affine-test/kit/utils/page-logic';
|
||||
import { setSelection } from '@affine-test/kit/utils/selection';
|
||||
import { createLocalWorkspace } from '@affine-test/kit/utils/workspace';
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
@@ -405,3 +410,48 @@ test('Inline latex modal should be not shown in shared mode when clicking', asyn
|
||||
await expect(modalLocator).not.toBeVisible();
|
||||
}
|
||||
});
|
||||
|
||||
test('share page should support copying content', async ({ page, browser }) => {
|
||||
await page.reload();
|
||||
await waitForEditorLoad(page);
|
||||
await createLocalWorkspace(
|
||||
{
|
||||
name: 'test',
|
||||
},
|
||||
page
|
||||
);
|
||||
await enableCloudWorkspaceFromShareButton(page);
|
||||
const title = getBlockSuiteEditorTitle(page);
|
||||
await title.pressSequentially('TEST TITLE', {
|
||||
delay: 50,
|
||||
});
|
||||
await page.keyboard.press('Enter', { delay: 50 });
|
||||
await page.keyboard.type('Hello World');
|
||||
|
||||
// enable share page and copy page link
|
||||
await enableShare(page);
|
||||
await page.getByTestId('share-menu-copy-link-button').click();
|
||||
await page.getByTestId('share-link-menu-copy-page').click();
|
||||
|
||||
// check share page is accessible and content can be copied
|
||||
{
|
||||
const context = await browser.newContext();
|
||||
await skipOnboarding(context);
|
||||
const url: string = await page.evaluate(() =>
|
||||
navigator.clipboard.readText()
|
||||
);
|
||||
const page2 = await context.newPage();
|
||||
await page2.goto(url);
|
||||
await waitForEditorLoad(page2);
|
||||
|
||||
const { blockIds: paragraphIds } = await getParagraphIds(page2);
|
||||
await setSelection(page2, paragraphIds[0], 0, paragraphIds[0], 11);
|
||||
await copyByKeyboard(page2);
|
||||
|
||||
// Verify copied content
|
||||
const copiedText = await page2.evaluate(() =>
|
||||
navigator.clipboard.readText()
|
||||
);
|
||||
expect(copiedText).toContain('Hello World');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,6 +3,8 @@ import { pasteContent } from '@affine-test/kit/utils/clipboard';
|
||||
import {
|
||||
clickEdgelessModeButton,
|
||||
clickPageModeButton,
|
||||
getCodeBlockIds,
|
||||
getParagraphIds,
|
||||
locateEditorContainer,
|
||||
} from '@affine-test/kit/utils/editor';
|
||||
import {
|
||||
@@ -84,28 +86,6 @@ async function verifyCodeBlockContent(
|
||||
);
|
||||
}
|
||||
|
||||
// Helper function to get block ids
|
||||
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
|
||||
async function getParagraphIds(page: Page) {
|
||||
return getBlockIds<ParagraphBlockComponent>(page, paragraphLocator);
|
||||
}
|
||||
|
||||
// Helper functions using the generic getBlockIds
|
||||
async function getCodeBlockIds(page: Page) {
|
||||
return getBlockIds<CodeBlockComponent>(page, codeBlockLocator);
|
||||
}
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await openHomePage(page);
|
||||
await clickNewPageButton(page, 'Clipboard Test');
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user