-
Notifications
You must be signed in to change notification settings - Fork 51
/
Dropdown.test.js
167 lines (156 loc) · 5.01 KB
/
Dropdown.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
jest.disableAutomock()
import React from 'react'
import ReactDOMServer from 'react-dom/server'
import TestUtils from 'react-dom/test-utils'
import Dropdown from '.'
describe('DropdownTest', () => {
it('Dropdown markup (closed)', () => {
const toggleTheDoor = () => {}
const actual = ReactDOMServer.renderToStaticMarkup(
<Dropdown
onToggle={toggleTheDoor}
isOpen={false}
enabled={true}
className="boom acka lacka">
<Dropdown.Button>
<button>Boom boom acka lacka lacka boom</button>
</Dropdown.Button>
<Dropdown.Content>
<ul>
<li>Open the door</li>
<li>Get on the floor</li>
<li>Everybody walk the dinosaur</li>
</ul>
<a href="https://youtu.be/vgiDcJi534Y">Was Not Was</a>
</Dropdown.Content>
</Dropdown>
)
const expected = ReactDOMServer.renderToStaticMarkup(
<div className="Dropdown boom acka lacka">
<div className="Dropdown-toggle"
aria-haspopup={true}
aria-expanded={false}
onClick={toggleTheDoor}>
<button>Boom boom acka lacka lacka boom</button>
</div>
<div className="Dropdown-content Dropdown-content--bordered">
<ul>
<li>Open the door</li>
<li>Get on the floor</li>
<li>Everybody walk the dinosaur</li>
</ul>
<a href="https://youtu.be/vgiDcJi534Y">Was Not Was</a>
</div>
</div>
)
expect(actual).toEqual(expected)
})
it('Dropdown markup (open)', () => {
const toggleTheDoor = () => {}
const actual = ReactDOMServer.renderToStaticMarkup(
<Dropdown
onToggle={toggleTheDoor}
isOpen={true}
enabled={true}
className="boom acka lacka">
<Dropdown.Button>
<button>Boom boom acka lacka lacka boom</button>
</Dropdown.Button>
<Dropdown.Content>
<ul>
<li>Open the door</li>
<li>Get on the floor</li>
<li>Everybody walk the dinosaur</li>
</ul>
<a href="https://youtu.be/83nFiPoSuzU">Was Not Was</a>
</Dropdown.Content>
</Dropdown>
)
const expected = ReactDOMServer.renderToStaticMarkup(
<div className="Dropdown is-active boom acka lacka">
<div className="Dropdown-toggle"
aria-haspopup={true}
aria-expanded={true}
onClick={toggleTheDoor}>
<button>Boom boom acka lacka lacka boom</button>
</div>
<div className="Dropdown-content Dropdown-content--bordered">
<ul>
<li>Open the door</li>
<li>Get on the floor</li>
<li>Everybody walk the dinosaur</li>
</ul>
<a href="https://youtu.be/83nFiPoSuzU">Was Not Was</a>
</div>
</div>
)
expect(actual).toEqual(expected)
})
it('Dropdown events', () => {
let theDoor = 'closed'
const toggleTheDoor = (buttonDOMNode) => {
theDoor = 'open'
}
const dinoWalkDropdown = TestUtils.renderIntoDocument(
<Dropdown
onToggle={toggleTheDoor}
isOpen={true}
enabled={true}
className="boom acka lacka">
<Dropdown.Button>
<button>Boom boom acka lacka lacka boom</button>
</Dropdown.Button>
<Dropdown.Content>
<ul>
<li>Open the door</li>
<li>Get on the floor</li>
<li>Everybody walk the dinosaur</li>
</ul>
<a href="https://youtu.be/83nFiPoSuzU">Was Not Was</a>
</Dropdown.Content>
</Dropdown>
)
const list = TestUtils.scryRenderedDOMComponentsWithClass(
dinoWalkDropdown, 'Dropdown-toggle')
TestUtils.Simulate.click(list[0])
expect(theDoor).toEqual('open',
'click on dropdown button should trigger given toggle function')
})
it('Dropdown disabled', () => {
let theDoor = 'closed'
const toggleTheDoor = () => {
theDoor = 'open'
}
const dinoWalkDropdown = TestUtils.renderIntoDocument(
<Dropdown
onToggle={toggleTheDoor}
isOpen={true}
enabled={false}
className="boom acka lacka">
<Dropdown.Button>
<button>Boom boom acka lacka lacka boom</button>
</Dropdown.Button>
<Dropdown.Content>
<ul>
<li>Open the door</li>
<li>Get on the floor</li>
<li>Everybody walk the dinosaur</li>
</ul>
<a href="https://youtu.be/83nFiPoSuzU">Was Not Was</a>
</Dropdown.Content>
</Dropdown>
)
// throws if onClick is not bound
try {
const list = TestUtils.scryRenderedDOMComponentsWithClass(
dinoWalkDropdown, 'Dropdown-toggle')
TestUtils.Simulate.click(list[0])
// dinoWalkDropdown.toggleDropdown()
} catch (e) {
// swallow on purpose, valid for code to not bind onClick
}
expect(theDoor).toEqual('closed',
'click on disabled dropdown button should not ' +
'trigger given toggle function')
})
})