1
- import { Position , useNodes } from '@xyflow/react' ;
1
+ import { Node , Position , useNodes } from '@xyflow/react' ;
2
2
import { ComponentProps } from 'react' ;
3
3
4
4
import { EMPLOYEES_NODE , ORDERS_NODE } from '@/mocks/datasets/nodes' ;
5
5
import { render , screen } from '@/mocks/testing-utils' ;
6
6
import { FloatingEdge } from '@/components/edge/floating-edge' ;
7
+ import { DEFAULT_FIELD_HEIGHT , DEFAULT_NODE_WIDTH } from '@/utilities/constants' ;
7
8
8
9
vi . mock ( '@xyflow/react' , async ( ) => {
9
10
const actual = await vi . importActual < typeof import ( '@xyflow/react' ) > ( '@xyflow/react' ) ;
@@ -13,14 +14,23 @@ vi.mock('@xyflow/react', async () => {
13
14
} ;
14
15
} ) ;
15
16
17
+ function mockNodes ( nodes : Node [ ] ) {
18
+ const mockedNodes = vi . mocked ( useNodes ) ;
19
+ mockedNodes . mockReturnValue ( nodes ) ;
20
+ }
21
+
16
22
describe ( 'floating-edge' , ( ) => {
23
+ const nodes = [
24
+ { ...ORDERS_NODE , data : { title : ORDERS_NODE . title , fields : ORDERS_NODE . fields } } ,
25
+ { ...EMPLOYEES_NODE , data : { title : EMPLOYEES_NODE . title , fields : EMPLOYEES_NODE . fields } } ,
26
+ ] ;
27
+
17
28
beforeEach ( ( ) => {
18
- const nodes = [
19
- { ...ORDERS_NODE , data : { title : ORDERS_NODE . title , fields : ORDERS_NODE . fields } } ,
20
- { ...EMPLOYEES_NODE , data : { title : EMPLOYEES_NODE . title , fields : EMPLOYEES_NODE . fields } } ,
21
- ] ;
22
- const mockedNodes = vi . mocked ( useNodes ) ;
23
- mockedNodes . mockReturnValue ( nodes ) ;
29
+ mockNodes ( nodes ) ;
30
+ } ) ;
31
+
32
+ afterEach ( ( ) => {
33
+ vi . clearAllMocks ( ) ;
24
34
} ) ;
25
35
26
36
const renderComponent = ( props ?: Partial < ComponentProps < typeof FloatingEdge > > ) => {
@@ -40,14 +50,44 @@ describe('floating-edge', () => {
40
50
) ;
41
51
} ;
42
52
43
- it ( 'Should render edge' , ( ) => {
44
- renderComponent ( ) ;
45
- const path = screen . getByTestId ( 'floating-edge-orders-to-employees' ) ;
46
- expect ( path ) . toHaveAttribute ( 'id' , 'orders-to-employees' ) ;
47
- expect ( path ) . toHaveAttribute (
48
- 'd' ,
49
- 'M240 143.5L240 163.5L 240,213Q 240,218 245,218L 381,218Q 386,218 386,223L386 272.5L386 292.5' ,
50
- ) ;
53
+ describe ( 'Without measured heights' , ( ) => {
54
+ it ( 'Should render edge' , ( ) => {
55
+ renderComponent ( ) ;
56
+ const path = screen . getByTestId ( 'floating-edge-orders-to-employees' ) ;
57
+ expect ( path ) . toHaveAttribute ( 'id' , 'orders-to-employees' ) ;
58
+ expect ( path ) . toHaveAttribute (
59
+ 'd' ,
60
+ 'M269.5 180L289.5 180L 386.5,180Q 391.5,180 391.5,185L 391.5,295Q 391.5,300 386.5,300L371.5 300' ,
61
+ ) ;
62
+ } ) ;
63
+ } ) ;
64
+
65
+ describe ( 'With measured heights' , ( ) => {
66
+ it ( 'Should render edge' , ( ) => {
67
+ mockNodes ( [
68
+ {
69
+ ...nodes [ 0 ] ,
70
+ measured : {
71
+ width : DEFAULT_NODE_WIDTH ,
72
+ height : DEFAULT_FIELD_HEIGHT * 2 ,
73
+ } ,
74
+ } ,
75
+ {
76
+ ...nodes [ 1 ] ,
77
+ measured : {
78
+ width : DEFAULT_NODE_WIDTH ,
79
+ height : DEFAULT_FIELD_HEIGHT * 4 ,
80
+ } ,
81
+ } ,
82
+ ] ) ;
83
+ renderComponent ( ) ;
84
+ const path = screen . getByTestId ( 'floating-edge-orders-to-employees' ) ;
85
+ expect ( path ) . toHaveAttribute ( 'id' , 'orders-to-employees' ) ;
86
+ expect ( path ) . toHaveAttribute (
87
+ 'd' ,
88
+ 'M240 143.5L240 163.5L 240,213Q 240,218 245,218L 381,218Q 386,218 386,223L386 272.5L386 292.5' ,
89
+ ) ;
90
+ } ) ;
51
91
} ) ;
52
92
53
93
it ( 'Should not render edge if source does not exist' , ( ) => {
0 commit comments