-
Notifications
You must be signed in to change notification settings - Fork 51
/
IconButton.test.js
101 lines (90 loc) · 2.64 KB
/
IconButton.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
jest.disableAutomock()
import React from 'react'
import ReactDOM from 'react-dom'
import ReactDOMServer from 'react-dom/server'
import TestUtils from 'react-dom/test-utils'
import { Icon } from '../../../components'
import IconButton from '.'
describe('IconButtonTest', () => {
it('IconButton markup', () => {
const clickFun = function (e) {}
const actual = ReactDOMServer.renderToStaticMarkup(<IconButton
icon="classical"
title="Mozart"
onClick={clickFun}
className="push-me" />)
const expected = ReactDOMServer.renderToStaticMarkup(
<button
className="push-me"
onClick={clickFun}
title="Mozart">
<Icon
name="classical" title="Mozart"
className="s1" />
</button>
)
expect(actual).toEqual(expected)
})
it('IconButton markup (disabled)', () => {
const clickFun = function (e) {}
const actual = ReactDOMServer.renderToStaticMarkup(<IconButton
icon="tea"
title="Tea"
onClick={clickFun}
className="drink-me"
disabled={true}/>)
const expected = ReactDOMServer.renderToStaticMarkup(
<button
className="drink-me is-disabled"
disabled="true"
onClick={clickFun}
title="Tea">
<Icon
name="tea"
title="Tea"
className="s1" />
</button>
)
expect(actual).toEqual(expected)
})
it('IconButton click event', () => {
let clickEvent = 'freshing'
const clickFun = function (e) {
clickEvent = e.value
}
const refreshButton = TestUtils.renderIntoDocument(
<IconButton
icon="iced-tea"
title="Iced Tea"
onClick={clickFun}/>
)
// simulate click event
TestUtils.Simulate.click(
ReactDOM.findDOMNode(refreshButton), {value: 'refreshing'})
expect(clickEvent).toEqual('refreshing',
'IconButton click event should fire with correct event payload')
})
it('IconButton does not fire click when disabled', () => {
let clickEvent = 'freshing'
const clickFun = function (e) {
clickEvent = e.value
}
const refreshButton = TestUtils.renderIntoDocument(
<IconButton
icon="iced-tea"
title="Iced Tea"
onClick={clickFun}
disabled={true}/>
)
// throws if onClick is not bound
try {
// simulate click event
TestUtils.Simulate.click(
ReactDOM.findDOMNode(refreshButton), {value: 'refreshing'})
} catch (e) {
// swallow on purpose, valid for code to not bind onClick
}
expect(clickEvent).toEqual('freshing',
'IconButton click event should not fire when props.disabled is true')
})
})