@@ -42,41 +42,84 @@ describe('<Node />', () => {
42
42
43
43
44
44
it ( 'applies correct base className if `nodeData._children` is defined' , ( ) => {
45
- const noChildrenComponent = shallow (
45
+ const leafNodeComponent = shallow (
46
46
< Node { ...mockProps } />
47
47
) ;
48
- const withChildrenComponent = shallow (
48
+ const nodeComponent = shallow (
49
49
< Node
50
50
{ ...mockProps }
51
51
nodeData = { { ...nodeData , _children : [ ] } }
52
52
/>
53
53
) ;
54
54
55
- expect ( noChildrenComponent . prop ( 'className' ) ) . toBe ( 'leafNodeBase' ) ;
56
- expect ( withChildrenComponent . prop ( 'className' ) ) . toBe ( 'nodeBase' ) ;
55
+ expect ( leafNodeComponent . prop ( 'className' ) ) . toBe ( 'leafNodeBase' ) ;
56
+ expect ( nodeComponent . prop ( 'className' ) ) . toBe ( 'nodeBase' ) ;
57
57
} ) ;
58
58
59
59
60
- it ( 'applies correct <circle> style prop if `nodeData._children` is defined' , ( ) => {
60
+ it ( 'applies correct node styles depending on `nodeData._children`' , ( ) => {
61
+ const initialStyle = { opacity : 0 } ; // state.initialStyle
62
+ const fixture = {
63
+ node : { ...initialStyle , fill : 'blue' } ,
64
+ leafNode : { ...initialStyle , fill : 'green' } ,
65
+ } ;
66
+ const leafNodeComponent = shallow (
67
+ < Node
68
+ { ...mockProps }
69
+ styles = { fixture }
70
+ />
71
+ ) ;
72
+ const nodeComponent = shallow (
73
+ < Node
74
+ { ...mockProps }
75
+ nodeData = { { ...nodeData , _children : [ ] } }
76
+ styles = { fixture }
77
+ />
78
+ ) ;
79
+
80
+ expect ( leafNodeComponent . prop ( 'style' ) ) . toEqual ( fixture . leafNode ) ;
81
+ expect ( nodeComponent . prop ( 'style' ) ) . toEqual ( fixture . node ) ;
82
+ } ) ;
83
+
84
+
85
+ it ( 'applies correct <circle> styles depending on `nodeData._children`' , ( ) => {
61
86
const leafCircle = { fill : 'blue' } ;
62
87
const circle = { fill : 'green' } ;
63
88
const styles = { circle, leafCircle } ;
64
- const noChildrenComponent = shallow (
89
+ const leafNodeComponent = shallow (
65
90
< Node
66
91
{ ...mockProps }
67
92
styles = { styles }
68
93
/>
69
94
) ;
70
- const withChildrenComponent = shallow (
95
+ const nodeComponent = shallow (
71
96
< Node
72
97
{ ...mockProps }
73
98
nodeData = { { ...nodeData , _children : [ ] } }
74
99
styles = { styles }
75
100
/>
76
101
) ;
77
102
78
- expect ( noChildrenComponent . find ( 'circle' ) . prop ( 'style' ) ) . toBe ( leafCircle ) ;
79
- expect ( withChildrenComponent . find ( 'circle' ) . prop ( 'style' ) ) . toBe ( circle ) ;
103
+ expect ( leafNodeComponent . find ( 'circle' ) . prop ( 'style' ) ) . toBe ( leafCircle ) ;
104
+ expect ( nodeComponent . find ( 'circle' ) . prop ( 'style' ) ) . toBe ( circle ) ;
105
+ } ) ;
106
+
107
+
108
+ it ( 'applies correct node attributes styles' , ( ) => {
109
+ const fixture = {
110
+ attributes : {
111
+ stroke : '#000' ,
112
+ strokeWidth : 12 ,
113
+ } ,
114
+ } ;
115
+ const renderedComponent = shallow (
116
+ < Node
117
+ { ...mockProps }
118
+ styles = { fixture }
119
+ />
120
+ ) ;
121
+
122
+ expect ( renderedComponent . find ( '.nodeAttributesBase' ) . prop ( 'style' ) ) . toBe ( fixture . attributes ) ;
80
123
} ) ;
81
124
82
125
0 commit comments