Files
AFFiNE-Mirror/tests/affine-local/e2e/local-first-avatar.spec.ts
EYHN 59ef4b227b refactor(nbstore): improve doc state management (#12359)
Move the `waitForSynced` method from `frontend` to `nbstore worker` to make the wait more reliable

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Added explicit tracking of document updating state to indicate when data is being applied or saved.
  - Introduced new methods to wait for update and synchronization completion with abort support.

- **Improvements**
  - Applied throttling with leading and trailing emissions to state observables for smoother UI updates.
  - Refined synchronization waiting logic for clearer separation between update completion and sync completion.
  - Removed throttling in workspace selector component for more immediate state feedback.
  - Updated import and clipper services to use the new synchronization waiting methods.
  - Simplified asynchronous waiting logic in indexer synchronization methods.

- **Bug Fixes**
  - Enhanced accuracy and reliability of document update and sync status indicators.

- **Tests**
  - Increased wait timeout in avatar selection test to improve stability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-05-20 07:33:20 +00:00

79 lines
2.6 KiB
TypeScript

import { ProjectRoot, test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { createLocalWorkspace } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
test('should create a page with a local first avatar and remove it', async ({
page,
workspace,
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await clickNewPageButton(page);
await createLocalWorkspace({ name: 'Test Workspace 1' }, page);
await page.waitForTimeout(1000);
await page.getByTestId('workspace-name').click();
await page
.getByTestId('workspace-card')
.nth(1)
.click({ position: { x: 10, y: 10 } });
await page.getByTestId('settings-modal-trigger').click();
await page.getByTestId('workspace-setting:preference').click();
await page
.getByTestId('upload-avatar')
.setInputFiles(ProjectRoot.join('tests', 'fixtures', 'blue.png').value);
await page.mouse.click(0, 0);
await page.getByTestId('workspace-name').click();
await page
.getByTestId('workspace-card')
.nth(0)
.getByTestId('workspace-avatar')
.click();
await page.waitForTimeout(2000);
await page.getByTestId('workspace-name').click();
await page
.getByTestId('workspace-card')
.nth(1)
.getByTestId('workspace-avatar')
.click();
const avatarCanvas = await page
.getByTestId('workspace-avatar')
.locator('canvas')
.first()
.elementHandle();
const avatarPixelData = await page.evaluate(
({ avatarCanvas }) => {
return Array.from(
(avatarCanvas as HTMLCanvasElement)
.getContext('2d')!
.getImageData(1, 1, 1, 1).data // get pixel data of the avatar
);
},
{ avatarCanvas }
);
expect(avatarPixelData).toEqual([0, 0, 255, 255]); // blue color
// Click remove button to remove workspace avatar
await page.getByTestId('settings-modal-trigger').click();
await page.getByTestId('workspace-setting:preference').click();
await page.getByTestId('workspace-setting-avatar').hover();
await page.getByTestId('workspace-setting-remove-avatar-button').click();
await page.mouse.click(0, 0);
await page.waitForTimeout(1000);
await page.getByTestId('workspace-name').click();
await page.getByTestId('workspace-card').nth(1).click();
const removedAvatarImage = await page
.getByTestId('workspace-avatar')
.locator('canvas')
.count();
expect(removedAvatarImage).toBe(0);
const currentWorkspace = await workspace.current();
expect(currentWorkspace.meta.flavour).toContain('local');
});