@@ -57,56 +57,56 @@ describe("Popover", () => {
57
57
describe ( "Open/Close scenarios" , ( ) => {
58
58
let targetHoverState : boolean = false ;
59
59
let targetInfos : Array < {
60
- targetType : TargetType ;
60
+ type : TargetType ;
61
61
component : any ;
62
- activateTarget : ( component : any ) => void ;
62
+ activate : ( component : any ) => void ;
63
63
} > = [
64
64
{
65
65
component : TargetClick ,
66
- targetType : "click" ,
67
- activateTarget : target => {
66
+ type : "click" ,
67
+ activate : target => {
68
68
target . props ( ) . onClick ( { } as any ) ;
69
69
}
70
70
} ,
71
71
{
72
72
component : TargetHover ,
73
- targetType : "hover" ,
74
- activateTarget : target => {
73
+ type : "hover" ,
74
+ activate : target => {
75
75
targetHoverState = ! targetHoverState ;
76
76
target . props ( ) . onHoverChange ( targetHoverState ) ;
77
77
}
78
78
}
79
79
] ;
80
80
let popperInfos : Array < {
81
- popperType : PopperType ;
81
+ type : PopperType ;
82
82
component : any ;
83
- activateTarget : ( component : any ) => void ;
83
+ activate : ( component : any ) => void ;
84
84
} > = [
85
85
{
86
86
component : PopperHover ,
87
- popperType : "hover" ,
88
- activateTarget : target => {
87
+ type : "hover" ,
88
+ activate : target => {
89
89
target . props ( ) . onHoverChange ( false ) ;
90
90
}
91
91
} ,
92
92
{
93
93
component : PopperHover ,
94
- popperType : "none" ,
95
- activateTarget : target => {
94
+ type : "none" ,
95
+ activate : target => {
96
96
target . props ( ) . onHoverChange ( false ) ;
97
97
}
98
98
} ,
99
99
{
100
100
component : PopperClick ,
101
- popperType : "click" ,
102
- activateTarget : target => {
101
+ type : "click" ,
102
+ activate : target => {
103
103
target . props ( ) . onDismiss ( ) ;
104
104
}
105
105
} ,
106
106
{
107
107
component : PopperBlur ,
108
- popperType : "blur" ,
109
- activateTarget : target => {
108
+ type : "blur" ,
109
+ activate : target => {
110
110
target . props ( ) . onDismiss ( { } as any ) ;
111
111
}
112
112
}
@@ -115,15 +115,15 @@ describe("Popover", () => {
115
115
describe ( "Target events" , ( ) => {
116
116
for ( let targetType of targetInfos ) {
117
117
for ( let popperType of popperInfos ) {
118
- describe ( `TargetType: ${ targetType . targetType } , PopperType: ${
119
- popperType . popperType
118
+ describe ( `TargetType: ${ targetType . type } , PopperType: ${
119
+ popperType . type
120
120
} `, ( ) => {
121
121
beforeEach ( ( ) => {
122
122
targetHoverState = false ;
123
123
defaultProps = {
124
124
...defaultProps ,
125
- popperType : popperType . popperType ,
126
- targetType : targetType . targetType
125
+ popperType : popperType . type ,
126
+ targetType : targetType . type
127
127
} ;
128
128
} ) ;
129
129
@@ -138,26 +138,25 @@ describe("Popover", () => {
138
138
it ( "Renders open/closed when clicked" , ( ) => {
139
139
let wrapper = shallow ( < Popover { ...defaultProps } /> ) ;
140
140
141
- // Click the target and open it
142
- let targetClick = wrapper . find ( targetType . component ) ;
143
- targetType . activateTarget ( targetClick ) ;
141
+ // Activate the target and open it
142
+ let target = wrapper . find ( targetType . component ) ;
143
+ targetType . activate ( target ) ;
144
144
145
145
// Verify the popper is open
146
146
let popper = wrapper . find ( popperType . component ) ;
147
147
expect ( popper ) . toHaveLength ( 1 ) ;
148
148
expect ( popper . hasClass ( "visible" ) ) . toBe ( true ) ;
149
149
150
- // Now click the target again to close it
151
- targetClick = wrapper . find ( targetType . component ) ;
152
- targetType . activateTarget ( targetClick ) ;
150
+ // Now activate the target again to close it
151
+ target = wrapper . find ( targetType . component ) ;
152
+ targetType . activate ( target ) ;
153
153
154
154
// Verify the popper is in expected state
155
155
popper = wrapper . find ( popperType . component ) ;
156
156
expect ( popper ) . toHaveLength ( 1 ) ;
157
157
if (
158
- targetType . targetType === "hover" &&
159
- ( popperType . popperType === "click" ||
160
- popperType . popperType === "blur" )
158
+ targetType . type === "hover" &&
159
+ ( popperType . type === "click" || popperType . type === "blur" )
161
160
) {
162
161
// For these types, the popper should open by the target but only the popper can close it, not the target
163
162
expect ( popper . hasClass ( "visible" ) ) . toBe ( true ) ;
@@ -174,15 +173,15 @@ describe("Popover", () => {
174
173
describe ( "Popper events" , ( ) => {
175
174
for ( let targetType of targetInfos ) {
176
175
for ( let popperType of popperInfos ) {
177
- describe ( `TargetType: ${ targetType . targetType } , PopperType: ${
178
- popperType . popperType
176
+ describe ( `TargetType: ${ targetType . type } , PopperType: ${
177
+ popperType . type
179
178
} `, ( ) => {
180
179
beforeEach ( ( ) => {
181
180
targetHoverState = false ;
182
181
defaultProps = {
183
182
...defaultProps ,
184
- popperType : popperType . popperType ,
185
- targetType : targetType . targetType
183
+ popperType : popperType . type ,
184
+ targetType : targetType . type
186
185
} ;
187
186
} ) ;
188
187
@@ -197,23 +196,24 @@ describe("Popover", () => {
197
196
it ( "Closes when requested" , ( ) => {
198
197
let wrapper = shallow ( < Popover { ...defaultProps } /> ) ;
199
198
200
- // Click the target and open it
201
- let targetClick = wrapper . find ( targetType . component ) ;
202
- targetType . activateTarget ( targetClick ) ;
199
+ // Actiate the target and open it
200
+ let target = wrapper . find ( targetType . component ) ;
201
+ targetType . activate ( target ) ;
203
202
204
203
// Verify the popper is open
205
204
let popper = wrapper . find ( popperType . component ) ;
206
205
expect ( popper ) . toHaveLength ( 1 ) ;
207
206
expect ( popper . hasClass ( "visible" ) ) . toBe ( true ) ;
208
207
209
- // Now activate the close scenario to close the popper
208
+ // Now activate the popper to close it
210
209
popper = wrapper . find ( popperType . component ) ;
211
- popperType . activateTarget ( popper ) ;
210
+ popperType . activate ( popper ) ;
212
211
213
- // Verify the popper is closed
212
+ // Verify the popper is in expected state
214
213
popper = wrapper . find ( popperType . component ) ;
215
214
expect ( popper ) . toHaveLength ( 1 ) ;
216
- if ( popperType . popperType === "none" ) {
215
+ if ( popperType . type === "none" ) {
216
+ // In the none case, the popper's callback should have no affect
217
217
expect ( popper . hasClass ( "visible" ) ) . toBe ( true ) ;
218
218
} else {
219
219
expect ( popper . hasClass ( "visible" ) ) . toBe ( false ) ;
@@ -239,41 +239,41 @@ describe("Popover", () => {
239
239
it ( "Opens by method" , ( ) => {
240
240
let wrapper = shallow ( < Popover { ...defaultProps } /> ) ;
241
241
242
- let popperHover = wrapper . find ( PopperHover ) ;
243
- expect ( popperHover ) . toHaveLength ( 1 ) ;
244
- expect ( popperHover . hasClass ( "visible" ) ) . toBe ( false ) ;
242
+ let popper = wrapper . find ( PopperHover ) ;
243
+ expect ( popper ) . toHaveLength ( 1 ) ;
244
+ expect ( popper . hasClass ( "visible" ) ) . toBe ( false ) ;
245
245
expect ( spy ) . not . toHaveBeenCalled ( ) ;
246
246
247
247
( wrapper . instance ( ) as Popover ) . open ( ) ;
248
248
249
- popperHover = wrapper . find ( PopperHover ) ;
250
- expect ( popperHover ) . toHaveLength ( 1 ) ;
251
- expect ( popperHover . hasClass ( "visible" ) ) . toBe ( true ) ;
249
+ popper = wrapper . find ( PopperHover ) ;
250
+ expect ( popper ) . toHaveLength ( 1 ) ;
251
+ expect ( popper . hasClass ( "visible" ) ) . toBe ( true ) ;
252
252
expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
253
253
expect ( spy ) . toHaveBeenLastCalledWith ( true ) ;
254
254
} ) ;
255
255
256
256
it ( "Opens by hover, closes on request" , ( ) => {
257
257
let wrapper = shallow ( < Popover { ...defaultProps } /> ) ;
258
258
259
- let popperHover = wrapper . find ( PopperHover ) ;
260
- expect ( popperHover ) . toHaveLength ( 1 ) ;
261
- expect ( popperHover . hasClass ( "visible" ) ) . toBe ( false ) ;
259
+ let popper = wrapper . find ( PopperHover ) ;
260
+ expect ( popper ) . toHaveLength ( 1 ) ;
261
+ expect ( popper . hasClass ( "visible" ) ) . toBe ( false ) ;
262
262
263
- popperHover . props ( ) . onHoverChange ( true ) ;
263
+ popper . props ( ) . onHoverChange ( true ) ;
264
264
265
- popperHover = wrapper . find ( PopperHover ) ;
266
- expect ( popperHover ) . toHaveLength ( 1 ) ;
267
- expect ( popperHover . hasClass ( "visible" ) ) . toBe ( true ) ;
265
+ popper = wrapper . find ( PopperHover ) ;
266
+ expect ( popper ) . toHaveLength ( 1 ) ;
267
+ expect ( popper . hasClass ( "visible" ) ) . toBe ( true ) ;
268
268
expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
269
269
expect ( spy ) . toHaveBeenLastCalledWith ( true ) ;
270
270
271
271
spy . mockReset ( ) ;
272
272
( wrapper . instance ( ) as Popover ) . close ( ) ;
273
273
274
- popperHover = wrapper . find ( PopperHover ) ;
275
- expect ( popperHover ) . toHaveLength ( 1 ) ;
276
- expect ( popperHover . hasClass ( "visible" ) ) . toBe ( false ) ;
274
+ popper = wrapper . find ( PopperHover ) ;
275
+ expect ( popper ) . toHaveLength ( 1 ) ;
276
+ expect ( popper . hasClass ( "visible" ) ) . toBe ( false ) ;
277
277
expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
278
278
expect ( spy ) . toHaveBeenLastCalledWith ( false ) ;
279
279
} ) ;
@@ -295,37 +295,37 @@ describe("Popover", () => {
295
295
lifecycleExperimental : true
296
296
} ) ;
297
297
298
- let popperHover = wrapper . find ( PopperHover ) ;
299
- expect ( popperHover ) . toHaveLength ( 1 ) ;
300
- expect ( popperHover . hasClass ( "visible" ) ) . toBe ( false ) ;
298
+ let popper = wrapper . find ( PopperHover ) ;
299
+ expect ( popper ) . toHaveLength ( 1 ) ;
300
+ expect ( popper . hasClass ( "visible" ) ) . toBe ( false ) ;
301
301
expect ( spy ) . not . toHaveBeenCalled ( ) ;
302
302
303
303
wrapper . setProps ( {
304
304
isOpen : true
305
305
} ) ;
306
306
307
- popperHover = wrapper . find ( PopperHover ) ;
308
- expect ( popperHover ) . toHaveLength ( 1 ) ;
309
- expect ( popperHover . hasClass ( "visible" ) ) . toBe ( true ) ;
307
+ popper = wrapper . find ( PopperHover ) ;
308
+ expect ( popper ) . toHaveLength ( 1 ) ;
309
+ expect ( popper . hasClass ( "visible" ) ) . toBe ( true ) ;
310
310
expect ( spy ) . not . toHaveBeenCalled ( ) ;
311
311
} ) ;
312
312
313
313
it ( "Closes by prop" , ( ) => {
314
314
let wrapper = shallow ( < Popover { ...defaultProps } isOpen = { true } /> ) ;
315
315
316
- let popperHover = wrapper . find ( PopperHover ) ;
317
- expect ( popperHover ) . toHaveLength ( 1 ) ;
318
- expect ( popperHover . hasClass ( "visible" ) ) . toBe ( true ) ;
316
+ let popper = wrapper . find ( PopperHover ) ;
317
+ expect ( popper ) . toHaveLength ( 1 ) ;
318
+ expect ( popper . hasClass ( "visible" ) ) . toBe ( true ) ;
319
319
expect ( spy ) . not . toHaveBeenCalled ( ) ;
320
320
321
321
wrapper . setProps ( {
322
322
isOpen : false
323
323
} ) ;
324
324
wrapper . update ( ) ;
325
325
326
- popperHover = wrapper . find ( PopperHover ) ;
327
- expect ( popperHover ) . toHaveLength ( 1 ) ;
328
- expect ( popperHover . hasClass ( "visible" ) ) . toBe ( false ) ;
326
+ popper = wrapper . find ( PopperHover ) ;
327
+ expect ( popper ) . toHaveLength ( 1 ) ;
328
+ expect ( popper . hasClass ( "visible" ) ) . toBe ( false ) ;
329
329
expect ( spy ) . not . toHaveBeenCalled ( ) ;
330
330
} ) ;
331
331
} ) ;
0 commit comments