1
1
import { screen } from '@testing-library/react' ;
2
- import { NodeProps } from '@xyflow/react' ;
2
+ import { NodeProps , useViewport } from '@xyflow/react' ;
3
3
4
4
import { render } from '@/mocks/testing-utils' ;
5
5
import { InternalNode } from '@/types/internal' ;
6
6
import { Node } from '@/components/node/node' ;
7
7
8
+ vi . mock ( '@xyflow/react' , async ( ) => {
9
+ const actual = await vi . importActual < typeof import ( '@xyflow/react' ) > ( '@xyflow/react' ) ;
10
+ return {
11
+ ...actual ,
12
+ useViewport : vi . fn ( ) ,
13
+ } ;
14
+ } ) ;
15
+
8
16
describe ( 'node' , ( ) => {
9
17
const DEFAULT_PROPS : NodeProps < InternalNode > = {
10
18
id : 'id' ,
@@ -21,13 +29,52 @@ describe('node', () => {
21
29
positionAbsoluteY : 0 ,
22
30
} ;
23
31
32
+ beforeEach ( ( ) => {
33
+ const mockedViewport = vi . mocked ( useViewport ) ;
34
+ mockedViewport . mockReturnValue ( { zoom : 1 , x : 0 , y : 0 } ) ;
35
+ } ) ;
36
+
24
37
it ( 'Should show table node' , ( ) => {
25
- render ( < Node { ...DEFAULT_PROPS } type = "table" data = { { title : 'orders' , fields : [ ] } } /> ) ;
38
+ render (
39
+ < Node
40
+ { ...DEFAULT_PROPS }
41
+ type = "table"
42
+ data = { { title : 'orders' , fields : [ { name : 'orderId' , type : 'varchar' } ] } }
43
+ /> ,
44
+ ) ;
45
+ expect ( screen . getByRole ( 'img' , { name : 'Drag Icon' } ) ) . toBeInTheDocument ( ) ;
26
46
expect ( screen . getByText ( 'orders' ) ) . toBeInTheDocument ( ) ;
47
+ expect ( screen . getByText ( 'orderId' ) ) . toBeInTheDocument ( ) ;
48
+ expect ( screen . getByText ( 'varchar' ) ) . toBeInTheDocument ( ) ;
27
49
} ) ;
28
50
29
51
it ( 'Should show collection node' , ( ) => {
30
- render ( < Node { ...DEFAULT_PROPS } type = "collection" data = { { title : 'employees' , fields : [ ] } } /> ) ;
52
+ render (
53
+ < Node
54
+ { ...DEFAULT_PROPS }
55
+ type = "collection"
56
+ data = { { title : 'employees' , fields : [ { name : 'employeeId' , type : 'string' } ] } }
57
+ /> ,
58
+ ) ;
59
+ expect ( screen . getByRole ( 'img' , { name : 'Drag Icon' } ) ) . toBeInTheDocument ( ) ;
60
+ expect ( screen . getByText ( 'employees' ) ) . toBeInTheDocument ( ) ;
61
+ expect ( screen . getByText ( 'employeeId' ) ) . toBeInTheDocument ( ) ;
62
+ expect ( screen . getByText ( 'string' ) ) . toBeInTheDocument ( ) ;
63
+ } ) ;
64
+
65
+ it ( 'Should show contextual zoom' , ( ) => {
66
+ const mockedViewport = vi . mocked ( useViewport ) ;
67
+ mockedViewport . mockReturnValue ( { zoom : 0.2 , x : 0 , y : 0 } ) ;
68
+ render (
69
+ < Node
70
+ { ...DEFAULT_PROPS }
71
+ type = "collection"
72
+ data = { { title : 'employees' , fields : [ { name : 'employeeId' , type : 'string' } ] } }
73
+ /> ,
74
+ ) ;
75
+ expect ( screen . queryByRole ( 'img' , { name : 'Drag Icon' } ) ) . not . toBeInTheDocument ( ) ;
31
76
expect ( screen . getByText ( 'employees' ) ) . toBeInTheDocument ( ) ;
77
+ expect ( screen . queryByText ( 'employeeId' ) ) . not . toBeInTheDocument ( ) ;
78
+ expect ( screen . queryByText ( 'string' ) ) . not . toBeInTheDocument ( ) ;
32
79
} ) ;
33
80
} ) ;
0 commit comments