-
Notifications
You must be signed in to change notification settings - Fork 8
/
Utils.test.js
62 lines (51 loc) · 1.79 KB
/
Utils.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
import { JSDOM } from 'jsdom'
import resolveSlidesNumber from '../utils/resolveSlidesNumber'
import { setStyle, getTranslateProperty, getStylingTransition } from '../utils'
describe('Util functions', () => {
beforeEach(() => {
const dom = new JSDOM(
'<!DOCTYPE html><html><head></head><body></body></html>'
)
global.window = dom.window
global.document = dom.window.document
const resizeEvent = document.createEvent('Event')
resizeEvent.initEvent('resize', true, true)
global.window.resizeTo = (width, height) => {
global.window.innerWidth = width || global.window.innerWidth
global.window.innerHeight = height || global.window.innerHeight
global.window.dispatchEvent(resizeEvent)
}
})
it('should resolve slides number correctly', () => {
expect(resolveSlidesNumber(5)).toEqual(5)
window.resizeTo(400, 1000)
expect(resolveSlidesNumber(1, { 400: 2, 1000: 3 })).toEqual(2)
window.resizeTo(1000, 1000)
expect(resolveSlidesNumber(1, { 400: 2, 1000: 3 })).toEqual(3)
})
it('should set style correctly', () => {
const target = {
style: {},
}
const styles = {
backgroundColor: 'pink',
color: 'black',
}
setStyle(target, styles)
expect(target.style).toEqual(styles)
})
it('should get translate property correctly', () => {
expect(getTranslateProperty(0, 5, -70)).toEqual({
transform: 'translate3d(0, 5%, -70%)',
WebkitTransform: 'translate3d(0, 5%, -70%)',
})
})
it('should get styling transition correctly', () => {
expect(
getStylingTransition('cubic-bezier(0.215, 0.61, 0.355, 1)', 500)
).toEqual({
WebkitTransition: 'all 500ms cubic-bezier(0.215, 0.61, 0.355, 1)',
transition: 'all 500ms cubic-bezier(0.215, 0.61, 0.355, 1)',
})
})
})