|
1 |
| -import { beforeEach, describe, expect, it } from 'vitest' |
| 1 | +import { beforeEach, describe, expect, it, vi } from 'vitest' |
2 | 2 |
|
3 | 3 | import { layoutStore } from '@/renderer/core/layout/store/layoutStore'
|
4 | 4 | import {
|
@@ -165,10 +165,11 @@ describe('layoutStore CRDT operations', () => {
|
165 | 165 | actor: layoutStore.getCurrentActor()
|
166 | 166 | })
|
167 | 167 |
|
168 |
| - // Wait for async notification |
169 |
| - await new Promise((resolve) => setTimeout(resolve, 50)) |
| 168 | + // Wait for onChange callback to be called (uses setTimeout internally) |
| 169 | + await vi.waitFor(() => { |
| 170 | + expect(changes.length).toBeGreaterThanOrEqual(1) |
| 171 | + }) |
170 | 172 |
|
171 |
| - expect(changes.length).toBeGreaterThanOrEqual(1) |
172 | 173 | const lastChange = changes[changes.length - 1]
|
173 | 174 | expect(lastChange.source).toBe('vue')
|
174 | 175 | expect(lastChange.operation.actor).toBe('user-123')
|
@@ -198,11 +199,14 @@ describe('layoutStore CRDT operations', () => {
|
198 | 199 | const newBounds = { x: 40, y: 60, width: 220, height: 120 }
|
199 | 200 | layoutStore.batchUpdateNodeBounds([{ nodeId, bounds: newBounds }])
|
200 | 201 |
|
201 |
| - await new Promise((resolve) => setTimeout(resolve, 50)) |
| 202 | + // Wait for onChange callback to be called (uses setTimeout internally) |
| 203 | + await vi.waitFor(() => { |
| 204 | + expect(changes.length).toBeGreaterThan(0) |
| 205 | + const lastChange = changes[changes.length - 1] |
| 206 | + expect(lastChange.operation.type).toBe('batchUpdateBounds') |
| 207 | + }) |
202 | 208 |
|
203 |
| - expect(changes.length).toBeGreaterThan(0) |
204 | 209 | const lastChange = changes[changes.length - 1]
|
205 |
| - expect(lastChange.operation.type).toBe('batchUpdateBounds') |
206 | 210 | if (lastChange.operation.type === 'batchUpdateBounds') {
|
207 | 211 | expect(lastChange.nodeIds).toContain(nodeId)
|
208 | 212 | expect(lastChange.operation.bounds[nodeId]?.bounds).toEqual(newBounds)
|
|
0 commit comments