forked from ucfopen/Obojobo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinline-nav-button.test.js
More file actions
75 lines (63 loc) · 2.31 KB
/
Copy pathinline-nav-button.test.js
File metadata and controls
75 lines (63 loc) · 2.31 KB
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
import { shallow } from 'enzyme'
import React from 'react'
import renderer from 'react-test-renderer'
import NavUtil from 'src/scripts/viewer/util/nav-util'
import NavButton from 'src/scripts/viewer/components/inline-nav-button'
jest.mock('src/scripts/viewer/util/nav-util', () => ({
goNext: jest.fn(),
goPrev: jest.fn()
}))
const getProps = (type, disabled = false, onClick = null) => ({
type,
disabled,
onClick,
title: 'testTitle'
})
describe('Inline Nav Button', () => {
beforeEach(() => {
jest.resetAllMocks()
})
test("NavUtil.goPrev is called if type prop is 'prev'", () => {
const el = shallow(<NavButton {...getProps('prev')} />)
el.find('.viewer--components--inline-nav-button').simulate('click')
expect(NavUtil.goPrev).toHaveBeenCalled()
})
test("NavUtil.goNext is called if type prop is 'next'", () => {
const el = shallow(<NavButton {...getProps('next')} />)
el.find('.viewer--components--inline-nav-button').simulate('click')
expect(NavUtil.goNext).toHaveBeenCalled()
})
test('onClick is not called if disabled prop is true', () => {
const el = shallow(<NavButton {...getProps('next', true)} />)
el.find('.viewer--components--inline-nav-button').simulate('click')
expect(NavUtil.goPrev).not.toHaveBeenCalled()
})
test('correctly renders when type prop is goPrev', () => {
const component = renderer.create(<NavButton {...getProps('goPrev')} />)
expect(component).toMatchSnapshot()
})
test('correctly renders when type prop is goNext', () => {
const component = renderer.create(<NavButton {...getProps('goNext')} />)
expect(component).toMatchSnapshot()
})
test('correctly renders when disabled prop is true', () => {
const component = renderer.create(<NavButton {...getProps('goNext', true)} />)
expect(component).toMatchSnapshot()
})
test('onClick calls blur on event.target', () => {
const blurFn = jest.fn()
const el = shallow(<NavButton {...getProps('goNext')} />)
el.find('.viewer--components--inline-nav-button').simulate('click', {
target: {
blur: blurFn
}
})
expect(blurFn).toHaveBeenCalled()
})
test('onClick calls calls prop onClick', () => {
const onClick = jest.fn()
const el = shallow(<NavButton {...getProps('goNext', false, onClick)} />)
el.find('.viewer--components--inline-nav-button').simulate('click')
expect(onClick).toHaveBeenCalled()
})
})