AFFiNE/tests/affine-desktop/e2e/workspace.spec.ts

102 lines
3.1 KiB
TypeScript
Raw Normal View History

import path from 'node:path';
import type { apis } from '@affine/electron-api';
import { test } from '@affine-test/kit/electron';
2024-05-24 07:49:07 +03:00
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';
declare global {
interface Window {
2024-08-19 17:24:34 +03:00
__apis: typeof apis;
}
}
test('check workspace has a DB file', async ({ appInfo, workspace }) => {
const w = await workspace.current();
const dbPath = path.join(
appInfo.sessionData,
'workspaces',
2023-12-15 10:20:50 +03:00
w.meta.id,
'storage.db'
);
// check if db file exists
expect(await fs.exists(dbPath)).toBe(true);
});
2024-05-24 07:49:07 +03:00
test('export then add', async ({ page, appInfo, workspace }) => {
await clickNewPageButton(page);
const w = await workspace.current();
2024-05-24 07:49:07 +03:00
await getBlockSuiteEditorTitle(page).fill('test1');
2023-07-28 18:15:32 +03:00
await page.getByTestId('slider-bar-workspace-setting-button').click();
await expect(page.getByTestId('setting-modal')).toBeVisible();
2023-12-15 10:20:50 +03:00
const originalId = w.meta.id;
const newWorkspaceName = 'new-test-name';
// goto workspace setting
await page.getByTestId('workspace-list-item').click();
const input = page.getByTestId('workspace-name-input');
await expect(input).toBeVisible();
// change workspace name
await input.fill(newWorkspaceName);
await page.getByTestId('save-workspace-name').click();
await page.waitForSelector('text="Update workspace name success"');
2023-12-15 10:20:50 +03:00
const tmpPath = path.join(appInfo.sessionData, w.meta.id + '-tmp.db');
// export db file to tmp folder
await page.evaluate(tmpPath => {
2024-08-19 17:24:34 +03:00
return window.__apis?.dialog.setFakeDialogResult({
filePath: tmpPath,
});
}, tmpPath);
await page.getByTestId('export-affine-backup').click();
await page.waitForSelector('text="Export success"');
await page.waitForTimeout(1000);
expect(await fs.exists(tmpPath)).toBe(true);
await page.getByTestId('modal-close-button').click();
// add 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.evaluate(tmpPath => {
2024-08-19 17:24:34 +03:00
return window.__apis?.dialog.setFakeDialogResult({
filePath: tmpPath,
});
}, tmpPath);
// load the db file
await page.getByTestId('add-workspace').click();
// should show "Added Successfully" dialog
// await page.waitForSelector('text="Added Successfully"');
// await page.getByTestId('create-workspace-continue-button').click();
// sleep for a while to wait for the workspace to be added :D
2023-07-31 08:47:13 +03:00
await page.waitForTimeout(2000);
const newWorkspace = await workspace.current();
2023-12-15 10:20:50 +03:00
expect(newWorkspace.meta.id).not.toBe(originalId);
// check its name is correct
await expect(page.getByTestId('workspace-name')).toHaveText(newWorkspaceName);
2023-07-28 18:15:32 +03:00
// find button which has the title "test1"
const test1PageButton = await page.waitForSelector(`text="test1"`);
await test1PageButton.click();
const title = page.locator('[data-block-is-title] >> text="test1"');
await expect(title).toBeVisible();
});