feat(core): save recent open mode of internal links (#11086)

Closes: [BS-2865](https://linear.app/affine-design/issue/BS-2865/internal-links-保存用户最近的打开方式)

Added `openDocMode` in settings.

https://github.com/user-attachments/assets/a452da73-83e4-4ef5-9b57-58291fc22785
This commit is contained in:
fundon
2025-03-24 06:12:47 +00:00
parent 4bacfbd640
commit 63762b75a1
13 changed files with 256 additions and 128 deletions
@@ -47,7 +47,7 @@ test('should update zindex of element when moving it into frame', async ({
await createEdgelessNoteBlock(page, [500, 500]);
await clickView(page, [0, 100]);
await clickView(page, [500, 500]);
await toolbar.getByLabel('more-menu').click();
await toolbar.getByLabel('More menu').click();
await toolbar.getByLabel('Send to Back').click();
await pressEscape(page);
@@ -190,8 +190,11 @@ test('outline viewer should be useable in doc peek preview', async ({
const toolbar = page.locator('affine-toolbar-widget editor-toolbar');
await expect(toolbar).toBeVisible();
await toolbar.getByLabel('Open doc').click();
await toolbar.getByLabel('Open in center peek').click();
await toolbar.getByLabel(/^Open doc$/).click();
await toolbar
.getByLabel('Open doc menu')
.getByLabel('Open in center peek')
.click();
const peekView = page.getByTestId('peek-view-modal');
await expect(peekView).toBeVisible();
+87 -1
View File
@@ -156,7 +156,7 @@ test('not allowed to switch to embed view when linking to block', async ({
await cardLink.click();
await toolbar.getByLabel('more-menu').click();
await toolbar.getByLabel('More menu').click();
await toolbar.getByLabel('Copy link to block').click();
await page.keyboard.press('Enter');
@@ -1035,3 +1035,89 @@ test.describe('Customize linked doc title and description', () => {
await expect(a.locator('.affine-reference-title')).toContainText(year);
});
});
test('should save open doc mode of internal links', async ({ page }) => {
await waitForEditorLoad(page);
await enableEmojiDocIcon(page);
await clickNewPageButton(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await createLinkedPage(page, 'Test Page');
const { toolbar, switchViewBtn, inlineViewBtn, cardViewBtn, embedViewBtn } =
toolbarButtons(page);
const inlineLink = page.locator('affine-reference');
await inlineLink.hover();
const recentOpenModeBtn = toolbar.getByLabel(/^Open/).nth(0);
await expect(recentOpenModeBtn).toHaveAttribute(
'aria-label',
'Open this doc'
);
await expect(
recentOpenModeBtn.locator('span.label:has-text("Open")')
).toBeVisible();
const openDocBtn = toolbar.getByLabel(/^Open doc$/);
await openDocBtn.click();
const openDocMenu = toolbar.getByLabel('Open doc menu');
const openThisDocBtn = openDocMenu.getByLabel('Open this doc');
// In Desktop
const openInSplitViewBtn = openDocMenu.getByLabel('Open in split view');
const openInNewTabBtn = openDocMenu.getByLabel('Open in new tab');
const openInCenterPeekBtn = openDocMenu.getByLabel('Open in center peek');
await expect(openThisDocBtn).toBeVisible();
await expect(openInSplitViewBtn).toBeHidden();
await expect(openInNewTabBtn).toBeVisible();
await expect(openInCenterPeekBtn).toBeVisible();
await openInCenterPeekBtn.click();
await page.keyboard.press('Escape');
await inlineLink.hover();
await expect(toolbar).toBeVisible();
await expect(recentOpenModeBtn).toHaveAttribute(
'aria-label',
'Open in center peek'
);
await switchViewBtn.click();
await cardViewBtn.click();
await expect(toolbar).toBeVisible();
await expect(recentOpenModeBtn).toHaveAttribute(
'aria-label',
'Open in center peek'
);
await switchViewBtn.click();
await embedViewBtn.click();
await expect(toolbar).toBeVisible();
await expect(recentOpenModeBtn).toHaveAttribute(
'aria-label',
'Open in center peek'
);
await switchViewBtn.click();
await inlineViewBtn.click();
await inlineLink.hover();
await page.waitForTimeout(250);
await expect(toolbar).toBeVisible();
await expect(recentOpenModeBtn).toHaveAttribute(
'aria-label',
'Open in center peek'
);
});
+5 -3
View File
@@ -26,9 +26,11 @@ test('can open peek view via link popover', async ({ page }) => {
const toolbar = page.locator('affine-toolbar-widget editor-toolbar');
await expect(toolbar).toBeVisible();
// click more button
await toolbar.getByLabel('Open doc').click();
await toolbar.getByLabel('Open in center peek').click();
await toolbar.getByLabel(/^Open doc$/).click();
await toolbar
.getByLabel('Open doc menu')
.getByLabel('Open in center peek')
.click();
// verify peek view is opened
await expect(page.getByTestId('peek-view-modal')).toBeVisible();
@@ -108,7 +108,7 @@ test.describe('frame copy and paste', () => {
await frameTitles.nth(0).click();
const moreMenu = page.getByLabel('more-menu');
const moreMenu = page.getByLabel('More menu');
await moreMenu.click();
await moreMenu
@@ -262,7 +262,7 @@ test('duplicate note should work correctly', async ({ page }) => {
await triggerComponentToolbarAction(page, 'duplicate');
await waitNextFrame(page, 200); // wait viewport fit animation
const moreActionsContainer = page.getByLabel('more-menu').getByRole('menu');
const moreActionsContainer = page.getByLabel('More menu').getByRole('menu');
await expect(moreActionsContainer).toBeHidden();
const noteLocator = page.locator('affine-edgeless-note');
@@ -797,7 +797,7 @@ export async function updateExistedBrushElementSize(
export async function openComponentToolbarMoreMenu(page: Page) {
const btn = page
.locator('affine-toolbar-widget editor-toolbar')
.getByLabel('more-menu');
.getByLabel('More menu');
await btn.click();
}
@@ -1023,7 +1023,7 @@ export function locatorComponentToolbar(page: Page) {
}
export function locatorComponentToolbarMoreButton(page: Page) {
const moreButton = locatorComponentToolbar(page).getByLabel('more-menu');
const moreButton = locatorComponentToolbar(page).getByLabel('More menu');
return moreButton;
}
type Action =