From d05897b724c87c2496b752394a13fef891a92c04 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Thu, 12 Oct 2023 00:04:58 -0500 Subject: [PATCH] chore: prohibit unnecessary `await` (#4586) --- .eslintrc.js | 2 + apps/core/src/bootstrap/plugins/setup.ts | 4 +- .../src/components/page-detail-editor.tsx | 5 +- apps/core/src/hooks/use-workspaces.ts | 2 +- apps/core/src/pages/share/detail-page.tsx | 2 +- apps/server/tests/prometheus-metrics.spec.ts | 3 +- .../use-block-suite-workspace-avatar-url.ts | 4 +- packages/i18n/build.mjs | 2 +- plugins/image-preview/src/component/index.tsx | 2 +- scripts/setup/i18n.ts | 2 +- tests/affine-local/e2e/all-page.spec.ts | 6 +- .../affine-local/e2e/change-page-mode.spec.ts | 18 +-- tests/affine-local/e2e/contact-us.spec.ts | 8 +- tests/affine-local/e2e/exception-page.spec.ts | 3 +- tests/affine-local/e2e/image-preview.spec.ts | 122 +++++++++--------- .../e2e/local-first-delete-workspace.spec.ts | 4 +- tests/affine-local/e2e/quick-search.spec.ts | 4 +- tests/affine-local/e2e/settings.spec.ts | 10 +- tests/kit/utils/load-page.ts | 5 +- 19 files changed, 104 insertions(+), 104 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index db19ab742a..c8f072b9d8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -132,6 +132,7 @@ const config = { '@typescript-eslint/no-non-null-assertion': 'error', '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-empty-function': 'off', + '@typescript-eslint/await-thenable': 'error', '@typescript-eslint/no-unused-vars': [ 'error', { @@ -202,6 +203,7 @@ const config = { ignore: ['^\\[[a-zA-Z0-9-_]+\\]\\.tsx$'], }, ], + 'unicorn/no-unnecessary-await': 'error', 'sonarjs/no-all-duplicated-branches': 'error', 'sonarjs/no-element-overwrite': 'error', 'sonarjs/no-empty-collection': 'error', diff --git a/apps/core/src/bootstrap/plugins/setup.ts b/apps/core/src/bootstrap/plugins/setup.ts index da8b986a89..f9efd839b2 100644 --- a/apps/core/src/bootstrap/plugins/setup.ts +++ b/apps/core/src/bootstrap/plugins/setup.ts @@ -358,9 +358,7 @@ function createSetupImpl(rootStore: ReturnType) { }, } ), - navigator: { - userAgent: navigator.userAgent, - }, + navigator: globalThis.navigator, MouseEvent: globalThis.MouseEvent, KeyboardEvent: globalThis.KeyboardEvent, diff --git a/apps/core/src/components/page-detail-editor.tsx b/apps/core/src/components/page-detail-editor.tsx index 43b039f8b5..9a175e12a4 100644 --- a/apps/core/src/components/page-detail-editor.tsx +++ b/apps/core/src/components/page-detail-editor.tsx @@ -42,7 +42,10 @@ export interface PageDetailEditorProps { isPublic?: boolean; workspace: Workspace; pageId: string; - onInit: (page: Page, editor: Readonly) => void; + onInit: ( + page: Page, + editor: Readonly + ) => Promise | void; onLoad?: OnLoadEditor; } diff --git a/apps/core/src/hooks/use-workspaces.ts b/apps/core/src/hooks/use-workspaces.ts index a6475f35d7..c47d77f73d 100644 --- a/apps/core/src/hooks/use-workspaces.ts +++ b/apps/core/src/hooks/use-workspaces.ts @@ -112,7 +112,7 @@ export function useAppHelper() { targetWorkspace ); // delete workspace from jotai storage - await set(workspaces => workspaces.filter(ws => ws.id !== workspaceId)); + set(workspaces => workspaces.filter(ws => ws.id !== workspaceId)); }, [jotaiWorkspaces, set] ), diff --git a/apps/core/src/pages/share/detail-page.tsx b/apps/core/src/pages/share/detail-page.tsx index e135a55a4c..70fd48689e 100644 --- a/apps/core/src/pages/share/detail-page.tsx +++ b/apps/core/src/pages/share/detail-page.tsx @@ -70,7 +70,7 @@ export const Component = (): ReactElement => { isPublic workspace={page.workspace} pageId={page.id} - onInit={useCallback(() => noop, [])} + onInit={noop} onLoad={useCallback(() => noop, [])} /> diff --git a/apps/server/tests/prometheus-metrics.spec.ts b/apps/server/tests/prometheus-metrics.spec.ts index c8fe384989..af0d6dd4a5 100644 --- a/apps/server/tests/prometheus-metrics.spec.ts +++ b/apps/server/tests/prometheus-metrics.spec.ts @@ -23,8 +23,7 @@ test.afterEach.always(async () => { test('should be able to increment counter', async t => { metrics.socketIOEventCounter(1, { event: 'client-handshake' }); - const socketIOCounterMetric = - await register.getSingleMetric('socket_io_counter'); + const socketIOCounterMetric = register.getSingleMetric('socket_io_counter'); t.truthy(socketIOCounterMetric); t.truthy( diff --git a/packages/hooks/src/use-block-suite-workspace-avatar-url.ts b/packages/hooks/src/use-block-suite-workspace-avatar-url.ts index 38fc4a2d48..8a6428dd63 100644 --- a/packages/hooks/src/use-block-suite-workspace-avatar-url.ts +++ b/packages/hooks/src/use-block-suite-workspace-avatar-url.ts @@ -13,7 +13,7 @@ export function useBlockSuiteWorkspaceAvatarUrl( const { data: avatar, mutate } = useSWR(url, { fetcher: async avatar => { assertExists(blockSuiteWorkspace); - const blobs = await blockSuiteWorkspace.blobs; + const blobs = blockSuiteWorkspace.blobs; const blob = await blobs.get(avatar); if (blob) { return URL.createObjectURL(blob); @@ -31,7 +31,7 @@ export function useBlockSuiteWorkspaceAvatarUrl( return; } const blob = new Blob([file], { type: file.type }); - const blobs = await blockSuiteWorkspace.blobs; + const blobs = blockSuiteWorkspace.blobs; const blobId = await blobs.set(blob); blockSuiteWorkspace.meta.setAvatar(blobId); await mutate(blobId); diff --git a/packages/i18n/build.mjs b/packages/i18n/build.mjs index 2a2f8bea80..c863e06cc8 100644 --- a/packages/i18n/build.mjs +++ b/packages/i18n/build.mjs @@ -1,7 +1,7 @@ import { runCli } from '@magic-works/i18n-codegen'; import { fileURLToPath } from 'url'; -await runCli( +runCli( { config: fileURLToPath(new URL('../../.i18n-codegen.json', import.meta.url)), watch: false, diff --git a/plugins/image-preview/src/component/index.tsx b/plugins/image-preview/src/component/index.tsx index aae2da848e..95436740aa 100644 --- a/plugins/image-preview/src/component/index.tsx +++ b/plugins/image-preview/src/component/index.tsx @@ -190,7 +190,7 @@ const ImagePreviewModalImpl = ( if (typeof blockId === 'string') { const block = page.getBlockById(blockId) as ImageBlockModel; assertExists(block); - const store = await block.page.blobs; + const store = block.page.blobs; const url = store?.get(block.sourceId); const img = await url; if (!img) { diff --git a/scripts/setup/i18n.ts b/scripts/setup/i18n.ts index 60093f1b3c..7a35fd73c0 100644 --- a/scripts/setup/i18n.ts +++ b/scripts/setup/i18n.ts @@ -5,7 +5,7 @@ import { runCli } from '@magic-works/i18n-codegen'; import { beforeAll } from 'vitest'; beforeAll(async () => { - await runCli( + runCli( { watch: false, cwd: join(fileURLToPath(import.meta.url), '../../../.i18n-codegen.json'), diff --git a/tests/affine-local/e2e/all-page.spec.ts b/tests/affine-local/e2e/all-page.spec.ts index 039a3a375e..4f8d5bc49d 100644 --- a/tests/affine-local/e2e/all-page.spec.ts +++ b/tests/affine-local/e2e/all-page.spec.ts @@ -80,9 +80,9 @@ test('allow creation of filters by favorite', async ({ page }) => { .locator('[data-testid="filter-arg"]', { hasText: 'true' }) .locator('div') .click(); - await expect( - await page.locator('[data-testid="filter-arg"]').textContent() - ).toBe('false'); + expect(await page.locator('[data-testid="filter-arg"]').textContent()).toBe( + 'false' + ); }); test('allow creation of filters by created time', async ({ page }) => { diff --git a/tests/affine-local/e2e/change-page-mode.spec.ts b/tests/affine-local/e2e/change-page-mode.spec.ts index 23e706de6b..c1351c8680 100644 --- a/tests/affine-local/e2e/change-page-mode.spec.ts +++ b/tests/affine-local/e2e/change-page-mode.spec.ts @@ -15,7 +15,7 @@ test('Switch to edgeless by switch edgeless item', async ({ page }) => { } await openHomePage(page); await waitForEditorLoad(page); - const btn = await page.getByTestId('switch-edgeless-mode-button'); + const btn = page.getByTestId('switch-edgeless-mode-button'); await page.evaluate(() => { // @ts-expect-error globalThis.__toastCount = 0; @@ -31,7 +31,7 @@ test('Switch to edgeless by switch edgeless item', async ({ page }) => { expect(count).toBe(1); } const edgeless = page.locator('affine-edgeless-page'); - expect(await edgeless.isVisible()).toBe(true); + await expect(edgeless).toBeVisible(); const editorWrapperPadding = await page .locator('.editor-wrapper.edgeless-mode') @@ -60,15 +60,15 @@ test('Convert to edgeless by editor header items', async ({ page }) => { const menusEdgelessItem = page.getByTestId('editor-option-menu-edgeless'); await menusEdgelessItem.click({ delay: 100 }); const edgeless = page.locator('affine-edgeless-page'); - expect(await edgeless.isVisible()).toBe(true); + await expect(edgeless).toBeVisible(); }); test('Able to insert the title of an untitled page', async ({ page }) => { await openHomePage(page); await waitForEditorLoad(page); - const titleBarTextContent = await page.getByTestId('title-edit-button'); + const titleBarTextContent = page.getByTestId('title-edit-button'); await titleBarTextContent.dblclick({ delay: 100 }); - const titleContent = await page.getByTestId('title-content'); + const titleContent = page.getByTestId('title-content'); await titleContent.fill('test'); await titleContent.blur(); expect(await titleBarTextContent.textContent()).toBe('test'); @@ -77,9 +77,9 @@ test('Able to insert the title of an untitled page', async ({ page }) => { test('Able to edit the title of an existing page', async ({ page }) => { await openHomePage(page); await waitForEditorLoad(page); - const titleBarTextContent = await page.getByTestId('title-edit-button'); + const titleBarTextContent = page.getByTestId('title-edit-button'); await titleBarTextContent.dblclick({ delay: 100 }); - const titleContent = await page.getByTestId('title-content'); + const titleContent = page.getByTestId('title-content'); await titleContent.fill('test'); await titleContent.blur(); expect(await titleBarTextContent.textContent()).toBe('test'); @@ -94,9 +94,9 @@ test('Clearing out the title bar will remove the page title', async ({ }) => { await openHomePage(page); await waitForEditorLoad(page); - const titleBarTextContent = await page.getByTestId('title-edit-button'); + const titleBarTextContent = page.getByTestId('title-edit-button'); await titleBarTextContent.dblclick({ delay: 100 }); - const titleContent = await page.getByTestId('title-content'); + const titleContent = page.getByTestId('title-content'); await titleContent.fill('test'); await titleContent.blur(); expect(await titleBarTextContent.textContent()).toBe('test'); diff --git a/tests/affine-local/e2e/contact-us.spec.ts b/tests/affine-local/e2e/contact-us.spec.ts index 4922c3ce17..6e9c0875d4 100644 --- a/tests/affine-local/e2e/contact-us.spec.ts +++ b/tests/affine-local/e2e/contact-us.spec.ts @@ -7,13 +7,11 @@ test('Click right-bottom corner contact icon', async ({ page }) => { await openHomePage(page); await waitForEditorLoad(page); await page.locator('[data-testid=help-island]').click(); - const rightBottomContactUs = page.locator( - '[data-testid=right-bottom-contact-us-icon]' - ); - expect(await rightBottomContactUs.isVisible()).toEqual(true); + const rightBottomContactUs = page.getByTestId('right-bottom-contact-us-icon'); + await expect(rightBottomContactUs).toBeVisible(); await rightBottomContactUs.click(); - const title = await page.getByTestId('about-title'); + const title = page.getByTestId('about-title'); await expect(title).toBeVisible(); }); diff --git a/tests/affine-local/e2e/exception-page.spec.ts b/tests/affine-local/e2e/exception-page.spec.ts index 1233f5b393..c7b761fd47 100644 --- a/tests/affine-local/e2e/exception-page.spec.ts +++ b/tests/affine-local/e2e/exception-page.spec.ts @@ -1,8 +1,9 @@ import { test } from '@affine-test/kit/playwright'; +import { open404Page } from '@affine-test/kit/utils/load-page'; import { expect } from '@playwright/test'; test('visit 404 page', async ({ page }) => { - await page.goto('http://localhost:8080/404'); + await open404Page(page); const notFoundTip = page.getByTestId('not-found'); await expect(notFoundTip).toBeVisible(); }); diff --git a/tests/affine-local/e2e/image-preview.spec.ts b/tests/affine-local/e2e/image-preview.spec.ts index 475bb69d48..a0a62666b8 100644 --- a/tests/affine-local/e2e/image-preview.spec.ts +++ b/tests/affine-local/e2e/image-preview.spec.ts @@ -44,15 +44,15 @@ test('image preview should be shown', async ({ page }) => { await openHomePage(page); await waitForEditorLoad(page); await clickNewPageButton(page); - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/large-image.png'); await page.locator('img').first().dblclick(); const locator = page.getByTestId('image-preview-modal'); - expect(locator.isVisible()).toBeTruthy(); + await expect(locator).toBeVisible(); await closeImagePreviewModal(page); - expect(await locator.isVisible()).toBeFalsy(); + await expect(locator).not.toBeVisible(); }); test('image go left and right', async ({ page }) => { @@ -61,7 +61,7 @@ test('image go left and right', async ({ page }) => { await clickNewPageButton(page); let blobId: string; { - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/large-image.png'); @@ -75,7 +75,7 @@ test('image go left and right', async ({ page }) => { await closeImagePreviewModal(page); } { - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/affine-preview.png'); @@ -108,7 +108,7 @@ test('image able to zoom in and out with mouse scroll', async ({ page }) => { await clickNewPageButton(page); let blobId: string; { - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/large-image.png'); @@ -130,26 +130,26 @@ test('image able to zoom in and out with mouse scroll', async ({ page }) => { height: window.innerHeight, })); - // zooom in + // zoom in await page.mouse.move(width / 2, height / 2); await page.mouse.wheel(0, 100); await page.mouse.wheel(0, 100); await page.mouse.wheel(0, 100); await page.waitForTimeout(1000); let imageBoundary = await locator.boundingBox(); - let imageWidth = await imageBoundary?.width; + let imageWidth = imageBoundary?.width; if (imageWidth) { expect((imageWidth / naturalWidth).toFixed(2)).toBe('0.54'); } - // zooom in + // zoom in await page.mouse.move(width / 2, height / 2); await page.mouse.wheel(0, -100); await page.mouse.wheel(0, -100); await page.mouse.wheel(0, -100); await page.waitForTimeout(1000); imageBoundary = await locator.boundingBox(); - imageWidth = await imageBoundary?.width; + imageWidth = imageBoundary?.width; if (imageWidth) { expect((imageWidth / naturalWidth).toFixed(2)).toBe('0.84'); } @@ -161,7 +161,7 @@ test('image able to zoom in and out with button click', async ({ page }) => { await clickNewPageButton(page); let blobId: string; { - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/large-image.png'); @@ -174,7 +174,7 @@ test('image able to zoom in and out with button click', async ({ page }) => { expect(blobId).toBeTruthy(); } const locator = page.getByTestId('image-content'); - expect(locator.isVisible()).toBeTruthy(); + await expect(locator).toBeVisible(); const naturalWidth = await locator.evaluate( (img: HTMLImageElement) => img.naturalWidth ); @@ -187,7 +187,7 @@ test('image able to zoom in and out with button click', async ({ page }) => { } await page.waitForTimeout(1000); let imageBoundary = await locator.boundingBox(); - let imageWidth = await imageBoundary?.width; + let imageWidth = imageBoundary?.width; if (imageWidth) { expect((imageWidth / naturalWidth).toFixed(2)).toBe('1.04'); } @@ -195,7 +195,7 @@ test('image able to zoom in and out with button click', async ({ page }) => { // zooom out await page.getByTestId('zoom-out-button').dblclick(); imageBoundary = await locator.boundingBox(); - imageWidth = await imageBoundary?.width; + imageWidth = imageBoundary?.width; if (imageWidth) { expect((imageWidth / naturalWidth).toFixed(2)).toBe('0.84'); } @@ -207,7 +207,7 @@ test('image should able to go left and right by buttons', async ({ page }) => { await clickNewPageButton(page); let blobId: string; { - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/large-image.png'); @@ -221,16 +221,14 @@ test('image should able to go left and right by buttons', async ({ page }) => { await closeImagePreviewModal(page); } { - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/affine-preview.png'); } const locator = page.getByTestId('image-preview-modal'); - expect(locator.isVisible()).toBeTruthy(); await page.locator('img').first().dblclick(); - // ensure the new image was imported - await page.waitForTimeout(1000); + await expect(locator).toBeVisible(); { const newBlobId = (await locator .getByTestId('image-content') @@ -261,7 +259,7 @@ test('image able to fit to screen by button', async ({ page }) => { await clickNewPageButton(page); let blobId: string; { - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/large-image.png'); @@ -274,7 +272,7 @@ test('image able to fit to screen by button', async ({ page }) => { expect(blobId).toBeTruthy(); } const locator = page.getByTestId('image-content'); - expect(locator.isVisible()).toBeTruthy(); + await expect(locator).toBeVisible(); const naturalWidth = await locator.evaluate( (img: HTMLImageElement) => img.naturalWidth ); @@ -289,7 +287,7 @@ test('image able to fit to screen by button', async ({ page }) => { } await page.waitForTimeout(1000); let imageBoundary = await locator.boundingBox(); - let imageWidth = await imageBoundary?.width; + let imageWidth = imageBoundary?.width; if (imageWidth) { expect((imageWidth / naturalWidth).toFixed(2)).toBe('1.04'); } else { @@ -302,8 +300,8 @@ test('image able to fit to screen by button', async ({ page }) => { await locator.getByTestId('fit-to-screen-button').click(); } imageBoundary = await locator.boundingBox(); - imageWidth = await imageBoundary?.width; - const imageHeight = await imageBoundary?.height; + imageWidth = imageBoundary?.width; + const imageHeight = imageBoundary?.height; if (imageWidth && imageHeight) { expect(imageWidth).toBeLessThan(viewportWidth); expect(imageHeight).toBeLessThan(viewportHeight); @@ -318,7 +316,7 @@ test('image able to reset zoom to 100%', async ({ page }) => { await clickNewPageButton(page); let blobId: string; { - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/large-image.png'); @@ -331,20 +329,20 @@ test('image able to reset zoom to 100%', async ({ page }) => { expect(blobId).toBeTruthy(); } const locator = page.getByTestId('image-content'); - expect(locator.isVisible()).toBeTruthy(); + await expect(locator).toBeVisible(); const naturalWidth = await locator.evaluate( (img: HTMLImageElement) => img.naturalWidth ); await page.waitForTimeout(500); - // zooom in + // zoom in { const locator = page.getByTestId('image-preview-modal'); await locator.getByTestId('zoom-in-button').dblclick(); } await page.waitForTimeout(1000); let imageBoundary = await locator.boundingBox(); - let imageWidth = await imageBoundary?.width; + let imageWidth = imageBoundary?.width; if (imageWidth) { expect((imageWidth / naturalWidth).toFixed(2)).toBe('1.04'); } else { @@ -357,7 +355,7 @@ test('image able to reset zoom to 100%', async ({ page }) => { await locator.getByTestId('reset-scale-button').click(); } imageBoundary = await locator.boundingBox(); - imageWidth = await imageBoundary?.width; + imageWidth = imageBoundary?.width; if (imageWidth) { expect((imageWidth / naturalWidth).toFixed(2)).toBe('1.00'); } else { @@ -371,7 +369,7 @@ test('image able to copy to clipboard', async ({ page }) => { await clickNewPageButton(page); let blobId: string; { - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/large-image.png'); @@ -384,11 +382,13 @@ test('image able to copy to clipboard', async ({ page }) => { expect(blobId).toBeTruthy(); } const locator = page.getByTestId('image-preview-modal'); - expect(locator.isVisible()).toBeTruthy(); - await page.waitForTimeout(500); + await expect(locator).toBeVisible(); await locator.getByTestId('copy-to-clipboard-button').click(); - await page.on('console', message => { - expect(message.text()).toBe('Image copied to clipboard'); + await new Promise(resolve => { + page.on('console', message => { + expect(message.text()).toBe('Image copied to clipboard'); + resolve(); + }); }); }); @@ -398,7 +398,7 @@ test('image able to download', async ({ page }) => { await clickNewPageButton(page); let blobId: string; { - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/large-image.png'); @@ -411,7 +411,7 @@ test('image able to download', async ({ page }) => { expect(blobId).toBeTruthy(); } const locator = page.getByTestId('image-preview-modal'); - expect(locator.isVisible()).toBeTruthy(); + await expect(locator).toBeVisible(); const downloadPromise = page.waitForEvent('download'); await locator.getByTestId('download-button').click(); const download = await downloadPromise; @@ -428,7 +428,7 @@ test('image should only able to move when image is larger than viewport', async await clickNewPageButton(page); let blobId: string; { - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/large-image.png'); @@ -441,7 +441,7 @@ test('image should only able to move when image is larger than viewport', async expect(blobId).toBeTruthy(); } const locator = page.getByTestId('image-content'); - expect(locator.isVisible()).toBeTruthy(); + await expect(locator).toBeVisible(); const { width, height } = await page.evaluate(() => ({ width: window.innerWidth, height: window.innerHeight, @@ -449,7 +449,7 @@ test('image should only able to move when image is larger than viewport', async let imageBoundary = await locator.boundingBox(); const initialXPos = imageBoundary?.x; const initialYPos = imageBoundary?.y; - // check will it able to move when zoomed in + // check will it be able to move when zoomed in { const locator = page.getByTestId('image-preview-modal'); await locator.getByTestId('zoom-in-button').dblclick(); @@ -463,7 +463,7 @@ test('image should only able to move when image is larger than viewport', async expect(initialXPos).not.toBe(imageBoundary?.x); expect(initialYPos).not.toBe(imageBoundary?.y); - // check will it able to move when zoomed out + // check will it be able to move when zoomed out { const locator = page.getByTestId('image-preview-modal'); await locator.getByTestId('fit-to-screen-button').click(); @@ -485,7 +485,7 @@ test('image should able to delete and when delete, it will move to previous/next await clickNewPageButton(page); let blobId: string; { - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/large-image.png'); @@ -499,14 +499,14 @@ test('image should able to delete and when delete, it will move to previous/next await closeImagePreviewModal(page); } { - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/affine-preview.png'); } const locator = page.getByTestId('image-preview-modal'); - await expect(locator.isVisible()).toBeTruthy(); await page.locator('img').first().dblclick(); + await expect(locator).toBeVisible(); // ensure the new image was imported await page.waitForTimeout(1000); { @@ -523,7 +523,7 @@ test('image should able to delete and when delete, it will move to previous/next .getAttribute('data-blob-id')) as string; expect(newBlobId).toBe(blobId); await closeImagePreviewModal(page); - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/affine-preview.png'); @@ -560,7 +560,7 @@ test('tooltips for all buttons should be visible when hovering', async ({ await clickNewPageButton(page); let blobId: string; { - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/large-image.png'); @@ -577,7 +577,7 @@ test('tooltips for all buttons should be visible when hovering', async ({ await locator.getByTestId('previous-image-button').hover(); await page.waitForTimeout(1000); { - const element = await page.getByRole('tooltip'); + const element = page.getByRole('tooltip'); const previousImageTooltip = await element.getByText('Previous').count(); expect(previousImageTooltip).toBe(1); } @@ -585,7 +585,7 @@ test('tooltips for all buttons should be visible when hovering', async ({ await locator.getByTestId('next-image-button').hover(); await page.waitForTimeout(1000); { - const element = await page.getByRole('tooltip'); + const element = page.getByRole('tooltip'); const nextImageTooltip = await element.getByText('Next').count(); expect(nextImageTooltip).toBe(1); } @@ -593,7 +593,7 @@ test('tooltips for all buttons should be visible when hovering', async ({ await locator.getByTestId('fit-to-screen-button').hover(); await page.waitForTimeout(1000); { - const element = await page.getByRole('tooltip'); + const element = page.getByRole('tooltip'); const fitToScreenToolTip = await element.getByText('Fit to Screen').count(); expect(fitToScreenToolTip).toBe(1); } @@ -601,7 +601,7 @@ test('tooltips for all buttons should be visible when hovering', async ({ await locator.getByTestId('zoom-out-button').hover(); await page.waitForTimeout(1000); { - const element = await page.getByRole('tooltip'); + const element = page.getByRole('tooltip'); const zoomOutToolTip = await element.getByText('Zoom out').count(); expect(zoomOutToolTip).toBe(1); } @@ -609,7 +609,7 @@ test('tooltips for all buttons should be visible when hovering', async ({ await locator.getByTestId('reset-scale-button').hover(); await page.waitForTimeout(1000); { - const element = await page.getByRole('tooltip'); + const element = page.getByRole('tooltip'); const resetScaleTooltip = await element.getByText('Reset Scale').count(); expect(resetScaleTooltip).toBe(1); } @@ -617,7 +617,7 @@ test('tooltips for all buttons should be visible when hovering', async ({ await locator.getByTestId('zoom-in-button').hover(); await page.waitForTimeout(1000); { - const element = await page.getByRole('tooltip'); + const element = page.getByRole('tooltip'); const zoominToolTip = await element.getByText('Zoom in').count(); expect(zoominToolTip).toBe(1); } @@ -625,7 +625,7 @@ test('tooltips for all buttons should be visible when hovering', async ({ await locator.getByTestId('download-button').hover(); await page.waitForTimeout(1000); { - const element = await page.getByRole('tooltip'); + const element = page.getByRole('tooltip'); const downloadTooltip = await element.getByText('Download').count(); expect(downloadTooltip).toBe(1); } @@ -633,7 +633,7 @@ test('tooltips for all buttons should be visible when hovering', async ({ await locator.getByTestId('copy-to-clipboard-button').hover(); await page.waitForTimeout(1000); { - const element = await page.getByRole('tooltip'); + const element = page.getByRole('tooltip'); const downloadTooltip = await element .getByText('Copy to clipboard') .count(); @@ -643,7 +643,7 @@ test('tooltips for all buttons should be visible when hovering', async ({ await locator.getByTestId('delete-button').hover(); await page.waitForTimeout(500); { - const element = await page.getByRole('tooltip'); + const element = page.getByRole('tooltip'); const downloadTooltip = await element.getByText('Delete').count(); expect(downloadTooltip).toBe(1); } @@ -653,7 +653,7 @@ test('keypress esc should close the modal', async ({ page }) => { await openHomePage(page); await waitForEditorLoad(page); await clickNewPageButton(page); - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/large-image.png'); @@ -671,18 +671,18 @@ test('when mouse moves outside, the modal should be closed', async ({ await openHomePage(page); await waitForEditorLoad(page); await clickNewPageButton(page); - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/large-image.png'); await page.locator('img').first().dblclick(); const locator = page.getByTestId('image-preview-modal'); - expect(await locator.isVisible()).toBeTruthy(); + await expect(locator).toBeVisible(); // animation delay await page.waitForTimeout(1000); await page.mouse.click(10, 10); await page.waitForTimeout(1000); - expect(await locator.isVisible()).toBeFalsy(); + await expect(locator).not.toBeVisible(); }); test('caption should be visible and different styles were applied if image zoomed larger than viewport', async ({ @@ -692,7 +692,7 @@ test('caption should be visible and different styles were applied if image zoome await openHomePage(page); await waitForEditorLoad(page); await clickNewPageButton(page); - const title = await getBlockSuiteEditorTitle(page); + const title = getBlockSuiteEditorTitle(page); await title.click(); await page.keyboard.press('Enter'); await importImage(page, 'http://localhost:8081/large-image.png'); @@ -711,8 +711,8 @@ test('caption should be visible and different styles were applied if image zoome await expect(captionLocator).toBeVisible(); expect(await captionLocator.innerText()).toBe(sampleCaption); await page.getByTestId('zoom-in-button').click({ clickCount: 4 }); - expect(await captionLocator.isVisible()).not.toBeTruthy(); + await expect(captionLocator).not.toBeVisible(); captionLocator = locator.getByTestId('image-caption-zoomedin'); - expect(await captionLocator.isVisible()).toBeTruthy(); + await expect(captionLocator).toBeVisible(); expect(await captionLocator.innerText()).toBe(sampleCaption); }); diff --git a/tests/affine-local/e2e/local-first-delete-workspace.spec.ts b/tests/affine-local/e2e/local-first-delete-workspace.spec.ts index 1b577df39e..e36bb5ec01 100644 --- a/tests/affine-local/e2e/local-first-delete-workspace.spec.ts +++ b/tests/affine-local/e2e/local-first-delete-workspace.spec.ts @@ -24,7 +24,7 @@ test('Create new workspace, then delete it', async ({ page, workspace }) => { await openSettingModal(page); await openWorkspaceSettingPanel(page, 'Test Workspace'); await page.getByTestId('delete-workspace-button').click(); - const workspaceNameDom = await page.getByTestId('workspace-name'); + const workspaceNameDom = page.getByTestId('workspace-name'); const currentWorkspaceName = (await workspaceNameDom.evaluate( node => node.textContent )) as string; @@ -51,7 +51,7 @@ test('Create new workspace, then delete it', async ({ page, workspace }) => { test('Delete last workspace', async ({ page }) => { await openHomePage(page); await waitForEditorLoad(page); - const workspaceNameDom = await page.getByTestId('workspace-name'); + const workspaceNameDom = page.getByTestId('workspace-name'); const currentWorkspaceName = await workspaceNameDom.evaluate( node => node.textContent ); diff --git a/tests/affine-local/e2e/quick-search.spec.ts b/tests/affine-local/e2e/quick-search.spec.ts index fb2d5f041f..e2ed988e1d 100644 --- a/tests/affine-local/e2e/quick-search.spec.ts +++ b/tests/affine-local/e2e/quick-search.spec.ts @@ -10,7 +10,7 @@ import { expect, type Page } from '@playwright/test'; const openQuickSearchByShortcut = async (page: Page) => { await withCtrlOrMeta(page, () => page.keyboard.press('k', { delay: 50 })); - await page.waitForTimeout(500); + await page.waitForTimeout(1000); }; const keyboardDownAndSelect = async (page: Page, label: string) => { @@ -151,6 +151,7 @@ test('Create a new page and search this page', async ({ page }) => { await page.waitForTimeout(300); await assertTitle(page, 'test123456'); }); + test('Navigate to the 404 page and try to open quick search', async ({ page, }) => { @@ -249,7 +250,6 @@ test('assert the recent browse pages are on the recent list', async ({ await page.waitForTimeout(200); await openQuickSearchByShortcut(page); - await page.waitForTimeout(200); { // check does all 3 pages exists on recent page list const quickSearchItems = page.locator( diff --git a/tests/affine-local/e2e/settings.spec.ts b/tests/affine-local/e2e/settings.spec.ts index 5a28768c0a..195f414041 100644 --- a/tests/affine-local/e2e/settings.spec.ts +++ b/tests/affine-local/e2e/settings.spec.ts @@ -16,7 +16,7 @@ test('Open settings modal', async ({ page }) => { await waitForEditorLoad(page); await openSettingModal(page); - const modal = await page.getByTestId('setting-modal'); + const modal = page.getByTestId('setting-modal'); await expect(modal).toBeVisible(); }); @@ -69,7 +69,7 @@ test('Change layout width', async ({ page }) => { await page.getByTestId('full-width-layout-trigger').click(); - const editorWrapper = await page.locator('.editor-wrapper'); + const editorWrapper = page.locator('.editor-wrapper'); const className = await editorWrapper.getAttribute('class'); expect(className).toContain('full-screen'); }); @@ -79,7 +79,7 @@ test('Open shortcuts panel', async ({ page }) => { await waitForEditorLoad(page); await openSettingModal(page); await openShortcutsPanel(page); - const title = await page.getByTestId('keyboard-shortcuts-title'); + const title = page.getByTestId('keyboard-shortcuts-title'); await expect(title).toBeVisible(); }); @@ -88,7 +88,7 @@ test('Open plugins panel', async ({ page }) => { await waitForEditorLoad(page); await openSettingModal(page); await openPluginsPanel(page); - const title = await page.getByTestId('plugins-title'); + const title = page.getByTestId('plugins-title'); await expect(title).toBeVisible(); }); @@ -97,7 +97,7 @@ test('Open about panel', async ({ page }) => { await waitForEditorLoad(page); await openSettingModal(page); await openAboutPanel(page); - const title = await page.getByTestId('about-title'); + const title = page.getByTestId('about-title'); await expect(title).toBeVisible(); }); diff --git a/tests/kit/utils/load-page.ts b/tests/kit/utils/load-page.ts index 91c0295164..7becb69368 100644 --- a/tests/kit/utils/load-page.ts +++ b/tests/kit/utils/load-page.ts @@ -1,7 +1,6 @@ import type { Page } from '@playwright/test'; export const coreUrl = 'http://localhost:8080'; -export const prototypeUrl = 'http://localhost:3003'; export async function openHomePage(page: Page) { await page.goto(coreUrl); @@ -11,6 +10,6 @@ export async function openPluginPage(page: Page) { await page.goto(`${coreUrl}/_plugin/index.html`); } -export async function openPrototypeProviderStatusPage(page: Page) { - await page.goto(`${prototypeUrl}/suite/provider-status.html`); +export async function open404Page(page: Page) { + await page.goto(`${coreUrl}/404`); }