@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,186 @@
|
|
|
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 { CondensedButton } from '../index'
|
|
31
|
+
|
|
32
|
+
describe('<CondensedButton/>', () => {
|
|
33
|
+
const icon = (
|
|
34
|
+
<svg
|
|
35
|
+
data-title="myIcon"
|
|
36
|
+
height="1em"
|
|
37
|
+
width="1em"
|
|
38
|
+
style={{ fill: 'currentcolor' }}
|
|
39
|
+
>
|
|
40
|
+
<circle cx="0.5em" cy="0.5em" r="0.5em" />
|
|
41
|
+
</svg>
|
|
42
|
+
)
|
|
43
|
+
const iconSelector = 'svg[data-title="myIcon"]'
|
|
44
|
+
|
|
45
|
+
it('should render children', () => {
|
|
46
|
+
const children = 'Hello world'
|
|
47
|
+
|
|
48
|
+
render(<CondensedButton>{children}</CondensedButton>)
|
|
49
|
+
|
|
50
|
+
const button = document.querySelector('button')
|
|
51
|
+
|
|
52
|
+
expect(button).toBeInTheDocument()
|
|
53
|
+
expect(button).toHaveTextContent(children)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('should provide a focused getter', () => {
|
|
57
|
+
let componentRef: CondensedButton | undefined
|
|
58
|
+
|
|
59
|
+
render(
|
|
60
|
+
<CondensedButton
|
|
61
|
+
ref={(component: CondensedButton) => {
|
|
62
|
+
componentRef = component
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
65
|
+
Hello
|
|
66
|
+
</CondensedButton>
|
|
67
|
+
)
|
|
68
|
+
const button = screen.getByRole('button', { name: 'Hello' })
|
|
69
|
+
|
|
70
|
+
button.focus()
|
|
71
|
+
|
|
72
|
+
expect(componentRef?.focused).toBe(true)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('should provide a focus function', () => {
|
|
76
|
+
let componentRef: CondensedButton | undefined
|
|
77
|
+
|
|
78
|
+
render(
|
|
79
|
+
<CondensedButton
|
|
80
|
+
ref={(component: CondensedButton) => {
|
|
81
|
+
componentRef = component
|
|
82
|
+
}}
|
|
83
|
+
>
|
|
84
|
+
Hello
|
|
85
|
+
</CondensedButton>
|
|
86
|
+
)
|
|
87
|
+
const button = screen.getByRole('button', { name: 'Hello' })
|
|
88
|
+
|
|
89
|
+
componentRef?.focus()
|
|
90
|
+
|
|
91
|
+
expect(document.activeElement).toBe(button)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('should pass the type attribute', () => {
|
|
95
|
+
render(<CondensedButton type="submit">Hello</CondensedButton>)
|
|
96
|
+
|
|
97
|
+
const button = screen.getByRole('button', { name: 'Hello' })
|
|
98
|
+
|
|
99
|
+
expect(button).toBeInTheDocument()
|
|
100
|
+
expect(button).toHaveAttribute('type', 'submit')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('should pass the `elementRef` prop', async () => {
|
|
104
|
+
const elementRef = jest.fn()
|
|
105
|
+
render(<CondensedButton elementRef={elementRef}>Hello</CondensedButton>)
|
|
106
|
+
const button = screen.getByRole('button', { name: 'Hello' })
|
|
107
|
+
|
|
108
|
+
expect(elementRef).toHaveBeenCalledWith(button)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('should pass the `as` prop', () => {
|
|
112
|
+
const { container } = render(
|
|
113
|
+
<CondensedButton as="li">Hello</CondensedButton>
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
const button = container.querySelector('[type="button"]')
|
|
117
|
+
|
|
118
|
+
expect(button).toBeInTheDocument()
|
|
119
|
+
expect(button).toHaveTextContent('Hello')
|
|
120
|
+
expect(button!.tagName).toBe('LI')
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('should set the disabled attribute when `interaction` is set to disabled', () => {
|
|
124
|
+
render(<CondensedButton interaction="disabled">Hello</CondensedButton>)
|
|
125
|
+
|
|
126
|
+
const button = screen.getByRole('button', { name: 'Hello' })
|
|
127
|
+
|
|
128
|
+
expect(button).toHaveAttribute('disabled')
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('should set the disabled attribute when `disabled` is set', () => {
|
|
132
|
+
render(<CondensedButton disabled>Hello</CondensedButton>)
|
|
133
|
+
|
|
134
|
+
const button = screen.getByRole('button', { name: 'Hello' })
|
|
135
|
+
|
|
136
|
+
expect(button).toHaveAttribute('disabled')
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('should set the disabled attribute when `interaction` is set to readonly', () => {
|
|
140
|
+
render(<CondensedButton interaction="readonly">Hello</CondensedButton>)
|
|
141
|
+
|
|
142
|
+
const button = screen.getByRole('button', { name: 'Hello' })
|
|
143
|
+
|
|
144
|
+
expect(button).toHaveAttribute('disabled')
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it('should set the disabled attribute when `readOnly` is set', () => {
|
|
148
|
+
render(<CondensedButton readOnly>Hello</CondensedButton>)
|
|
149
|
+
|
|
150
|
+
const button = screen.getByRole('button', { name: 'Hello' })
|
|
151
|
+
|
|
152
|
+
expect(button).toHaveAttribute('disabled')
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('should pass the `href` prop', () => {
|
|
156
|
+
render(<CondensedButton href="#">Hello</CondensedButton>)
|
|
157
|
+
|
|
158
|
+
const linkButton = screen.getByRole('link', { name: 'Hello' })
|
|
159
|
+
|
|
160
|
+
expect(linkButton).toBeInTheDocument()
|
|
161
|
+
expect(linkButton).toHaveAttribute('href', '#')
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
it('should pass the `renderIcon` prop', async () => {
|
|
165
|
+
render(<CondensedButton renderIcon={icon}>Hello</CondensedButton>)
|
|
166
|
+
|
|
167
|
+
const svgIcon = document.querySelector(iconSelector)
|
|
168
|
+
const button = screen.getByRole('button', { name: 'Hello' })
|
|
169
|
+
|
|
170
|
+
expect(button).toBeInTheDocument()
|
|
171
|
+
expect(svgIcon).toBeInTheDocument()
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
it('should pass the `onClick` prop', async () => {
|
|
175
|
+
const onClick = jest.fn()
|
|
176
|
+
render(<CondensedButton onClick={onClick}>Hello</CondensedButton>)
|
|
177
|
+
|
|
178
|
+
const button = screen.getByRole('button', { name: 'Hello' })
|
|
179
|
+
|
|
180
|
+
await userEvent.click(button)
|
|
181
|
+
|
|
182
|
+
await waitFor(() => {
|
|
183
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
184
|
+
})
|
|
185
|
+
})
|
|
186
|
+
})
|
|
@@ -0,0 +1,214 @@
|
|
|
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 { IconButton } from '../index'
|
|
31
|
+
|
|
32
|
+
describe('<IconButton/>', () => {
|
|
33
|
+
const icon = (
|
|
34
|
+
<svg
|
|
35
|
+
data-title="myIcon"
|
|
36
|
+
height="1em"
|
|
37
|
+
width="1em"
|
|
38
|
+
style={{ fill: 'currentcolor' }}
|
|
39
|
+
>
|
|
40
|
+
<circle cx="0.5em" cy="0.5em" r="0.5em" />
|
|
41
|
+
</svg>
|
|
42
|
+
)
|
|
43
|
+
const iconSelector = 'svg[data-title="myIcon"]'
|
|
44
|
+
|
|
45
|
+
it('should render an icon when provided as the `children` prop', () => {
|
|
46
|
+
render(<IconButton screenReaderLabel="some action">{icon}</IconButton>)
|
|
47
|
+
|
|
48
|
+
const svgIcon = document.querySelector(iconSelector)
|
|
49
|
+
const button = screen.getByRole('button')
|
|
50
|
+
|
|
51
|
+
expect(button).toBeInTheDocument()
|
|
52
|
+
expect(svgIcon).toBeInTheDocument()
|
|
53
|
+
expect(button).toHaveTextContent('some action')
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('should render an icon when provided as the `renderIcon` prop', () => {
|
|
57
|
+
render(<IconButton screenReaderLabel="some action" renderIcon={icon} />)
|
|
58
|
+
const svgIcon = document.querySelector(iconSelector)
|
|
59
|
+
const button = screen.getByRole('button')
|
|
60
|
+
|
|
61
|
+
expect(button).toBeInTheDocument()
|
|
62
|
+
expect(svgIcon).toBeInTheDocument()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('should provide a focused getter', () => {
|
|
66
|
+
let componentRef: IconButton | undefined
|
|
67
|
+
|
|
68
|
+
render(
|
|
69
|
+
<IconButton
|
|
70
|
+
screenReaderLabel="some action"
|
|
71
|
+
renderIcon={icon}
|
|
72
|
+
ref={(component: IconButton) => {
|
|
73
|
+
componentRef = component
|
|
74
|
+
}}
|
|
75
|
+
/>
|
|
76
|
+
)
|
|
77
|
+
const button = screen.getByRole('button')
|
|
78
|
+
|
|
79
|
+
button.focus()
|
|
80
|
+
|
|
81
|
+
expect(componentRef?.focused).toBe(true)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('should provide a focus function', () => {
|
|
85
|
+
let componentRef: IconButton | undefined
|
|
86
|
+
|
|
87
|
+
render(
|
|
88
|
+
<IconButton
|
|
89
|
+
screenReaderLabel="some action"
|
|
90
|
+
renderIcon={icon}
|
|
91
|
+
ref={(component: IconButton) => {
|
|
92
|
+
componentRef = component
|
|
93
|
+
}}
|
|
94
|
+
/>
|
|
95
|
+
)
|
|
96
|
+
const button = screen.getByRole('button')
|
|
97
|
+
|
|
98
|
+
componentRef?.focus()
|
|
99
|
+
|
|
100
|
+
expect(document.activeElement).toBe(button)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('should pass the `href` prop', () => {
|
|
104
|
+
render(
|
|
105
|
+
<IconButton screenReaderLabel="some action" renderIcon={icon} href="#" />
|
|
106
|
+
)
|
|
107
|
+
const linkButton = screen.getByRole('link')
|
|
108
|
+
|
|
109
|
+
expect(linkButton).toBeInTheDocument()
|
|
110
|
+
expect(linkButton).toHaveAttribute('href', '#')
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('should pass the `type` prop', () => {
|
|
114
|
+
render(
|
|
115
|
+
<IconButton
|
|
116
|
+
screenReaderLabel="some action"
|
|
117
|
+
renderIcon={icon}
|
|
118
|
+
type="reset"
|
|
119
|
+
/>
|
|
120
|
+
)
|
|
121
|
+
const button = screen.getByRole('button')
|
|
122
|
+
|
|
123
|
+
expect(button).toBeInTheDocument()
|
|
124
|
+
expect(button).toHaveAttribute('type', 'reset')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('should pass the `elementRef` prop', () => {
|
|
128
|
+
const elementRef = jest.fn()
|
|
129
|
+
render(
|
|
130
|
+
<IconButton
|
|
131
|
+
screenReaderLabel="some action"
|
|
132
|
+
renderIcon={icon}
|
|
133
|
+
elementRef={elementRef}
|
|
134
|
+
/>
|
|
135
|
+
)
|
|
136
|
+
const button = screen.getByRole('button')
|
|
137
|
+
|
|
138
|
+
expect(elementRef).toHaveBeenCalledWith(button)
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
it('should pass the `as` prop', () => {
|
|
142
|
+
const { container } = render(
|
|
143
|
+
<IconButton screenReaderLabel="some action" renderIcon={icon} as="li" />
|
|
144
|
+
)
|
|
145
|
+
const button = container.querySelector('[type="button"]')
|
|
146
|
+
|
|
147
|
+
expect(button).toBeInTheDocument()
|
|
148
|
+
expect(button).toHaveTextContent('some action')
|
|
149
|
+
expect(button!.tagName).toBe('LI')
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it('should set the disabled attribute when `interaction` is set to disabled', () => {
|
|
153
|
+
render(
|
|
154
|
+
<IconButton
|
|
155
|
+
screenReaderLabel="some action"
|
|
156
|
+
renderIcon={icon}
|
|
157
|
+
interaction="disabled"
|
|
158
|
+
/>
|
|
159
|
+
)
|
|
160
|
+
const button = screen.getByRole('button')
|
|
161
|
+
|
|
162
|
+
expect(button).toHaveAttribute('disabled')
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
it('should set the disabled attribute when `disabled` is set', () => {
|
|
166
|
+
render(
|
|
167
|
+
<IconButton screenReaderLabel="some action" renderIcon={icon} disabled />
|
|
168
|
+
)
|
|
169
|
+
const button = screen.getByRole('button')
|
|
170
|
+
|
|
171
|
+
expect(button).toHaveAttribute('disabled')
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
it('should set the disabled attribute when `interaction` is set to readonly', () => {
|
|
175
|
+
render(
|
|
176
|
+
<IconButton
|
|
177
|
+
screenReaderLabel="some action"
|
|
178
|
+
renderIcon={icon}
|
|
179
|
+
interaction="readonly"
|
|
180
|
+
/>
|
|
181
|
+
)
|
|
182
|
+
const button = screen.getByRole('button')
|
|
183
|
+
|
|
184
|
+
expect(button).toHaveAttribute('disabled')
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it('should set the disabled attribute when `readOnly` is set', () => {
|
|
188
|
+
render(
|
|
189
|
+
<IconButton screenReaderLabel="some action" renderIcon={icon} readOnly />
|
|
190
|
+
)
|
|
191
|
+
const button = screen.getByRole('button')
|
|
192
|
+
|
|
193
|
+
expect(button).toHaveAttribute('disabled')
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
it('should pass the `onClick` prop', async () => {
|
|
197
|
+
const onClick = jest.fn()
|
|
198
|
+
|
|
199
|
+
render(
|
|
200
|
+
<IconButton
|
|
201
|
+
screenReaderLabel="some action"
|
|
202
|
+
renderIcon={icon}
|
|
203
|
+
onClick={onClick}
|
|
204
|
+
/>
|
|
205
|
+
)
|
|
206
|
+
const button = screen.getByRole('button')
|
|
207
|
+
|
|
208
|
+
await userEvent.click(button)
|
|
209
|
+
|
|
210
|
+
await waitFor(() => {
|
|
211
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
212
|
+
})
|
|
213
|
+
})
|
|
214
|
+
})
|
|
@@ -0,0 +1,200 @@
|
|
|
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 { ToggleButton } from '../index'
|
|
31
|
+
|
|
32
|
+
describe('<ToggleButton />', () => {
|
|
33
|
+
const icon = (
|
|
34
|
+
<svg data-title="myIcon" height="1em" width="1em">
|
|
35
|
+
<circle cx="0.5em" cy="0.5em" r="0.5em" />
|
|
36
|
+
</svg>
|
|
37
|
+
)
|
|
38
|
+
const iconSelector = 'svg[data-title="myIcon"]'
|
|
39
|
+
|
|
40
|
+
it('should render', () => {
|
|
41
|
+
render(
|
|
42
|
+
<ToggleButton
|
|
43
|
+
screenReaderLabel="This is a screen reader label"
|
|
44
|
+
renderIcon={icon}
|
|
45
|
+
renderTooltipContent="This is tooltip content"
|
|
46
|
+
status="pressed"
|
|
47
|
+
/>
|
|
48
|
+
)
|
|
49
|
+
const button = screen.getByRole('button')
|
|
50
|
+
const svgIcon = document.querySelector(iconSelector)
|
|
51
|
+
const tooltip = screen.getByRole('tooltip')
|
|
52
|
+
|
|
53
|
+
expect(button).toBeInTheDocument()
|
|
54
|
+
expect(button).toHaveTextContent('This is a screen reader label')
|
|
55
|
+
expect(svgIcon).toBeInTheDocument()
|
|
56
|
+
expect(tooltip).toBeInTheDocument()
|
|
57
|
+
expect(tooltip).toHaveTextContent('This is tooltip content')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('should set `aria-pressed` to `true` if `status` is `pressed`', () => {
|
|
61
|
+
render(
|
|
62
|
+
<ToggleButton
|
|
63
|
+
screenReaderLabel="This is a screen reader label"
|
|
64
|
+
renderIcon={icon}
|
|
65
|
+
renderTooltipContent="This is tooltip content"
|
|
66
|
+
status="pressed"
|
|
67
|
+
/>
|
|
68
|
+
)
|
|
69
|
+
const button = screen.getByRole('button')
|
|
70
|
+
|
|
71
|
+
expect(button).toHaveAttribute('aria-pressed', 'true')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('should set `aria-pressed` to `false` if `status` is `unpressed`', () => {
|
|
75
|
+
render(
|
|
76
|
+
<ToggleButton
|
|
77
|
+
screenReaderLabel="This is a screen reader label"
|
|
78
|
+
renderIcon={icon}
|
|
79
|
+
renderTooltipContent="This is tooltip content"
|
|
80
|
+
status="unpressed"
|
|
81
|
+
/>
|
|
82
|
+
)
|
|
83
|
+
const button = screen.getByRole('button')
|
|
84
|
+
|
|
85
|
+
expect(button).toHaveAttribute('aria-pressed', 'false')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('should render an icon', () => {
|
|
89
|
+
render(
|
|
90
|
+
<ToggleButton
|
|
91
|
+
screenReaderLabel="This is a screen reader label"
|
|
92
|
+
renderIcon={icon}
|
|
93
|
+
renderTooltipContent="This is tooltip content"
|
|
94
|
+
status="pressed"
|
|
95
|
+
/>
|
|
96
|
+
)
|
|
97
|
+
const button = screen.getByRole('button')
|
|
98
|
+
const svgIcon = document.querySelector(iconSelector)
|
|
99
|
+
|
|
100
|
+
expect(button).toBeInTheDocument()
|
|
101
|
+
expect(svgIcon).toBeInTheDocument()
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('should pass the `as` prop', () => {
|
|
105
|
+
const { container } = render(
|
|
106
|
+
<ToggleButton
|
|
107
|
+
screenReaderLabel="This is a screen reader label"
|
|
108
|
+
renderIcon={icon}
|
|
109
|
+
renderTooltipContent="This is tooltip content"
|
|
110
|
+
as="li"
|
|
111
|
+
status="pressed"
|
|
112
|
+
/>
|
|
113
|
+
)
|
|
114
|
+
const button = container.querySelector('[type="button"]')
|
|
115
|
+
|
|
116
|
+
expect(button).toBeInTheDocument()
|
|
117
|
+
expect(button!.tagName).toBe('LI')
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
it('should set the disabled attribute when `interaction` prop is set to disabled', () => {
|
|
121
|
+
render(
|
|
122
|
+
<ToggleButton
|
|
123
|
+
screenReaderLabel="This is a screen reader label"
|
|
124
|
+
renderIcon={icon}
|
|
125
|
+
renderTooltipContent="This is tooltip content"
|
|
126
|
+
interaction="disabled"
|
|
127
|
+
status="pressed"
|
|
128
|
+
/>
|
|
129
|
+
)
|
|
130
|
+
const button = screen.getByRole('button')
|
|
131
|
+
|
|
132
|
+
expect(button).toHaveAttribute('disabled')
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
it('should set the disabled attribute when `disabled` prop is set', () => {
|
|
136
|
+
render(
|
|
137
|
+
<ToggleButton
|
|
138
|
+
screenReaderLabel="This is a screen reader label"
|
|
139
|
+
renderIcon={icon}
|
|
140
|
+
renderTooltipContent="This is tooltip content"
|
|
141
|
+
disabled
|
|
142
|
+
status="pressed"
|
|
143
|
+
/>
|
|
144
|
+
)
|
|
145
|
+
const button = screen.getByRole('button')
|
|
146
|
+
|
|
147
|
+
expect(button).toHaveAttribute('disabled')
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('should set the disabled attribute when `interaction` prop is set to readonly', () => {
|
|
151
|
+
render(
|
|
152
|
+
<ToggleButton
|
|
153
|
+
screenReaderLabel="This is a screen reader label"
|
|
154
|
+
renderIcon={icon}
|
|
155
|
+
renderTooltipContent="This is tooltip content"
|
|
156
|
+
interaction="readonly"
|
|
157
|
+
status="pressed"
|
|
158
|
+
/>
|
|
159
|
+
)
|
|
160
|
+
const button = screen.getByRole('button')
|
|
161
|
+
|
|
162
|
+
expect(button).toHaveAttribute('disabled')
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
it('should set the disabled attribute when `readOnly` prop is set', () => {
|
|
166
|
+
render(
|
|
167
|
+
<ToggleButton
|
|
168
|
+
screenReaderLabel="This is a screen reader label"
|
|
169
|
+
renderIcon={icon}
|
|
170
|
+
renderTooltipContent="This is tooltip content"
|
|
171
|
+
readOnly
|
|
172
|
+
status="pressed"
|
|
173
|
+
/>
|
|
174
|
+
)
|
|
175
|
+
const button = screen.getByRole('button')
|
|
176
|
+
|
|
177
|
+
expect(button).toHaveAttribute('disabled')
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('should pass the `onClick` prop', async () => {
|
|
181
|
+
const onClick = jest.fn()
|
|
182
|
+
|
|
183
|
+
render(
|
|
184
|
+
<ToggleButton
|
|
185
|
+
screenReaderLabel="This is a screen reader label"
|
|
186
|
+
renderIcon={icon}
|
|
187
|
+
renderTooltipContent="This is tooltip content"
|
|
188
|
+
onClick={onClick}
|
|
189
|
+
status="pressed"
|
|
190
|
+
/>
|
|
191
|
+
)
|
|
192
|
+
const button = screen.getByRole('button')
|
|
193
|
+
|
|
194
|
+
await userEvent.click(button)
|
|
195
|
+
|
|
196
|
+
await waitFor(() => {
|
|
197
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
198
|
+
})
|
|
199
|
+
})
|
|
200
|
+
})
|
package/tsconfig.build.json
CHANGED
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
"include": ["src"],
|
|
9
9
|
"references": [
|
|
10
10
|
{ "path": "../ui-babel-preset/tsconfig.build.json" },
|
|
11
|
-
{ "path": "../ui-test-locator/tsconfig.build.json" },
|
|
12
|
-
{ "path": "../ui-test-queries/tsconfig.build.json" },
|
|
13
11
|
{ "path": "../ui-test-utils/tsconfig.build.json" },
|
|
14
12
|
{ "path": "../ui-themes/tsconfig.build.json" },
|
|
15
13
|
{ "path": "../console/tsconfig.build.json" },
|
|
@@ -25,6 +23,7 @@
|
|
|
25
23
|
{ "path": "../ui-testable/tsconfig.build.json" },
|
|
26
24
|
{ "path": "../ui-tooltip/tsconfig.build.json" },
|
|
27
25
|
{ "path": "../ui-utils/tsconfig.build.json" },
|
|
28
|
-
{ "path": "../ui-view/tsconfig.build.json" }
|
|
26
|
+
{ "path": "../ui-view/tsconfig.build.json" },
|
|
27
|
+
{ "path": "../ui-axe-check/tsconfig.build.json" }
|
|
29
28
|
]
|
|
30
29
|
}
|