2023-05-09 10:30:01 +03:00
|
|
|
import path from 'node:path';
|
|
|
|
|
|
|
|
import { expect } from '@playwright/test';
|
|
|
|
import fs from 'fs-extra';
|
|
|
|
|
|
|
|
import { test } from './fixture';
|
|
|
|
|
2023-07-04 20:47:42 +03:00
|
|
|
test('check workspace has a DB file', async ({ appInfo, workspace }) => {
|
2023-05-09 10:30:01 +03:00
|
|
|
const w = await workspace.current();
|
|
|
|
const dbPath = path.join(
|
|
|
|
appInfo.sessionData,
|
|
|
|
'workspaces',
|
|
|
|
w.id,
|
|
|
|
'storage.db'
|
|
|
|
);
|
|
|
|
// check if db file exists
|
|
|
|
expect(await fs.exists(dbPath)).toBe(true);
|
|
|
|
});
|
|
|
|
|
2023-07-06 15:48:20 +03:00
|
|
|
test('move workspace db file', async ({ page, appInfo, workspace }) => {
|
2023-05-09 10:30:01 +03:00
|
|
|
const w = await workspace.current();
|
2023-07-06 15:48:20 +03:00
|
|
|
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();
|
2023-05-09 10:30:01 +03:00
|
|
|
|
2023-05-29 07:53:15 +03:00
|
|
|
const tmpPath = path.join(appInfo.sessionData, w.id + '-tmp-dir');
|
2023-05-09 10:30:01 +03:00
|
|
|
|
|
|
|
// move db file to tmp folder
|
|
|
|
await page.evaluate(tmpPath => {
|
2023-06-07 17:47:02 +03:00
|
|
|
// @ts-expect-error
|
2023-05-09 10:30:01 +03:00
|
|
|
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);
|
2023-05-29 07:53:15 +03:00
|
|
|
// 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);
|
2023-05-09 10:30:01 +03:00
|
|
|
});
|
|
|
|
|
2023-07-06 15:48:20 +03:00
|
|
|
test('export then add', async ({ page, appInfo, workspace }) => {
|
2023-05-09 10:30:01 +03:00
|
|
|
const w = await workspace.current();
|
2023-07-06 15:48:20 +03:00
|
|
|
|
|
|
|
await page.getByTestId('slider-bar-workspace-setting-button').click();
|
|
|
|
await expect(page.getByTestId('setting-modal')).toBeVisible();
|
2023-05-09 10:30:01 +03:00
|
|
|
|
|
|
|
const originalId = w.id;
|
|
|
|
|
|
|
|
const newWorkspaceName = 'new-test-name';
|
|
|
|
|
2023-07-06 15:48:20 +03:00
|
|
|
// goto workspace setting
|
|
|
|
await page.getByTestId('workspace-list-item').click();
|
|
|
|
|
2023-05-09 10:30:01 +03:00
|
|
|
// change workspace name
|
|
|
|
await page.getByTestId('workspace-name-input').fill(newWorkspaceName);
|
|
|
|
await page.getByTestId('save-workspace-name').click();
|
|
|
|
await page.waitForSelector('text="Update workspace name success"');
|
2023-07-06 15:48:20 +03:00
|
|
|
await page.waitForTimeout(500);
|
2023-05-09 10:30:01 +03:00
|
|
|
|
|
|
|
const tmpPath = path.join(appInfo.sessionData, w.id + '-tmp.db');
|
|
|
|
|
2023-05-29 07:53:15 +03:00
|
|
|
// export db file to tmp folder
|
2023-05-09 10:30:01 +03:00
|
|
|
await page.evaluate(tmpPath => {
|
2023-06-07 17:47:02 +03:00
|
|
|
// @ts-expect-error
|
2023-05-09 10:30:01 +03:00
|
|
|
window.apis?.dialog.setFakeDialogResult({
|
|
|
|
filePath: tmpPath,
|
|
|
|
});
|
|
|
|
}, tmpPath);
|
|
|
|
|
|
|
|
await page.getByTestId('export-affine-backup').click();
|
|
|
|
await page.waitForSelector('text="Export success"');
|
|
|
|
|
|
|
|
expect(await fs.exists(tmpPath)).toBe(true);
|
|
|
|
|
2023-07-06 15:48:20 +03:00
|
|
|
await page.getByTestId('modal-close-button').click();
|
|
|
|
|
2023-05-09 10:30:01 +03:00
|
|
|
// add workspace
|
|
|
|
// we are reusing the same db file so that we don't need to maintain one
|
|
|
|
// in the codebase
|
|
|
|
await page.getByTestId('current-workspace').click();
|
|
|
|
await page.getByTestId('add-or-new-workspace').click();
|
|
|
|
|
|
|
|
await page.evaluate(tmpPath => {
|
2023-06-07 17:47:02 +03:00
|
|
|
// @ts-expect-error
|
2023-05-09 10:30:01 +03:00
|
|
|
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
|
|
|
|
await page.waitForTimeout(2000);
|
|
|
|
const newWorkspace = await workspace.current();
|
|
|
|
expect(newWorkspace.id).not.toBe(originalId);
|
|
|
|
// check its name is correct
|
|
|
|
await expect(page.getByTestId('workspace-name')).toHaveText(newWorkspaceName);
|
|
|
|
});
|