feat(electron): backup panel (#9738)

fix PD-2071, PD-2059, PD-2069, PD-2068
This commit is contained in:
pengx17
2025-01-22 03:11:28 +00:00
committed by Peng Xiao
parent 862a9d0bc4
commit 088ae0ac0a
22 changed files with 754 additions and 30 deletions

View File

@@ -125,16 +125,6 @@ test('delete workspace', async ({ page }) => {
await expect(page.getByTestId('workspace-name-input')).toHaveValue(
'Delete Me'
);
const contentElement = page.getByTestId('setting-modal-content');
const boundingBox = await contentElement.boundingBox();
if (!boundingBox) {
throw new Error('boundingBox is null');
}
await page.mouse.move(
boundingBox.x + boundingBox.width / 2,
boundingBox.y + boundingBox.height / 2
);
await page.mouse.wheel(0, 500);
await page.getByTestId('delete-workspace-button').click();
await page.getByTestId('delete-workspace-input').fill('Delete Me');
await page.getByTestId('delete-workspace-confirm-button').click();

View File

@@ -101,3 +101,64 @@ test('export then add', async ({ page, appInfo, workspace }) => {
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
await clickSideBarCurrentWorkspaceBanner(page);
const newWorkspaceName = 'new-test-name';
await page.getByTestId('new-workspace').click();
await page.getByTestId('create-workspace-input').fill(newWorkspaceName);
await page.getByTestId('create-workspace-create-button').click();
//#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
//#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();
});

View File

@@ -3,7 +3,7 @@
"private": true,
"type": "module",
"scripts": {
"e2e": "DEBUG=pw:browser yarn playwright test"
"e2e": "yarn playwright test --reporter=list"
},
"devDependencies": {
"@affine-test/kit": "workspace:*",

View File

@@ -29,7 +29,6 @@ const config: PlaywrightTestConfig = {
};
if (process.env.CI) {
// todo: fix the flaky tests
config.retries = 5;
}

View File

@@ -160,7 +160,6 @@ export const test = base.extend<{
});
await use(electronApp);
console.log('Cleaning up...');
const pages = electronApp.windows();
for (const page of pages) {
await page.close();

View File

@@ -24,11 +24,9 @@ export async function removeWithRetry(
for (let i = 0; i < maxRetries; i++) {
try {
await fs.remove(filePath);
console.log(`File ${filePath} successfully deleted.`);
return true;
} catch (err: any) {
if (err.code === 'EBUSY' || err.code === 'EPERM') {
console.log(`File ${filePath} is busy or locked, retrying...`);
await setTimeout(delay);
} else {
console.error(`Failed to delete file ${filePath}:`, err);