@@ -23,9 +23,13 @@ describe('<Node />', () => {
23
23
onClick : ( ) => { } ,
24
24
} ;
25
25
26
+
27
+ jest . spyOn ( Node . prototype , 'applyTransform' ) ;
28
+
26
29
// Clear method spies on prototype after each test
27
30
afterEach ( ( ) => jest . clearAllMocks ( ) ) ;
28
31
32
+
29
33
it ( 'has the correct `id` attribute value' , ( ) => {
30
34
const renderedComponent = shallow (
31
35
< Node { ...mockProps } />
@@ -34,6 +38,7 @@ describe('<Node />', () => {
34
38
expect ( renderedComponent . find ( 'g' ) . prop ( 'id' ) ) . toBe ( nodeData . id ) ;
35
39
} ) ;
36
40
41
+
37
42
it ( 'applies correct base className if `nodeData._children` is defined' , ( ) => {
38
43
const noChildrenComponent = shallow (
39
44
< Node { ...mockProps } />
@@ -49,6 +54,7 @@ describe('<Node />', () => {
49
54
expect ( withChildrenComponent . prop ( 'className' ) ) . toBe ( 'nodeBase' ) ;
50
55
} ) ;
51
56
57
+
52
58
it ( 'applies correct <circle> style prop if `nodeData._children` is defined' , ( ) => {
53
59
const leafCircleStyle = { fill : 'blue' } ;
54
60
const circleStyle = { fill : 'green' } ;
@@ -72,6 +78,7 @@ describe('<Node />', () => {
72
78
expect ( withChildrenComponent . find ( 'circle' ) . prop ( 'style' ) ) . toBe ( circleStyle ) ;
73
79
} ) ;
74
80
81
+
75
82
it ( 'applies correct `transform` prop based on its `orientation`' , ( ) => {
76
83
const horizontalTransform = `translate(${ nodeData . parent . y } ,${ nodeData . parent . x } )` ;
77
84
const verticalTransform = `translate(${ nodeData . parent . x } ,${ nodeData . parent . y } )` ;
@@ -88,6 +95,7 @@ describe('<Node />', () => {
88
95
expect ( verticalComponent . find ( 'g' ) . prop ( 'transform' ) ) . toBe ( verticalTransform ) ;
89
96
} ) ;
90
97
98
+
91
99
it ( 'should take an `onClick` prop' , ( ) => {
92
100
const renderedComponent = shallow (
93
101
< Node
@@ -99,6 +107,7 @@ describe('<Node />', () => {
99
107
expect ( renderedComponent . prop ( 'onClick' ) ) . toBeDefined ( ) ;
100
108
} ) ;
101
109
110
+
102
111
it ( 'handles click events and passes its nodeId to onClick handler' , ( ) => {
103
112
const onClickSpy = jest . fn ( ) ;
104
113
const renderedComponent = shallow (
@@ -112,6 +121,7 @@ describe('<Node />', () => {
112
121
expect ( onClickSpy ) . toHaveBeenCalledWith ( nodeData . id ) ;
113
122
} ) ;
114
123
124
+
115
125
it ( 'maps each `props.secondaryLabels` to a <tspan> element' , ( ) => {
116
126
const fixture = { keyA : 'valA' , keyB : 'valB' } ;
117
127
const renderedComponent = shallow (
@@ -132,6 +142,7 @@ describe('<Node />', () => {
132
142
) . toBe ( 1 ) ;
133
143
} ) ;
134
144
145
+
135
146
it ( 'mutates the node\'s `y` property according to `depthFactor`, when specified' , ( ) => {
136
147
const depthFactor = 100 ;
137
148
const expectedY = nodeData . depth * depthFactor ;
@@ -146,8 +157,8 @@ describe('<Node />', () => {
146
157
expect ( renderedComponent . prop ( 'transform' ) ) . toBe ( `translate(${ nodeData . parent . x } ,${ expectedY } )` ) ;
147
158
} ) ;
148
159
160
+
149
161
it ( 'applies its own x/y coords on `transform` once mounted' , ( ) => {
150
- jest . spyOn ( Node . prototype , 'applyTransform' ) ;
151
162
const fixture = `translate(${ nodeData . y } ,${ nodeData . x } )` ;
152
163
const renderedComponent = mount (
153
164
< Node
@@ -158,8 +169,9 @@ describe('<Node />', () => {
158
169
expect ( renderedComponent . instance ( ) . applyTransform ) . toHaveBeenCalledWith ( fixture ) ;
159
170
} ) ;
160
171
172
+
161
173
it ( 'updates its transform attribute if either the `x` or `y` prop changes' , ( ) => {
162
- jest . spyOn ( Node . prototype , 'applyTransform' ) ;
174
+ // jest.spyOn(Node.prototype, 'applyTransform');
163
175
const updatedProps = {
164
176
...mockProps ,
165
177
nodeData : {
0 commit comments