@telus-uds/components-base 1.25.0 → 1.27.0

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.
Files changed (86) hide show
  1. package/CHANGELOG.md +46 -2
  2. package/component-docs.json +57 -2
  3. package/lib/Button/ButtonBase.js +2 -1
  4. package/lib/Carousel/Carousel.js +19 -1
  5. package/lib/Carousel/CarouselStepTracker/CarouselStepTracker.js +11 -2
  6. package/lib/MultiSelectFilter/ModalOverlay.js +136 -0
  7. package/lib/MultiSelectFilter/MultiSelectFilter.js +64 -26
  8. package/lib-module/Button/ButtonBase.js +2 -1
  9. package/lib-module/Carousel/Carousel.js +16 -1
  10. package/lib-module/Carousel/CarouselStepTracker/CarouselStepTracker.js +10 -2
  11. package/lib-module/MultiSelectFilter/ModalOverlay.js +112 -0
  12. package/lib-module/MultiSelectFilter/MultiSelectFilter.js +65 -27
  13. package/package.json +2 -2
  14. package/src/Button/ButtonBase.jsx +1 -1
  15. package/src/Carousel/Carousel.jsx +16 -2
  16. package/src/Carousel/CarouselStepTracker/CarouselStepTracker.jsx +7 -1
  17. package/src/MultiSelectFilter/ModalOverlay.jsx +86 -0
  18. package/src/MultiSelectFilter/MultiSelectFilter.jsx +73 -49
  19. package/.eslintrc.js +0 -9
  20. package/__tests17__/A11yText/A11yText.test.jsx +0 -34
  21. package/__tests17__/ActivityIndicator/ActivityIndicator.test.jsx +0 -68
  22. package/__tests17__/ActivityIndicator/__snapshots__/ActivityIndicator.test.jsx.snap +0 -299
  23. package/__tests17__/Box/Box.test.jsx +0 -111
  24. package/__tests17__/Button/Button.test.jsx +0 -86
  25. package/__tests17__/Button/ButtonBase.test.jsx +0 -82
  26. package/__tests17__/Button/ButtonGroup.test.jsx +0 -347
  27. package/__tests17__/Button/ButtonLink.test.jsx +0 -61
  28. package/__tests17__/Card/Card.test.jsx +0 -63
  29. package/__tests17__/Carousel/Carousel.test.jsx +0 -128
  30. package/__tests17__/Carousel/CarouselTabs.test.jsx +0 -142
  31. package/__tests17__/Checkbox/Checkbox.test.jsx +0 -94
  32. package/__tests17__/Checkbox/CheckboxGroup.test.jsx +0 -246
  33. package/__tests17__/Divider/Divider.test.jsx +0 -91
  34. package/__tests17__/ExpandCollapse/ExpandCollapse.test.jsx +0 -109
  35. package/__tests17__/Feedback/Feedback.test.jsx +0 -42
  36. package/__tests17__/FlexGrid/Col.test.jsx +0 -261
  37. package/__tests17__/FlexGrid/FlexGrid.test.jsx +0 -136
  38. package/__tests17__/FlexGrid/Row.test.jsx +0 -273
  39. package/__tests17__/HorizontalScroll/HorizontalScroll.test.jsx +0 -165
  40. package/__tests17__/Icon/Icon.test.jsx +0 -61
  41. package/__tests17__/IconButton/IconButton.test.jsx +0 -52
  42. package/__tests17__/InputLabel/InputLabel.test.jsx +0 -28
  43. package/__tests17__/InputLabel/__snapshots__/InputLabel.test.jsx.snap +0 -3
  44. package/__tests17__/InputSupports/InputSupports.test.jsx +0 -60
  45. package/__tests17__/Link/Link.test.jsx +0 -63
  46. package/__tests17__/Link/TextButton.test.jsx +0 -35
  47. package/__tests17__/List/List.test.jsx +0 -82
  48. package/__tests17__/Modal/Modal.test.jsx +0 -47
  49. package/__tests17__/Notification/Notification.test.jsx +0 -20
  50. package/__tests17__/Pagination/Pagination.test.jsx +0 -160
  51. package/__tests17__/Progress/Progress.test.jsx +0 -79
  52. package/__tests17__/Radio/Radio.test.jsx +0 -87
  53. package/__tests17__/Radio/RadioGroup.test.jsx +0 -220
  54. package/__tests17__/RadioCard/RadioCard.test.jsx +0 -87
  55. package/__tests17__/RadioCard/RadioCardGroup.test.jsx +0 -246
  56. package/__tests17__/Search/Search.test.jsx +0 -87
  57. package/__tests17__/Select/Select.test.jsx +0 -94
  58. package/__tests17__/SideNav/SideNav.test.jsx +0 -110
  59. package/__tests17__/Skeleton/Skeleton.test.jsx +0 -61
  60. package/__tests17__/SkipLink/SkipLink.test.jsx +0 -61
  61. package/__tests17__/Spacer/Spacer.test.jsx +0 -63
  62. package/__tests17__/StackView/StackView.test.jsx +0 -211
  63. package/__tests17__/StackView/StackWrap.test.jsx +0 -47
  64. package/__tests17__/StackView/getStackedContent.test.jsx +0 -295
  65. package/__tests17__/StepTracker/StepTracker.test.jsx +0 -108
  66. package/__tests17__/Tabs/Tabs.test.jsx +0 -49
  67. package/__tests17__/Tags/Tags.test.jsx +0 -327
  68. package/__tests17__/TextInput/TextArea.test.jsx +0 -35
  69. package/__tests17__/TextInput/TextInputBase.test.jsx +0 -125
  70. package/__tests17__/ThemeProvider/ThemeProvider.test.jsx +0 -82
  71. package/__tests17__/ThemeProvider/useThemeTokens.test.jsx +0 -514
  72. package/__tests17__/ThemeProvider/utils/theme-tokens.test.js +0 -41
  73. package/__tests17__/ToggleSwitch/ToggleSwitch.test.jsx +0 -82
  74. package/__tests17__/ToggleSwitch/ToggleSwitchGroup.test.jsx +0 -192
  75. package/__tests17__/Tooltip/Tooltip.test.jsx +0 -65
  76. package/__tests17__/Tooltip/getTooltipPosition.test.js +0 -79
  77. package/__tests17__/Typography/typography.test.jsx +0 -90
  78. package/__tests17__/utils/children.test.jsx +0 -128
  79. package/__tests17__/utils/containUniqueFields.test.js +0 -25
  80. package/__tests17__/utils/input.test.js +0 -375
  81. package/__tests17__/utils/props.test.js +0 -36
  82. package/__tests17__/utils/semantics.test.jsx +0 -34
  83. package/__tests17__/utils/useCopy.test.js +0 -42
  84. package/__tests17__/utils/useResponsiveProp.test.jsx +0 -202
  85. package/__tests17__/utils/useSpacingScale.test.jsx +0 -273
  86. package/__tests17__/utils/useUniqueId.test.js +0 -31
@@ -1,327 +0,0 @@
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(one, 'press', { nativeEvent: 'example' })
242
- expect(handleChange).toHaveBeenCalledTimes(1)
243
- expect(handleChange).toHaveBeenLastCalledWith(['one'], { nativeEvent: 'example' })
244
-
245
- const two = getByText('Two')
246
- await fireEvent(two, 'press', { nativeEvent: 'example2' })
247
- expect(handleChange).toHaveBeenCalledTimes(2)
248
- expect(handleChange).toHaveBeenLastCalledWith(['two'], { nativeEvent: 'example2' })
249
- })
250
-
251
- it("Doesn't change its own selection if `values` is passed", async () => {
252
- const { getByText, queryAllByA11yState } = render(
253
- <Theme>
254
- <Tags items={items} values={['one']} onChange={() => {}} />
255
- </Theme>
256
- )
257
-
258
- expect(queryAllByA11yState(checked)).toHaveLength(1)
259
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
260
-
261
- const one = getByText('One')
262
- await fireEvent.press(one)
263
- expect(queryAllByA11yState(checked)).toHaveLength(1)
264
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
265
-
266
- const two = getByText('Two')
267
- await fireEvent.press(two)
268
- expect(queryAllByA11yState(checked)).toHaveLength(1)
269
- expect(containsText(queryAllByA11yState(checked), 'Two')).not.toBeTruthy()
270
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
271
- })
272
-
273
- it('Does not render an invalid `values` invalidly', async () => {
274
- const { queryAllByA11yState } = render(
275
- <Theme>
276
- <Tags items={items} values={['one', 'two', 'three']} maxValues={2} onChange={() => {}} />
277
- </Theme>
278
- )
279
- expect(queryAllByA11yState(checked)).toHaveLength(2)
280
- expect(containsText(queryAllByA11yState(checked), 'One')).not.toBeTruthy()
281
- expect(containsText(queryAllByA11yState(checked), 'Two')).toBeTruthy()
282
- expect(containsText(queryAllByA11yState(checked), 'Three')).toBeTruthy()
283
- })
284
- })
285
-
286
- describe('Tags (read-only)', () => {
287
- it("Doesn't call onChange handler when read-only", async () => {
288
- const handleChange = jest.fn((arg) => arg)
289
- const { getByText } = render(
290
- <Theme>
291
- <Tags items={items} values={[]} onChange={handleChange} readOnly />
292
- </Theme>
293
- )
294
-
295
- expect(handleChange).toHaveBeenCalledTimes(0)
296
-
297
- const one = getByText('One')
298
- await fireEvent.press(one)
299
- expect(handleChange).toHaveBeenCalledTimes(0)
300
-
301
- const two = getByText('Two')
302
- await fireEvent.press(two)
303
- expect(handleChange).toHaveBeenCalledTimes(0)
304
- })
305
-
306
- it("Doesn't change its selection on press", async () => {
307
- const { getByText, queryAllByA11yState } = render(
308
- <Theme>
309
- <Tags items={items} values={['one']} readOnly />
310
- </Theme>
311
- )
312
-
313
- expect(queryAllByA11yState(checked)).toHaveLength(1)
314
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
315
-
316
- const one = getByText('One')
317
- await fireEvent.press(one)
318
- expect(queryAllByA11yState(checked)).toHaveLength(1)
319
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
320
-
321
- const two = getByText('Two')
322
- await fireEvent.press(two)
323
- expect(queryAllByA11yState(checked)).toHaveLength(1)
324
- expect(containsText(queryAllByA11yState(checked), 'Two')).not.toBeTruthy()
325
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
326
- })
327
- })
@@ -1,35 +0,0 @@
1
- import React from 'react'
2
- import { 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
- import { fireChange } from '../../__fixtures__/test-utils'
8
-
9
- describe('TextArea', () => {
10
- it('renders', () => {
11
- // at least one called test is required in a suite
12
- render(<TextArea />, { wrapper: Theme })
13
- })
14
-
15
- // TODO: this won't be called until cross-platform Jest tests are configured
16
- // see https://github.com/telus/universal-design-system/issues/319
17
- if (Platform.OS === 'web') {
18
- it('grows in size on input', () => {
19
- const { getByTestId } = render(
20
- <TextArea tokens={{ minLines: 1, maxLines: 5, lineHeight: 20 }} testID="textarea" />,
21
- {
22
- wrapper: Theme
23
- }
24
- )
25
-
26
- const textarea = getByTestId('textarea')
27
-
28
- expect(textarea).toHaveStyle({ height: 20 })
29
-
30
- fireChange(textarea, '\n\n\n')
31
-
32
- expect(textarea).toHaveStyle({ height: 60 })
33
- })
34
- }
35
- })
@@ -1,125 +0,0 @@
1
- import { fireEvent, render } from '@testing-library/react-native'
2
- import React from 'react'
3
- import TextInputBase from '../../src/TextInput/TextInputBase'
4
- import Viewport from '../../__fixtures__/Viewport'
5
- import Theme from '../../__fixtures__/Theme'
6
- import { getMockEvent, fireChange } from '../../__fixtures__/test-utils'
7
-
8
- // eslint-disable-next-line react/prop-types
9
- const Wrapper = ({ children }) => (
10
- <Viewport viewport="xs">
11
- <Theme>{children}</Theme>
12
- </Viewport>
13
- )
14
-
15
- const text = 'new value'
16
- const changeEvent = getMockEvent({ text })
17
-
18
- describe('TextInputBaseBase', () => {
19
- it('triggers the interactive callbacks', () => {
20
- const onFocus = jest.fn()
21
- const onBlur = jest.fn()
22
- const onMouseOver = jest.fn()
23
- const onMouseOut = jest.fn()
24
-
25
- const { getByA11yLabel } = render(
26
- <TextInputBase
27
- accessibilityLabel="Input label"
28
- onFocus={onFocus}
29
- onBlur={onBlur}
30
- onMouseOver={onMouseOver}
31
- onMouseOut={onMouseOut}
32
- />,
33
- {
34
- wrapper: Wrapper
35
- }
36
- )
37
-
38
- const input = getByA11yLabel('Input label')
39
-
40
- expect(onFocus).not.toHaveBeenCalled()
41
- fireEvent(input, 'focus')
42
- expect(onFocus).toHaveBeenCalledTimes(1)
43
-
44
- expect(onBlur).not.toHaveBeenCalled()
45
- fireEvent(input, 'blur')
46
- expect(onBlur).toHaveBeenCalledTimes(1)
47
-
48
- expect(onMouseOver).not.toHaveBeenCalled()
49
- fireEvent(input, 'mouseOver')
50
- expect(onMouseOver).toHaveBeenCalledTimes(1)
51
-
52
- expect(onMouseOut).not.toHaveBeenCalled()
53
- fireEvent(input, 'mouseOut')
54
- expect(onMouseOut).toHaveBeenCalledTimes(1)
55
- })
56
-
57
- it("can't be edited when inactive", () => {
58
- const { getByA11yLabel } = render(<TextInputBase accessibilityLabel="Input label" inactive />, {
59
- wrapper: Wrapper
60
- })
61
-
62
- const input = getByA11yLabel('Input label')
63
-
64
- expect(input).toHaveProp('editable', false)
65
- })
66
-
67
- it('changes value when uncontrolled', () => {
68
- const onChange = jest.fn()
69
-
70
- const { getByA11yLabel } = render(
71
- <TextInputBase accessibilityLabel="Input label" onChange={onChange} />,
72
- {
73
- wrapper: Wrapper
74
- }
75
- )
76
-
77
- const input = getByA11yLabel('Input label')
78
-
79
- expect(onChange).not.toHaveBeenCalled()
80
- fireChange(input, text)
81
- expect(onChange).toHaveBeenCalledTimes(1)
82
- expect(onChange).toHaveBeenLastCalledWith(text, changeEvent)
83
- })
84
-
85
- it('changes value when controlled', () => {
86
- const onChange = jest.fn()
87
-
88
- const { getByA11yLabel } = render(
89
- <TextInputBase accessibilityLabel="Input label" onChange={onChange} value="initial value" />,
90
- {
91
- wrapper: Wrapper
92
- }
93
- )
94
-
95
- const input = getByA11yLabel('Input label')
96
-
97
- expect(onChange).not.toHaveBeenCalled()
98
-
99
- fireChange(input, text)
100
- expect(onChange).toHaveBeenCalledTimes(1)
101
- expect(onChange).toHaveBeenLastCalledWith(text, changeEvent)
102
- })
103
-
104
- it("doesn't change value when readOnly", () => {
105
- const onChange = jest.fn()
106
-
107
- const { getByA11yLabel } = render(
108
- <TextInputBase
109
- accessibilityLabel="Input label"
110
- onChange={onChange}
111
- value="initial value"
112
- readOnly
113
- />,
114
- {
115
- wrapper: Wrapper
116
- }
117
- )
118
-
119
- const input = getByA11yLabel('Input label')
120
-
121
- expect(onChange).not.toHaveBeenCalled()
122
- fireChange(input, text)
123
- expect(onChange).not.toHaveBeenCalled()
124
- })
125
- })
@@ -1,82 +0,0 @@
1
- import React from 'react'
2
- import PropTypes from 'prop-types'
3
- import { renderHook } from '@testing-library/react-hooks'
4
- import semVerSatisfies from 'semver/functions/satisfies'
5
- import ThemeProvider, { useTheme, useSetTheme } from '../../src/ThemeProvider'
6
- import pkg from '../../package.json'
7
-
8
- jest.mock('semver/functions/satisfies')
9
-
10
- const expectedThemeTokensVersion = 'expected'
11
- const actualThemeTokensVersion = 'actual'
12
- pkg.dependencies['@telus-uds/system-theme-tokens'] = expectedThemeTokensVersion
13
- const theme = {
14
- metadata: {
15
- name: 'tokens-test',
16
- themeTokensVersion: actualThemeTokensVersion
17
- },
18
- components: {},
19
- themeOptions: {
20
- enableHelmetSSR: true,
21
- forceAbsoluteFontSizing: true,
22
- forceZIndex: true
23
- }
24
- }
25
-
26
- beforeEach(() => {
27
- semVerSatisfies.mockReset()
28
- })
29
-
30
- describe('Uninitialized ThemeProvider context', () => {
31
- test('throws on useTheme', () => {
32
- const { result } = renderHook(useTheme)
33
- expect(() => result.current).toThrow('Theme context used outside of ThemeProvider')
34
- })
35
-
36
- test('error useSetTheme hook without provider', () => {
37
- const { result } = renderHook(useSetTheme)
38
- expect(() => result.current).toThrow('Theme context used outside of ThemeProvider')
39
- })
40
- })
41
-
42
- describe('ThemeProvider theme tokens version validation', () => {
43
- const renderThemeHook = (hookFn) => {
44
- const ThemeWrapper = ({ children }) => (
45
- <ThemeProvider defaultTheme={theme}>{children}</ThemeProvider>
46
- )
47
- ThemeWrapper.propTypes = { children: PropTypes.node.isRequired }
48
-
49
- return renderHook(hookFn, {
50
- wrapper: ThemeWrapper
51
- })
52
- }
53
-
54
- test('validates theme tokens version with semver', () => {
55
- semVerSatisfies.mockImplementationOnce(() => true)
56
-
57
- const { result } = renderThemeHook(useTheme)
58
-
59
- expect(result.current).toEqual(theme)
60
- expect(semVerSatisfies).toHaveBeenCalledWith(
61
- actualThemeTokensVersion,
62
- expectedThemeTokensVersion
63
- )
64
- })
65
-
66
- test('warning if theme tokens version does not match', () => {
67
- semVerSatisfies.mockImplementationOnce(() => false)
68
-
69
- const { result } = renderThemeHook(useTheme)
70
-
71
- expect(() => result.current).toThrow('Invalid UDS token schema version detected')
72
- })
73
-
74
- test('validates on every render', () => {
75
- semVerSatisfies.mockImplementationOnce(() => true)
76
-
77
- const { rerender } = renderThemeHook(useTheme)
78
- rerender()
79
-
80
- expect(semVerSatisfies).toHaveBeenCalledTimes(2)
81
- })
82
- })