@telus-uds/components-base 1.14.1 → 1.15.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 (149) hide show
  1. package/CHANGELOG.md +33 -2
  2. package/__tests17__/A11yText/A11yText.test.jsx +34 -0
  3. package/__tests17__/ActivityIndicator/ActivityIndicator.test.jsx +68 -0
  4. package/__tests17__/ActivityIndicator/__snapshots__/ActivityIndicator.test.jsx.snap +299 -0
  5. package/__tests17__/Box/Box.test.jsx +111 -0
  6. package/__tests17__/Button/Button.test.jsx +86 -0
  7. package/__tests17__/Button/ButtonBase.test.jsx +82 -0
  8. package/__tests17__/Button/ButtonGroup.test.jsx +347 -0
  9. package/__tests17__/Button/ButtonLink.test.jsx +61 -0
  10. package/__tests17__/Card/Card.test.jsx +63 -0
  11. package/__tests17__/Carousel/Carousel.test.jsx +128 -0
  12. package/__tests17__/Carousel/CarouselTabs.test.jsx +142 -0
  13. package/__tests17__/Checkbox/Checkbox.test.jsx +94 -0
  14. package/__tests17__/Checkbox/CheckboxGroup.test.jsx +246 -0
  15. package/__tests17__/Divider/Divider.test.jsx +91 -0
  16. package/__tests17__/ExpandCollapse/ExpandCollapse.test.jsx +109 -0
  17. package/__tests17__/Feedback/Feedback.test.jsx +42 -0
  18. package/__tests17__/FlexGrid/Col.test.jsx +261 -0
  19. package/__tests17__/FlexGrid/FlexGrid.test.jsx +136 -0
  20. package/__tests17__/FlexGrid/Row.test.jsx +273 -0
  21. package/__tests17__/HorizontalScroll/HorizontalScroll.test.jsx +165 -0
  22. package/__tests17__/Icon/Icon.test.jsx +61 -0
  23. package/__tests17__/IconButton/IconButton.test.jsx +52 -0
  24. package/__tests17__/InputLabel/InputLabel.test.jsx +28 -0
  25. package/__tests17__/InputLabel/__snapshots__/InputLabel.test.jsx.snap +3 -0
  26. package/__tests17__/InputSupports/InputSupports.test.jsx +60 -0
  27. package/__tests17__/Link/Link.test.jsx +63 -0
  28. package/__tests17__/Link/TextButton.test.jsx +35 -0
  29. package/__tests17__/List/List.test.jsx +82 -0
  30. package/__tests17__/Modal/Modal.test.jsx +47 -0
  31. package/__tests17__/Notification/Notification.test.jsx +20 -0
  32. package/__tests17__/Pagination/Pagination.test.jsx +160 -0
  33. package/__tests17__/Progress/Progress.test.jsx +79 -0
  34. package/__tests17__/Radio/Radio.test.jsx +87 -0
  35. package/__tests17__/Radio/RadioGroup.test.jsx +220 -0
  36. package/__tests17__/RadioCard/RadioCard.test.jsx +87 -0
  37. package/__tests17__/RadioCard/RadioCardGroup.test.jsx +246 -0
  38. package/__tests17__/Search/Search.test.jsx +87 -0
  39. package/__tests17__/Select/Select.test.jsx +94 -0
  40. package/__tests17__/SideNav/SideNav.test.jsx +110 -0
  41. package/__tests17__/Skeleton/Skeleton.test.jsx +61 -0
  42. package/__tests17__/SkipLink/SkipLink.test.jsx +61 -0
  43. package/__tests17__/Spacer/Spacer.test.jsx +63 -0
  44. package/__tests17__/StackView/StackView.test.jsx +211 -0
  45. package/__tests17__/StackView/StackWrap.test.jsx +47 -0
  46. package/__tests17__/StackView/getStackedContent.test.jsx +295 -0
  47. package/__tests17__/StepTracker/StepTracker.test.jsx +108 -0
  48. package/__tests17__/Tabs/Tabs.test.jsx +49 -0
  49. package/__tests17__/Tags/Tags.test.jsx +327 -0
  50. package/__tests17__/TextInput/TextArea.test.jsx +35 -0
  51. package/__tests17__/TextInput/TextInputBase.test.jsx +125 -0
  52. package/__tests17__/ThemeProvider/ThemeProvider.test.jsx +80 -0
  53. package/__tests17__/ThemeProvider/useThemeTokens.test.jsx +514 -0
  54. package/__tests17__/ThemeProvider/utils/theme-tokens.test.js +41 -0
  55. package/__tests17__/ToggleSwitch/ToggleSwitch.test.jsx +82 -0
  56. package/__tests17__/ToggleSwitch/ToggleSwitchGroup.test.jsx +192 -0
  57. package/__tests17__/Tooltip/Tooltip.test.jsx +65 -0
  58. package/__tests17__/Tooltip/getTooltipPosition.test.js +79 -0
  59. package/__tests17__/Typography/typography.test.jsx +90 -0
  60. package/__tests17__/utils/children.test.jsx +128 -0
  61. package/__tests17__/utils/containUniqueFields.test.js +25 -0
  62. package/__tests17__/utils/input.test.js +375 -0
  63. package/__tests17__/utils/props.test.js +36 -0
  64. package/__tests17__/utils/semantics.test.jsx +34 -0
  65. package/__tests17__/utils/useCopy.test.js +42 -0
  66. package/__tests17__/utils/useResponsiveProp.test.jsx +202 -0
  67. package/__tests17__/utils/useSpacingScale.test.jsx +273 -0
  68. package/__tests17__/utils/useUniqueId.test.js +31 -0
  69. package/component-docs.json +95 -438
  70. package/lib/A11yInfoProvider/index.js +14 -5
  71. package/lib/Button/ButtonGroup.js +3 -2
  72. package/lib/Checkbox/Checkbox.js +9 -6
  73. package/lib/ExpandCollapse/Control.js +6 -5
  74. package/lib/ExpandCollapse/Panel.js +5 -4
  75. package/lib/List/ListItem.js +10 -236
  76. package/lib/List/ListItemBase.js +162 -0
  77. package/lib/List/ListItemContent.js +85 -0
  78. package/lib/List/ListItemMark.js +158 -0
  79. package/lib/List/PressableListItemBase.js +147 -0
  80. package/lib/Notification/Notification.js +2 -1
  81. package/lib/Pagination/Pagination.js +4 -3
  82. package/lib/Pagination/SideButton.js +17 -7
  83. package/lib/Radio/Radio.js +9 -6
  84. package/lib/RadioCard/RadioCard.js +9 -6
  85. package/lib/Select/Select.js +1 -0
  86. package/lib/Tabs/Tabs.js +12 -3
  87. package/lib/Tags/Tags.js +3 -3
  88. package/lib/TextInput/TextInput.js +5 -4
  89. package/lib/ViewportProvider/useViewportListener.js +11 -5
  90. package/lib/utils/hasOwnProperty.js +18 -0
  91. package/lib/utils/props/a11yProps.js +212 -45
  92. package/lib/utils/props/getPropSelector.js +47 -5
  93. package/lib/utils/ssr.js +116 -1
  94. package/lib/utils/useResponsiveProp.js +5 -3
  95. package/lib/utils/withLinkRouter.js +3 -5
  96. package/lib-module/A11yInfoProvider/index.js +14 -4
  97. package/lib-module/Button/ButtonGroup.js +3 -2
  98. package/lib-module/Checkbox/Checkbox.js +9 -6
  99. package/lib-module/ExpandCollapse/Control.js +6 -5
  100. package/lib-module/ExpandCollapse/Panel.js +5 -4
  101. package/lib-module/List/ListItem.js +13 -235
  102. package/lib-module/List/ListItemBase.js +139 -0
  103. package/lib-module/List/ListItemContent.js +66 -0
  104. package/lib-module/List/ListItemMark.js +143 -0
  105. package/lib-module/List/PressableListItemBase.js +117 -0
  106. package/lib-module/Notification/Notification.js +2 -1
  107. package/lib-module/Pagination/Pagination.js +5 -3
  108. package/lib-module/Pagination/SideButton.js +18 -8
  109. package/lib-module/Radio/Radio.js +9 -6
  110. package/lib-module/RadioCard/RadioCard.js +9 -6
  111. package/lib-module/Select/Select.js +1 -0
  112. package/lib-module/Tabs/Tabs.js +13 -4
  113. package/lib-module/Tags/Tags.js +3 -3
  114. package/lib-module/TextInput/TextInput.js +5 -4
  115. package/lib-module/ViewportProvider/useViewportListener.js +10 -4
  116. package/lib-module/utils/hasOwnProperty.js +11 -0
  117. package/lib-module/utils/props/a11yProps.js +210 -45
  118. package/lib-module/utils/props/getPropSelector.js +44 -5
  119. package/lib-module/utils/ssr.js +106 -0
  120. package/lib-module/utils/useResponsiveProp.js +3 -4
  121. package/lib-module/utils/withLinkRouter.js +3 -5
  122. package/package.json +12 -17
  123. package/src/A11yInfoProvider/index.jsx +20 -4
  124. package/src/Button/ButtonGroup.jsx +4 -2
  125. package/src/Checkbox/Checkbox.jsx +7 -3
  126. package/src/ExpandCollapse/Control.jsx +8 -5
  127. package/src/ExpandCollapse/Panel.jsx +7 -5
  128. package/src/List/ListItem.jsx +12 -191
  129. package/src/List/ListItemBase.jsx +118 -0
  130. package/src/List/ListItemContent.jsx +52 -0
  131. package/src/List/ListItemMark.jsx +99 -0
  132. package/src/List/PressableListItemBase.jsx +102 -0
  133. package/src/Notification/Notification.jsx +1 -1
  134. package/src/Pagination/Pagination.jsx +6 -1
  135. package/src/Pagination/SideButton.jsx +4 -1
  136. package/src/Radio/Radio.jsx +7 -3
  137. package/src/RadioCard/RadioCard.jsx +7 -3
  138. package/src/Select/Select.jsx +1 -1
  139. package/src/Tabs/Tabs.jsx +19 -2
  140. package/src/Tags/Tags.jsx +3 -3
  141. package/src/TextInput/TextInput.jsx +4 -4
  142. package/src/ViewportProvider/useViewportListener.js +10 -5
  143. package/src/utils/hasOwnProperty.js +11 -0
  144. package/src/utils/props/a11yProps.js +168 -55
  145. package/src/utils/props/getPropSelector.js +45 -4
  146. package/src/utils/ssr.jsx +124 -0
  147. package/src/utils/useResponsiveProp.js +3 -3
  148. package/src/utils/withLinkRouter.jsx +1 -3
  149. package/src/utils/ssr.js +0 -35
package/CHANGELOG.md CHANGED
@@ -1,12 +1,43 @@
1
1
  # Change Log - @telus-uds/components-base
2
2
 
3
- This log was last generated on Wed, 17 Aug 2022 20:48:46 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 08 Sep 2022 15:35:51 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 1.15.0
8
+
9
+ Thu, 08 Sep 2022 15:35:51 GMT
10
+
11
+ ### Minor changes
12
+
13
+ - Add support for React 18 (srikanthkhari@gmail.com)
14
+
15
+ ### Patches
16
+
17
+ - undefined (srikanthkhari@gmail.com)
18
+ - Refactor ListItem to support a private pressable list item subcomponent (alan.slater@nearform.com)
19
+
20
+ ## 1.14.3
21
+
22
+ Thu, 01 Sep 2022 15:40:38 GMT
23
+
24
+ ### Patches
25
+
26
+ - add input validation to select component (evander.owusu@telus.com)
27
+ - Refactor ssr support to match ssrStyles approach proven in ds-allium (alan.slater@nearform.com)
28
+
29
+ ## 1.14.2
30
+
31
+ Tue, 23 Aug 2022 19:32:37 GMT
32
+
33
+ ### Patches
34
+
35
+ - fix: remove extra icons from pagination (ruslan.bredikhin@nearform.com)
36
+ - Bump @telus-uds/system-theme-tokens to v2.4.0
37
+
7
38
  ## 1.14.1
8
39
 
9
- Wed, 17 Aug 2022 20:48:46 GMT
40
+ Wed, 17 Aug 2022 20:50:59 GMT
10
41
 
11
42
  ### Patches
12
43
 
@@ -0,0 +1,34 @@
1
+ import React from 'react'
2
+ import { render } from '@testing-library/react-native'
3
+ import A11yText from '../../src/A11yText'
4
+
5
+ describe('A11yText', () => {
6
+ it('has an accessible label', async () => {
7
+ const { getByA11yLabel } = render(<A11yText text="Some text" />)
8
+
9
+ const a11yText = getByA11yLabel('Some text')
10
+ expect(a11yText).toBeTruthy()
11
+ expect(() => getByA11yLabel('Not some text')).toThrow()
12
+ })
13
+
14
+ it("doesn't render regular text", async () => {
15
+ const { getByText } = render(<A11yText text="Some text" />)
16
+ expect(() => getByText('Some text')).toThrow()
17
+ })
18
+
19
+ it('defaults to text role', async () => {
20
+ const { getByRole } = render(<A11yText text="Some text" />)
21
+
22
+ const a11yText = getByRole('text')
23
+ expect(a11yText).toBeTruthy()
24
+ expect(() => getByRole('header')).toThrow()
25
+ })
26
+
27
+ it('can be set to header role', async () => {
28
+ const { getByRole } = render(<A11yText text="Some text" heading />)
29
+
30
+ const a11yText = getByRole('header')
31
+ expect(a11yText).toBeTruthy()
32
+ expect(() => getByRole('text')).toThrow()
33
+ })
34
+ })
@@ -0,0 +1,68 @@
1
+ import React from 'react'
2
+ import { Platform } from 'react-native'
3
+ import { render as baseRender } from '@testing-library/react-native'
4
+ import Theme from '../../__fixtures__/Theme'
5
+ import ActivityIndicator from '../../src/ActivityIndicator'
6
+ import * as A11yInfoProvider from '../../src/A11yInfoProvider'
7
+
8
+ // Used to remove the "Animated: `useNativeDriver` is not supported because the native animated module is missing." warnings
9
+ jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper')
10
+
11
+ const render = (jsx) => baseRender(jsx, { wrapper: Theme })
12
+
13
+ describe('ActivityIndicator', () => {
14
+ it('has an accessible label', async () => {
15
+ const { getByA11yLabel } = render(<ActivityIndicator label="I'm a loader" />)
16
+
17
+ expect(getByA11yLabel("I'm a loader")).toBeTruthy()
18
+ })
19
+
20
+ it('has a role of progressbar', async () => {
21
+ const { getByRole } = render(<ActivityIndicator label="I'm a loader" />)
22
+
23
+ expect(getByRole('progressbar')).toBeTruthy()
24
+ })
25
+
26
+ it('has an a11y state of busy', async () => {
27
+ const { getAllByAccessibilityState } = render(<ActivityIndicator label="I'm a loader" />)
28
+ expect(getAllByAccessibilityState({ busy: true })).toBeTruthy()
29
+ })
30
+
31
+ it("doesn't render regular text for the label", async () => {
32
+ const { getByText } = render(<ActivityIndicator label="I'm a loader" />)
33
+ expect(() => getByText("I'm a loader")).toThrow()
34
+ })
35
+
36
+ it("doesn't animate when reduced motion is enabled", async () => {
37
+ jest
38
+ .spyOn(A11yInfoProvider, 'useA11yInfo')
39
+ .mockImplementation(() => ({ reduceMotionEnabled: true }))
40
+ // TODO: this won't be called until cross-platform Jest tests are configured
41
+ // see https://github.com/telus/universal-design-system/issues/319
42
+ if (Platform.OS === 'web') {
43
+ const { container } = render(<ActivityIndicator label="I'm a loader" />)
44
+ expect(container.querySelector('[attributeName="transform"]')).not.toBeInTheDocument()
45
+ expect(container.querySelector('[attributeName="stroke-dashoffset"]')).not.toBeInTheDocument()
46
+ expect(container.querySelector('[attributeName="stroke-dasharray"]')).not.toBeInTheDocument()
47
+ } else {
48
+ const component = render(<ActivityIndicator label="I'm a loader" />)
49
+ expect(component).toMatchSnapshot()
50
+ }
51
+ })
52
+ it("animates when reduced motion isn't enabled", async () => {
53
+ jest
54
+ .spyOn(A11yInfoProvider, 'useA11yInfo')
55
+ .mockImplementation(() => ({ reduceMotionEnabled: false }))
56
+ // TODO: this won't be called until cross-platform Jest tests are configured
57
+ // see https://github.com/telus/universal-design-system/issues/319
58
+ if (Platform.OS === 'web') {
59
+ const { container } = render(<ActivityIndicator label="I'm a loader" />)
60
+ expect(container.querySelector('[attributeName="transform"]')).toBeInTheDocument()
61
+ expect(container.querySelector('[attributeName="stroke-dashoffset"]')).toBeInTheDocument()
62
+ expect(container.querySelector('[attributeName="stroke-dasharray"]')).toBeInTheDocument()
63
+ } else {
64
+ const component = render(<ActivityIndicator label="I'm a loader" />)
65
+ expect(component).toMatchSnapshot()
66
+ }
67
+ })
68
+ })
@@ -0,0 +1,299 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ActivityIndicator animates when reduced motion isn't enabled 1`] = `
4
+ <View
5
+ accessibilityLabel="I'm a loader"
6
+ accessibilityRole="progressbar"
7
+ accessibilityState={
8
+ Object {
9
+ "busy": true,
10
+ }
11
+ }
12
+ accessible={true}
13
+ style={
14
+ Array [
15
+ Object {
16
+ "flexGrow": 0,
17
+ "flexShrink": 0,
18
+ },
19
+ ]
20
+ }
21
+ >
22
+ <View
23
+ collapsable={false}
24
+ style={
25
+ Object {
26
+ "height": 24,
27
+ "width": 24,
28
+ }
29
+ }
30
+ >
31
+ <View
32
+ collapsable={false}
33
+ style={
34
+ Object {
35
+ "alignItems": "center",
36
+ "bottom": 0,
37
+ "justifyContent": "center",
38
+ "left": 0,
39
+ "position": "absolute",
40
+ "right": 0,
41
+ "top": 0,
42
+ }
43
+ }
44
+ >
45
+ <View
46
+ collapsable={false}
47
+ style={
48
+ Object {
49
+ "height": 24,
50
+ "transform": Array [
51
+ Object {
52
+ "rotate": "45deg",
53
+ },
54
+ ],
55
+ "width": 24,
56
+ }
57
+ }
58
+ >
59
+ <View
60
+ collapsable={false}
61
+ style={
62
+ Object {
63
+ "height": 12,
64
+ "overflow": "hidden",
65
+ "width": 24,
66
+ }
67
+ }
68
+ >
69
+ <View
70
+ collapsable={false}
71
+ style={
72
+ Object {
73
+ "height": 24,
74
+ "transform": Array [
75
+ Object {
76
+ "translateY": 0,
77
+ },
78
+ Object {
79
+ "rotate": "-165deg",
80
+ },
81
+ ],
82
+ "width": 24,
83
+ }
84
+ }
85
+ >
86
+ <View
87
+ collapsable={false}
88
+ style={
89
+ Object {
90
+ "height": 12,
91
+ "overflow": "hidden",
92
+ "width": 24,
93
+ }
94
+ }
95
+ >
96
+ <View
97
+ collapsable={false}
98
+ style={
99
+ Object {
100
+ "borderColor": "#0e6ac8",
101
+ "borderRadius": 12,
102
+ "borderWidth": 2,
103
+ "height": 24,
104
+ "width": 24,
105
+ }
106
+ }
107
+ />
108
+ </View>
109
+ </View>
110
+ </View>
111
+ </View>
112
+ </View>
113
+ <View
114
+ collapsable={false}
115
+ style={
116
+ Object {
117
+ "alignItems": "center",
118
+ "bottom": 0,
119
+ "justifyContent": "center",
120
+ "left": 0,
121
+ "position": "absolute",
122
+ "right": 0,
123
+ "top": 0,
124
+ }
125
+ }
126
+ >
127
+ <View
128
+ collapsable={false}
129
+ style={
130
+ Object {
131
+ "height": 24,
132
+ "transform": Array [
133
+ Object {
134
+ "rotate": "45deg",
135
+ },
136
+ ],
137
+ "width": 24,
138
+ }
139
+ }
140
+ >
141
+ <View
142
+ collapsable={false}
143
+ style={
144
+ Object {
145
+ "height": 12,
146
+ "overflow": "hidden",
147
+ "top": 12,
148
+ "width": 24,
149
+ }
150
+ }
151
+ >
152
+ <View
153
+ collapsable={false}
154
+ style={
155
+ Object {
156
+ "height": 24,
157
+ "transform": Array [
158
+ Object {
159
+ "translateY": -12,
160
+ },
161
+ Object {
162
+ "rotate": "345deg",
163
+ },
164
+ ],
165
+ "width": 24,
166
+ }
167
+ }
168
+ >
169
+ <View
170
+ collapsable={false}
171
+ style={
172
+ Object {
173
+ "height": 12,
174
+ "overflow": "hidden",
175
+ "width": 24,
176
+ }
177
+ }
178
+ >
179
+ <View
180
+ collapsable={false}
181
+ style={
182
+ Object {
183
+ "borderColor": "#0e6ac8",
184
+ "borderRadius": 12,
185
+ "borderWidth": 2,
186
+ "height": 24,
187
+ "width": 24,
188
+ }
189
+ }
190
+ />
191
+ </View>
192
+ </View>
193
+ </View>
194
+ </View>
195
+ </View>
196
+ </View>
197
+ </View>
198
+ `;
199
+
200
+ exports[`ActivityIndicator doesn't animate when reduced motion is enabled 1`] = `
201
+ <View
202
+ accessibilityLabel="I'm a loader"
203
+ accessibilityRole="progressbar"
204
+ accessibilityState={
205
+ Object {
206
+ "busy": true,
207
+ }
208
+ }
209
+ accessible={true}
210
+ style={
211
+ Array [
212
+ Object {
213
+ "flexGrow": 0,
214
+ "flexShrink": 0,
215
+ },
216
+ ]
217
+ }
218
+ >
219
+ <View
220
+ collapsable={false}
221
+ style={
222
+ Object {
223
+ "height": 24,
224
+ "width": 24,
225
+ }
226
+ }
227
+ >
228
+ <View
229
+ collapsable={false}
230
+ style={
231
+ Object {
232
+ "alignItems": "center",
233
+ "bottom": 0,
234
+ "justifyContent": "center",
235
+ "left": 0,
236
+ "position": "absolute",
237
+ "right": 0,
238
+ "top": 0,
239
+ }
240
+ }
241
+ >
242
+ <View
243
+ collapsable={false}
244
+ style={
245
+ Object {
246
+ "height": 24,
247
+ "width": 24,
248
+ }
249
+ }
250
+ >
251
+ <View
252
+ collapsable={false}
253
+ style={
254
+ Object {
255
+ "height": 16,
256
+ "overflow": "hidden",
257
+ "width": 24,
258
+ }
259
+ }
260
+ >
261
+ <View
262
+ collapsable={false}
263
+ style={
264
+ Object {
265
+ "height": 24,
266
+ "width": 24,
267
+ }
268
+ }
269
+ >
270
+ <View
271
+ collapsable={false}
272
+ style={
273
+ Object {
274
+ "height": 16,
275
+ "overflow": "hidden",
276
+ "width": 24,
277
+ }
278
+ }
279
+ >
280
+ <View
281
+ collapsable={false}
282
+ style={
283
+ Object {
284
+ "borderColor": "#0e6ac8",
285
+ "borderRadius": 12,
286
+ "borderWidth": 2,
287
+ "height": 24,
288
+ "width": 24,
289
+ }
290
+ }
291
+ />
292
+ </View>
293
+ </View>
294
+ </View>
295
+ </View>
296
+ </View>
297
+ </View>
298
+ </View>
299
+ `;
@@ -0,0 +1,111 @@
1
+ import React from 'react'
2
+ import { Text } from 'react-native'
3
+ import { render, fireEvent } from '@testing-library/react-native'
4
+ import { Box } from '../../src'
5
+ import Theme from '../../__fixtures__/Theme'
6
+
7
+ const textContent = 'Some text content'
8
+
9
+ // Based on testTheme
10
+ const expectedScale = [0, 4, 8, 16, 24, 32, 36]
11
+
12
+ describe('Box', () => {
13
+ it('is scrollable if scroll props provided', async () => {
14
+ const onScroll = jest.fn()
15
+ const { getByText } = render(
16
+ <Theme>
17
+ <Box scroll={{ onScroll }}>
18
+ <Text>{textContent}</Text>
19
+ </Box>
20
+ </Theme>
21
+ )
22
+ const content = getByText(textContent)
23
+
24
+ expect(onScroll).toHaveBeenCalledTimes(0)
25
+ await fireEvent.scroll(content)
26
+ expect(onScroll).toHaveBeenCalledTimes(1)
27
+ })
28
+
29
+ it('maps regular props to RN styles', () => {
30
+ const props = {
31
+ top: 1,
32
+ bottom: 2,
33
+ left: 3,
34
+ right: 4
35
+ }
36
+ const { getByText } = render(
37
+ <Theme>
38
+ <Box {...props}>
39
+ <Text>{textContent}</Text>
40
+ </Box>
41
+ </Theme>
42
+ )
43
+ expect(getByText(textContent).parent).toHaveStyle({
44
+ paddingTop: expectedScale[1],
45
+ paddingBottom: expectedScale[2],
46
+ paddingLeft: expectedScale[3],
47
+ paddingRight: expectedScale[4]
48
+ })
49
+ })
50
+
51
+ it(`maps horizontal and vertical props to RN styles`, () => {
52
+ const props = {
53
+ horizontal: 1,
54
+ vertical: 2
55
+ }
56
+ const { getByText } = render(
57
+ <Theme>
58
+ <Box {...props}>
59
+ <Text>{textContent}</Text>
60
+ </Box>
61
+ </Theme>
62
+ )
63
+ expect(getByText(textContent).parent).toHaveStyle({
64
+ paddingLeft: expectedScale[1],
65
+ paddingRight: expectedScale[1],
66
+ paddingTop: expectedScale[2],
67
+ paddingBottom: expectedScale[2]
68
+ })
69
+ })
70
+
71
+ it(`maps all-sides space prop to RN styles`, () => {
72
+ const props = {
73
+ space: 3
74
+ }
75
+ const { getByText } = render(
76
+ <Theme>
77
+ <Box {...props}>
78
+ <Text>{textContent}</Text>
79
+ </Box>
80
+ </Theme>
81
+ )
82
+ expect(getByText(textContent).parent).toHaveStyle({
83
+ paddingLeft: expectedScale[3],
84
+ paddingRight: expectedScale[3],
85
+ paddingTop: expectedScale[3],
86
+ paddingBottom: expectedScale[3]
87
+ })
88
+ })
89
+
90
+ it(`applies side overrides in increasing specificity`, () => {
91
+ const props = {
92
+ space: 1,
93
+ horizontal: 2,
94
+ top: 3,
95
+ right: 4
96
+ }
97
+ const { getByText } = render(
98
+ <Theme>
99
+ <Box {...props}>
100
+ <Text>{textContent}</Text>
101
+ </Box>
102
+ </Theme>
103
+ )
104
+ expect(getByText(textContent).parent).toHaveStyle({
105
+ paddingLeft: expectedScale[2],
106
+ paddingRight: expectedScale[4],
107
+ paddingTop: expectedScale[3],
108
+ paddingBottom: expectedScale[1]
109
+ })
110
+ })
111
+ })
@@ -0,0 +1,86 @@
1
+ import React from 'react'
2
+ import { render, fireEvent } from '@testing-library/react-native'
3
+ import { StyleSheet } from 'react-native'
4
+ import testTheme from '../../__fixtures__/testTheme'
5
+
6
+ import Theme from '../../__fixtures__/Theme'
7
+ import Button from '../../src/Button/Button'
8
+
9
+ const label = 'Test label text'
10
+
11
+ describe('Button', () => {
12
+ it('renders a labelled, pressable button', async () => {
13
+ const handlePress = jest.fn()
14
+ const { getByRole } = render(
15
+ <Theme>
16
+ <Button onPress={handlePress}>{label}</Button>
17
+ </Theme>
18
+ )
19
+
20
+ const button = getByRole('button')
21
+ expect(button).toHaveTextContent(label)
22
+
23
+ expect(handlePress).toHaveBeenCalledTimes(0)
24
+ await fireEvent.press(button)
25
+ expect(handlePress).toHaveBeenCalledTimes(1)
26
+ })
27
+
28
+ it('applies theme variants', () => {
29
+ const { tokens } = testTheme.components.Button
30
+ const { getByText } = render(
31
+ <Theme>
32
+ <Button onPress={() => {}}>regular</Button>
33
+ <Button variant={{ solid: true }} onPress={() => {}}>
34
+ solid
35
+ </Button>
36
+ </Theme>
37
+ )
38
+
39
+ expect(getByText('regular')).toHaveStyle({ color: tokens.color })
40
+ expect(getByText('solid')).toHaveStyle({ color: '#ffffff' })
41
+ })
42
+
43
+ it('maintains size if border width changes as state changes', async () => {
44
+ // React Native Testing Library doesn't seem to support Pressable states
45
+ // so we have to simulate the pressed-in state
46
+ const { getByText } = render(
47
+ <Theme>
48
+ <Button onPress={() => {}}>default</Button>
49
+ <Button variant={{ pressed: true }} onPress={() => {}}>
50
+ pressed
51
+ </Button>
52
+ </Theme>
53
+ )
54
+ const defaultButton = getByText('default')
55
+ const pressedButton = getByText('pressed')
56
+
57
+ const getStyle = (element) => StyleSheet.flatten(element.props.style)
58
+ const getElementHeight = ({
59
+ borderWidth = 0,
60
+ paddingVertical = 0,
61
+ paddingTop = 0,
62
+ paddingBottom = 0,
63
+ lineHeight = 0
64
+ }) =>
65
+ borderWidth * 2 +
66
+ (paddingTop || paddingVertical) +
67
+ (paddingBottom || paddingVertical) +
68
+ lineHeight
69
+ const getTotalHeight = (element) =>
70
+ getElementHeight(getStyle(element)) +
71
+ getElementHeight(getStyle(element.parent.parent)) +
72
+ getElementHeight(getStyle(element.parent.parent.parent))
73
+
74
+ const containerStyle = getStyle(defaultButton.parent.parent.parent)
75
+ const pressedContainerStyle = getStyle(pressedButton.parent.parent.parent)
76
+
77
+ // test theme has border width that increases during pressed state
78
+ expect(containerStyle.borderWidth).toEqual(2)
79
+ expect(pressedContainerStyle.borderWidth).toEqual(8)
80
+
81
+ // ensure that the overall height is balanced to not change
82
+ const expectedHeight = 56
83
+ expect(getTotalHeight(defaultButton)).toBe(expectedHeight)
84
+ expect(getTotalHeight(pressedButton)).toBe(expectedHeight)
85
+ })
86
+ })