Some checks failed
Build & Test / Analyze (javascript, affine) (push) Failing after 4s
Build & Test / Analyze (typescript, affine) (push) Failing after 3s
Build & Test / Rust test filter (push) Failing after 4s
Build & Test / Check yarn binary (push) Failing after 3s
Build & Test / E2E BlockSuite Test (3) (push) Failing after 3s
Build & Test / Analyze (javascript, blocksuite) (push) Failing after 3s
Build & Test / Analyze (typescript, blocksuite) (push) Failing after 3s
Build & Test / Mobile native build filter (push) Failing after 3s
Build & Test / E2E BlockSuite Test (1) (push) Failing after 4s
Build & Test / E2E BlockSuite Test (2) (push) Failing after 4s
Build & Test / E2E Mobile Test (1) (push) Failing after 3s
Build & Test / Unit Test (1) (push) Has been skipped
Build & Test / Unit Test (2) (push) Has been skipped
Build & Test / Unit Test (3) (push) Has been skipped
Build & Test / Unit Test (4) (push) Has been skipped
Build & Test / Unit Test (5) (push) Has been skipped
Build & Test / Native Unit Test (push) Has been skipped
Build & Test / E2E BlockSuite Test (4) (push) Failing after 3s
Build & Test / E2E BlockSuite Test (5) (push) Failing after 3s
Build & Test / E2E BlockSuite Cross Browser Test (push) Failing after 3s
Build & Test / E2E Mobile Test (2) (push) Failing after 3s
Build & Test / Build AFFiNE native (x86_64-unknown-linux-gnu) (push) Failing after 3s
Build & Test / Build Server native (push) Failing after 3s
Build & Test / Check Git Status (push) Has been skipped
Build & Test / Server Test (0, 4) (push) Has been skipped
Build & Test / Server Test (1, 4) (push) Has been skipped
Build & Test / Server Test (2, 4) (push) Has been skipped
Build & Test / Server Test (3, 4) (push) Has been skipped
Build & Test / Server Test with Elasticsearch (push) Has been skipped
Build & Test / Build @affine/electron renderer (push) Failing after 3s
Build & Test / Copilot test filter (push) Failing after 4s
Build & Test / Lint Rust (push) Has been skipped
Build & Test / Server Test with Embedded Search (push) Has been skipped
Build & Test / Server Test with Manticore Search (push) Has been skipped
Build & Test / Server E2E Test (push) Has been skipped
Build & Test / Cloud Desktop E2E Test (push) Has been skipped
Build & Test / Cloud E2E Test 1/2 (push) Has been skipped
Build & Test / Cloud E2E Test 2/2 (push) Has been skipped
Build & Test / Build Android app (push) Has been skipped
Build & Test / Test Android app (push) Has been skipped
Build & Test / Run native tests (push) Has been skipped
Build & Test / Server Copilot Api Test (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (1, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (2, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (3, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (4, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (5, 5) (push) Has been skipped
Release / Canary Gate (push) Has been skipped
Build & Test / Build AFFiNE native (aarch64-apple-darwin) (push) Has been cancelled
Build & Test / Lint (push) Has been cancelled
Build & Test / Typecheck (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-apple-darwin) (push) Has been cancelled
Build & Test / Desktop Test (ubuntu-latest, linux, x64, x86_64-unknown-linux-gnu, true) (push) Has been cancelled
Build & Test / Desktop Test (windows-latest, windows, x64, x86_64-pc-windows-msvc, true) (push) Has been cancelled
Build & Test / E2E Test (1) (push) Has been cancelled
Build & Test / E2E Test (2) (push) Has been cancelled
Build & Test / E2E Test (3) (push) Has been cancelled
Build & Test / E2E Test (4) (push) Has been cancelled
Build & Test / E2E Test (5) (push) Has been cancelled
Build & Test / Build AFFiNE native (aarch64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, arm64, aarch64-apple-darwin, true) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, x64, x86_64-apple-darwin, false) (push) Has been cancelled
Build & Test / 3, 2, 1 Launch (push) Has been cancelled
Build & Test / Build iOS app (push) Has been cancelled
Copilot Test Automatically / Setup Test (push) Failing after 1s
Release / Prepare (push) Failing after 2s
Release / Release Cloud (push) Has been skipped
Release / Release Desktop (push) Has been skipped
Release / Release Docker Image (push) Has been skipped
Release / Release Mobile (push) Has been skipped
189 lines
6.0 KiB
TypeScript
189 lines
6.0 KiB
TypeScript
import path from 'node:path';
|
|
|
|
import type { apis } from '@affine/electron-api';
|
|
import { test } from '@affine-test/kit/electron';
|
|
import {
|
|
getBlockSuiteEditorTitle,
|
|
getPageByTitle,
|
|
waitForEditorLoad,
|
|
} from '@affine-test/kit/utils/page-logic';
|
|
import {
|
|
clickNewPageButton,
|
|
clickSideBarCurrentWorkspaceBanner,
|
|
} from '@affine-test/kit/utils/sidebar';
|
|
import { createLocalWorkspace } from '@affine-test/kit/utils/workspace';
|
|
import { expect } from '@playwright/test';
|
|
import fs from 'fs-extra';
|
|
import type { ElectronApplication } from 'playwright';
|
|
|
|
declare global {
|
|
interface Window {
|
|
__apis: typeof apis;
|
|
}
|
|
}
|
|
|
|
async function mockNextSaveDialog(
|
|
electronApp: ElectronApplication,
|
|
filePath: string
|
|
) {
|
|
await electronApp.evaluate(({ dialog }, mockedFilePath) => {
|
|
const original = dialog.showSaveDialog.bind(dialog);
|
|
dialog.showSaveDialog = async () => {
|
|
dialog.showSaveDialog = original;
|
|
return { canceled: false, filePath: mockedFilePath };
|
|
};
|
|
}, filePath);
|
|
}
|
|
|
|
async function mockNextOpenDialog(
|
|
electronApp: ElectronApplication,
|
|
filePath: string
|
|
) {
|
|
await electronApp.evaluate(({ dialog }, mockedFilePath) => {
|
|
const original = dialog.showOpenDialog.bind(dialog);
|
|
dialog.showOpenDialog = async () => {
|
|
dialog.showOpenDialog = original;
|
|
return { canceled: false, filePaths: [mockedFilePath] };
|
|
};
|
|
}, filePath);
|
|
}
|
|
|
|
test('check workspace has a DB file', async ({ appInfo, workspace }) => {
|
|
const w = await workspace.current();
|
|
const dbPath = path.join(
|
|
appInfo.sessionData,
|
|
'workspaces',
|
|
'local',
|
|
w.meta.id,
|
|
'storage.db'
|
|
);
|
|
// check if db file exists
|
|
expect(await fs.exists(dbPath)).toBe(true);
|
|
});
|
|
|
|
test('export then add', async ({ electronApp, page, appInfo, workspace }) => {
|
|
await clickNewPageButton(page);
|
|
const w = await workspace.current();
|
|
|
|
await getBlockSuiteEditorTitle(page).fill('test1');
|
|
|
|
await page.getByTestId('slider-bar-workspace-setting-button').click();
|
|
await expect(page.getByTestId('setting-modal')).toBeVisible();
|
|
|
|
const originalId = w.meta.id;
|
|
|
|
const newWorkspaceName = 'new-test-name';
|
|
|
|
// goto workspace setting
|
|
await page.getByTestId('workspace-setting:preference').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"');
|
|
|
|
const tmpPath = path.join(appInfo.sessionData, w.meta.id + '-tmp.db');
|
|
|
|
// export db file to tmp folder
|
|
await mockNextSaveDialog(electronApp, tmpPath);
|
|
|
|
await page.getByTestId('workspace-setting:storage').click();
|
|
await page.getByTestId('export-affine-backup').click();
|
|
await page.waitForSelector('text="Export success"');
|
|
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 mockNextOpenDialog(electronApp, tmpPath);
|
|
|
|
// load the db file
|
|
await page.getByTestId('add-workspace').click();
|
|
|
|
// should show "Added Successfully" dialog
|
|
// await page.waitForSelector('text="Added Successfully"');
|
|
|
|
await expect
|
|
.poll(async () => {
|
|
const newWorkspace = await workspace.current();
|
|
return newWorkspace.meta.id !== originalId;
|
|
})
|
|
.toBe(true);
|
|
|
|
// check its name is correct
|
|
await expect(page.getByTestId('workspace-name')).toHaveText(newWorkspaceName);
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
// find button which has the title "test1"
|
|
await getPageByTitle(page, 'test1').click();
|
|
await waitForEditorLoad(page);
|
|
const title = page.locator('[data-block-is-title] >> text="test1"');
|
|
await expect(title).toBeVisible();
|
|
});
|
|
|
|
test('delete workspace and then restore it from backup', async ({ page }) => {
|
|
//#region 1. create a new workspace
|
|
const newWorkspaceName = 'new-test-name';
|
|
await createLocalWorkspace({ name: newWorkspaceName }, page);
|
|
//#endregion
|
|
|
|
//#region 2. create a page in the new workspace (will verify later if it is successfully recovered)
|
|
await clickNewPageButton(page);
|
|
|
|
await getBlockSuiteEditorTitle(page).fill('test1');
|
|
//#endregion
|
|
|
|
//#region 3. delete the workspace
|
|
await page.getByTestId('slider-bar-workspace-setting-button').click();
|
|
await expect(page.getByTestId('setting-modal')).toBeVisible();
|
|
|
|
await page.getByTestId('workspace-setting:preference').click();
|
|
await page.getByTestId('delete-workspace-button').click();
|
|
await page.getByTestId('delete-workspace-input').fill(newWorkspaceName);
|
|
|
|
await page.getByTestId('delete-workspace-confirm-button').click();
|
|
|
|
// we are back to the original workspace
|
|
await expect(page.getByTestId('workspace-name')).toContainText(
|
|
'Demo Workspace'
|
|
);
|
|
//#endregion
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
//#region 4. restore the workspace from backup
|
|
await page.getByTestId('slider-bar-workspace-setting-button').click();
|
|
await expect(page.getByTestId('setting-modal')).toBeVisible();
|
|
|
|
await page.getByTestId('backup-panel-trigger').click();
|
|
await expect(page.getByTestId('backup-workspace-item')).toHaveCount(1);
|
|
await page.getByTestId('backup-workspace-item').click();
|
|
await page.getByRole('menuitem', { name: 'Enable local workspace' }).click();
|
|
const toast = page.locator(
|
|
'[data-sonner-toast]:has-text("Workspace enabled successfully")'
|
|
);
|
|
await expect(toast).toBeVisible();
|
|
await toast.getByRole('button', { name: 'Open' }).click();
|
|
//#endregion
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
// verify the workspace name & page title
|
|
await expect(page.getByTestId('workspace-name')).toContainText(
|
|
newWorkspaceName
|
|
);
|
|
// 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();
|
|
});
|