fix(infra): avoid data loss (#6111)

This commit is contained in:
EYHN
2024-03-14 06:27:49 +00:00
parent d2bad68b74
commit b9fc848824
6 changed files with 106 additions and 6 deletions

View File

@@ -15,7 +15,10 @@ import {
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { clickUserInfoCard } from '@affine-test/kit/utils/setting';
import { clickSideBarSettingButton } from '@affine-test/kit/utils/sidebar';
import {
clickSideBarCurrentWorkspaceBanner,
clickSideBarSettingButton,
} from '@affine-test/kit/utils/sidebar';
import { createLocalWorkspace } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
@@ -294,3 +297,72 @@ test('can sync svg between different browsers', async ({ page, browser }) => {
expect(svg2).toEqual(svg1);
}
});
test('When the first sync is not completed, should always show loading', async ({
page,
browser,
}) => {
await page.reload();
await waitForEditorLoad(page);
await createLocalWorkspace(
{
name: 'test',
},
page
);
await enableCloudWorkspace(page);
await clickNewPageButton(page);
await waitForEditorLoad(page);
const title = getBlockSuiteEditorTitle(page);
await title.pressSequentially('TEST TITLE', {
delay: 50,
});
const context = await browser.newContext();
await skipOnboarding(context);
const page2 = await context.newPage();
await loginUser(page2, user.email);
// simulate sync stuck
await page2.evaluate(() => {
(window as any)._TEST_SIMULATE_SYNC_LAG = new Promise(() => {});
});
const localWorkspaceUrl = page2.url();
await clickSideBarCurrentWorkspaceBanner(page2);
await page2.getByTestId('workspace-card').getByText('test').click(); // enter "test" workspace
await page2.waitForTimeout(1000);
await expect(
page2.getByTestId('page-list-item').getByText('TEST TITLE')
).not.toBeVisible(); // should be loading
// Simulate user refresh and re-enter workspace, should still be loading
await page2.goto(localWorkspaceUrl);
// setup sync lag
await page2.evaluate(() => {
(window as any).resolveSyncLag = null;
(window as any)._TEST_SIMULATE_SYNC_LAG = new Promise(resolve => {
(window as any).resolveSyncLag = resolve;
});
});
await clickSideBarCurrentWorkspaceBanner(page2);
await page2.getByTestId('workspace-card').getByText('test').click(); // enter "test" workspace
await page2.waitForTimeout(1000);
await expect(
page2.getByTestId('page-list-item').getByText('TEST TITLE')
).not.toBeVisible(); // should be loading
await page2.evaluate(() => {
(window as any).resolveSyncLag();
}); // start syncing
await page2.getByTestId('page-list-item').getByText('TEST TITLE').click(); // should be able to click page
await waitForEditorLoad(page2);
expect(await getBlockSuiteEditorTitle(page2).innerText()).toContain(
'TEST TITLE'
);
});