@@ -31,44 +31,51 @@ const popperStub = (popperInstance) => sinon.stub().returns(popperInstance)
31
31
describe ( '<PortalPopper />' , ( ) => {
32
32
it ( 'renders a <Portal /> with a placement class' , ( ) => {
33
33
const component = shallow ( < PortalPopper { ...getProps ( ) } /> )
34
+
34
35
expect ( component . find ( '.tooltip-top' ) ) . to . exist
35
36
} )
36
37
37
38
it ( 'renders a <Portal /> with default styles' , ( ) => {
38
39
const component = shallow ( < PortalPopper { ...getProps ( ) } /> )
39
40
const style = component . find ( '.tooltip-top' ) . prop ( 'style' )
41
+
40
42
expect ( style . position ) . to . equal ( 'absolute' )
41
43
expect ( style . transform ) . to . equal ( 'translate3d(0px, 0px, 0)' )
42
44
expect ( style . WebkitTransform ) . to . equal ( 'translate3d(0px, 0px, 0)' )
43
45
} )
44
46
45
47
it ( 'renders the title specified' , ( ) => {
46
48
const component = shallow ( < PortalPopper { ...getProps ( ) } /> )
49
+
47
50
expect ( component . find ( 'span' ) ) . to . have . text ( 'tooltip title' )
48
51
} )
49
52
50
53
it ( 'renders the tooltip arrow with default styles' , ( ) => {
51
54
const component = shallow ( < PortalPopper { ...getProps ( { } ) } /> )
52
55
const style = component . find ( '.tooltip-arrow' ) . prop ( 'style' )
56
+
53
57
expect ( style . left ) . to . equal ( 0 )
54
58
expect ( style . top ) . to . equal ( 0 )
55
59
} )
56
60
57
61
it ( 'renders with className specified' , ( ) => {
58
62
const component = shallow ( < PortalPopper { ...getProps ( { className : 'custom-class' } ) } /> )
63
+
59
64
expect ( component . find ( '.custom-class' ) ) . to . exist
60
65
expect ( component . find ( '.custom-class-top' ) ) . to . exist
61
66
expect ( component . find ( '.custom-class-arrow' ) ) . to . exist
62
67
} )
63
68
64
69
it ( 'uses last className as prefix if multiple' , ( ) => {
65
70
const component = shallow ( < PortalPopper { ...getProps ( { className : 'custom-class tooltip' } ) } /> )
71
+
66
72
expect ( component . find ( '.custom-class' ) . prop ( 'className' ) ) . to . equal ( 'custom-class tooltip tooltip-top' )
67
73
expect ( component . find ( '.tooltip-arrow' ) ) . to . exist
68
74
} )
69
75
70
76
it ( 'creates Popper instance with the right props' , ( ) => {
71
77
const Popper = popperStub ( popperInstanceStub ( ) )
78
+
72
79
mount ( < PortalPopper { ...getProps ( { Popper, boundary : 'boundary' } ) } /> )
73
80
expect ( Popper ) . to . have . been . called
74
81
expect ( Popper . firstCall . args [ 0 ] ) . to . equal ( 'target node' )
@@ -83,13 +90,15 @@ describe('<PortalPopper />', () => {
83
90
84
91
it ( 'calls scheduleUpdate() on the Popper instance' , ( ) => {
85
92
const popperInstance = popperInstanceStub ( )
93
+
86
94
mount ( < PortalPopper { ...getProps ( { Popper : popperStub ( popperInstance ) } ) } /> )
87
95
expect ( popperInstance . scheduleUpdate ) . to . have . been . called
88
96
} )
89
97
90
98
it ( 'destroys the Popper instance on unmount' , ( ) => {
91
99
const popperInstance = popperInstanceStub ( )
92
100
const component = mount ( < PortalPopper { ...getProps ( { Popper : popperStub ( popperInstance ) } ) } /> )
101
+
93
102
component . unmount ( )
94
103
expect ( popperInstance . destroy ) . to . have . been . called
95
104
} )
@@ -99,9 +108,11 @@ describe('<PortalPopper />', () => {
99
108
const popperInstance = popperInstanceStub ( )
100
109
const Popper = popperStub ( popperInstance )
101
110
const component = mount ( < PortalPopper { ...getProps ( { Popper } ) } /> )
111
+
102
112
Popper . firstCall . args [ 2 ] . onUpdate ( { offsets : { arrow : { left : 5 , top : 10 } } } )
103
113
component . update ( )
104
114
const style = component . find ( '.tooltip-arrow' ) . prop ( 'style' )
115
+
105
116
expect ( style . left ) . to . equal ( 5 )
106
117
expect ( style . top ) . to . equal ( 10 )
107
118
} )
@@ -110,9 +121,11 @@ describe('<PortalPopper />', () => {
110
121
const popperInstance = popperInstanceStub ( )
111
122
const Popper = popperStub ( popperInstance )
112
123
const component = mount ( < PortalPopper { ...getProps ( { Popper } ) } /> )
124
+
113
125
Popper . firstCall . args [ 2 ] . onUpdate ( { offsets : { } } )
114
126
component . update ( )
115
127
const style = component . find ( '.tooltip-arrow' ) . prop ( 'style' )
128
+
116
129
expect ( style . left ) . to . equal ( 0 )
117
130
expect ( style . top ) . to . equal ( 0 )
118
131
} )
@@ -121,9 +134,11 @@ describe('<PortalPopper />', () => {
121
134
const popperInstance = popperInstanceStub ( )
122
135
const Popper = popperStub ( popperInstance )
123
136
const component = mount ( < PortalPopper { ...getProps ( { Popper } ) } /> )
137
+
124
138
Popper . firstCall . args [ 2 ] . onUpdate ( { offsets : { arrow : { top : 20 } } } )
125
139
component . update ( )
126
140
const style = component . find ( '.tooltip-arrow' ) . prop ( 'style' )
141
+
127
142
expect ( style . left ) . to . equal ( null )
128
143
expect ( style . top ) . to . equal ( 20 )
129
144
} )
@@ -132,9 +147,11 @@ describe('<PortalPopper />', () => {
132
147
const popperInstance = popperInstanceStub ( )
133
148
const Popper = popperStub ( popperInstance )
134
149
const component = mount ( < PortalPopper { ...getProps ( { Popper } ) } /> )
150
+
135
151
Popper . firstCall . args [ 2 ] . onUpdate ( { offsets : { arrow : { left : 7.2 , top : 20.8 } } } )
136
152
component . update ( )
137
153
const style = component . find ( '.tooltip-arrow' ) . prop ( 'style' )
154
+
138
155
expect ( style . left ) . to . equal ( 7 )
139
156
expect ( style . top ) . to . equal ( 21 )
140
157
} )
@@ -143,9 +160,11 @@ describe('<PortalPopper />', () => {
143
160
const popperInstance = popperInstanceStub ( )
144
161
const Popper = popperStub ( popperInstance )
145
162
const component = mount ( < PortalPopper { ...getProps ( { Popper } ) } /> )
163
+
146
164
Popper . firstCall . args [ 2 ] . onUpdate ( { offsets : { popper : { position : 'relative' , left : 2 , top : 4 } } } )
147
165
component . update ( )
148
166
const style = component . find ( '.tooltip-top' ) . prop ( 'style' )
167
+
149
168
expect ( style . position ) . to . equal ( 'relative' )
150
169
expect ( style . transform ) . to . equal ( 'translate3d(2px, 4px, 0)' )
151
170
expect ( style . WebkitTransform ) . to . equal ( 'translate3d(2px, 4px, 0)' )
@@ -155,9 +174,11 @@ describe('<PortalPopper />', () => {
155
174
const popperInstance = popperInstanceStub ( )
156
175
const Popper = popperStub ( popperInstance )
157
176
const component = mount ( < PortalPopper { ...getProps ( { Popper } ) } /> )
177
+
158
178
Popper . firstCall . args [ 2 ] . onUpdate ( { offsets : { } } )
159
179
component . update ( )
160
180
const style = component . find ( '.tooltip-top' ) . prop ( 'style' )
181
+
161
182
expect ( style . position ) . to . equal ( 'absolute' )
162
183
expect ( style . transform ) . to . equal ( 'translate3d(0px, 0px, 0)' )
163
184
expect ( style . WebkitTransform ) . to . equal ( 'translate3d(0px, 0px, 0)' )
@@ -167,9 +188,11 @@ describe('<PortalPopper />', () => {
167
188
const popperInstance = popperInstanceStub ( )
168
189
const Popper = popperStub ( popperInstance )
169
190
const component = mount ( < PortalPopper { ...getProps ( { Popper } ) } /> )
191
+
170
192
Popper . firstCall . args [ 2 ] . onUpdate ( { offsets : { popper : { left : 15.2 , top : 2.8 } } } )
171
193
component . update ( )
172
194
const style = component . find ( '.tooltip-top' ) . prop ( 'style' )
195
+
173
196
expect ( style . transform ) . to . equal ( 'translate3d(15px, 3px, 0)' )
174
197
expect ( style . WebkitTransform ) . to . equal ( 'translate3d(15px, 3px, 0)' )
175
198
} )
0 commit comments