|
1 | 1 | import { createTestingPinia } from '@pinia/testing' |
2 | 2 | import type * as VueUse from '@vueuse/core' |
3 | 3 | import { setActivePinia } from 'pinia' |
4 | | -import { effectScope, nextTick, ref } from 'vue' |
| 4 | +import { computed, effectScope, nextTick, ref } from 'vue' |
5 | 5 | import type { ShallowRef } from 'vue' |
6 | 6 | import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' |
7 | 7 |
|
@@ -277,6 +277,84 @@ describe('viewport virtualization behavior', () => { |
277 | 277 | scope.stop() |
278 | 278 | }) |
279 | 279 |
|
| 280 | + it('retries a settled refresh when the node manager becomes available', () => { |
| 281 | + vi.useFakeTimers() |
| 282 | + setActivePinia(createTestingPinia({ stubActions: false })) |
| 283 | + const { runAnimationFrame } = stubAnimationFrames() |
| 284 | + const nodeData = createNodeData(1) |
| 285 | + const node = createNode(1, 0, 0) |
| 286 | + const canvas = { |
| 287 | + ds: { |
| 288 | + scale: 1, |
| 289 | + offset: [0, 0], |
| 290 | + visible_area: [0, 0, 200, 200], |
| 291 | + computeVisibleArea: vi.fn() |
| 292 | + }, |
| 293 | + graph: {}, |
| 294 | + linkConnector: { renderLinks: [] }, |
| 295 | + viewport: [0, 0, 200, 200] |
| 296 | + } as unknown as LGraphCanvas |
| 297 | + const nodeManager = ref<GraphNodeManager | null>(null) |
| 298 | + const scope = effectScope() |
| 299 | + const virtualization = scope.run(() => |
| 300 | + useViewportVirtualization({ |
| 301 | + allNodes: [nodeData], |
| 302 | + canvas, |
| 303 | + enabled: true, |
| 304 | + nodeManager |
| 305 | + }) |
| 306 | + ) |
| 307 | + if (!virtualization) |
| 308 | + throw new Error('Failed to create virtualization scope') |
| 309 | + |
| 310 | + virtualization.onNodeMounted(nodeData.id) |
| 311 | + runAnimationFrame() |
| 312 | + runAnimationFrame() |
| 313 | + expect(virtualization.renderedNodes.value).toEqual([]) |
| 314 | + |
| 315 | + nodeManager.value = { |
| 316 | + getNode: vi.fn(() => node) |
| 317 | + } as unknown as GraphNodeManager |
| 318 | + vi.advanceTimersByTime(150) |
| 319 | + |
| 320 | + expect(virtualization.renderedNodes.value).toEqual([nodeData]) |
| 321 | + scope.stop() |
| 322 | + }) |
| 323 | + |
| 324 | + it('does not reconcile node ids when only node data changes', async () => { |
| 325 | + setActivePinia(createTestingPinia({ stubActions: false })) |
| 326 | + const { animationFrames, runAnimationFrame } = stubAnimationFrames() |
| 327 | + const title = ref('Initial') |
| 328 | + const allNodes = computed(() => [ |
| 329 | + { |
| 330 | + ...createNodeData(1), |
| 331 | + title: title.value |
| 332 | + } |
| 333 | + ]) |
| 334 | + const scope = effectScope() |
| 335 | + const virtualization = scope.run(() => |
| 336 | + useViewportVirtualization({ |
| 337 | + allNodes, |
| 338 | + canvas: null, |
| 339 | + enabled: true, |
| 340 | + nodeManager: null |
| 341 | + }) |
| 342 | + ) |
| 343 | + if (!virtualization) |
| 344 | + throw new Error('Failed to create virtualization scope') |
| 345 | + |
| 346 | + virtualization.onNodeMounted(toNodeId(1)) |
| 347 | + runAnimationFrame() |
| 348 | + runAnimationFrame() |
| 349 | + expect(animationFrames.size).toBe(0) |
| 350 | + |
| 351 | + title.value = 'Updated' |
| 352 | + await nextTick() |
| 353 | + |
| 354 | + expect(animationFrames.size).toBe(0) |
| 355 | + scope.stop() |
| 356 | + }) |
| 357 | + |
280 | 358 | it('recomputes the viewport after a canvas transform settles', () => { |
281 | 359 | vi.useFakeTimers() |
282 | 360 | setActivePinia(createTestingPinia({ stubActions: false })) |
|
0 commit comments