@instructure/ui-buttons 8.55.0 → 8.55.1-snapshot-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/es/BaseButton/__new-tests__/BaseButton.test.js +361 -0
- package/es/Button/__new-tests__/Button.test.js +459 -0
- package/es/CloseButton/__new-tests__/CloseButton.test.js +63 -0
- package/es/CondensedButton/__new-tests__/CondensedButton.test.js +181 -0
- package/es/IconButton/__new-tests__/IconButton.test.js +185 -0
- package/es/ToggleButton/__new-tests__/ToggleButton.test.js +163 -0
- package/lib/BaseButton/__new-tests__/BaseButton.test.js +363 -0
- package/lib/Button/__new-tests__/Button.test.js +461 -0
- package/lib/CloseButton/__new-tests__/CloseButton.test.js +65 -0
- package/lib/CondensedButton/__new-tests__/CondensedButton.test.js +183 -0
- package/lib/IconButton/__new-tests__/IconButton.test.js +187 -0
- package/lib/ToggleButton/__new-tests__/ToggleButton.test.js +165 -0
- package/package.json +22 -20
- package/src/BaseButton/__new-tests__/BaseButton.test.tsx +407 -0
- package/src/Button/__new-tests__/Button.test.tsx +500 -0
- package/src/CloseButton/__new-tests__/CloseButton.test.tsx +70 -0
- package/src/CondensedButton/__new-tests__/CondensedButton.test.tsx +186 -0
- package/src/IconButton/__new-tests__/IconButton.test.tsx +214 -0
- package/src/ToggleButton/__new-tests__/ToggleButton.test.tsx +200 -0
- package/tsconfig.build.json +2 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/BaseButton/__new-tests__/BaseButton.test.d.ts +2 -0
- package/types/BaseButton/__new-tests__/BaseButton.test.d.ts.map +1 -0
- package/types/Button/__new-tests__/Button.test.d.ts +2 -0
- package/types/Button/__new-tests__/Button.test.d.ts.map +1 -0
- package/types/CloseButton/__new-tests__/CloseButton.test.d.ts +2 -0
- package/types/CloseButton/__new-tests__/CloseButton.test.d.ts.map +1 -0
- package/types/CondensedButton/__new-tests__/CondensedButton.test.d.ts +2 -0
- package/types/CondensedButton/__new-tests__/CondensedButton.test.d.ts.map +1 -0
- package/types/IconButton/__new-tests__/IconButton.test.d.ts +2 -0
- package/types/IconButton/__new-tests__/IconButton.test.d.ts.map +1 -0
- package/types/ToggleButton/__new-tests__/ToggleButton.test.d.ts +2 -0
- package/types/ToggleButton/__new-tests__/ToggleButton.test.d.ts.map +1 -0
- package/es/BaseButton/BaseButtonLocator.js +0 -34
- package/es/BaseButton/locator.js +0 -27
- package/es/Button/ButtonLocator.js +0 -33
- package/es/Button/locator.js +0 -28
- package/es/CloseButton/CloseButtonLocator.js +0 -29
- package/es/CloseButton/locator.js +0 -27
- package/es/CondensedButton/CondensedButtonLocator.js +0 -33
- package/es/CondensedButton/locator.js +0 -26
- package/es/IconButton/IconButtonLocator.js +0 -33
- package/es/IconButton/locator.js +0 -26
- package/es/ToggleButton/ToggleButtonLocator.js +0 -46
- package/lib/BaseButton/BaseButtonLocator.js +0 -39
- package/lib/BaseButton/locator.js +0 -37
- package/lib/Button/ButtonLocator.js +0 -39
- package/lib/Button/locator.js +0 -39
- package/lib/CloseButton/CloseButtonLocator.js +0 -34
- package/lib/CloseButton/locator.js +0 -37
- package/lib/CondensedButton/CondensedButtonLocator.js +0 -39
- package/lib/CondensedButton/locator.js +0 -37
- package/lib/IconButton/IconButtonLocator.js +0 -39
- package/lib/IconButton/locator.js +0 -37
- package/lib/ToggleButton/ToggleButtonLocator.js +0 -51
- package/src/BaseButton/BaseButtonLocator.ts +0 -35
- package/src/BaseButton/locator.ts +0 -28
- package/src/Button/ButtonLocator.ts +0 -34
- package/src/Button/locator.ts +0 -27
- package/src/CloseButton/CloseButtonLocator.ts +0 -29
- package/src/CloseButton/locator.ts +0 -28
- package/src/CondensedButton/CondensedButtonLocator.ts +0 -34
- package/src/CondensedButton/locator.ts +0 -27
- package/src/IconButton/IconButtonLocator.ts +0 -34
- package/src/IconButton/locator.ts +0 -27
- package/src/ToggleButton/ToggleButtonLocator.ts +0 -44
- package/types/BaseButton/BaseButtonLocator.d.ts +0 -577
- package/types/BaseButton/BaseButtonLocator.d.ts.map +0 -1
- package/types/BaseButton/locator.d.ts +0 -4
- package/types/BaseButton/locator.d.ts.map +0 -1
- package/types/Button/ButtonLocator.d.ts +0 -577
- package/types/Button/ButtonLocator.d.ts.map +0 -1
- package/types/Button/locator.d.ts +0 -581
- package/types/Button/locator.d.ts.map +0 -1
- package/types/CloseButton/CloseButtonLocator.d.ts +0 -566
- package/types/CloseButton/CloseButtonLocator.d.ts.map +0 -1
- package/types/CloseButton/locator.d.ts +0 -4
- package/types/CloseButton/locator.d.ts.map +0 -1
- package/types/CondensedButton/CondensedButtonLocator.d.ts +0 -577
- package/types/CondensedButton/CondensedButtonLocator.d.ts.map +0 -1
- package/types/CondensedButton/locator.d.ts +0 -4
- package/types/CondensedButton/locator.d.ts.map +0 -1
- package/types/IconButton/IconButtonLocator.d.ts +0 -577
- package/types/IconButton/IconButtonLocator.d.ts.map +0 -1
- package/types/IconButton/locator.d.ts +0 -4
- package/types/IconButton/locator.d.ts.map +0 -1
- package/types/ToggleButton/ToggleButtonLocator.d.ts +0 -582
- package/types/ToggleButton/ToggleButtonLocator.d.ts.map +0 -1
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React from 'react'
|
|
26
|
+
import { render, screen, waitFor } from '@testing-library/react'
|
|
27
|
+
import userEvent from '@testing-library/user-event'
|
|
28
|
+
import '@testing-library/jest-dom'
|
|
29
|
+
|
|
30
|
+
import { BaseButton } from '../index'
|
|
31
|
+
import { runAxeCheck } from '@instructure/ui-axe-check'
|
|
32
|
+
|
|
33
|
+
describe('<BaseButton/>', () => {
|
|
34
|
+
let consoleWarningMock: jest.SpyInstance
|
|
35
|
+
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
// Mocking console to prevent test output pollution
|
|
38
|
+
consoleWarningMock = jest.spyOn(console, 'warn').mockImplementation()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
consoleWarningMock.mockRestore()
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('should render a button and the children as button text', () => {
|
|
46
|
+
render(<BaseButton>Hello World</BaseButton>)
|
|
47
|
+
|
|
48
|
+
const button = document.querySelector('button')
|
|
49
|
+
|
|
50
|
+
expect(button).toBeInTheDocument()
|
|
51
|
+
expect(button).toHaveTextContent('Hello World')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('should not error with a null child', () => {
|
|
55
|
+
render(<BaseButton>Hello World{null}</BaseButton>)
|
|
56
|
+
|
|
57
|
+
const button = document.querySelector('button')
|
|
58
|
+
|
|
59
|
+
expect(button).toBeInTheDocument()
|
|
60
|
+
expect(button).toHaveTextContent('Hello World')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('should render a link styled as a button if href is provided', () => {
|
|
64
|
+
render(<BaseButton href="example.html">Hello World</BaseButton>)
|
|
65
|
+
|
|
66
|
+
const linkButton = screen.getByRole('link', { name: 'Hello World' })
|
|
67
|
+
|
|
68
|
+
expect(linkButton).toBeInTheDocument()
|
|
69
|
+
expect(linkButton).toHaveAttribute('href', 'example.html')
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('should render as a link when `to` prop is provided', () => {
|
|
73
|
+
const { container } = render(<BaseButton to="/example">Test</BaseButton>)
|
|
74
|
+
|
|
75
|
+
const linkButton = container.querySelector('a')
|
|
76
|
+
|
|
77
|
+
expect(linkButton!.getAttribute('to')).toBe('/example')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('should render designated tag if `as` prop is specified', () => {
|
|
81
|
+
const { container } = render(<BaseButton as="span">Hello World</BaseButton>)
|
|
82
|
+
|
|
83
|
+
const button = container.querySelector('[type="button"]')
|
|
84
|
+
|
|
85
|
+
expect(button).toBeInTheDocument()
|
|
86
|
+
expect(button).toHaveTextContent('Hello World')
|
|
87
|
+
expect(button!.tagName).toBe('SPAN')
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('should set role="button"', () => {
|
|
91
|
+
const onClick = jest.fn()
|
|
92
|
+
|
|
93
|
+
const { container } = render(
|
|
94
|
+
<BaseButton as="span" onClick={onClick}>
|
|
95
|
+
Hello World
|
|
96
|
+
</BaseButton>
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
const button = container.querySelector('span[type="button"]')
|
|
100
|
+
|
|
101
|
+
expect(button).toBeInTheDocument()
|
|
102
|
+
expect(button).toHaveAttribute('role', 'button')
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('should set tabIndex="0"', () => {
|
|
106
|
+
const onClick = jest.fn()
|
|
107
|
+
|
|
108
|
+
render(
|
|
109
|
+
<BaseButton as="span" onClick={onClick}>
|
|
110
|
+
Hello World
|
|
111
|
+
</BaseButton>
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
115
|
+
|
|
116
|
+
expect(button).toBeInTheDocument()
|
|
117
|
+
expect(button).toHaveAttribute('tabIndex', '0')
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
it('should pass down the type prop to the button element', async () => {
|
|
121
|
+
const onClick = jest.fn()
|
|
122
|
+
render(
|
|
123
|
+
<BaseButton type="submit" onClick={onClick}>
|
|
124
|
+
Hello World
|
|
125
|
+
</BaseButton>
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
129
|
+
|
|
130
|
+
expect(button).toBeInTheDocument()
|
|
131
|
+
expect(button).toHaveAttribute('type', 'submit')
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it('should pass down an icon via the icon property', () => {
|
|
135
|
+
const SomeIcon = () => (
|
|
136
|
+
<svg>
|
|
137
|
+
<circle cx="25" cy="75" r="20" />
|
|
138
|
+
</svg>
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
render(<BaseButton renderIcon={SomeIcon}>Hello World</BaseButton>)
|
|
142
|
+
|
|
143
|
+
const icon = document.querySelector('svg')
|
|
144
|
+
|
|
145
|
+
expect(icon).toBeInTheDocument()
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
it('focuses with the focus helper', async () => {
|
|
149
|
+
render(<BaseButton>Hello World</BaseButton>)
|
|
150
|
+
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
151
|
+
|
|
152
|
+
button.focus()
|
|
153
|
+
|
|
154
|
+
expect(document.activeElement).toBe(button)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
it('should provide an elementRef prop', async () => {
|
|
158
|
+
const elementRef = jest.fn()
|
|
159
|
+
render(<BaseButton elementRef={elementRef}>Hello World</BaseButton>)
|
|
160
|
+
|
|
161
|
+
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
162
|
+
|
|
163
|
+
expect(elementRef).toBeCalledWith(button)
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
describe('onClick', () => {
|
|
167
|
+
it('should call onClick when clicked', async () => {
|
|
168
|
+
const onClick = jest.fn()
|
|
169
|
+
render(<BaseButton onClick={onClick}>Hello World</BaseButton>)
|
|
170
|
+
|
|
171
|
+
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
172
|
+
|
|
173
|
+
await userEvent.click(button)
|
|
174
|
+
|
|
175
|
+
await waitFor(() => {
|
|
176
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('should not call onClick when interaction is "disabled"', async () => {
|
|
181
|
+
const onClick = jest.fn()
|
|
182
|
+
|
|
183
|
+
render(
|
|
184
|
+
<BaseButton interaction="disabled" onClick={onClick}>
|
|
185
|
+
Hello World
|
|
186
|
+
</BaseButton>
|
|
187
|
+
)
|
|
188
|
+
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
189
|
+
|
|
190
|
+
await userEvent.click(button)
|
|
191
|
+
|
|
192
|
+
await waitFor(() => {
|
|
193
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
194
|
+
})
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
it('should not call onClick when disabled is set"', async () => {
|
|
198
|
+
const onClick = jest.fn()
|
|
199
|
+
|
|
200
|
+
render(
|
|
201
|
+
<BaseButton disabled onClick={onClick}>
|
|
202
|
+
Hello World
|
|
203
|
+
</BaseButton>
|
|
204
|
+
)
|
|
205
|
+
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
206
|
+
|
|
207
|
+
await userEvent.click(button)
|
|
208
|
+
|
|
209
|
+
await waitFor(() => {
|
|
210
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
211
|
+
})
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
it('should not call onClick when interaction is "readonly"', async () => {
|
|
215
|
+
const onClick = jest.fn()
|
|
216
|
+
|
|
217
|
+
render(
|
|
218
|
+
<BaseButton interaction="readonly" onClick={onClick}>
|
|
219
|
+
Hello World
|
|
220
|
+
</BaseButton>
|
|
221
|
+
)
|
|
222
|
+
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
223
|
+
|
|
224
|
+
await userEvent.click(button)
|
|
225
|
+
|
|
226
|
+
await waitFor(() => {
|
|
227
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
228
|
+
})
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
it('should not call onClick when readOnly is set', async () => {
|
|
232
|
+
const onClick = jest.fn()
|
|
233
|
+
|
|
234
|
+
render(
|
|
235
|
+
<BaseButton readOnly onClick={onClick}>
|
|
236
|
+
Hello World
|
|
237
|
+
</BaseButton>
|
|
238
|
+
)
|
|
239
|
+
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
240
|
+
|
|
241
|
+
await userEvent.click(button)
|
|
242
|
+
|
|
243
|
+
await waitFor(() => {
|
|
244
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
245
|
+
})
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
it('should not call onClick when button is disabled and an href prop is provided', async () => {
|
|
249
|
+
const onClick = jest.fn()
|
|
250
|
+
|
|
251
|
+
render(<BaseButton href="#">Hello World</BaseButton>)
|
|
252
|
+
|
|
253
|
+
const button = screen.getByRole('link', { name: 'Hello World' })
|
|
254
|
+
|
|
255
|
+
await userEvent.click(button)
|
|
256
|
+
|
|
257
|
+
await waitFor(() => {
|
|
258
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
259
|
+
})
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
it('should not call onClick when interaction is "readonly" and an href prop is provided', async () => {
|
|
263
|
+
const onClick = jest.fn()
|
|
264
|
+
|
|
265
|
+
render(
|
|
266
|
+
<BaseButton interaction="readonly" onClick={onClick} href="#">
|
|
267
|
+
Hello World
|
|
268
|
+
</BaseButton>
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
const button = screen.getByRole('link', { name: 'Hello World' })
|
|
272
|
+
|
|
273
|
+
await userEvent.click(button)
|
|
274
|
+
|
|
275
|
+
await waitFor(() => {
|
|
276
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
277
|
+
})
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
it('should call onClick when space key is pressed if href is provided', async () => {
|
|
281
|
+
const onClick = jest.fn()
|
|
282
|
+
|
|
283
|
+
render(
|
|
284
|
+
<BaseButton onClick={onClick} href="#">
|
|
285
|
+
Hello World
|
|
286
|
+
</BaseButton>
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
const button = screen.getByRole('link', { name: 'Hello World' })
|
|
290
|
+
|
|
291
|
+
await userEvent.type(button, '{space}')
|
|
292
|
+
|
|
293
|
+
await waitFor(() => {
|
|
294
|
+
expect(onClick).toHaveBeenCalled()
|
|
295
|
+
})
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
it('should call onClick when enter key is pressed when not a button or link', async () => {
|
|
299
|
+
const onClick = jest.fn()
|
|
300
|
+
|
|
301
|
+
render(
|
|
302
|
+
<BaseButton as="span" onClick={onClick}>
|
|
303
|
+
Hello World
|
|
304
|
+
</BaseButton>
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
308
|
+
|
|
309
|
+
await userEvent.type(button, '{enter}')
|
|
310
|
+
|
|
311
|
+
await waitFor(() => {
|
|
312
|
+
expect(onClick).toHaveBeenCalled()
|
|
313
|
+
})
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
it('should not call onClick when interaction is "disabled" and space key is pressed', async () => {
|
|
317
|
+
const onClick = jest.fn()
|
|
318
|
+
|
|
319
|
+
render(
|
|
320
|
+
<BaseButton interaction="disabled" onClick={onClick} href="#">
|
|
321
|
+
Hello World
|
|
322
|
+
</BaseButton>
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
const button = screen.getByRole('link', { name: 'Hello World' })
|
|
326
|
+
|
|
327
|
+
await userEvent.type(button, '{space}')
|
|
328
|
+
|
|
329
|
+
await waitFor(() => {
|
|
330
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
331
|
+
})
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
it('should not call onClick when interaction is "readonly" and space key is pressed', async () => {
|
|
335
|
+
const onClick = jest.fn()
|
|
336
|
+
|
|
337
|
+
render(
|
|
338
|
+
<BaseButton interaction="readonly" onClick={onClick} href="#">
|
|
339
|
+
Hello World
|
|
340
|
+
</BaseButton>
|
|
341
|
+
)
|
|
342
|
+
const button = screen.getByRole('link', { name: 'Hello World' })
|
|
343
|
+
|
|
344
|
+
await userEvent.type(button, '{space}')
|
|
345
|
+
|
|
346
|
+
await waitFor(() => {
|
|
347
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
348
|
+
})
|
|
349
|
+
})
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
describe('when passing down props to View', () => {
|
|
353
|
+
it("passes cursor='pointer' to View by default", async () => {
|
|
354
|
+
render(<BaseButton>Hello World</BaseButton>)
|
|
355
|
+
|
|
356
|
+
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
357
|
+
const style = window.getComputedStyle(button)
|
|
358
|
+
|
|
359
|
+
expect(style.cursor).toBe('pointer')
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
it("passes cursor='not-allowed' to View when disabled", async () => {
|
|
363
|
+
render(<BaseButton interaction="disabled">Hello World</BaseButton>)
|
|
364
|
+
|
|
365
|
+
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
366
|
+
const style = window.getComputedStyle(button)
|
|
367
|
+
|
|
368
|
+
expect(style.cursor).toBe('not-allowed')
|
|
369
|
+
})
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
describe('for a11y', () => {
|
|
373
|
+
it('should meet standards when onClick is given', async () => {
|
|
374
|
+
const onClick = jest.fn()
|
|
375
|
+
|
|
376
|
+
render(<BaseButton onClick={onClick}>Hello World</BaseButton>)
|
|
377
|
+
|
|
378
|
+
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
379
|
+
|
|
380
|
+
await userEvent.click(button)
|
|
381
|
+
|
|
382
|
+
await waitFor(async () => {
|
|
383
|
+
const axeCheck = await runAxeCheck(button)
|
|
384
|
+
|
|
385
|
+
expect(axeCheck).toBe(true)
|
|
386
|
+
})
|
|
387
|
+
})
|
|
388
|
+
|
|
389
|
+
describe('when disabled', () => {
|
|
390
|
+
it('sets the disabled attribute so that the button is not in tab order', () => {
|
|
391
|
+
render(<BaseButton interaction="disabled">Hello World</BaseButton>)
|
|
392
|
+
|
|
393
|
+
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
394
|
+
expect(button).toHaveAttribute('disabled')
|
|
395
|
+
})
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
describe('when readonly', () => {
|
|
399
|
+
it('sets the disabled attribute so that the button is not in tab order', async () => {
|
|
400
|
+
render(<BaseButton interaction="readonly">Hello World</BaseButton>)
|
|
401
|
+
|
|
402
|
+
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
403
|
+
expect(button).toHaveAttribute('disabled')
|
|
404
|
+
})
|
|
405
|
+
})
|
|
406
|
+
})
|
|
407
|
+
})
|