From 5e1528b50b94bf921a5975df2b92b454eecfeb85 Mon Sep 17 00:00:00 2001 From: pengx17 Date: Fri, 24 May 2024 04:49:07 +0000 Subject: [PATCH] fix: export then add test case (#7024) --- .../frontend/component/src/ui/modal/modal.tsx | 1 + .../electron/src/helper/dialog/dialog.ts | 12 +++-- tests/affine-desktop/e2e/basic.spec.ts | 4 +- tests/affine-desktop/e2e/workspace.spec.ts | 44 +++++-------------- 4 files changed, 20 insertions(+), 41 deletions(-) diff --git a/packages/frontend/component/src/ui/modal/modal.tsx b/packages/frontend/component/src/ui/modal/modal.tsx index 39a586a8107fc..ba258f134a730 100644 --- a/packages/frontend/component/src/ui/modal/modal.tsx +++ b/packages/frontend/component/src/ui/modal/modal.tsx @@ -89,6 +89,7 @@ export const Modal = forwardRef( className={styles.closeButton} aria-label="Close" type="plain" + data-testid="modal-close-button" {...closeButtonOptions} > diff --git a/packages/frontend/electron/src/helper/dialog/dialog.ts b/packages/frontend/electron/src/helper/dialog/dialog.ts index a652e4f535604..26c065721f505 100644 --- a/packages/frontend/electron/src/helper/dialog/dialog.ts +++ b/packages/frontend/electron/src/helper/dialog/dialog.ts @@ -92,8 +92,10 @@ export async function saveDBFileAs( ): Promise { try { const db = await ensureSQLiteDB(workspaceId); + const fakedResult = getFakedResult(); + const ret = - getFakedResult() ?? + fakedResult ?? (await mainRPC.showSaveDialog({ properties: ['showOverwriteConfirmation'], title: 'Save Workspace', @@ -120,9 +122,11 @@ export async function saveDBFileAs( await fs.copyFile(db.path, filePath); logger.log('saved', filePath); - mainRPC.showItemInFolder(filePath).catch(err => { - console.error(err); - }); + if (!fakedResult) { + mainRPC.showItemInFolder(filePath).catch(err => { + console.error(err); + }); + } return { filePath }; } catch (err) { logger.error('saveDBFileAs', err); diff --git a/tests/affine-desktop/e2e/basic.spec.ts b/tests/affine-desktop/e2e/basic.spec.ts index 0574d012742a0..12b34d1cb3534 100644 --- a/tests/affine-desktop/e2e/basic.spec.ts +++ b/tests/affine-desktop/e2e/basic.spec.ts @@ -20,9 +20,7 @@ const historyShortcut = async (page: Page, command: 'goBack' | 'goForward') => { }; test('new page', async ({ page, workspace }) => { - await page.getByTestId('sidebar-new-page-button').click({ - delay: 100, - }); + await page.getByTestId('sidebar-new-page-button').click(); await page.waitForSelector('v-line'); const flavour = (await workspace.current()).meta.flavour; expect(flavour).toBe('local'); diff --git a/tests/affine-desktop/e2e/workspace.spec.ts b/tests/affine-desktop/e2e/workspace.spec.ts index 8e4ba69fa167d..fda7784e104f5 100644 --- a/tests/affine-desktop/e2e/workspace.spec.ts +++ b/tests/affine-desktop/e2e/workspace.spec.ts @@ -2,7 +2,11 @@ import path from 'node:path'; import type { apis } from '@affine/electron-api'; import { test } from '@affine-test/kit/electron'; -import { clickSideBarCurrentWorkspaceBanner } from '@affine-test/kit/utils/sidebar'; +import { getBlockSuiteEditorTitle } from '@affine-test/kit/utils/page-logic'; +import { + clickNewPageButton, + clickSideBarCurrentWorkspaceBanner, +} from '@affine-test/kit/utils/sidebar'; import { expect } from '@playwright/test'; import fs from 'fs-extra'; @@ -24,38 +28,11 @@ test('check workspace has a DB file', async ({ appInfo, workspace }) => { expect(await fs.exists(dbPath)).toBe(true); }); -test.skip('move workspace db file', async ({ page, appInfo, workspace }) => { - const w = await workspace.current(); - await page.getByTestId('slider-bar-workspace-setting-button').click(); - await expect(page.getByTestId('setting-modal')).toBeVisible(); - - // goto workspace setting - await page.getByTestId('workspace-list-item').click(); - - const tmpPath = path.join(appInfo.sessionData, w.meta.id + '-tmp-dir'); - - // move db file to tmp folder - await page.evaluate(tmpPath => { - window.apis?.dialog.setFakeDialogResult({ - filePath: tmpPath, - }); - }, tmpPath); - - await page.getByTestId('move-folder').click(); - // check if db file exists - await page.waitForSelector('text="Move folder success"'); - expect(await fs.exists(tmpPath)).toBe(true); - // check if db file exists under tmpPath (a file ends with .affine) - const files = await fs.readdir(tmpPath); - expect(files.some(f => f.endsWith('.affine'))).toBe(true); -}); - -//TODO:fix test -test.fixme('export then add', async ({ page, appInfo, workspace }) => { +test('export then add', async ({ page, appInfo, workspace }) => { + await clickNewPageButton(page); const w = await workspace.current(); - await page.focus('.affine-doc-page-block-title'); - await page.fill('.affine-doc-page-block-title', 'test1'); + await getBlockSuiteEditorTitle(page).fill('test1'); await page.getByTestId('slider-bar-workspace-setting-button').click(); await expect(page.getByTestId('setting-modal')).toBeVisible(); @@ -78,7 +55,7 @@ test.fixme('export then add', async ({ page, appInfo, workspace }) => { // export db file to tmp folder await page.evaluate(tmpPath => { - window.apis?.dialog.setFakeDialogResult({ + return window.apis?.dialog.setFakeDialogResult({ filePath: tmpPath, }); }, tmpPath); @@ -94,10 +71,9 @@ test.fixme('export then add', async ({ page, appInfo, workspace }) => { // we are reusing the same db file so that we don't need to maintain one // in the codebase await clickSideBarCurrentWorkspaceBanner(page); - await page.getByTestId('add-or-new-workspace').click(); await page.evaluate(tmpPath => { - window.apis?.dialog.setFakeDialogResult({ + return window.apis?.dialog.setFakeDialogResult({ filePath: tmpPath, }); }, tmpPath);