fix: test stability

This commit is contained in:
DarkSky
2026-04-09 11:21:25 +08:00
parent 156cfc7e76
commit 7138fea9db

View File

@@ -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();