diff --git a/blocksuite/integration-test/src/__tests__/edgeless/connector-dom.spec.ts b/blocksuite/integration-test/src/__tests__/edgeless/connector-dom.spec.ts index 952eb7342..846814e55 100644 --- a/blocksuite/integration-test/src/__tests__/edgeless/connector-dom.spec.ts +++ b/blocksuite/integration-test/src/__tests__/edgeless/connector-dom.spec.ts @@ -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, + 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, 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( `[data-element-id="${connectorId}"]` ); @@ -25,6 +41,26 @@ async function waitForConnectorElement( return null; } +async function waitForConnectorElementRemoval( + surfaceView: ReturnType, + 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); }); });