test: fix flaky on local-first-workspace-list.spec.ts (#2727)

This commit is contained in:
Himself65
2023-06-08 16:18:10 +08:00
committed by GitHub
parent 18dc427bc3
commit 27b14af388
5 changed files with 30 additions and 30 deletions

View File

@@ -91,6 +91,7 @@ jobs:
ENABLE_PLUGIN: true ENABLE_PLUGIN: true
ENABLE_ALL_PAGE_FILTER: true ENABLE_ALL_PAGE_FILTER: true
ENABLE_LEGACY_PROVIDER: true ENABLE_LEGACY_PROVIDER: true
ENABLE_PRELOADING: false
COVERAGE: true COVERAGE: true
- name: Upload artifact - name: Upload artifact
@@ -115,6 +116,7 @@ jobs:
ENABLE_PLUGIN: true ENABLE_PLUGIN: true
ENABLE_ALL_PAGE_FILTER: true ENABLE_ALL_PAGE_FILTER: true
ENABLE_LEGACY_PROVIDER: false ENABLE_LEGACY_PROVIDER: false
ENABLE_PRELOADING: false
COVERAGE: true COVERAGE: true
- name: Export static resources - name: Export static resources

View File

@@ -308,7 +308,9 @@ export const WorkspaceLayoutInner: FC<PropsWithChildren> = ({ children }) => {
assertEquals(page.id, pageId); assertEquals(page.id, pageId);
setEditorFlags(currentWorkspace.blockSuiteWorkspace); setEditorFlags(currentWorkspace.blockSuiteWorkspace);
if (config.enablePreloading) { if (config.enablePreloading) {
initPageWithPreloading(page); initPageWithPreloading(page).catch(error => {
console.error('import error:', error);
});
} else { } else {
initEmptyPage(page); initEmptyPage(page);
} }
@@ -333,10 +335,6 @@ export const WorkspaceLayoutInner: FC<PropsWithChildren> = ({ children }) => {
}; };
}, [currentWorkspace]); }, [currentWorkspace]);
useEffect(() => {
if (!currentWorkspace) {
return;
}
const page = currentWorkspace.blockSuiteWorkspace.getPage( const page = currentWorkspace.blockSuiteWorkspace.getPage(
DEFAULT_HELLO_WORLD_PAGE_ID DEFAULT_HELLO_WORLD_PAGE_ID
); );
@@ -350,13 +348,6 @@ export const WorkspaceLayoutInner: FC<PropsWithChildren> = ({ children }) => {
setCurrentPageId(currentPageId); setCurrentPageId(currentPageId);
void jumpToPage(currentWorkspace.id, page.id); void jumpToPage(currentWorkspace.id, page.id);
} }
}, [
currentPageId,
currentWorkspace,
jumpToPage,
router.query.pageId,
setCurrentPageId,
]);
const { openPage } = useRouterHelper(router); const { openPage } = useRouterHelper(router);
const [, setOpenWorkspacesModal] = useAtom(openWorkspacesModalAtom); const [, setOpenWorkspacesModal] = useAtom(openWorkspacesModalAtom);

View File

@@ -38,7 +38,7 @@ test('enable public workspace', async ({ page, context }) => {
await page2.waitForSelector('thead', { await page2.waitForSelector('thead', {
timeout: 10000, timeout: 10000,
}); });
await page2.getByText('AFFiNE - not just a note taking app').click(); await page2.getByText('Untitled').click();
}); });
test('access public workspace page', async ({ page, browser }) => { test('access public workspace page', async ({ page, browser }) => {

View File

@@ -17,7 +17,7 @@ test('drag a page from "All pages" list onto the "Trash" folder in the sidebar t
// Drag-and-drop // Drag-and-drop
// Ref: https://playwright.dev/docs/input#dragging-manually // Ref: https://playwright.dev/docs/input#dragging-manually
await page.getByText('AFFiNE - not just a note taking app').hover(); await page.getByText('Untitled').hover();
await page.mouse.down(); await page.mouse.down();
await page.waitForTimeout(1000); await page.waitForTimeout(1000);
await page.getByText('Trash').hover(); await page.getByText('Trash').hover();
@@ -29,7 +29,7 @@ test('drag a page from "All pages" list onto the "Trash" folder in the sidebar t
).toBeVisible(); ).toBeVisible();
await expect( await expect(
page.getByText('AFFiNE - not just a note taking app'), page.getByText('Untitled'),
'The deleted post is no longer on the All Page list' 'The deleted post is no longer on the All Page list'
).toHaveCount(0); ).toHaveCount(0);
@@ -37,7 +37,7 @@ test('drag a page from "All pages" list onto the "Trash" folder in the sidebar t
// Visit trash page via url // Visit trash page via url
await page.getByText('Trash', { exact: true }).click(); await page.getByText('Trash', { exact: true }).click();
await expect( await expect(
page.getByText('AFFiNE - not just a note taking app'), page.getByText('Untitled'),
'The deleted post exists in the Trash list' 'The deleted post exists in the Trash list'
).toHaveCount(1); ).toHaveCount(1);
}); });

View File

@@ -109,8 +109,15 @@ test('create multi workspace in the workspace list', async ({ page }) => {
expect(workspaceCards1.length).toBe(3); expect(workspaceCards1.length).toBe(3);
} }
const workspaceChangePromise = page.evaluate(() => {
new Promise(resolve => {
window.addEventListener('affine:workspace:change', resolve, {
once: true,
});
});
});
await page.getByTestId('draggable-item').nth(2).click(); await page.getByTestId('draggable-item').nth(2).click();
await page.waitForTimeout(100); await workspaceChangePromise;
// @ts-expect-error // @ts-expect-error
const nextId: string = await page.evaluate(() => currentWorkspace.id); const nextId: string = await page.evaluate(() => currentWorkspace.id);