Skip to content

Commit

Permalink
test(core): add tests for card view with edgeless mode link (#8887)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Sun committed Dec 4, 2024
1 parent f4f005b commit f7d2088
Showing 1 changed file with 133 additions and 0 deletions.
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 @@ -447,3 +448,135 @@ test('linked doc should show markdown preview in the backlink section', async ({
);
await expect(page.locator('text-renderer')).toContainText('Test Page');
});

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);
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();
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();
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
);
});

0 comments on commit f7d2088

Please sign in to comment.