-
Notifications
You must be signed in to change notification settings - Fork 673
Expand file tree
/
Copy pathrootGraphReadiness.test.ts
More file actions
72 lines (57 loc) · 2.09 KB
/
Copy pathrootGraphReadiness.test.ts
File metadata and controls
72 lines (57 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { useEventListener } from '@vueuse/core'
import { effectScope, nextTick, watchEffect } from 'vue'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { LGraph } from '@/lib/litegraph/src/litegraph'
import { getRootGraph, setRootGraph } from '@/scripts/__tests__/appTestUtils'
import { app } from '@/scripts/app'
describe('ComfyApp root graph readiness', () => {
let scope: ReturnType<typeof effectScope>
let previousRootGraph: LGraph | undefined
beforeEach(() => {
vi.spyOn(console, 'error').mockImplementation(() => {})
previousRootGraph = getRootGraph(app)
setRootGraph(app, undefined)
scope = effectScope()
})
afterEach(() => {
scope.stop()
setRootGraph(app, previousRootGraph)
vi.restoreAllMocks()
})
it('re-runs an effect reading isGraphReady when the graph is assigned', async () => {
const readiness: boolean[] = []
scope.run(() => {
watchEffect(() => readiness.push(app.isGraphReady))
})
expect(readiness).toEqual([false])
setRootGraph(app, new LGraph())
await nextTick()
expect(readiness).toEqual([false, true])
})
it('binds a rootGraph.events listener registered before the graph exists', async () => {
const onConfigured = vi.fn()
scope.run(() => {
useEventListener(() => app.rootGraph?.events, 'configured', onConfigured)
})
const graph = new LGraph()
setRootGraph(app, graph)
await nextTick()
graph.events.dispatch('configured')
expect(onConfigured).toHaveBeenCalledOnce()
})
it('rebinds a rootGraph.events listener when the graph is replaced', async () => {
const onConfigured = vi.fn()
const firstGraph = new LGraph()
setRootGraph(app, firstGraph)
scope.run(() => {
useEventListener(() => app.rootGraph?.events, 'configured', onConfigured)
})
const secondGraph = new LGraph()
setRootGraph(app, secondGraph)
await nextTick()
firstGraph.events.dispatch('configured')
expect(onConfigured).not.toHaveBeenCalled()
secondGraph.events.dispatch('configured')
expect(onConfigured).toHaveBeenCalledOnce()
})
})