mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-05-08 22:07:32 +08:00
fix: test stability
This commit is contained in:
@@ -5,6 +5,26 @@ import { wait } from '../utils/common.js';
|
||||
import { getSurface } from '../utils/edgeless.js';
|
||||
import { setupEditor } from '../utils/setup.js';
|
||||
|
||||
async function waitForConnectorElement(
|
||||
surfaceView: ReturnType<typeof getSurface>,
|
||||
connectorId: string,
|
||||
timeout = 1000
|
||||
) {
|
||||
const startedAt = Date.now();
|
||||
|
||||
while (Date.now() - startedAt < timeout) {
|
||||
const connectorElement = surfaceView.renderRoot.querySelector<HTMLElement>(
|
||||
`[data-element-id="${connectorId}"]`
|
||||
);
|
||||
|
||||
if (connectorElement) return connectorElement;
|
||||
|
||||
await wait(50);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
describe('Connector rendering with DOM renderer', () => {
|
||||
beforeEach(async () => {
|
||||
const cleanup = await setupEditor('edgeless', [], {
|
||||
@@ -44,10 +64,9 @@ describe('Connector rendering with DOM renderer', () => {
|
||||
};
|
||||
const connectorId = surfaceModel.addElement(connectorProps);
|
||||
|
||||
await wait(100);
|
||||
|
||||
const connectorElement = surfaceView?.renderRoot.querySelector(
|
||||
`[data-element-id="${connectorId}"]`
|
||||
const connectorElement = await waitForConnectorElement(
|
||||
surfaceView,
|
||||
connectorId
|
||||
);
|
||||
|
||||
expect(connectorElement).not.toBeNull();
|
||||
@@ -73,11 +92,9 @@ describe('Connector rendering with DOM renderer', () => {
|
||||
};
|
||||
const connectorId = surfaceModel.addElement(connectorProps);
|
||||
|
||||
// Wait for path generation and rendering
|
||||
await wait(500);
|
||||
|
||||
const connectorElement = surfaceView?.renderRoot.querySelector(
|
||||
`[data-element-id="${connectorId}"]`
|
||||
const connectorElement = await waitForConnectorElement(
|
||||
surfaceView,
|
||||
connectorId
|
||||
);
|
||||
|
||||
expect(connectorElement).not.toBeNull();
|
||||
@@ -110,10 +127,9 @@ describe('Connector rendering with DOM renderer', () => {
|
||||
};
|
||||
const connectorId = surfaceModel.addElement(connectorProps);
|
||||
|
||||
await wait(100);
|
||||
|
||||
const connectorElement = surfaceView?.renderRoot.querySelector(
|
||||
`[data-element-id="${connectorId}"]`
|
||||
const connectorElement = await waitForConnectorElement(
|
||||
surfaceView,
|
||||
connectorId
|
||||
);
|
||||
|
||||
expect(connectorElement).not.toBeNull();
|
||||
@@ -139,10 +155,9 @@ describe('Connector rendering with DOM renderer', () => {
|
||||
};
|
||||
const connectorId = surfaceModel.addElement(connectorProps);
|
||||
|
||||
await wait(100);
|
||||
|
||||
let connectorElement = surfaceView.renderRoot.querySelector(
|
||||
`[data-element-id="${connectorId}"]`
|
||||
let connectorElement = await waitForConnectorElement(
|
||||
surfaceView,
|
||||
connectorId
|
||||
);
|
||||
expect(connectorElement).not.toBeNull();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user