forked from atomiks/tippyjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.test.js
57 lines (46 loc) · 1.77 KB
/
options.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import createReferenceElement from '../helpers/createReferenceElement'
import createArrayOfReferenceElements from '../helpers/createArrayOfReferenceElements'
import hasTippy from '../helpers/hasTippy'
import cleanDocument from '../helpers/cleanDocument'
import tippy from '../../src/js/tippy'
import { Tippy } from '../../src/js/core/Tippy'
const o = options => ({ createPopperInstanceOnInit: true, ...options })
afterEach(cleanDocument)
test('createPopperInstanceOnInit', () => {
const el = createReferenceElement()
tippy(el, { createPopperInstanceOnInit: true })
expect(el._tippy.options.createPopperInstanceOnInit).toBe(true)
expect(el._tippy.popperInstance).not.toBeNull()
expect(el._tippy.popperInstance.state.eventsEnabled).toBe(false)
})
test('placement', () => {
const placements = ['top', 'bottom', 'left', 'right'].reduce(
(acc, placement) => [...acc, placement, `${placement}-start`, `${placement}-end`],
[]
)
placements.forEach(placement => {
const el = createReferenceElement()
tippy(el, o({ placement }))
expect(el._tippy.options.placement).toBe(placement)
expect(el._tippy.popperInstance.options.placement).toBe(placement)
})
})
test('trigger', () => {
const trigger = 'mouseenter focus click'
let el
el = createReferenceElement(true)
tippy(el, o({ trigger }))
expect(el._tippy.options.trigger).toBe(trigger)
el.dispatchEvent(new Event('mouseenter'))
expect(el._tippy.state.visible).toBe(true)
cleanDocument()
el = createReferenceElement(true)
tippy(el, o({ trigger }))
el.dispatchEvent(new Event('focus'))
expect(el._tippy.state.visible).toBe(true)
cleanDocument()
el = createReferenceElement(true)
tippy(el, o({ trigger }))
el.dispatchEvent(new Event('click'))
expect(el._tippy.state.visible).toBe(true)
})