-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
141 lines (97 loc) Β· 3.14 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const assert = require('assert')
const { describe, it, afterEach } = require('kocha')
const genel = require('genel')
const capsid = require('capsid')
const capsidPopper = require('./index')
describe('capsid-popper', () => {
afterEach(() => {
window.document.body.innerHTML = ''
})
it('can install', () => {
capsid.install(capsidPopper)
})
describe('popper component', () => {
it('throws when data-popper-ref is not defined', () => {
const el = genel.div``
assert.throws(() => {
capsid.make('popper', el)
})
})
it('throws when data-popper-ref is defined but not found', () => {
const el = genel.div``
el.dataset.popperRef = 'section'
assert.throws(() => {
capsid.make('popper', el)
})
})
it('throws when data-popper-placement is not defined', () => {
document.body.appendChild(genel.p``)
const el = genel.div``
document.body.appendChild(el)
el.dataset.popperRef = 'p'
assert.throws(() => {
capsid.make('popper', el)
})
})
it('initializes the element with the given popper options', () => {
const p = genel.p``
document.body.appendChild(p)
const el = genel.div``
document.body.appendChild(el)
el.dataset.popperRef = 'p'
el.dataset.popperPlacement = 'top'
capsid.make('popper', el)
assert.strictEqual(el.getAttribute('x-placement'), 'top') // popper put this attribute
})
it('removes display none property if set', () => {
const p = genel.p``
document.body.appendChild(p)
const el = genel.div``
document.body.appendChild(el)
el.dataset.popperRef = 'p'
el.dataset.popperPlacement = 'top'
el.style.display = 'none'
capsid.make('popper', el)
assert.strictEqual(el.style.display, '')
})
it('sets modifiers based on data-popper-modifiers', () => {
const p = genel.p``
document.body.appendChild(p)
const el = genel.div``
document.body.appendChild(el)
el.dataset.popperRef = 'p'
el.dataset.popperPlacement = 'top'
el.dataset.popperModifiers = '{"preventOverflow":{"enabled": false}}'
const popper = capsid.make('popper', el)
const preventOverflow = popper.popper.modifiers.find(
m => m.name === 'preventOverflow'
)
assert.strictEqual(preventOverflow.enabled, false)
})
describe('update', () => {
it('updates the popper layout', () => {
const p = genel.p``
document.body.appendChild(p)
const el = genel.div``
document.body.appendChild(el)
el.dataset.popperRef = 'p'
el.dataset.popperPlacement = 'top'
el.style.display = 'none'
const popper = capsid.make('popper', el)
popper.update()
// TODO: assert something
})
})
})
describe('updateAll', () => {
it('dispatches UPDATE event on .popper component', done => {
const el = genel.div``
el.classList.add('popper')
el.addEventListener(capsidPopper.UPDATE, () => {
done()
})
document.body.appendChild(el)
capsidPopper.updateAll()
})
})
})