-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathrevealable-container.test.js
More file actions
75 lines (64 loc) · 2.09 KB
/
Copy pathrevealable-container.test.js
File metadata and controls
75 lines (64 loc) · 2.09 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 React from 'react'
import RevealableContainer from './revealable-container'
import TestRenderer from 'react-test-renderer'
describe('RevealableContainer', () => {
test('RevealableContainer renders correctly', () => {
const testRenderer = TestRenderer.create(
<RevealableContainer
className="class-name"
onClick={jest.fn()}
onDeleteButtonClick={jest.fn()}
onDeleteButtonKeyDown={jest.fn()}
maxWidth={100}
isSelected={true}
/>
)
const tree = testRenderer.toJSON()
expect(tree).toMatchSnapshot()
})
test('RevealableContainer renders correctly without className', () => {
const testRenderer = TestRenderer.create(
<RevealableContainer
onClick={jest.fn()}
onDeleteButtonClick={jest.fn()}
onDeleteButtonKeyDown={jest.fn()}
maxWidth={100}
isSelected={false}
/>
)
const tree = testRenderer.toJSON()
expect(tree).toMatchSnapshot()
})
test('All methods are called as expected', () => {
const onDeleteButtonClick = jest.fn()
const onDeleteButtonKeyDown = jest.fn()
const onClick = jest.fn()
const testRenderer = TestRenderer.create(
<RevealableContainer
className="class-name"
onClick={onClick}
onDeleteButtonClick={onDeleteButtonClick}
onDeleteButtonKeyDown={onDeleteButtonKeyDown}
maxWidth={100}
isSelected={true}
/>
)
expect(onDeleteButtonClick).not.toBeCalled()
expect(onDeleteButtonKeyDown).not.toBeCalled()
expect(onClick).not.toBeCalled()
testRenderer.root
.findByProps({ className: 'obojobo-draft--components--revealable-container class-name' })
.props.onClick()
expect(onDeleteButtonClick).not.toBeCalled()
expect(onDeleteButtonKeyDown).not.toBeCalled()
expect(onClick).toBeCalledTimes(1)
testRenderer.root.findByType('button').props.onClick()
expect(onDeleteButtonClick).toBeCalledTimes(1)
expect(onDeleteButtonKeyDown).not.toBeCalled()
expect(onClick).toBeCalledTimes(1)
testRenderer.root.findByType('button').props.onKeyDown()
expect(onDeleteButtonClick).toBeCalledTimes(1)
expect(onDeleteButtonKeyDown).toBeCalledTimes(1)
expect(onClick).toBeCalledTimes(1)
})
})