-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
69 lines (54 loc) · 1.88 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
require('@babel/register')
const Window = require('window')
const window = new Window()
global.window = window
global.document = window.document
const { describe, context, it, beforeEach } = require('kocha')
const assert = require('assert')
const capsid = require('capsid')
const { make } = capsid
const capsidScrollLock = require('./index.js')
const { LOCK, UNLOCK } = capsidScrollLock
capsidScrollLock.install(capsid)
const body = () => window.document.createElement('body')
describe('capsid-scroll-lock', () => {
describe('install', () => {
it('defines scroll-lock component', () => {
make('scroll-lock', body())
})
context('when name option is given', () => {
it('defines the component of the given name', () => {
capsidScrollLock.install(capsid, { name: 'foo0' })
make('foo0', body())
})
})
})
describe('scroll-lock component', () => {
let el
beforeEach(() => {
el = body()
make('scroll-lock', el)
})
context('when LOCK event is dispatched', () => {
it('applies the styles for locking the body scroll', () => {
el.dispatchEvent(new window.CustomEvent(LOCK))
assert.strictEqual(el.style.overflow, 'hidden')
})
})
context('when LOCK dispatched once and UNLOCK dispatched once', () => {
it('unlocks the body scroll', () => {
el.dispatchEvent(new window.CustomEvent(LOCK))
el.dispatchEvent(new window.CustomEvent(UNLOCK))
assert.strictEqual(el.style.overflow, '')
})
})
context('when LOCK dispatched twice and UNLOCK dispatched once', () => {
it('does not unlock the body scroll', () => {
el.dispatchEvent(new window.CustomEvent(LOCK))
el.dispatchEvent(new window.CustomEvent(LOCK))
el.dispatchEvent(new window.CustomEvent(UNLOCK))
assert.strictEqual(el.style.overflow, 'hidden')
})
})
})
})