Skip to content

Commit 7f6ae2f

Browse files
committed
tests: add tests for useNodesData
1 parent 1dff3a1 commit 7f6ae2f

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import type { Node } from '@vue-flow/core'
2+
import { useNodesData } from '@vue-flow/core'
3+
import { defineComponent, h } from 'vue'
4+
import { getElements } from '../../utils'
5+
6+
const { nodes } = getElements()
7+
8+
describe('Composable: `useNodesData`', () => {
9+
describe('returns node data for a single node', () => {
10+
let data: any = null
11+
12+
const node = nodes[0]
13+
14+
beforeEach(() => {
15+
cy.vueFlow(
16+
{
17+
nodes: nodes.map((node) => ({ ...node, type: 'custom' })),
18+
},
19+
{},
20+
{
21+
'node-custom': defineComponent({
22+
setup() {
23+
data = useNodesData(nodes[0].id)
24+
25+
return () => h('div', 'Custom Node')
26+
},
27+
}),
28+
},
29+
)
30+
})
31+
32+
it('should return the node data', () => {
33+
expect(data.value).to.deep.equal(node.data)
34+
})
35+
})
36+
37+
describe('returns node data for multiple nodes', () => {
38+
let data: any = null
39+
40+
const nodeIds = nodes.map((node) => node.id)
41+
42+
beforeEach(() => {
43+
cy.vueFlow(
44+
{
45+
nodes: nodes.map((node) => ({ ...node, type: 'custom' })),
46+
},
47+
{},
48+
{
49+
'node-custom': defineComponent({
50+
setup() {
51+
data = useNodesData(nodeIds)
52+
53+
return () => h('div', 'Custom Node')
54+
},
55+
}),
56+
},
57+
)
58+
})
59+
60+
it('should return the node data', () => {
61+
expect(data.value).to.deep.equal(nodes.map((node) => node.data))
62+
})
63+
})
64+
65+
describe('returns node data for multiple nodes with a guard', () => {
66+
let data: any = null
67+
68+
const nodeIds = nodes.map((node) => node.id)
69+
70+
beforeEach(() => {
71+
cy.vueFlow(
72+
{
73+
nodes: nodes.map((node) => ({ ...node, type: 'custom' })),
74+
},
75+
{},
76+
{
77+
'node-custom': defineComponent({
78+
setup() {
79+
data = useNodesData(nodeIds, (node): node is Node<{ randomData: number }> => node.type === 'custom')
80+
81+
return () => h('div', 'Custom Node')
82+
},
83+
}),
84+
},
85+
)
86+
})
87+
88+
it('should return the node data', () => {
89+
expect(data.value).to.deep.equal(nodes.map((node) => node.data))
90+
})
91+
})
92+
})

0 commit comments

Comments
 (0)