Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(core): add tests for card view with edgeless mode link #8887

Draft
wants to merge 1 commit into
base: canary
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions tests/affine-local/e2e/links.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test } from '@affine-test/kit/playwright';
import { locateModeSwitchButton } from '@affine-test/kit/utils/editor';
import {
pasteByKeyboard,
writeTextToClipboard,
Expand Down Expand Up @@ -108,7 +109,7 @@
const href0 = await page
.locator('affine-reference')
.locator('a')
.getAttribute('href');

Check failure on line 112 in tests/affine-local/e2e/links.spec.ts

View workflow job for this annotation

GitHub Actions / E2E Test (3)

links.spec.ts:72:5 › not allowed to switch to embed view when linking to block

3) links.spec.ts:72:5 › not allowed to switch to embed view when linking to block ──────────────── TimeoutError: locator.getAttribute: Timeout 5000ms exceeded. Call log: - waiting for locator('affine-reference').locator('a') 110 | .locator('affine-reference') 111 | .locator('a') > 112 | .getAttribute('href'); | ^ 113 | 114 | await page.locator('affine-reference').hover(); 115 | await page.getByLabel('Switch view').click(); at /home/runner/work/AFFiNE/AFFiNE/tests/affine-local/e2e/links.spec.ts:112:6

await page.locator('affine-reference').hover();
await page.getByLabel('Switch view').click();
Expand Down Expand Up @@ -331,3 +332,135 @@
url2.searchParams.delete('refreshKey');
expect(url.toJSON()).toStrictEqual(url2.toJSON());
});

test('the viewport should be fit when the linked document is with edgeless mode', async ({
page,
}) => {
await page.keyboard.press('Enter');

await locateModeSwitchButton(page, 'edgeless').click();

const note = page.locator('affine-edgeless-note');
const noteBoundingBox = await note.boundingBox();
expect(noteBoundingBox).not.toBeNull();
if (!noteBoundingBox) return;

// move viewport
const { x, y } = noteBoundingBox;
await page.mouse.click(x, y);
await page.keyboard.down('Space');
await page.waitForTimeout(50);
await page.mouse.down();
await page.mouse.move(x + 1000, y);
await page.mouse.up();
await page.keyboard.up('Space');

// create edgeless text
await page.keyboard.press('t');
await page.mouse.click(x, y);
await page.locator('affine-edgeless-text').waitFor({ state: 'visible' });
await page.keyboard.type('Edgeless Text');

const url = new URL(page.url());

await clickNewPageButton(page);
await page.keyboard.press('Enter');

await writeTextToClipboard(page, url.toString());
await pasteByKeyboard(page);

// Inline
await page.locator('affine-reference').hover();
await page.getByLabel('Switch view').click();
await page.getByTestId('link-to-embed').click();

const viewport = await page
.locator('affine-embed-synced-doc-block')
.boundingBox();
expect(viewport).not.toBeNull();
if (!viewport) return;

const edgelessText = await page
.locator('affine-embed-synced-doc-block affine-edgeless-text')
.boundingBox();
expect(edgelessText).not.toBeNull();
if (!edgelessText) return;

// the edgeless text should be in the viewport
expect(viewport.x).toBeLessThanOrEqual(edgelessText.x);

Check failure on line 390 in tests/affine-local/e2e/links.spec.ts

View workflow job for this annotation

GitHub Actions / E2E Test (3)

links.spec.ts:336:5 › the viewport should be fit when the linked document is with edgeless mode

1) links.spec.ts:336:5 › the viewport should be fit when the linked document is with edgeless mode Error: expect(received).toBeLessThanOrEqual(expected) Expected: <= -181 Received: 468 388 | 389 | // the edgeless text should be in the viewport > 390 | expect(viewport.x).toBeLessThanOrEqual(edgelessText.x); | ^ 391 | expect(viewport.y).toBeLessThanOrEqual(edgelessText.y); 392 | expect(viewport.x + viewport.width).toBeGreaterThanOrEqual( 393 | edgelessText.x + edgelessText.width at /home/runner/work/AFFiNE/AFFiNE/tests/affine-local/e2e/links.spec.ts:390:22

Check failure on line 390 in tests/affine-local/e2e/links.spec.ts

View workflow job for this annotation

GitHub Actions / E2E Test (3)

links.spec.ts:336:5 › the viewport should be fit when the linked document is with edgeless mode

1) links.spec.ts:336:5 › the viewport should be fit when the linked document is with edgeless mode Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBeLessThanOrEqual(expected) Expected: <= -181 Received: 468 388 | 389 | // the edgeless text should be in the viewport > 390 | expect(viewport.x).toBeLessThanOrEqual(edgelessText.x); | ^ 391 | expect(viewport.y).toBeLessThanOrEqual(edgelessText.y); 392 | expect(viewport.x + viewport.width).toBeGreaterThanOrEqual( 393 | edgelessText.x + edgelessText.width at /home/runner/work/AFFiNE/AFFiNE/tests/affine-local/e2e/links.spec.ts:390:22

Check failure on line 390 in tests/affine-local/e2e/links.spec.ts

View workflow job for this annotation

GitHub Actions / E2E Test (3)

links.spec.ts:336:5 › the viewport should be fit when the linked document is with edgeless mode

1) links.spec.ts:336:5 › the viewport should be fit when the linked document is with edgeless mode Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBeLessThanOrEqual(expected) Expected: <= -181 Received: 468 388 | 389 | // the edgeless text should be in the viewport > 390 | expect(viewport.x).toBeLessThanOrEqual(edgelessText.x); | ^ 391 | expect(viewport.y).toBeLessThanOrEqual(edgelessText.y); 392 | expect(viewport.x + viewport.width).toBeGreaterThanOrEqual( 393 | edgelessText.x + edgelessText.width at /home/runner/work/AFFiNE/AFFiNE/tests/affine-local/e2e/links.spec.ts:390:22

Check failure on line 390 in tests/affine-local/e2e/links.spec.ts

View workflow job for this annotation

GitHub Actions / E2E Test (3)

links.spec.ts:336:5 › the viewport should be fit when the linked document is with edgeless mode

1) links.spec.ts:336:5 › the viewport should be fit when the linked document is with edgeless mode Retry #3 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBeLessThanOrEqual(expected) Expected: <= -181 Received: 468 388 | 389 | // the edgeless text should be in the viewport > 390 | expect(viewport.x).toBeLessThanOrEqual(edgelessText.x); | ^ 391 | expect(viewport.y).toBeLessThanOrEqual(edgelessText.y); 392 | expect(viewport.x + viewport.width).toBeGreaterThanOrEqual( 393 | edgelessText.x + edgelessText.width at /home/runner/work/AFFiNE/AFFiNE/tests/affine-local/e2e/links.spec.ts:390:22
expect(viewport.y).toBeLessThanOrEqual(edgelessText.y);
expect(viewport.x + viewport.width).toBeGreaterThanOrEqual(
edgelessText.x + edgelessText.width
);
expect(viewport.y + viewport.height).toBeGreaterThanOrEqual(
edgelessText.y + edgelessText.height
);
});

test('should show edgeless content when switching card view of linked mode doc in edgeless', async ({
page,
}) => {
await page.keyboard.press('Enter');

await locateModeSwitchButton(page, 'edgeless').click();

const note = page.locator('affine-edgeless-note');
const noteBoundingBox = await note.boundingBox();
expect(noteBoundingBox).not.toBeNull();
if (!noteBoundingBox) return;

// move viewport
const { x, y } = noteBoundingBox;
await page.mouse.click(x, y);
await page.keyboard.down('Space');
await page.waitForTimeout(50);
await page.mouse.down();
await page.mouse.move(x + 1000, y);
await page.mouse.up();
await page.keyboard.up('Space');

// create edgeless text
await page.keyboard.press('t');
await page.mouse.click(x, y);
await page.locator('affine-edgeless-text').waitFor({ state: 'visible' });
await page.keyboard.type('Edgeless Text');

const url = new URL(page.url());

await clickNewPageButton(page);
await locateModeSwitchButton(page, 'edgeless').click();

await page.mouse.move(x, y);
await writeTextToClipboard(page, url.toString());
await pasteByKeyboard(page);

// Inline
await page
.locator('affine-embed-edgeless-linked-doc-block')
.waitFor({ state: 'visible' });
await page.mouse.click(x - 50, y - 50);
await page.getByLabel('Switch view').click();

Check failure on line 442 in tests/affine-local/e2e/links.spec.ts

View workflow job for this annotation

GitHub Actions / E2E Test (3)

links.spec.ts:400:5 › should show edgeless content when switching card view of linked mode doc in edgeless

2) links.spec.ts:400:5 › should show edgeless content when switching card view of linked mode doc in edgeless TimeoutError: locator.click: Timeout 5000ms exceeded. Call log: - waiting for getByLabel('Switch view') 440 | .waitFor({ state: 'visible' }); 441 | await page.mouse.click(x - 50, y - 50); > 442 | await page.getByLabel('Switch view').click(); | ^ 443 | await page.getByTestId('link-to-embed').click(); 444 | 445 | const viewport = await page at /home/runner/work/AFFiNE/AFFiNE/tests/affine-local/e2e/links.spec.ts:442:40
await page.getByTestId('link-to-embed').click();

const viewport = await page
.locator('affine-embed-edgeless-synced-doc-block')
.boundingBox();
expect(viewport).not.toBeNull();
if (!viewport) return;

const edgelessText = await page
.locator('affine-embed-edgeless-synced-doc-block affine-edgeless-text')
.boundingBox();

Check failure on line 453 in tests/affine-local/e2e/links.spec.ts

View workflow job for this annotation

GitHub Actions / E2E Test (3)

links.spec.ts:400:5 › should show edgeless content when switching card view of linked mode doc in edgeless

2) links.spec.ts:400:5 › should show edgeless content when switching card view of linked mode doc in edgeless Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── TimeoutError: locator.boundingBox: Timeout 5000ms exceeded. Call log: - waiting for locator('affine-embed-edgeless-synced-doc-block affine-edgeless-text') 451 | const edgelessText = await page 452 | .locator('affine-embed-edgeless-synced-doc-block affine-edgeless-text') > 453 | .boundingBox(); | ^ 454 | expect(edgelessText).not.toBeNull(); 455 | if (!edgelessText) return; 456 | at /home/runner/work/AFFiNE/AFFiNE/tests/affine-local/e2e/links.spec.ts:453:6

Check failure on line 453 in tests/affine-local/e2e/links.spec.ts

View workflow job for this annotation

GitHub Actions / E2E Test (3)

links.spec.ts:400:5 › should show edgeless content when switching card view of linked mode doc in edgeless

2) links.spec.ts:400:5 › should show edgeless content when switching card view of linked mode doc in edgeless Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── TimeoutError: locator.boundingBox: Timeout 5000ms exceeded. Call log: - waiting for locator('affine-embed-edgeless-synced-doc-block affine-edgeless-text') 451 | const edgelessText = await page 452 | .locator('affine-embed-edgeless-synced-doc-block affine-edgeless-text') > 453 | .boundingBox(); | ^ 454 | expect(edgelessText).not.toBeNull(); 455 | if (!edgelessText) return; 456 | at /home/runner/work/AFFiNE/AFFiNE/tests/affine-local/e2e/links.spec.ts:453:6

Check failure on line 453 in tests/affine-local/e2e/links.spec.ts

View workflow job for this annotation

GitHub Actions / E2E Test (3)

links.spec.ts:400:5 › should show edgeless content when switching card view of linked mode doc in edgeless

2) links.spec.ts:400:5 › should show edgeless content when switching card view of linked mode doc in edgeless Retry #3 ─────────────────────────────────────────────────────────────────────────────────────── TimeoutError: locator.boundingBox: Timeout 5000ms exceeded. Call log: - waiting for locator('affine-embed-edgeless-synced-doc-block affine-edgeless-text') 451 | const edgelessText = await page 452 | .locator('affine-embed-edgeless-synced-doc-block affine-edgeless-text') > 453 | .boundingBox(); | ^ 454 | expect(edgelessText).not.toBeNull(); 455 | if (!edgelessText) return; 456 | at /home/runner/work/AFFiNE/AFFiNE/tests/affine-local/e2e/links.spec.ts:453:6
expect(edgelessText).not.toBeNull();
if (!edgelessText) return;

// the edgeless text should be in the viewport
expect(viewport.x).toBeLessThanOrEqual(edgelessText.x);
expect(viewport.y).toBeLessThanOrEqual(edgelessText.y);
expect(viewport.x + viewport.width).toBeGreaterThanOrEqual(
edgelessText.x + edgelessText.width
);
expect(viewport.y + viewport.height).toBeGreaterThanOrEqual(
edgelessText.y + edgelessText.height
);
});
Loading