mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-05-08 22:07:32 +08:00
chore: improve test stability
This commit is contained in:
@@ -5,14 +5,30 @@ import { wait } from '../utils/common.js';
|
||||
import { getSurface } from '../utils/edgeless.js';
|
||||
import { setupEditor } from '../utils/setup.js';
|
||||
|
||||
function hasConnectorPath(
|
||||
surfaceView: ReturnType<typeof getSurface>,
|
||||
connectorId: string
|
||||
) {
|
||||
const connector = surfaceView.model.getElementById(connectorId);
|
||||
if (!connector || !('path' in connector)) return false;
|
||||
|
||||
const { path } = connector as { path: unknown };
|
||||
return Array.isArray(path) && path.length >= 2;
|
||||
}
|
||||
|
||||
async function waitForConnectorElement(
|
||||
surfaceView: ReturnType<typeof getSurface>,
|
||||
connectorId: string,
|
||||
timeout = 1000
|
||||
timeout = 5000
|
||||
) {
|
||||
const startedAt = Date.now();
|
||||
|
||||
while (Date.now() - startedAt < timeout) {
|
||||
if (!hasConnectorPath(surfaceView, connectorId)) {
|
||||
await wait(50);
|
||||
continue;
|
||||
}
|
||||
|
||||
const connectorElement = surfaceView.renderRoot.querySelector<HTMLElement>(
|
||||
`[data-element-id="${connectorId}"]`
|
||||
);
|
||||
@@ -25,6 +41,26 @@ async function waitForConnectorElement(
|
||||
return null;
|
||||
}
|
||||
|
||||
async function waitForConnectorElementRemoval(
|
||||
surfaceView: ReturnType<typeof getSurface>,
|
||||
connectorId: string,
|
||||
timeout = 5000
|
||||
) {
|
||||
const startedAt = Date.now();
|
||||
|
||||
while (Date.now() - startedAt < timeout) {
|
||||
const connectorElement = surfaceView.renderRoot.querySelector(
|
||||
`[data-element-id="${connectorId}"]`
|
||||
);
|
||||
|
||||
if (!connectorElement) return true;
|
||||
|
||||
await wait(50);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
describe('Connector rendering with DOM renderer', () => {
|
||||
beforeEach(async () => {
|
||||
const cleanup = await setupEditor('edgeless', [], {
|
||||
@@ -163,11 +199,10 @@ describe('Connector rendering with DOM renderer', () => {
|
||||
|
||||
surfaceModel.deleteElement(connectorId);
|
||||
|
||||
await wait(100);
|
||||
|
||||
connectorElement = surfaceView.renderRoot.querySelector(
|
||||
`[data-element-id="${connectorId}"]`
|
||||
const removed = await waitForConnectorElementRemoval(
|
||||
surfaceView,
|
||||
connectorId
|
||||
);
|
||||
expect(connectorElement).toBeNull();
|
||||
expect(removed).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user