fix(core): stuck when quick switch doc mode (#7599)

This commit is contained in:
EYHN
2024-07-25 12:21:21 +00:00
parent 11a2dc7d7f
commit 549e7befed
3 changed files with 74 additions and 11 deletions
@@ -181,8 +181,6 @@ const DetailPageImpl = memo(function DetailPageImpl() {
const pageService =
editorHost?.std.spec.getService<PageRootService>('affine:page');
const disposable = new DisposableGroup();
doc.setMode(mode);
if (pageService) {
disposable.add(
pageService.slots.docLinkClicked.on(({ docId, blockId }) => {
@@ -204,15 +202,7 @@ const DetailPageImpl = memo(function DetailPageImpl() {
disposable.dispose();
};
},
[
doc,
mode,
jumpToPageBlock,
docCollection.id,
openPage,
jumpToTag,
workspace.id,
]
[jumpToPageBlock, docCollection.id, openPage, jumpToTag, workspace.id]
);
return (
@@ -1,4 +1,9 @@
import { test } from '@affine-test/kit/playwright';
import {
ensureInEdgelessMode,
ensureInPageMode,
getPageMode,
} from '@affine-test/kit/utils/editor';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
@@ -55,6 +60,40 @@ test('Switch to edgeless by switch edgeless item', async ({ page }) => {
}
});
test('Quick Switch Doc Mode, Doc Mode should stable', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await ensureInEdgelessMode(page);
await page.keyboard.down('Alt');
await page.keyboard.down('S');
await page.keyboard.up('S');
await page.keyboard.up('Alt');
await page.keyboard.down('Alt');
await page.keyboard.down('S');
await page.keyboard.up('S');
await page.keyboard.up('Alt');
await page.keyboard.down('Alt');
await page.keyboard.down('S');
await page.keyboard.up('S');
await page.keyboard.up('Alt');
await page.keyboard.down('Alt');
await page.keyboard.down('S');
await page.keyboard.up('S');
await page.keyboard.up('Alt');
await page.keyboard.down('Alt');
await page.keyboard.down('S');
await page.keyboard.up('S');
await page.keyboard.up('Alt');
await ensureInPageMode(page);
await page.waitForTimeout(1000);
expect(await getPageMode(page)).toBe('page');
});
test('Convert to edgeless by editor header items', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
+34
View File
@@ -19,3 +19,37 @@ export async function clickPageModeButton(page: Page) {
page.locator('[data-testid="switch-page-mode-button"][data-active="true"]')
).toBeVisible();
}
export async function ensureInPageMode(page: Page) {
await expect(
page.locator('[data-testid="switch-page-mode-button"][data-active="true"]')
).toBeVisible();
}
export async function ensureInEdgelessMode(page: Page) {
await expect(
page.locator(
'[data-testid="switch-edgeless-mode-button"][data-active="true"]'
)
).toBeVisible();
}
export async function getPageMode(page: Page): Promise<'page' | 'edgeless'> {
if (
await page
.locator('[data-testid="switch-page-mode-button"][data-active="true"]')
.isVisible()
) {
return 'page';
}
if (
await page
.locator(
'[data-testid="switch-edgeless-mode-button"][data-active="true"]'
)
.isVisible()
) {
return 'edgeless';
}
throw new Error('Unknown mode');
}