@telus-uds/components-base 1.26.0 → 1.28.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 (74) hide show
  1. package/CHANGELOG.md +28 -2
  2. package/component-docs.json +2 -1
  3. package/lib/Carousel/dictionary.js +6 -6
  4. package/lib-module/Carousel/dictionary.js +6 -6
  5. package/package.json +2 -2
  6. package/src/Carousel/dictionary.js +6 -6
  7. package/.eslintrc.js +0 -9
  8. package/__tests17__/A11yText/A11yText.test.jsx +0 -34
  9. package/__tests17__/ActivityIndicator/ActivityIndicator.test.jsx +0 -68
  10. package/__tests17__/ActivityIndicator/__snapshots__/ActivityIndicator.test.jsx.snap +0 -299
  11. package/__tests17__/Box/Box.test.jsx +0 -111
  12. package/__tests17__/Button/Button.test.jsx +0 -86
  13. package/__tests17__/Button/ButtonBase.test.jsx +0 -82
  14. package/__tests17__/Button/ButtonGroup.test.jsx +0 -347
  15. package/__tests17__/Button/ButtonLink.test.jsx +0 -61
  16. package/__tests17__/Card/Card.test.jsx +0 -63
  17. package/__tests17__/Carousel/Carousel.test.jsx +0 -128
  18. package/__tests17__/Carousel/CarouselTabs.test.jsx +0 -142
  19. package/__tests17__/Checkbox/Checkbox.test.jsx +0 -94
  20. package/__tests17__/Checkbox/CheckboxGroup.test.jsx +0 -246
  21. package/__tests17__/Divider/Divider.test.jsx +0 -91
  22. package/__tests17__/ExpandCollapse/ExpandCollapse.test.jsx +0 -109
  23. package/__tests17__/Feedback/Feedback.test.jsx +0 -42
  24. package/__tests17__/FlexGrid/Col.test.jsx +0 -261
  25. package/__tests17__/FlexGrid/FlexGrid.test.jsx +0 -136
  26. package/__tests17__/FlexGrid/Row.test.jsx +0 -273
  27. package/__tests17__/HorizontalScroll/HorizontalScroll.test.jsx +0 -165
  28. package/__tests17__/Icon/Icon.test.jsx +0 -61
  29. package/__tests17__/IconButton/IconButton.test.jsx +0 -52
  30. package/__tests17__/InputLabel/InputLabel.test.jsx +0 -28
  31. package/__tests17__/InputLabel/__snapshots__/InputLabel.test.jsx.snap +0 -3
  32. package/__tests17__/InputSupports/InputSupports.test.jsx +0 -60
  33. package/__tests17__/Link/Link.test.jsx +0 -63
  34. package/__tests17__/Link/TextButton.test.jsx +0 -35
  35. package/__tests17__/List/List.test.jsx +0 -82
  36. package/__tests17__/Modal/Modal.test.jsx +0 -47
  37. package/__tests17__/Notification/Notification.test.jsx +0 -20
  38. package/__tests17__/Pagination/Pagination.test.jsx +0 -160
  39. package/__tests17__/Progress/Progress.test.jsx +0 -79
  40. package/__tests17__/Radio/Radio.test.jsx +0 -87
  41. package/__tests17__/Radio/RadioGroup.test.jsx +0 -220
  42. package/__tests17__/RadioCard/RadioCard.test.jsx +0 -87
  43. package/__tests17__/RadioCard/RadioCardGroup.test.jsx +0 -246
  44. package/__tests17__/Search/Search.test.jsx +0 -87
  45. package/__tests17__/Select/Select.test.jsx +0 -94
  46. package/__tests17__/SideNav/SideNav.test.jsx +0 -110
  47. package/__tests17__/Skeleton/Skeleton.test.jsx +0 -61
  48. package/__tests17__/SkipLink/SkipLink.test.jsx +0 -61
  49. package/__tests17__/Spacer/Spacer.test.jsx +0 -63
  50. package/__tests17__/StackView/StackView.test.jsx +0 -211
  51. package/__tests17__/StackView/StackWrap.test.jsx +0 -47
  52. package/__tests17__/StackView/getStackedContent.test.jsx +0 -295
  53. package/__tests17__/StepTracker/StepTracker.test.jsx +0 -108
  54. package/__tests17__/Tabs/Tabs.test.jsx +0 -49
  55. package/__tests17__/Tags/Tags.test.jsx +0 -327
  56. package/__tests17__/TextInput/TextArea.test.jsx +0 -35
  57. package/__tests17__/TextInput/TextInputBase.test.jsx +0 -125
  58. package/__tests17__/ThemeProvider/ThemeProvider.test.jsx +0 -82
  59. package/__tests17__/ThemeProvider/useThemeTokens.test.jsx +0 -514
  60. package/__tests17__/ThemeProvider/utils/theme-tokens.test.js +0 -41
  61. package/__tests17__/ToggleSwitch/ToggleSwitch.test.jsx +0 -82
  62. package/__tests17__/ToggleSwitch/ToggleSwitchGroup.test.jsx +0 -192
  63. package/__tests17__/Tooltip/Tooltip.test.jsx +0 -65
  64. package/__tests17__/Tooltip/getTooltipPosition.test.js +0 -79
  65. package/__tests17__/Typography/typography.test.jsx +0 -90
  66. package/__tests17__/utils/children.test.jsx +0 -128
  67. package/__tests17__/utils/containUniqueFields.test.js +0 -25
  68. package/__tests17__/utils/input.test.js +0 -375
  69. package/__tests17__/utils/props.test.js +0 -36
  70. package/__tests17__/utils/semantics.test.jsx +0 -34
  71. package/__tests17__/utils/useCopy.test.js +0 -42
  72. package/__tests17__/utils/useResponsiveProp.test.jsx +0 -202
  73. package/__tests17__/utils/useSpacingScale.test.jsx +0 -273
  74. package/__tests17__/utils/useUniqueId.test.js +0 -31
@@ -1,220 +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 RadioGroup from '../../src/Radio/RadioGroup'
7
-
8
- const items = [
9
- { label: 'One', id: 'one' },
10
- { label: 'Two', id: 'two' },
11
- { label: 'Three', id: 'three' },
12
- { label: 'Four', id: '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('RadioGroup', () => {
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 `checkedId` without `onChange`', () => {
33
- expect(() =>
34
- render(
35
- <Theme>
36
- <RadioGroup items={items} checkedId="one" />
37
- </Theme>
38
- )
39
- ).toThrow(/value.+without.+onChange/)
40
- })
41
- it("Doesn't throw if has `checkedId` without `onChange` and is read only", () => {
42
- expect(() =>
43
- render(
44
- <Theme>
45
- <RadioGroup items={items} checkedId="one" readOnly />
46
- </Theme>
47
- )
48
- ).not.toThrow()
49
- })
50
- it('Throws if has both `checkedId` and `initialCheckedId`', () => {
51
- expect(() =>
52
- render(
53
- <Theme>
54
- <RadioGroup items={items} initialCheckedId="one" checkedId="one" onChange={() => {}} />
55
- </Theme>
56
- )
57
- ).toThrow(/both(?=.*initialValue)(?=.*value){2}/)
58
- })
59
- })
60
-
61
- describe('RadioGroup (uncontrolled)', () => {
62
- it('Selects one and only one item', async () => {
63
- const { getByText, queryAllByA11yState } = render(
64
- <Theme>
65
- <RadioGroup items={items} />
66
- </Theme>
67
- )
68
-
69
- expect(queryAllByA11yState(checked)).toHaveLength(0)
70
-
71
- const one = getByText('One')
72
- await fireEvent.press(one)
73
- expect(queryAllByA11yState(checked)).toHaveLength(1)
74
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
75
-
76
- const two = getByText('Two')
77
- await fireEvent.press(two)
78
- expect(queryAllByA11yState(checked)).toHaveLength(1)
79
- expect(containsText(queryAllByA11yState(checked), 'Two')).toBeTruthy()
80
- expect(containsText(queryAllByA11yState(checked), 'One')).not.toBeTruthy()
81
- })
82
-
83
- it('Does not deselect if the selected item is pressed', async () => {
84
- const { getByText, queryAllByA11yState } = render(
85
- <Theme>
86
- <RadioGroup items={items} />
87
- </Theme>
88
- )
89
-
90
- expect(queryAllByA11yState(checked)).toHaveLength(0)
91
-
92
- const three = getByText('Three')
93
- await fireEvent.press(three)
94
- expect(queryAllByA11yState(checked)).toHaveLength(1)
95
- expect(containsText(queryAllByA11yState(checked), 'Three')).toBeTruthy()
96
-
97
- await fireEvent.press(three)
98
- expect(queryAllByA11yState(checked)).toHaveLength(1)
99
- expect(containsText(queryAllByA11yState(checked), 'Three')).toBeTruthy()
100
- })
101
-
102
- it('Is accessible as a radio button', async () => {
103
- const { queryAllByA11yRole, queryAllByA11yState } = render(
104
- <Theme>
105
- <RadioGroup items={items} />
106
- </Theme>
107
- )
108
-
109
- expect(queryAllByA11yRole('checkbox')).toHaveLength(0)
110
- expect(queryAllByA11yRole('radiogroup')).toHaveLength(1)
111
- const radios = queryAllByA11yRole('radio')
112
- expect(radios).toHaveLength(4)
113
-
114
- expect(queryAllByA11yState(checked)).toHaveLength(0)
115
- await fireEvent.press(radios[0])
116
- expect(queryAllByA11yState(checked)).toHaveLength(1)
117
- })
118
-
119
- it('Auto-selects initialCheckedId', async () => {
120
- const { getByText, queryAllByA11yState } = render(
121
- <Theme>
122
- <RadioGroup items={items} initialCheckedId="two" />
123
- </Theme>
124
- )
125
- expect(queryAllByA11yState(checked)).toHaveLength(1)
126
- expect(containsText(queryAllByA11yState(checked), 'One')).not.toBeTruthy()
127
- expect(containsText(queryAllByA11yState(checked), 'Two')).toBeTruthy()
128
-
129
- const three = getByText('Three')
130
- await fireEvent.press(three)
131
-
132
- expect(queryAllByA11yState(checked)).toHaveLength(1)
133
- expect(containsText(queryAllByA11yState(checked), 'Three')).toBeTruthy()
134
- expect(containsText(queryAllByA11yState(checked), 'Two')).not.toBeTruthy()
135
- expect(containsText(queryAllByA11yState(checked), 'One')).not.toBeTruthy()
136
- })
137
- })
138
-
139
- describe('RadioGroup (controlled)', () => {
140
- it('Calls onChange handler on press in controlled mode, providing pressed id', async () => {
141
- const handleChange = jest.fn((arg) => arg)
142
- const { getByText } = render(
143
- <Theme>
144
- <RadioGroup items={items} checkedId={null} onChange={handleChange} />
145
- </Theme>
146
- )
147
-
148
- expect(handleChange).toHaveBeenCalledTimes(0)
149
-
150
- const one = getByText('One')
151
- await fireEvent(one, 'press', { nativeEvent: 'example' })
152
- expect(handleChange).toHaveBeenCalledTimes(1)
153
- expect(handleChange).toHaveBeenLastCalledWith('one', { nativeEvent: 'example' })
154
-
155
- const two = getByText('Two')
156
- await fireEvent(two, 'press', { nativeEvent: 'example2' })
157
- expect(handleChange).toHaveBeenCalledTimes(2)
158
- expect(handleChange).toHaveBeenLastCalledWith('two', { nativeEvent: 'example2' })
159
- })
160
-
161
- it("Doesn't change its own selection if `checkedId` is passed", async () => {
162
- const { getByText, queryAllByA11yState } = render(
163
- <Theme>
164
- <RadioGroup items={items} checkedId="one" onChange={() => {}} />
165
- </Theme>
166
- )
167
-
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(1)
174
- expect(containsText(queryAllByA11yState(checked), 'Two')).not.toBeTruthy()
175
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
176
- })
177
- })
178
-
179
- describe('RadioGroup (read-only)', () => {
180
- it("Doesn't call onChange handler when read-only", async () => {
181
- const handleChange = jest.fn((arg) => arg)
182
- const { getByText } = render(
183
- <Theme>
184
- <RadioGroup items={items} checkedId="two" onChange={handleChange} readOnly />
185
- </Theme>
186
- )
187
-
188
- expect(handleChange).toHaveBeenCalledTimes(0)
189
-
190
- const one = getByText('One')
191
- await fireEvent.press(one)
192
- expect(handleChange).toHaveBeenCalledTimes(0)
193
-
194
- const two = getByText('Two')
195
- await fireEvent.press(two)
196
- expect(handleChange).toHaveBeenCalledTimes(0)
197
- })
198
-
199
- it("Doesn't change its selection on press", async () => {
200
- const { getByText, queryAllByA11yState } = render(
201
- <Theme>
202
- <RadioGroup items={items} checkedId="one" readOnly />
203
- </Theme>
204
- )
205
-
206
- expect(queryAllByA11yState(checked)).toHaveLength(1)
207
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
208
-
209
- const one = getByText('One')
210
- await fireEvent.press(one)
211
- expect(queryAllByA11yState(checked)).toHaveLength(1)
212
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
213
-
214
- const two = getByText('Two')
215
- await fireEvent.press(two)
216
- expect(queryAllByA11yState(checked)).toHaveLength(1)
217
- expect(containsText(queryAllByA11yState(checked), 'Two')).not.toBeTruthy()
218
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
219
- })
220
- })
@@ -1,87 +0,0 @@
1
- import React from 'react'
2
- import { fireEvent, render } from '@testing-library/react-native'
3
-
4
- import { RadioCard } from '../../src'
5
- import Theme from '../../__fixtures__/Theme'
6
-
7
- const checkedId = 'Radio-Checked'
8
- const inputId = 'Radio-Input'
9
- const setup = (props) =>
10
- render(
11
- <Theme>
12
- <RadioCard {...props} />
13
- </Theme>
14
- )
15
-
16
- describe('RadioCard', () => {
17
- it('renders with defaults', () => {
18
- const { getByRole } = setup()
19
-
20
- expect(getByRole('radio')).toBeTruthy()
21
- })
22
-
23
- it('renders a title', () => {
24
- const title = 'Test title message'
25
- const { queryByText } = setup({ title })
26
-
27
- expect(queryByText(title)).toBeTruthy()
28
- })
29
-
30
- it('renders error styling on validation failure', () => {
31
- const errorBorderColor = '#676e73' // from __fixtures__/testTheme.js
32
- const { getByTestId } = setup({ error: true })
33
-
34
- const radioInput = getByTestId(inputId)
35
- expect(radioInput).toHaveStyle({ borderColor: errorBorderColor })
36
- })
37
-
38
- it('triggers the callback', () => {
39
- const onChange = jest.fn()
40
-
41
- const { getByRole } = setup({ onChange })
42
-
43
- const radio = getByRole('radio')
44
- expect(onChange).not.toHaveBeenCalled()
45
- fireEvent(radio, 'press')
46
- expect(onChange).toHaveBeenCalledTimes(1)
47
- })
48
-
49
- it('cannot be changed if inactive', () => {
50
- const { getByRole, queryByTestId } = setup({ inactive: true })
51
-
52
- const radio = getByRole('radio')
53
- expect(queryByTestId(checkedId)).toBeFalsy()
54
- fireEvent(radio, 'press')
55
- expect(queryByTestId(checkedId)).toBeFalsy()
56
- })
57
-
58
- describe('when uncontrolled', () => {
59
- it('uses `defaultChecked` as the initial value', () => {
60
- const { queryByTestId } = setup({ defaultChecked: true })
61
-
62
- expect(queryByTestId(checkedId)).toBeTruthy()
63
- })
64
-
65
- it('changes value', () => {
66
- const { getByRole, queryByTestId } = setup({ defaultChecked: false })
67
-
68
- const radio = getByRole('radio')
69
- expect(queryByTestId(checkedId)).toBeFalsy()
70
- fireEvent(radio, 'press')
71
- expect(queryByTestId(checkedId)).toBeTruthy()
72
- })
73
- })
74
-
75
- describe('when controlled', () => {
76
- it('calls `onChange` with the new value', () => {
77
- const onChange = jest.fn()
78
- const { getByRole, queryByTestId } = setup({ onChange, checked: false })
79
-
80
- const radio = getByRole('radio')
81
- expect(queryByTestId(checkedId)).toBeFalsy()
82
- fireEvent(radio, 'press', { nativeEvent: 'example' })
83
- expect(onChange).toHaveBeenCalledTimes(1)
84
- expect(onChange).toHaveBeenCalledWith(true, { nativeEvent: 'example' })
85
- })
86
- })
87
- })
@@ -1,246 +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 RadioCardGroup from '../../src/RadioCard/RadioCardGroup'
7
- import Typography from '../../src/Typography'
8
-
9
- const items = [
10
- { title: 'One', id: 'one', content: <Typography>More card 1 content</Typography> },
11
- { title: 'Two', id: 'two', content: <Typography>More card 2 content</Typography> },
12
- { title: 'Three', id: 'three', content: <Typography>More card 3 content</Typography> },
13
- { title: 'Four', id: 'four', content: <Typography>More card 4 content</Typography> }
14
- ]
15
- const checked = { checked: true }
16
-
17
- // expect().toHaveTextContent doesn't work on arrays, expect().toContain etc doesn't match elements
18
- const containsText = (queryResult, text) =>
19
- queryResult.some((testInstance) => toHaveTextContent(testInstance, text).pass)
20
-
21
- describe('RadioCardGroup', () => {
22
- // eslint-disable-next-line no-console
23
- const consoleError = console.error
24
- beforeEach(() => {
25
- // eslint-disable-next-line no-console
26
- console.error = () => {}
27
- })
28
- afterEach(() => {
29
- // eslint-disable-next-line no-console
30
- console.error = consoleError
31
- })
32
-
33
- it('Throws if has `checkedId` without `onChange`', () => {
34
- expect(() =>
35
- render(
36
- <Theme>
37
- <RadioCardGroup items={items} checkedId="one" />
38
- </Theme>
39
- )
40
- ).toThrow(/value.+without.+onChange/)
41
- })
42
- it("Doesn't throw if has `checkedId` without `onChange` and is read only", () => {
43
- expect(() =>
44
- render(
45
- <Theme>
46
- <RadioCardGroup items={items} checkedId="one" readOnly />
47
- </Theme>
48
- )
49
- ).not.toThrow()
50
- })
51
- it('Throws if has both `checkedId` and `initialCheckedId`', () => {
52
- expect(() =>
53
- render(
54
- <Theme>
55
- <RadioCardGroup
56
- items={items}
57
- initialCheckedId="one"
58
- checkedId="one"
59
- onChange={() => {}}
60
- />
61
- </Theme>
62
- )
63
- ).toThrow(/both(?=.*initialValue)(?=.*value){2}/)
64
- })
65
- })
66
-
67
- describe('RadioCardGroup (uncontrolled)', () => {
68
- it('Selects one and only one item', async () => {
69
- const { getByText, queryAllByA11yState } = render(
70
- <Theme>
71
- <RadioCardGroup items={items} />
72
- </Theme>
73
- )
74
-
75
- expect(queryAllByA11yState(checked)).toHaveLength(0)
76
-
77
- const one = getByText('One')
78
- await fireEvent.press(one)
79
- expect(queryAllByA11yState(checked)).toHaveLength(1)
80
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
81
-
82
- const two = getByText('Two')
83
- await fireEvent.press(two)
84
- expect(queryAllByA11yState(checked)).toHaveLength(1)
85
- expect(containsText(queryAllByA11yState(checked), 'Two')).toBeTruthy()
86
- expect(containsText(queryAllByA11yState(checked), 'One')).not.toBeTruthy()
87
- })
88
-
89
- it('Treats presses on content the same as presses on title', async () => {
90
- const { getByText, queryAllByA11yState } = render(
91
- <Theme>
92
- <RadioCardGroup items={items} />
93
- </Theme>
94
- )
95
-
96
- expect(queryAllByA11yState(checked)).toHaveLength(0)
97
-
98
- const one = getByText('More card 1 content')
99
- await fireEvent.press(one)
100
- expect(queryAllByA11yState(checked)).toHaveLength(1)
101
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
102
-
103
- const two = getByText('More card 2 content')
104
- await fireEvent.press(two)
105
- expect(queryAllByA11yState(checked)).toHaveLength(1)
106
- expect(containsText(queryAllByA11yState(checked), 'Two')).toBeTruthy()
107
- expect(containsText(queryAllByA11yState(checked), 'One')).not.toBeTruthy()
108
- })
109
-
110
- it('Does not deselect if the selected item is pressed', async () => {
111
- const { getByText, queryAllByA11yState } = render(
112
- <Theme>
113
- <RadioCardGroup items={items} />
114
- </Theme>
115
- )
116
-
117
- expect(queryAllByA11yState(checked)).toHaveLength(0)
118
-
119
- const three = getByText('Three')
120
- await fireEvent.press(three)
121
- expect(queryAllByA11yState(checked)).toHaveLength(1)
122
- expect(containsText(queryAllByA11yState(checked), 'Three')).toBeTruthy()
123
-
124
- await fireEvent.press(three)
125
- expect(queryAllByA11yState(checked)).toHaveLength(1)
126
- expect(containsText(queryAllByA11yState(checked), 'Three')).toBeTruthy()
127
- })
128
-
129
- it('Is accessible as a radio button', async () => {
130
- const { queryAllByA11yRole, queryAllByA11yState } = render(
131
- <Theme>
132
- <RadioCardGroup items={items} />
133
- </Theme>
134
- )
135
- expect(queryAllByA11yRole('checkbox')).toHaveLength(0)
136
- expect(queryAllByA11yRole('radiogroup').length).toBeTruthy()
137
- const radios = queryAllByA11yRole('radio')
138
- expect(radios).toHaveLength(4)
139
-
140
- expect(queryAllByA11yState(checked)).toHaveLength(0)
141
- await fireEvent.press(radios[0])
142
- expect(queryAllByA11yState(checked)).toHaveLength(1)
143
- })
144
-
145
- it('Auto-selects initialCheckedId', async () => {
146
- const { getByText, queryAllByA11yState } = render(
147
- <Theme>
148
- <RadioCardGroup items={items} initialCheckedId="two" />
149
- </Theme>
150
- )
151
- expect(queryAllByA11yState(checked)).toHaveLength(1)
152
- expect(containsText(queryAllByA11yState(checked), 'One')).not.toBeTruthy()
153
- expect(containsText(queryAllByA11yState(checked), 'Two')).toBeTruthy()
154
-
155
- const three = getByText('Three')
156
- await fireEvent.press(three)
157
-
158
- expect(queryAllByA11yState(checked)).toHaveLength(1)
159
- expect(containsText(queryAllByA11yState(checked), 'Three')).toBeTruthy()
160
- expect(containsText(queryAllByA11yState(checked), 'Two')).not.toBeTruthy()
161
- expect(containsText(queryAllByA11yState(checked), 'One')).not.toBeTruthy()
162
- })
163
- })
164
-
165
- describe('RadioCardGroup (controlled)', () => {
166
- it('Calls onChange handler on press in controlled mode, providing pressed id', async () => {
167
- const handleChange = jest.fn((arg) => arg)
168
- const { getByText } = render(
169
- <Theme>
170
- <RadioCardGroup items={items} checkedId={null} onChange={handleChange} />
171
- </Theme>
172
- )
173
-
174
- expect(handleChange).toHaveBeenCalledTimes(0)
175
-
176
- const one = getByText('One')
177
- await fireEvent(one, 'press', { nativeEvent: 'example' })
178
- expect(handleChange).toHaveBeenCalledTimes(1)
179
- expect(handleChange).toHaveBeenLastCalledWith('one', { nativeEvent: 'example' })
180
-
181
- const two = getByText('Two')
182
- await fireEvent(two, 'press', { nativeEvent: 'example2' })
183
- expect(handleChange).toHaveBeenCalledTimes(2)
184
- expect(handleChange).toHaveBeenLastCalledWith('two', { nativeEvent: 'example2' })
185
- })
186
-
187
- it("Doesn't change its own selection if `checkedId` is passed", async () => {
188
- const { getByText, queryAllByA11yState } = render(
189
- <Theme>
190
- <RadioCardGroup items={items} checkedId="one" onChange={() => {}} />
191
- </Theme>
192
- )
193
-
194
- expect(queryAllByA11yState(checked)).toHaveLength(1)
195
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
196
-
197
- const two = getByText('Two')
198
- await fireEvent.press(two)
199
- expect(queryAllByA11yState(checked)).toHaveLength(1)
200
- expect(containsText(queryAllByA11yState(checked), 'Two')).not.toBeTruthy()
201
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
202
- })
203
- })
204
-
205
- describe('RadioCardGroup (read-only)', () => {
206
- it("Doesn't call onChange handler when read-only", async () => {
207
- const handleChange = jest.fn((arg) => arg)
208
- const { getByText } = render(
209
- <Theme>
210
- <RadioCardGroup items={items} checkedId="two" onChange={handleChange} readOnly />
211
- </Theme>
212
- )
213
-
214
- expect(handleChange).toHaveBeenCalledTimes(0)
215
-
216
- const one = getByText('One')
217
- await fireEvent.press(one)
218
- expect(handleChange).toHaveBeenCalledTimes(0)
219
-
220
- const two = getByText('Two')
221
- await fireEvent.press(two)
222
- expect(handleChange).toHaveBeenCalledTimes(0)
223
- })
224
-
225
- it("Doesn't change its selection on press", async () => {
226
- const { getByText, queryAllByA11yState } = render(
227
- <Theme>
228
- <RadioCardGroup items={items} checkedId="one" readOnly />
229
- </Theme>
230
- )
231
-
232
- expect(queryAllByA11yState(checked)).toHaveLength(1)
233
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
234
-
235
- const one = getByText('One')
236
- await fireEvent.press(one)
237
- expect(queryAllByA11yState(checked)).toHaveLength(1)
238
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
239
-
240
- const two = getByText('Two')
241
- await fireEvent.press(two)
242
- expect(queryAllByA11yState(checked)).toHaveLength(1)
243
- expect(containsText(queryAllByA11yState(checked), 'Two')).not.toBeTruthy()
244
- expect(containsText(queryAllByA11yState(checked), 'One')).toBeTruthy()
245
- })
246
- })
@@ -1,87 +0,0 @@
1
- import React from 'react'
2
- import { render, fireEvent } from '@testing-library/react-native'
3
-
4
- import { Search } from '../../src'
5
- import Theme from '../../__fixtures__/Theme'
6
- import { fireChange } from '../../__fixtures__/test-utils'
7
-
8
- describe('Search', () => {
9
- const commonProps = {
10
- accessibilityLabel: 'input',
11
- copy: {
12
- clearButtonAccessibilityLabel: 'clear-button',
13
- submitButtonAccessibilityLabel: 'submit-button'
14
- }
15
- }
16
-
17
- it('triggers the onSubmit callback when submitted', () => {
18
- const onSubmit = jest.fn()
19
-
20
- const { getByA11yLabel } = render(
21
- <Search onSubmit={onSubmit} initialValue="initial value" {...commonProps} />,
22
- {
23
- wrapper: Theme
24
- }
25
- )
26
-
27
- expect(onSubmit).not.toHaveBeenCalled()
28
-
29
- fireEvent(getByA11yLabel('submit-button'), 'press', { nativeEvent: 'example' })
30
-
31
- expect(onSubmit).toHaveBeenCalledTimes(1)
32
- expect(onSubmit).toHaveBeenLastCalledWith('initial value', { nativeEvent: 'example' })
33
-
34
- fireChange(getByA11yLabel('input'), 'new value')
35
- fireEvent(getByA11yLabel('submit-button'), 'press', { nativeEvent: 'example' })
36
-
37
- expect(onSubmit).toHaveBeenCalledTimes(2)
38
- expect(onSubmit).toHaveBeenLastCalledWith('new value', { nativeEvent: 'example' })
39
- })
40
-
41
- it('shows the clear button when text is entered', () => {
42
- const { getByA11yLabel } = render(<Search {...commonProps} />, {
43
- wrapper: Theme
44
- })
45
-
46
- expect(() => getByA11yLabel('clear-button')).toThrow()
47
-
48
- fireChange(getByA11yLabel('input'), 'test value')
49
-
50
- expect(() => getByA11yLabel('clear-button')).not.toThrow()
51
- })
52
-
53
- it('removes the input value when clear button is pressed', () => {
54
- const onClear = jest.fn()
55
- const onChange = jest.fn()
56
-
57
- const { getByA11yLabel } = render(
58
- <Search initialValue="test value" onClear={onClear} onChange={onChange} {...commonProps} />,
59
- {
60
- wrapper: Theme
61
- }
62
- )
63
-
64
- expect(onClear).not.toHaveBeenCalled()
65
- expect(onChange).not.toHaveBeenCalled()
66
-
67
- fireEvent(getByA11yLabel('clear-button'), 'press', { nativeEvent: 'example' })
68
-
69
- expect(onClear).toHaveBeenCalledTimes(1)
70
- expect(onChange).toHaveBeenCalledTimes(1)
71
- expect(onChange).toHaveBeenLastCalledWith('', { nativeEvent: 'example' })
72
- })
73
-
74
- it('triggers the onFocus callback when focused', () => {
75
- const onFocus = jest.fn()
76
-
77
- const { getByA11yLabel } = render(
78
- <Search onFocus={onFocus} initialValue="initial value" {...commonProps} />,
79
- {
80
- wrapper: Theme
81
- }
82
- )
83
- expect(onFocus).not.toHaveBeenCalled()
84
- fireEvent(getByA11yLabel('input'), 'focus', { nativeEvent: 'example' })
85
- expect(onFocus).toHaveBeenCalledTimes(1)
86
- })
87
- })