Skip to content

Commit

Permalink
fix: export then add test case (#7024)
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 committed May 24, 2024
1 parent 7c2f60c commit 5e1528b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 41 deletions.
1 change: 1 addition & 0 deletions packages/frontend/component/src/ui/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const Modal = forwardRef<HTMLDivElement, ModalProps>(
className={styles.closeButton}
aria-label="Close"
type="plain"
data-testid="modal-close-button"
{...closeButtonOptions}
>
<CloseIcon />
Expand Down
12 changes: 8 additions & 4 deletions packages/frontend/electron/src/helper/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ export async function saveDBFileAs(
): Promise<SaveDBFileResult> {
try {
const db = await ensureSQLiteDB(workspaceId);
const fakedResult = getFakedResult();

const ret =
getFakedResult() ??
fakedResult ??
(await mainRPC.showSaveDialog({
properties: ['showOverwriteConfirmation'],
title: 'Save Workspace',
Expand All @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions tests/affine-desktop/e2e/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
44 changes: 10 additions & 34 deletions tests/affine-desktop/e2e/workspace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 5e1528b

Please sign in to comment.