@telus-uds/components-base 0.0.2-prerelease.6 → 0.0.2-prerelease.7
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/.ultra.cache.json +1 -1
- package/CHANGELOG.md +20 -0
- package/__fixtures__/testTheme.js +424 -37
- package/__tests__/Button/ButtonBase.test.jsx +2 -31
- package/__tests__/Checkbox/Checkbox.test.jsx +94 -0
- package/__tests__/InputSupports/InputSupports.test.jsx +50 -0
- package/__tests__/List/List.test.jsx +60 -0
- package/__tests__/Radio/Radio.test.jsx +87 -0
- package/__tests__/Select/Select.test.jsx +93 -0
- package/__tests__/Skeleton/Skeleton.test.jsx +61 -0
- package/__tests__/Tags/Tags.test.jsx +328 -0
- package/__tests__/TextInput/TextArea.test.jsx +34 -0
- package/__tests__/TextInput/{TextInput.test.jsx → TextInputBase.test.jsx} +20 -46
- package/jest.config.js +3 -1
- package/lib/Button/Button.js +10 -3
- package/lib/Button/ButtonBase.js +73 -59
- package/lib/Button/ButtonGroup.js +11 -27
- package/lib/Button/ButtonLink.js +5 -0
- package/lib/Checkbox/Checkbox.js +308 -0
- package/lib/Checkbox/CheckboxInput.native.js +6 -0
- package/lib/Checkbox/CheckboxInput.web.js +57 -0
- package/lib/Checkbox/index.js +2 -0
- package/lib/Feedback/Feedback.js +20 -3
- package/lib/Icon/Icon.js +8 -5
- package/lib/Icon/IconText.js +72 -0
- package/lib/Icon/index.js +2 -1
- package/lib/InputSupports/InputSupports.js +90 -0
- package/lib/InputSupports/index.js +2 -0
- package/lib/InputSupports/propTypes.js +55 -0
- package/lib/Link/ChevronLink.js +23 -20
- package/lib/Link/InlinePressable.native.js +78 -0
- package/lib/Link/InlinePressable.web.js +32 -0
- package/lib/Link/Link.js +11 -10
- package/lib/Link/LinkBase.js +62 -123
- package/lib/Link/TextButton.js +20 -9
- package/lib/Link/index.js +2 -1
- package/lib/List/List.js +52 -0
- package/lib/List/ListItem.js +207 -0
- package/lib/List/index.js +2 -0
- package/lib/Pagination/PageButton.js +2 -25
- package/lib/Pagination/SideButton.js +27 -37
- package/lib/Radio/Radio.js +291 -0
- package/lib/Radio/RadioInput.native.js +6 -0
- package/lib/Radio/RadioInput.web.js +59 -0
- package/lib/Radio/index.js +2 -0
- package/lib/Select/Group.native.js +14 -0
- package/lib/Select/Group.web.js +18 -0
- package/lib/Select/Item.native.js +9 -0
- package/lib/Select/Item.web.js +15 -0
- package/lib/Select/Picker.native.js +87 -0
- package/lib/Select/Picker.web.js +63 -0
- package/lib/Select/Select.js +272 -0
- package/lib/Select/index.js +6 -0
- package/lib/Skeleton/Skeleton.js +119 -0
- package/lib/Skeleton/index.js +2 -0
- package/lib/Tags/Tags.js +217 -0
- package/lib/Tags/index.js +2 -0
- package/lib/TextInput/TextArea.js +82 -0
- package/lib/TextInput/TextInput.js +23 -304
- package/lib/TextInput/TextInputBase.js +229 -0
- package/lib/TextInput/index.js +2 -1
- package/lib/TextInput/propTypes.js +31 -0
- package/lib/ThemeProvider/useThemeTokens.js +54 -3
- package/lib/ToggleSwitch/ToggleSwitch.js +1 -1
- package/lib/Typography/Typography.js +4 -19
- package/lib/index.js +8 -1
- package/lib/utils/a11y/index.js +1 -0
- package/lib/utils/a11y/textSize.js +33 -0
- package/lib/utils/index.js +3 -0
- package/lib/utils/info/index.js +7 -0
- package/lib/utils/info/platform/index.js +11 -0
- package/lib/utils/info/platform/platform.android.js +1 -0
- package/lib/utils/info/platform/platform.ios.js +1 -0
- package/lib/utils/info/platform/platform.native.js +4 -0
- package/lib/utils/info/platform/platform.web.js +1 -0
- package/lib/utils/info/versions.js +5 -0
- package/lib/utils/pressability.js +92 -0
- package/lib/utils/propTypes.js +78 -17
- package/package.json +5 -4
- package/release-context.json +4 -4
- package/src/Button/Button.jsx +6 -3
- package/src/Button/ButtonBase.jsx +66 -57
- package/src/Button/ButtonGroup.jsx +9 -22
- package/src/Button/ButtonLink.jsx +11 -2
- package/src/Checkbox/Checkbox.jsx +275 -0
- package/src/Checkbox/CheckboxInput.native.jsx +6 -0
- package/src/Checkbox/CheckboxInput.web.jsx +55 -0
- package/src/Checkbox/index.js +3 -0
- package/src/Feedback/Feedback.jsx +13 -4
- package/src/Icon/Icon.jsx +9 -5
- package/src/Icon/IconText.jsx +63 -0
- package/src/Icon/index.js +2 -1
- package/src/InputSupports/InputSupports.jsx +86 -0
- package/src/InputSupports/index.js +3 -0
- package/src/InputSupports/propTypes.js +44 -0
- package/src/Link/ChevronLink.jsx +20 -17
- package/src/Link/InlinePressable.native.jsx +73 -0
- package/src/Link/InlinePressable.web.jsx +37 -0
- package/src/Link/Link.jsx +17 -13
- package/src/Link/LinkBase.jsx +57 -140
- package/src/Link/TextButton.jsx +25 -11
- package/src/Link/index.js +2 -1
- package/src/List/List.jsx +47 -0
- package/src/List/ListItem.jsx +187 -0
- package/src/List/index.js +3 -0
- package/src/Pagination/PageButton.jsx +2 -16
- package/src/Pagination/SideButton.jsx +23 -34
- package/src/Radio/Radio.jsx +270 -0
- package/src/Radio/RadioInput.native.jsx +6 -0
- package/src/Radio/RadioInput.web.jsx +57 -0
- package/src/Radio/index.js +3 -0
- package/src/Select/Group.native.jsx +14 -0
- package/src/Select/Group.web.jsx +15 -0
- package/src/Select/Item.native.jsx +10 -0
- package/src/Select/Item.web.jsx +11 -0
- package/src/Select/Picker.native.jsx +95 -0
- package/src/Select/Picker.web.jsx +67 -0
- package/src/Select/Select.jsx +265 -0
- package/src/Select/index.js +8 -0
- package/src/Skeleton/Skeleton.jsx +101 -0
- package/src/Skeleton/index.js +3 -0
- package/src/Tags/Tags.jsx +206 -0
- package/src/Tags/index.js +3 -0
- package/src/TextInput/TextArea.jsx +78 -0
- package/src/TextInput/TextInput.jsx +17 -284
- package/src/TextInput/TextInputBase.jsx +220 -0
- package/src/TextInput/index.js +2 -1
- package/src/TextInput/propTypes.js +29 -0
- package/src/ThemeProvider/useThemeTokens.js +54 -3
- package/src/ToggleSwitch/ToggleSwitch.jsx +1 -1
- package/src/Typography/Typography.jsx +4 -15
- package/src/index.js +8 -1
- package/src/utils/a11y/index.js +1 -0
- package/src/utils/a11y/textSize.js +30 -0
- package/src/utils/index.js +3 -0
- package/src/utils/info/index.js +8 -0
- package/src/utils/info/platform/index.js +11 -0
- package/src/utils/info/platform/platform.android.js +1 -0
- package/src/utils/info/platform/platform.ios.js +1 -0
- package/src/utils/info/platform/platform.native.js +4 -0
- package/src/utils/info/platform/platform.web.js +1 -0
- package/src/utils/info/versions.js +6 -0
- package/src/utils/pressability.js +92 -0
- package/src/utils/propTypes.js +97 -22
- package/stories/Button/Button.stories.jsx +5 -0
- package/stories/Checkbox/Checkbox.stories.jsx +71 -0
- package/stories/Feedback/Feedback.stories.jsx +5 -6
- package/stories/Link/Link.stories.jsx +15 -1
- package/stories/List/List.stories.jsx +117 -0
- package/stories/Radio/Radio.stories.jsx +113 -0
- package/stories/Select/Select.stories.jsx +55 -0
- package/stories/Skeleton/Skeleton.stories.jsx +36 -0
- package/stories/Tags/Tags.stories.jsx +69 -0
- package/stories/TextInput/TextArea.stories.jsx +100 -0
- package/stories/supports.jsx +1 -1
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { render, fireEvent } from '@testing-library/react-native'
|
|
3
|
+
import { toHaveTextContent } from '@testing-library/jest-native'
|
|
4
|
+
|
|
5
|
+
import Theme from '../../__fixtures__/Theme'
|
|
6
|
+
import Tags from '../../src/Tags'
|
|
7
|
+
|
|
8
|
+
const items = [
|
|
9
|
+
{ label: 'One', id: 'one', accessibilityLabel: 'Option one' },
|
|
10
|
+
{ label: 'Two', id: 'two', accessibilityLabel: 'Option two' },
|
|
11
|
+
{ label: 'Three', id: 'three', accessibilityLabel: 'Option three' },
|
|
12
|
+
{ label: 'Four', id: 'four', accessibilityLabel: 'Option four' }
|
|
13
|
+
]
|
|
14
|
+
const checked = { checked: true }
|
|
15
|
+
|
|
16
|
+
// expect().toHaveTextContent doesn't work on arrays, expect().toContain etc doesn't match elements
|
|
17
|
+
const containsText = (queryResult, text) =>
|
|
18
|
+
queryResult.some((testInstance) => toHaveTextContent(testInstance, text).pass)
|
|
19
|
+
|
|
20
|
+
describe('Tags', () => {
|
|
21
|
+
// eslint-disable-next-line no-console
|
|
22
|
+
const consoleError = console.error
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
// eslint-disable-next-line no-console
|
|
25
|
+
console.error = () => {}
|
|
26
|
+
})
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
// eslint-disable-next-line no-console
|
|
29
|
+
console.error = consoleError
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('Throws if has `values` without `onChange`', () => {
|
|
33
|
+
expect(() =>
|
|
34
|
+
render(
|
|
35
|
+
<Theme>
|
|
36
|
+
<Tags items={items} values={['one']} />
|
|
37
|
+
</Theme>
|
|
38
|
+
)
|
|
39
|
+
).toThrow(/values.+without.+onChange/)
|
|
40
|
+
})
|
|
41
|
+
it("Doesn't throw if has `values` without `onChange` and is read only", () => {
|
|
42
|
+
expect(() =>
|
|
43
|
+
render(
|
|
44
|
+
<Theme>
|
|
45
|
+
<Tags items={items} values={['one']} readOnly />
|
|
46
|
+
</Theme>
|
|
47
|
+
)
|
|
48
|
+
).not.toThrow()
|
|
49
|
+
})
|
|
50
|
+
it('Throws if has both `values` and `initialValues`', () => {
|
|
51
|
+
expect(() =>
|
|
52
|
+
render(
|
|
53
|
+
<Theme>
|
|
54
|
+
<Tags items={items} values={['one']} initialValues={['one']} onChange={() => {}} />
|
|
55
|
+
</Theme>
|
|
56
|
+
)
|
|
57
|
+
).toThrow(/both(?=.*initialValues)(?=.*values){2}/)
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
describe('Tags (uncontrolled)', () => {
|
|
62
|
+
// These tests are almost the same as ButtonGroup while Tags-specific behaviours are still TBC
|
|
63
|
+
it('Selects one and only one item if maxValues is passed', async () => {
|
|
64
|
+
const { getByText, queryAllByA11yState } = render(
|
|
65
|
+
<Theme>
|
|
66
|
+
<Tags items={items} maxValues={1} />
|
|
67
|
+
</Theme>
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
expect(queryAllByA11yState(checked)).toHaveLength(0)
|
|
71
|
+
|
|
72
|
+
const one = getByText('One')
|
|
73
|
+
await fireEvent.press(one)
|
|
74
|
+
expect(queryAllByA11yState(checked)).toHaveLength(1)
|
|
75
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
|
|
76
|
+
|
|
77
|
+
const two = getByText('Two')
|
|
78
|
+
await fireEvent.press(two)
|
|
79
|
+
expect(queryAllByA11yState(checked)).toHaveLength(1)
|
|
80
|
+
expect(containsText(queryAllByA11yState(checked), 'Two')).toBeTruthy()
|
|
81
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).not.toBeTruthy()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('Deselects if the selected item is pressed', async () => {
|
|
85
|
+
const { getByText, queryAllByA11yState } = render(
|
|
86
|
+
<Theme>
|
|
87
|
+
<Tags items={items} />
|
|
88
|
+
</Theme>
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
expect(queryAllByA11yState(checked)).toHaveLength(0)
|
|
92
|
+
|
|
93
|
+
const three = getByText('Three')
|
|
94
|
+
await fireEvent.press(three)
|
|
95
|
+
expect(queryAllByA11yState(checked)).toHaveLength(1)
|
|
96
|
+
expect(containsText(queryAllByA11yState(checked), 'Three')).toBeTruthy()
|
|
97
|
+
|
|
98
|
+
await fireEvent.press(three)
|
|
99
|
+
expect(queryAllByA11yState(checked)).toHaveLength(0)
|
|
100
|
+
expect(containsText(queryAllByA11yState(checked), 'Three')).not.toBeTruthy()
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('Selects <= two items when maxValues === 2', async () => {
|
|
104
|
+
const { getByText, queryAllByA11yState } = render(
|
|
105
|
+
<Theme>
|
|
106
|
+
<Tags items={items} maxValues={2} />
|
|
107
|
+
</Theme>
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
expect(queryAllByA11yState(checked)).toHaveLength(0)
|
|
111
|
+
|
|
112
|
+
const one = getByText('One')
|
|
113
|
+
await fireEvent.press(one)
|
|
114
|
+
expect(queryAllByA11yState(checked)).toHaveLength(1)
|
|
115
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
|
|
116
|
+
|
|
117
|
+
const two = getByText('Two')
|
|
118
|
+
await fireEvent.press(two)
|
|
119
|
+
expect(queryAllByA11yState(checked)).toHaveLength(2)
|
|
120
|
+
expect(containsText(queryAllByA11yState(checked), 'Two')).toBeTruthy()
|
|
121
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
|
|
122
|
+
|
|
123
|
+
const three = getByText('Three')
|
|
124
|
+
await fireEvent.press(three)
|
|
125
|
+
expect(queryAllByA11yState(checked)).toHaveLength(2)
|
|
126
|
+
expect(containsText(queryAllByA11yState(checked), 'Three')).toBeTruthy()
|
|
127
|
+
expect(containsText(queryAllByA11yState(checked), 'Two')).toBeTruthy()
|
|
128
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).not.toBeTruthy()
|
|
129
|
+
|
|
130
|
+
const four = getByText('Four')
|
|
131
|
+
await fireEvent.press(four)
|
|
132
|
+
expect(queryAllByA11yState(checked)).toHaveLength(2)
|
|
133
|
+
expect(containsText(queryAllByA11yState(checked), 'Four')).toBeTruthy()
|
|
134
|
+
expect(containsText(queryAllByA11yState(checked), 'Three')).toBeTruthy()
|
|
135
|
+
expect(containsText(queryAllByA11yState(checked), 'Two')).not.toBeTruthy()
|
|
136
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).not.toBeTruthy()
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('Is accessible as checkboxes by default', async () => {
|
|
140
|
+
const { queryAllByA11yRole, queryAllByA11yState } = render(
|
|
141
|
+
<Theme>
|
|
142
|
+
<Tags items={items} />
|
|
143
|
+
</Theme>
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
expect(queryAllByA11yRole('radioGroup')).toHaveLength(0)
|
|
147
|
+
expect(queryAllByA11yRole('radio')).toHaveLength(0)
|
|
148
|
+
|
|
149
|
+
const checks = queryAllByA11yRole('checkbox')
|
|
150
|
+
expect(checks).toHaveLength(4)
|
|
151
|
+
|
|
152
|
+
expect(queryAllByA11yState(checked)).toHaveLength(0)
|
|
153
|
+
await fireEvent.press(checks[0])
|
|
154
|
+
expect(queryAllByA11yState(checked)).toHaveLength(1)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
it('Selects unlimited items by default', async () => {
|
|
158
|
+
const { getByText, queryAllByA11yState } = render(
|
|
159
|
+
<Theme>
|
|
160
|
+
<Tags items={items} />
|
|
161
|
+
</Theme>
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
expect(queryAllByA11yState(checked)).toHaveLength(0)
|
|
165
|
+
|
|
166
|
+
const one = getByText('One')
|
|
167
|
+
await fireEvent.press(one)
|
|
168
|
+
expect(queryAllByA11yState(checked)).toHaveLength(1)
|
|
169
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
|
|
170
|
+
|
|
171
|
+
const two = getByText('Two')
|
|
172
|
+
await fireEvent.press(two)
|
|
173
|
+
expect(queryAllByA11yState(checked)).toHaveLength(2)
|
|
174
|
+
expect(containsText(queryAllByA11yState(checked), 'Two')).toBeTruthy()
|
|
175
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
|
|
176
|
+
|
|
177
|
+
const three = getByText('Three')
|
|
178
|
+
await fireEvent.press(three)
|
|
179
|
+
expect(queryAllByA11yState(checked)).toHaveLength(3)
|
|
180
|
+
expect(containsText(queryAllByA11yState(checked), 'Three')).toBeTruthy()
|
|
181
|
+
expect(containsText(queryAllByA11yState(checked), 'Two')).toBeTruthy()
|
|
182
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
|
|
183
|
+
|
|
184
|
+
const four = getByText('Four')
|
|
185
|
+
await fireEvent.press(four)
|
|
186
|
+
expect(queryAllByA11yState(checked)).toHaveLength(4)
|
|
187
|
+
expect(containsText(queryAllByA11yState(checked), 'Four')).toBeTruthy()
|
|
188
|
+
expect(containsText(queryAllByA11yState(checked), 'Three')).toBeTruthy()
|
|
189
|
+
expect(containsText(queryAllByA11yState(checked), 'Two')).toBeTruthy()
|
|
190
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
it('Auto-selects any provided initialValues', async () => {
|
|
194
|
+
const { getByText, queryAllByA11yState } = render(
|
|
195
|
+
<Theme>
|
|
196
|
+
<Tags items={items} initialValues={['one', 'two']} maxValues={3} />
|
|
197
|
+
</Theme>
|
|
198
|
+
)
|
|
199
|
+
expect(queryAllByA11yState(checked)).toHaveLength(2)
|
|
200
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
|
|
201
|
+
expect(containsText(queryAllByA11yState(checked), 'Two')).toBeTruthy()
|
|
202
|
+
|
|
203
|
+
const three = getByText('Three')
|
|
204
|
+
await fireEvent.press(three)
|
|
205
|
+
|
|
206
|
+
expect(queryAllByA11yState(checked)).toHaveLength(3)
|
|
207
|
+
expect(containsText(queryAllByA11yState(checked), 'Three')).toBeTruthy()
|
|
208
|
+
expect(containsText(queryAllByA11yState(checked), 'Two')).toBeTruthy()
|
|
209
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
|
|
210
|
+
|
|
211
|
+
const four = getByText('Four')
|
|
212
|
+
await fireEvent.press(four)
|
|
213
|
+
expect(queryAllByA11yState(checked)).toHaveLength(3)
|
|
214
|
+
expect(containsText(queryAllByA11yState(checked), 'Four')).toBeTruthy()
|
|
215
|
+
expect(containsText(queryAllByA11yState(checked), 'Three')).toBeTruthy()
|
|
216
|
+
expect(containsText(queryAllByA11yState(checked), 'Two')).toBeTruthy()
|
|
217
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).not.toBeTruthy()
|
|
218
|
+
|
|
219
|
+
const two = getByText('Two')
|
|
220
|
+
await fireEvent.press(two)
|
|
221
|
+
expect(queryAllByA11yState(checked)).toHaveLength(2)
|
|
222
|
+
expect(containsText(queryAllByA11yState(checked), 'Four')).toBeTruthy()
|
|
223
|
+
expect(containsText(queryAllByA11yState(checked), 'Three')).toBeTruthy()
|
|
224
|
+
expect(containsText(queryAllByA11yState(checked), 'Two')).not.toBeTruthy()
|
|
225
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).not.toBeTruthy()
|
|
226
|
+
})
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
describe('Tags (controlled)', () => {
|
|
230
|
+
it('Calls onChange handler on press in controlled mode, providing pressed id', async () => {
|
|
231
|
+
const handleChange = jest.fn((arg) => arg)
|
|
232
|
+
const { getByText } = render(
|
|
233
|
+
<Theme>
|
|
234
|
+
<Tags items={items} values={[]} onChange={handleChange} />
|
|
235
|
+
</Theme>
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
expect(handleChange).toHaveBeenCalledTimes(0)
|
|
239
|
+
|
|
240
|
+
const one = getByText('One')
|
|
241
|
+
await fireEvent.press(one)
|
|
242
|
+
expect(handleChange).toHaveBeenCalledTimes(1)
|
|
243
|
+
|
|
244
|
+
expect(handleChange.mock.calls[0][0]).toEqual(['one'])
|
|
245
|
+
|
|
246
|
+
const two = getByText('Two')
|
|
247
|
+
await fireEvent.press(two)
|
|
248
|
+
expect(handleChange).toHaveBeenCalledTimes(2)
|
|
249
|
+
expect(handleChange.mock.calls[1][0]).toEqual(['two'])
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
it("Doesn't change its own selection if `values` is passed", async () => {
|
|
253
|
+
const { getByText, queryAllByA11yState } = render(
|
|
254
|
+
<Theme>
|
|
255
|
+
<Tags items={items} values={['one']} onChange={() => {}} />
|
|
256
|
+
</Theme>
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
expect(queryAllByA11yState(checked)).toHaveLength(1)
|
|
260
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
|
|
261
|
+
|
|
262
|
+
const one = getByText('One')
|
|
263
|
+
await fireEvent.press(one)
|
|
264
|
+
expect(queryAllByA11yState(checked)).toHaveLength(1)
|
|
265
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
|
|
266
|
+
|
|
267
|
+
const two = getByText('Two')
|
|
268
|
+
await fireEvent.press(two)
|
|
269
|
+
expect(queryAllByA11yState(checked)).toHaveLength(1)
|
|
270
|
+
expect(containsText(queryAllByA11yState(checked), 'Two')).not.toBeTruthy()
|
|
271
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
it('Does not render an invalid `values` invalidly', async () => {
|
|
275
|
+
const { queryAllByA11yState } = render(
|
|
276
|
+
<Theme>
|
|
277
|
+
<Tags items={items} values={['one', 'two', 'three']} maxValues={2} onChange={() => {}} />
|
|
278
|
+
</Theme>
|
|
279
|
+
)
|
|
280
|
+
expect(queryAllByA11yState(checked)).toHaveLength(2)
|
|
281
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).not.toBeTruthy()
|
|
282
|
+
expect(containsText(queryAllByA11yState(checked), 'Two')).toBeTruthy()
|
|
283
|
+
expect(containsText(queryAllByA11yState(checked), 'Three')).toBeTruthy()
|
|
284
|
+
})
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
describe('Tags (read-only)', () => {
|
|
288
|
+
it("Doesn't call onChange handler when read-only", async () => {
|
|
289
|
+
const handleChange = jest.fn((arg) => arg)
|
|
290
|
+
const { getByText } = render(
|
|
291
|
+
<Theme>
|
|
292
|
+
<Tags items={items} values={[]} onChange={handleChange} readOnly />
|
|
293
|
+
</Theme>
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
expect(handleChange).toHaveBeenCalledTimes(0)
|
|
297
|
+
|
|
298
|
+
const one = getByText('One')
|
|
299
|
+
await fireEvent.press(one)
|
|
300
|
+
expect(handleChange).toHaveBeenCalledTimes(0)
|
|
301
|
+
|
|
302
|
+
const two = getByText('Two')
|
|
303
|
+
await fireEvent.press(two)
|
|
304
|
+
expect(handleChange).toHaveBeenCalledTimes(0)
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
it("Doesn't change its selection on press", async () => {
|
|
308
|
+
const { getByText, queryAllByA11yState } = render(
|
|
309
|
+
<Theme>
|
|
310
|
+
<Tags items={items} values={['one']} readOnly />
|
|
311
|
+
</Theme>
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
expect(queryAllByA11yState(checked)).toHaveLength(1)
|
|
315
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
|
|
316
|
+
|
|
317
|
+
const one = getByText('One')
|
|
318
|
+
await fireEvent.press(one)
|
|
319
|
+
expect(queryAllByA11yState(checked)).toHaveLength(1)
|
|
320
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
|
|
321
|
+
|
|
322
|
+
const two = getByText('Two')
|
|
323
|
+
await fireEvent.press(two)
|
|
324
|
+
expect(queryAllByA11yState(checked)).toHaveLength(1)
|
|
325
|
+
expect(containsText(queryAllByA11yState(checked), 'Two')).not.toBeTruthy()
|
|
326
|
+
expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
|
|
327
|
+
})
|
|
328
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { fireEvent, render } from '@testing-library/react-native'
|
|
3
|
+
|
|
4
|
+
import { Platform } from 'react-native'
|
|
5
|
+
import { TextArea } from '../../src'
|
|
6
|
+
import Theme from '../../__fixtures__/Theme'
|
|
7
|
+
|
|
8
|
+
describe('TextArea', () => {
|
|
9
|
+
it('renders', () => {
|
|
10
|
+
// at least one called test is required in a suite
|
|
11
|
+
render(<TextArea />, { wrapper: Theme })
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
// TODO: this won't be called until cross-platform Jest tests are configured
|
|
15
|
+
// see https://github.com/telus/universal-design-system/issues/319
|
|
16
|
+
if (Platform.OS === 'web') {
|
|
17
|
+
it('grows in size on input', () => {
|
|
18
|
+
const { getByTestId } = render(
|
|
19
|
+
<TextArea tokens={{ minLines: 1, maxLines: 5, lineHeight: 20 }} testID="textarea" />,
|
|
20
|
+
{
|
|
21
|
+
wrapper: Theme
|
|
22
|
+
}
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
const textarea = getByTestId('textarea')
|
|
26
|
+
|
|
27
|
+
expect(textarea).toHaveStyle({ height: 20 })
|
|
28
|
+
|
|
29
|
+
fireEvent.changeText(textarea, '\n\n\n')
|
|
30
|
+
|
|
31
|
+
expect(textarea).toHaveStyle({ height: 60 })
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
})
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
1
|
import { fireEvent, render } from '@testing-library/react-native'
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import Theme from '../../__fixtures__/Theme'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import TextInputBase from '../../src/TextInput/TextInputBase'
|
|
6
4
|
import Viewport from '../../__fixtures__/Viewport'
|
|
5
|
+
import Theme from '../../__fixtures__/Theme'
|
|
7
6
|
|
|
8
7
|
// eslint-disable-next-line react/prop-types
|
|
9
8
|
const Wrapper = ({ children }) => (
|
|
@@ -12,40 +11,7 @@ const Wrapper = ({ children }) => (
|
|
|
12
11
|
</Viewport>
|
|
13
12
|
)
|
|
14
13
|
|
|
15
|
-
describe('
|
|
16
|
-
it('renders the label', () => {
|
|
17
|
-
const { queryByText } = render(<TextInput label="Test label content" />, { wrapper: Wrapper })
|
|
18
|
-
|
|
19
|
-
expect(queryByText('Test label content')).toBeTruthy()
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('renders the hint', () => {
|
|
23
|
-
const { queryByText } = render(
|
|
24
|
-
<TextInput label="Test label content" hint="Test hint content" />,
|
|
25
|
-
{ wrapper: Wrapper }
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
expect(queryByText('Test hint content')).toBeTruthy()
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
it('renders the feedback', () => {
|
|
32
|
-
const { queryByText } = render(<TextInput feedback="Test feedback content" />, {
|
|
33
|
-
wrapper: Wrapper
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
expect(queryByText('Test feedback content')).toBeTruthy()
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('renders the tooltip which content shows up when pressed', () => {
|
|
40
|
-
const { queryByText, getByRole } = render(
|
|
41
|
-
<TextInput label="Test label content" tooltip="Test tooltip content" />,
|
|
42
|
-
{ wrapper: Wrapper }
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
fireEvent(getByRole('button'), 'press')
|
|
46
|
-
expect(queryByText('Test tooltip content')).toBeTruthy()
|
|
47
|
-
})
|
|
48
|
-
|
|
14
|
+
describe('TextInputBaseBase', () => {
|
|
49
15
|
it('triggers the interactive callbacks', () => {
|
|
50
16
|
const onFocus = jest.fn()
|
|
51
17
|
const onBlur = jest.fn()
|
|
@@ -53,8 +19,8 @@ describe('TextInput', () => {
|
|
|
53
19
|
const onMouseOut = jest.fn()
|
|
54
20
|
|
|
55
21
|
const { getByA11yLabel } = render(
|
|
56
|
-
<
|
|
57
|
-
|
|
22
|
+
<TextInputBase
|
|
23
|
+
accessibilityLabel="Input label"
|
|
58
24
|
onFocus={onFocus}
|
|
59
25
|
onBlur={onBlur}
|
|
60
26
|
onMouseOver={onMouseOver}
|
|
@@ -85,7 +51,7 @@ describe('TextInput', () => {
|
|
|
85
51
|
})
|
|
86
52
|
|
|
87
53
|
it("can't be edited when inactive", () => {
|
|
88
|
-
const { getByA11yLabel } = render(<
|
|
54
|
+
const { getByA11yLabel } = render(<TextInputBase accessibilityLabel="Input label" inactive />, {
|
|
89
55
|
wrapper: Wrapper
|
|
90
56
|
})
|
|
91
57
|
|
|
@@ -97,9 +63,12 @@ describe('TextInput', () => {
|
|
|
97
63
|
it('changes value when uncontrolled', () => {
|
|
98
64
|
const onChange = jest.fn()
|
|
99
65
|
|
|
100
|
-
const { getByA11yLabel } = render(
|
|
101
|
-
|
|
102
|
-
|
|
66
|
+
const { getByA11yLabel } = render(
|
|
67
|
+
<TextInputBase accessibilityLabel="Input label" onChange={onChange} />,
|
|
68
|
+
{
|
|
69
|
+
wrapper: Wrapper
|
|
70
|
+
}
|
|
71
|
+
)
|
|
103
72
|
|
|
104
73
|
const input = getByA11yLabel('Input label')
|
|
105
74
|
|
|
@@ -113,7 +82,7 @@ describe('TextInput', () => {
|
|
|
113
82
|
const onChange = jest.fn()
|
|
114
83
|
|
|
115
84
|
const { getByA11yLabel } = render(
|
|
116
|
-
<
|
|
85
|
+
<TextInputBase accessibilityLabel="Input label" onChange={onChange} value="initial value" />,
|
|
117
86
|
{
|
|
118
87
|
wrapper: Wrapper
|
|
119
88
|
}
|
|
@@ -131,7 +100,12 @@ describe('TextInput', () => {
|
|
|
131
100
|
const onChange = jest.fn()
|
|
132
101
|
|
|
133
102
|
const { getByA11yLabel } = render(
|
|
134
|
-
<
|
|
103
|
+
<TextInputBase
|
|
104
|
+
accessibilityLabel="Input label"
|
|
105
|
+
onChange={onChange}
|
|
106
|
+
value="initial value"
|
|
107
|
+
readOnly
|
|
108
|
+
/>,
|
|
135
109
|
{
|
|
136
110
|
wrapper: Wrapper
|
|
137
111
|
}
|
package/jest.config.js
CHANGED
|
@@ -21,7 +21,9 @@ module.exports = {
|
|
|
21
21
|
moduleNameMapper: {
|
|
22
22
|
'.+\\.(otf|svg|png|jpg)$': 'identity-obj-proxy'
|
|
23
23
|
},
|
|
24
|
-
transformIgnorePatterns:
|
|
24
|
+
transformIgnorePatterns: [
|
|
25
|
+
'node_modules/(?!(jest-)?react-native|@react-native-community|@react-native-picker)'
|
|
26
|
+
],
|
|
25
27
|
// Count everything in src when calculating coverage
|
|
26
28
|
collectCoverageFrom: ['src/**/*.{js,jsx}']
|
|
27
29
|
}
|
package/lib/Button/Button.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import ButtonBase from './ButtonBase';
|
|
3
3
|
import buttonPropTypes from './propTypes';
|
|
4
|
+
import { useThemeTokensCallback } from '../ThemeProvider';
|
|
4
5
|
import { a11yProps } from '../utils/propTypes';
|
|
5
6
|
|
|
6
7
|
const Button = ({
|
|
7
8
|
accessibilityRole = 'button',
|
|
9
|
+
tokens,
|
|
10
|
+
variant,
|
|
8
11
|
...props
|
|
9
|
-
}) =>
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
+
}) => {
|
|
13
|
+
const getTokens = useThemeTokensCallback('Button', tokens, variant);
|
|
14
|
+
return /*#__PURE__*/React.createElement(ButtonBase, Object.assign({}, props, {
|
|
15
|
+
tokens: getTokens,
|
|
16
|
+
accessibilityRole: accessibilityRole
|
|
17
|
+
}));
|
|
18
|
+
};
|
|
12
19
|
|
|
13
20
|
Button.propTypes = { ...a11yProps.types,
|
|
14
21
|
...buttonPropTypes
|