1
1
import EventHandler from '../../src/dom/event-handler.js'
2
2
import Popover from '../../src/popover.js'
3
- import { clearFixture , getFixture , jQueryMock } from '../helpers/fixture.js'
3
+ import {
4
+ clearFixture , getFixture , jQueryMock , createEvent
5
+ } from '../helpers/fixture.js'
4
6
5
7
describe ( 'Popover' , ( ) => {
6
8
let fixtureEl
@@ -58,7 +60,7 @@ describe('Popover', () => {
58
60
describe ( 'show' , ( ) => {
59
61
it ( 'should toggle a popover after show' , ( ) => {
60
62
return new Promise ( resolve => {
61
- fixtureEl . innerHTML = '<a href="#" title="Popover" data-bs -content="https://twitter .com/getbootstrap">BS twitter </a>'
63
+ fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui -content="https://x .com/getbootstrap">BS X </a>'
62
64
63
65
const popoverEl = fixtureEl . querySelector ( 'a' )
64
66
const popover = new Popover ( popoverEl )
@@ -78,7 +80,7 @@ describe('Popover', () => {
78
80
79
81
it ( 'should show a popover' , ( ) => {
80
82
return new Promise ( resolve => {
81
- fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://twitter .com/getbootstrap">BS twitter </a>'
83
+ fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://x .com/getbootstrap">BS X </a>'
82
84
83
85
const popoverEl = fixtureEl . querySelector ( 'a' )
84
86
const popover = new Popover ( popoverEl )
@@ -94,7 +96,7 @@ describe('Popover', () => {
94
96
95
97
it ( 'should set title and content from functions' , ( ) => {
96
98
return new Promise ( resolve => {
97
- fixtureEl . innerHTML = '<a href="#">BS twitter </a>'
99
+ fixtureEl . innerHTML = '<a href="#">BS X </a>'
98
100
99
101
const popoverEl = fixtureEl . querySelector ( 'a' )
100
102
const popover = new Popover ( popoverEl , {
@@ -117,7 +119,7 @@ describe('Popover', () => {
117
119
118
120
it ( 'should call content and title functions with trigger element' , ( ) => {
119
121
return new Promise ( resolve => {
120
- fixtureEl . innerHTML = '<a href="#" data-foo="bar">BS twitter </a>'
122
+ fixtureEl . innerHTML = '<a href="#" data-foo="bar">BS X </a>'
121
123
122
124
const popoverEl = fixtureEl . querySelector ( 'a' )
123
125
const popover = new Popover ( popoverEl , {
@@ -144,7 +146,7 @@ describe('Popover', () => {
144
146
145
147
it ( 'should call content and title functions with correct this value' , ( ) => {
146
148
return new Promise ( resolve => {
147
- fixtureEl . innerHTML = '<a href="#" data-foo="bar">BS twitter </a>'
149
+ fixtureEl . innerHTML = '<a href="#" data-foo="bar">BS X </a>'
148
150
149
151
const popoverEl = fixtureEl . querySelector ( 'a' )
150
152
const popover = new Popover ( popoverEl , {
@@ -247,7 +249,7 @@ describe('Popover', () => {
247
249
} )
248
250
249
251
it ( '"setContent" should keep the initial template' , ( ) => {
250
- fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://twitter .com/getbootstrap" data-coreui-custom-class="custom-class">BS twitter </a>'
252
+ fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://x .com/getbootstrap" data-coreui-custom-class="custom-class">BS X </a>'
251
253
252
254
const popoverEl = fixtureEl . querySelector ( 'a' )
253
255
const popover = new Popover ( popoverEl )
@@ -264,7 +266,7 @@ describe('Popover', () => {
264
266
265
267
it ( 'should call setContent once' , ( ) => {
266
268
return new Promise ( resolve => {
267
- fixtureEl . innerHTML = '<a href="#">BS twitter </a>'
269
+ fixtureEl . innerHTML = '<a href="#">BS X </a>'
268
270
269
271
const popoverEl = fixtureEl . querySelector ( 'a' )
270
272
const popover = new Popover ( popoverEl , {
@@ -298,7 +300,7 @@ describe('Popover', () => {
298
300
299
301
it ( 'should show a popover with provided custom class' , ( ) => {
300
302
return new Promise ( resolve => {
301
- fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://twitter .com/getbootstrap" data-coreui-custom-class="custom-class">BS twitter </a>'
303
+ fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://x .com/getbootstrap" data-coreui-custom-class="custom-class">BS X </a>'
302
304
303
305
const popoverEl = fixtureEl . querySelector ( 'a' )
304
306
const popover = new Popover ( popoverEl )
@@ -315,10 +317,32 @@ describe('Popover', () => {
315
317
} )
316
318
} )
317
319
320
+ it ( 'should keep popover open when mouse leaves after click trigger' , ( ) => {
321
+ return new Promise ( resolve => {
322
+ fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://x.com/getbootstrap" data-coreui-trigger="hover click">BS X</a>'
323
+
324
+ const popoverEl = fixtureEl . querySelector ( 'a' )
325
+ new Popover ( popoverEl ) // eslint-disable-line no-new
326
+
327
+ popoverEl . addEventListener ( 'shown.coreui.popover' , ( ) => {
328
+ popoverEl . dispatchEvent ( createEvent ( 'mouseout' ) )
329
+
330
+ popoverEl . addEventListener ( 'hide.coreui.popover' , ( ) => {
331
+ throw new Error ( 'Popover should not hide when mouse leaves after click' )
332
+ } )
333
+
334
+ expect ( document . querySelector ( '.popover' ) ) . not . toBeNull ( )
335
+ resolve ( )
336
+ } )
337
+
338
+ popoverEl . click ( )
339
+ } )
340
+ } )
341
+
318
342
describe ( 'hide' , ( ) => {
319
343
it ( 'should hide a popover' , ( ) => {
320
344
return new Promise ( resolve => {
321
- fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://twitter .com/getbootstrap">BS twitter </a>'
345
+ fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://x .com/getbootstrap">BS X </a>'
322
346
323
347
const popoverEl = fixtureEl . querySelector ( 'a' )
324
348
const popover = new Popover ( popoverEl )
@@ -339,7 +363,7 @@ describe('Popover', () => {
339
363
340
364
describe ( 'jQueryInterface' , ( ) => {
341
365
it ( 'should create a popover' , ( ) => {
342
- fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://twitter .com/getbootstrap">BS twitter </a>'
366
+ fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://x .com/getbootstrap">BS X </a>'
343
367
344
368
const popoverEl = fixtureEl . querySelector ( 'a' )
345
369
@@ -352,7 +376,7 @@ describe('Popover', () => {
352
376
} )
353
377
354
378
it ( 'should create a popover with a config object' , ( ) => {
355
- fixtureEl . innerHTML = '<a href="#" title="Popover">BS twitter </a>'
379
+ fixtureEl . innerHTML = '<a href="#" title="Popover">BS X </a>'
356
380
357
381
const popoverEl = fixtureEl . querySelector ( 'a' )
358
382
@@ -367,7 +391,7 @@ describe('Popover', () => {
367
391
} )
368
392
369
393
it ( 'should not re create a popover' , ( ) => {
370
- fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://twitter .com/getbootstrap">BS twitter </a>'
394
+ fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://x .com/getbootstrap">BS X </a>'
371
395
372
396
const popoverEl = fixtureEl . querySelector ( 'a' )
373
397
const popover = new Popover ( popoverEl )
@@ -381,7 +405,7 @@ describe('Popover', () => {
381
405
} )
382
406
383
407
it ( 'should throw error on undefined method' , ( ) => {
384
- fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://twitter .com/getbootstrap">BS twitter </a>'
408
+ fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://x .com/getbootstrap">BS X </a>'
385
409
386
410
const popoverEl = fixtureEl . querySelector ( 'a' )
387
411
const action = 'undefinedMethod'
@@ -395,7 +419,7 @@ describe('Popover', () => {
395
419
} )
396
420
397
421
it ( 'should should call show method' , ( ) => {
398
- fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://twitter .com/getbootstrap">BS twitter </a>'
422
+ fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://x .com/getbootstrap">BS X </a>'
399
423
400
424
const popoverEl = fixtureEl . querySelector ( 'a' )
401
425
const popover = new Popover ( popoverEl )
@@ -413,7 +437,7 @@ describe('Popover', () => {
413
437
414
438
describe ( 'getInstance' , ( ) => {
415
439
it ( 'should return popover instance' , ( ) => {
416
- fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://twitter .com/getbootstrap">BS twitter </a>'
440
+ fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://x .com/getbootstrap">BS X </a>'
417
441
418
442
const popoverEl = fixtureEl . querySelector ( 'a' )
419
443
const popover = new Popover ( popoverEl )
@@ -423,7 +447,7 @@ describe('Popover', () => {
423
447
} )
424
448
425
449
it ( 'should return null when there is no popover instance' , ( ) => {
426
- fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://twitter .com/getbootstrap">BS twitter </a>'
450
+ fixtureEl . innerHTML = '<a href="#" title="Popover" data-coreui-content="https://x .com/getbootstrap">BS X </a>'
427
451
428
452
const popoverEl = fixtureEl . querySelector ( 'a' )
429
453
0 commit comments