From b5ce9ea28318f9727511e13acd819b0b636104d5 Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Thu, 28 Nov 2024 18:15:55 +0800 Subject: [PATCH] test(core): a simple e2e case for linked doc preview --- .../bi-directional-link-panel.css.ts | 1 - .../bi-directional-link-panel.tsx | 10 ++++--- .../modules/docs-search/worker/in-worker.ts | 2 +- packages/frontend/i18n/src/resources/en.json | 4 ++- tests/affine-local/e2e/links.spec.ts | 29 +++++++++++++++++++ 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/packages/frontend/core/src/components/blocksuite/block-suite-editor/bi-directional-link-panel.css.ts b/packages/frontend/core/src/components/blocksuite/block-suite-editor/bi-directional-link-panel.css.ts index 39458f7ecdd07..e4c1fab6b5460 100644 --- a/packages/frontend/core/src/components/blocksuite/block-suite-editor/bi-directional-link-panel.css.ts +++ b/packages/frontend/core/src/components/blocksuite/block-suite-editor/bi-directional-link-panel.css.ts @@ -50,7 +50,6 @@ export const title = style({ }); export const showButton = style({ - width: '56px', height: '28px', borderRadius: '8px', border: '1px solid ' + cssVar('--affine-border-color'), diff --git a/packages/frontend/core/src/components/blocksuite/block-suite-editor/bi-directional-link-panel.tsx b/packages/frontend/core/src/components/blocksuite/block-suite-editor/bi-directional-link-panel.tsx index c7c4754af5f2c..0892d011e5b04 100644 --- a/packages/frontend/core/src/components/blocksuite/block-suite-editor/bi-directional-link-panel.tsx +++ b/packages/frontend/core/src/components/blocksuite/block-suite-editor/bi-directional-link-panel.tsx @@ -1,4 +1,4 @@ -import { createReactComponentFromLit } from '@affine/component'; +import { Button, createReactComponentFromLit } from '@affine/component'; import { TextRenderer } from '@affine/core/blocksuite/presets'; import { type Backlink, @@ -132,9 +132,11 @@ export const BiDirectionalLinkPanel = () => {
Bi-Directional Links
-
- {show ? 'Hide' : 'Show'} -
+
{show && ( diff --git a/packages/frontend/core/src/modules/docs-search/worker/in-worker.ts b/packages/frontend/core/src/modules/docs-search/worker/in-worker.ts index 3aa36f8541711..54239af69c69d 100644 --- a/packages/frontend/core/src/modules/docs-search/worker/in-worker.ts +++ b/packages/frontend/core/src/modules/docs-search/worker/in-worker.ts @@ -724,7 +724,7 @@ async function crawlingDocData({ content: block.get('prop:latex')?.toString() ?? '', yblock: block, }); - } else if (bookmarkFlavours.includes(flavour)) { + } else if (bookmarkFlavours.has(flavour)) { blockDocuments.push({ docId, flavour, diff --git a/packages/frontend/i18n/src/resources/en.json b/packages/frontend/i18n/src/resources/en.json index 9df5cfc21d01c..6e3e1668a7913 100644 --- a/packages/frontend/i18n/src/resources/en.json +++ b/packages/frontend/i18n/src/resources/en.json @@ -1486,5 +1486,7 @@ "com.affine.editor.at-menu.import": "Import", "com.affine.editor.at-menu.more-docs-hint": "{{count}} more docs", "com.affine.editor.at-menu.journal": "Journal", - "com.affine.editor.at-menu.date-picker": "Select a specific date" + "com.affine.editor.at-menu.date-picker": "Select a specific date", + "com.affine.editor.bi-directional-link-panel.show": "Show", + "com.affine.editor.bi-directional-link-panel.hide": "Hide" } diff --git a/tests/affine-local/e2e/links.spec.ts b/tests/affine-local/e2e/links.spec.ts index d35b30d937bcf..103fc70a5e7eb 100644 --- a/tests/affine-local/e2e/links.spec.ts +++ b/tests/affine-local/e2e/links.spec.ts @@ -7,6 +7,7 @@ import { coreUrl, openHomePage } from '@affine-test/kit/utils/load-page'; import { clickNewPageButton, createLinkedPage, + getBlockSuiteEditorTitle, waitForEmptyEditor, } from '@affine-test/kit/utils/page-logic'; import { expect, type Locator } from '@playwright/test'; @@ -418,3 +419,31 @@ test('@ popover with click "select a specific date" should show a date picker', page.locator('affine-reference:has-text("' + date + '")') ).toBeVisible(); }); + +test('linked doc should show markdown preview in the backlink section', async ({ + page, +}) => { + await waitForEmptyEditor(page); + await page.keyboard.type('source page'); + await page.keyboard.press('Enter'); + + await page.keyboard.type('some inline content'); + await page.keyboard.press('Enter'); + + await createLinkedPage(page, 'Test Page'); + await page.locator('affine-reference:has-text("Test Page")').click(); + + await expect(getBlockSuiteEditorTitle(page)).toHaveText('Test Page'); + await page + .getByRole('button', { + name: 'Show', + }) + .click(); + + await page.getByRole('button', { name: 'source page' }).click(); + + await expect(page.locator('text-renderer')).toContainText( + 'some inline content' + ); + await expect(page.locator('text-renderer')).toContainText('Test Page'); +});