@telus-uds/components-base 0.0.2-prerelease.4 → 0.0.2-prerelease.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/__fixtures__/testTheme.js +83 -11
- package/__tests__/Divider/Divider.test.jsx +26 -5
- package/__tests__/Feedback/Feedback.test.jsx +42 -0
- package/__tests__/Spacer/Spacer.test.jsx +63 -0
- package/__tests__/StackView/StackView.test.jsx +242 -0
- package/__tests__/StackView/StackWrap.test.jsx +47 -0
- package/__tests__/StackView/getStackedContent.test.jsx +295 -0
- package/__tests__/TextInput/TextInput.test.jsx +146 -0
- package/__tests__/utils/useUniqueId.test.js +31 -0
- package/lib/Box/Box.js +7 -2
- package/lib/Button/ButtonBase.js +6 -16
- package/lib/Button/ButtonGroup.js +13 -22
- package/lib/Divider/Divider.js +40 -2
- package/lib/Feedback/Feedback.js +110 -0
- package/lib/Feedback/index.js +2 -0
- package/lib/Icon/Icon.js +1 -1
- package/lib/InputLabel/InputLabel.js +86 -0
- package/lib/InputLabel/LabelContent.native.js +8 -0
- package/lib/InputLabel/LabelContent.web.js +17 -0
- package/lib/InputLabel/index.js +2 -0
- package/lib/Link/LinkBase.js +9 -3
- package/lib/Spacer/Spacer.js +98 -0
- package/lib/Spacer/index.js +2 -0
- package/lib/StackView/StackView.js +105 -0
- package/lib/StackView/StackWrap.js +32 -0
- package/lib/StackView/StackWrap.native.js +3 -0
- package/lib/StackView/StackWrapBox.js +85 -0
- package/lib/StackView/StackWrapGap.js +45 -0
- package/lib/StackView/common.js +30 -0
- package/lib/StackView/getStackedContent.js +111 -0
- package/lib/StackView/index.js +5 -0
- package/lib/TextInput/TextInput.js +337 -0
- package/lib/TextInput/index.js +2 -0
- package/lib/Typography/Typography.js +0 -4
- package/lib/index.js +6 -1
- package/lib/utils/input.js +3 -1
- package/lib/utils/propTypes.js +9 -1
- package/lib/utils/useUniqueId.js +12 -0
- package/package.json +2 -2
- package/release-context.json +4 -4
- package/src/Box/Box.jsx +4 -2
- package/src/Button/ButtonBase.jsx +6 -18
- package/src/Button/ButtonGroup.jsx +13 -17
- package/src/Divider/Divider.jsx +38 -3
- package/src/Feedback/Feedback.jsx +99 -0
- package/src/Feedback/index.js +3 -0
- package/src/Icon/Icon.jsx +2 -1
- package/src/InputLabel/InputLabel.jsx +99 -0
- package/src/InputLabel/LabelContent.native.jsx +6 -0
- package/src/InputLabel/LabelContent.web.jsx +13 -0
- package/src/InputLabel/index.js +3 -0
- package/src/Link/LinkBase.jsx +9 -3
- package/src/Spacer/Spacer.jsx +91 -0
- package/src/Spacer/index.js +3 -0
- package/src/StackView/StackView.jsx +103 -0
- package/src/StackView/StackWrap.jsx +33 -0
- package/src/StackView/StackWrap.native.jsx +4 -0
- package/src/StackView/StackWrapBox.jsx +82 -0
- package/src/StackView/StackWrapGap.jsx +39 -0
- package/src/StackView/common.jsx +28 -0
- package/src/StackView/getStackedContent.jsx +106 -0
- package/src/StackView/index.js +6 -0
- package/src/TextInput/TextInput.jsx +325 -0
- package/src/TextInput/index.js +3 -0
- package/src/Typography/Typography.jsx +0 -4
- package/src/index.js +6 -1
- package/src/utils/input.js +2 -1
- package/src/utils/propTypes.js +9 -0
- package/src/utils/useUniqueId.js +14 -0
- package/stories/A11yText/A11yText.stories.jsx +11 -5
- package/stories/ActivityIndicator/ActivityIndicator.stories.jsx +11 -2
- package/stories/Box/Box.stories.jsx +29 -2
- package/stories/Button/Button.stories.jsx +17 -21
- package/stories/Button/ButtonGroup.stories.jsx +2 -1
- package/stories/Button/ButtonLink.stories.jsx +6 -4
- package/stories/Card/Card.stories.jsx +13 -1
- package/stories/Divider/Divider.stories.jsx +26 -2
- package/stories/ExpandCollapse/ExpandCollapse.stories.jsx +74 -79
- package/stories/Feedback/Feedback.stories.jsx +97 -0
- package/stories/FlexGrid/01 FlexGrid.stories.jsx +20 -7
- package/stories/Icon/Icon.stories.jsx +11 -3
- package/stories/InputLabel/InputLabel.stories.jsx +37 -0
- package/stories/Link/ChevronLink.stories.jsx +20 -4
- package/stories/Link/Link.stories.jsx +24 -2
- package/stories/Link/TextButton.stories.jsx +24 -2
- package/stories/Pagination/Pagination.stories.jsx +28 -14
- package/stories/SideNav/SideNav.stories.jsx +17 -2
- package/stories/Spacer/Spacer.stories.jsx +33 -0
- package/stories/StackView/StackView.stories.jsx +65 -0
- package/stories/StackView/StackWrap.stories.jsx +52 -0
- package/stories/TextInput/TextInput.stories.jsx +103 -0
- package/stories/ToggleSwitch/ToggleSwitch.stories.jsx +16 -3
- package/stories/Typography/Typography.stories.jsx +12 -3
- package/stories/platform-supports.web.jsx +1 -1
- package/stories/supports.jsx +109 -13
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import React, { Fragment } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import { View } from 'react-native'
|
|
4
|
+
import { render } from '@testing-library/react-native'
|
|
5
|
+
|
|
6
|
+
import Theme from '../../__fixtures__/Theme'
|
|
7
|
+
import { getStackedContent, Typography } from '../../src'
|
|
8
|
+
|
|
9
|
+
// Make test composition simpler by wrapping getStackedContent in a component
|
|
10
|
+
const StackedContent = ({ children, ...props }) => <View>{getStackedContent(children, props)}</View>
|
|
11
|
+
StackedContent.propTypes = { children: PropTypes.node }
|
|
12
|
+
|
|
13
|
+
describe('getStackedContent (Spacers)', () => {
|
|
14
|
+
it('renders spacers between simple children', () => {
|
|
15
|
+
const { queryAllByTestId } = render(
|
|
16
|
+
<StackedContent space={1}>
|
|
17
|
+
<Typography>A</Typography>
|
|
18
|
+
<Typography>B</Typography>
|
|
19
|
+
<Typography>C</Typography>
|
|
20
|
+
</StackedContent>,
|
|
21
|
+
{ wrapper: Theme }
|
|
22
|
+
)
|
|
23
|
+
expect(queryAllByTestId(/Stack-Spacer/)).toHaveLength(2)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('gives spacers sizes according to own space prop and spacing scale', () => {
|
|
27
|
+
const expectedSize = 8 // from __fixtures__/testTheme.js
|
|
28
|
+
const expectedStyle = { height: expectedSize }
|
|
29
|
+
|
|
30
|
+
const { getByTestId } = render(
|
|
31
|
+
<StackedContent space={2}>
|
|
32
|
+
<Typography>A</Typography>
|
|
33
|
+
<Typography>B</Typography>
|
|
34
|
+
<Typography>C</Typography>
|
|
35
|
+
</StackedContent>,
|
|
36
|
+
{ wrapper: Theme }
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
expect(getByTestId('Stack-Spacer-1')).toHaveStyle(expectedStyle)
|
|
40
|
+
expect(getByTestId('Stack-Spacer-2')).toHaveStyle(expectedStyle)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('renders spacers between children wrapped in one Fragment', () => {
|
|
44
|
+
const content = (
|
|
45
|
+
<>
|
|
46
|
+
<Typography>A</Typography>
|
|
47
|
+
<Typography>B</Typography>
|
|
48
|
+
<Typography>C</Typography>
|
|
49
|
+
</>
|
|
50
|
+
)
|
|
51
|
+
const { queryAllByTestId } = render(<StackedContent space={1}>{content}</StackedContent>, {
|
|
52
|
+
wrapper: Theme
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
expect(queryAllByTestId(/Stack-Spacer/)).toHaveLength(2)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('renders spacers between children wrapped in sibling Fragments', () => {
|
|
59
|
+
// Simulate common pattern of using fragments for conditional rendering
|
|
60
|
+
const someCondition = true
|
|
61
|
+
|
|
62
|
+
const content = (
|
|
63
|
+
<>
|
|
64
|
+
<Typography>A</Typography>
|
|
65
|
+
<Typography>B</Typography>
|
|
66
|
+
{someCondition && (
|
|
67
|
+
<>
|
|
68
|
+
<Typography>C</Typography>
|
|
69
|
+
<Typography>D</Typography>
|
|
70
|
+
<Typography>E</Typography>
|
|
71
|
+
</>
|
|
72
|
+
)}
|
|
73
|
+
</>
|
|
74
|
+
)
|
|
75
|
+
const { queryAllByTestId } = render(<StackedContent space={1}>{content}</StackedContent>, {
|
|
76
|
+
wrapper: Theme
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
expect(queryAllByTestId(/Stack-Spacer/)).toHaveLength(4)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('does not render spacers between children wrapped in a component', () => {
|
|
83
|
+
const content = (
|
|
84
|
+
<View>
|
|
85
|
+
<Typography>A</Typography>
|
|
86
|
+
<Typography>B</Typography>
|
|
87
|
+
<Typography>C</Typography>
|
|
88
|
+
</View>
|
|
89
|
+
)
|
|
90
|
+
const { queryAllByTestId } = render(<StackedContent space={1}>{content}</StackedContent>, {
|
|
91
|
+
wrapper: Theme
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
expect(queryAllByTestId(/Stack-Spacer/)).toHaveLength(0)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('does not render spacers between empty or nullish children', () => {
|
|
98
|
+
const { queryAllByTestId } = render(
|
|
99
|
+
<StackedContent space={1}>
|
|
100
|
+
<Typography>A</Typography>
|
|
101
|
+
{/* this is a comment */}
|
|
102
|
+
<Typography>B</Typography>
|
|
103
|
+
{null}
|
|
104
|
+
<Typography>C</Typography>
|
|
105
|
+
{false}
|
|
106
|
+
<Typography>D</Typography>
|
|
107
|
+
{undefined}
|
|
108
|
+
{null}
|
|
109
|
+
{false}
|
|
110
|
+
<Typography>E</Typography>
|
|
111
|
+
</StackedContent>,
|
|
112
|
+
{ wrapper: Theme }
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
expect(queryAllByTestId(/Stack-Spacer/)).toHaveLength(4)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('renders spacers between valid children in an array', () => {
|
|
119
|
+
const content = [
|
|
120
|
+
<Typography key="A">A</Typography>,
|
|
121
|
+
null,
|
|
122
|
+
false,
|
|
123
|
+
<Typography key="B">B</Typography>,
|
|
124
|
+
undefined,
|
|
125
|
+
<View key="C">
|
|
126
|
+
<Typography key="D">D</Typography>
|
|
127
|
+
<Typography key="E">E</Typography>
|
|
128
|
+
<Typography key="F">F</Typography>
|
|
129
|
+
</View>,
|
|
130
|
+
<Fragment key="G">
|
|
131
|
+
<Typography key="H">H</Typography>
|
|
132
|
+
<Typography key="I">I</Typography>
|
|
133
|
+
</Fragment>
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
const { queryAllByTestId } = render(<StackedContent space={1}>{content}</StackedContent>, {
|
|
137
|
+
wrapper: Theme
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
// Between A, B, C, H, I = 4
|
|
141
|
+
expect(queryAllByTestId(/Stack-Spacer/)).toHaveLength(4)
|
|
142
|
+
})
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
describe('getStackedContent (Dividers)', () => {
|
|
146
|
+
it('renders dividers between simple children', () => {
|
|
147
|
+
const { queryAllByTestId } = render(
|
|
148
|
+
<StackedContent divider>
|
|
149
|
+
<Typography>A</Typography>
|
|
150
|
+
<Typography>B</Typography>
|
|
151
|
+
<Typography>C</Typography>
|
|
152
|
+
</StackedContent>,
|
|
153
|
+
{ wrapper: Theme }
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
expect(queryAllByTestId(/Stack-Divider-\d$/)).toHaveLength(2)
|
|
157
|
+
expect(queryAllByTestId(/Stack-Spacer/)).toHaveLength(0)
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
it('renders dividers between valid children in an array', () => {
|
|
161
|
+
const content = [
|
|
162
|
+
<Typography key="A">A</Typography>,
|
|
163
|
+
null,
|
|
164
|
+
false,
|
|
165
|
+
<Typography key="B">B</Typography>,
|
|
166
|
+
undefined,
|
|
167
|
+
<View key="C">
|
|
168
|
+
<Typography key="D">D</Typography>
|
|
169
|
+
<Typography key="E">E</Typography>
|
|
170
|
+
<Typography key="F">F</Typography>
|
|
171
|
+
</View>,
|
|
172
|
+
<Fragment key="G">
|
|
173
|
+
<Typography key="H">H</Typography>
|
|
174
|
+
<Typography key="I">I</Typography>
|
|
175
|
+
</Fragment>
|
|
176
|
+
]
|
|
177
|
+
|
|
178
|
+
const { queryAllByTestId } = render(
|
|
179
|
+
<StackedContent space={1} divider>
|
|
180
|
+
{content}
|
|
181
|
+
</StackedContent>,
|
|
182
|
+
{
|
|
183
|
+
wrapper: Theme
|
|
184
|
+
}
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
// Between A, B, C, H, I = 4
|
|
188
|
+
expect(queryAllByTestId(/Stack-Divider-\d+$/)).toHaveLength(4)
|
|
189
|
+
expect(queryAllByTestId(/Stack-Spacer/)).toHaveLength(0)
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
it('gives dividers spacing according to own space prop and spacing scale', () => {
|
|
193
|
+
const expectedSize = 8 // from __fixtures__/testTheme.js
|
|
194
|
+
const expectedStyle = { height: expectedSize }
|
|
195
|
+
|
|
196
|
+
const { getByTestId } = render(
|
|
197
|
+
<StackedContent space={2} divider>
|
|
198
|
+
<Typography>A</Typography>
|
|
199
|
+
<Typography>B</Typography>
|
|
200
|
+
<Typography>C</Typography>
|
|
201
|
+
</StackedContent>,
|
|
202
|
+
{ wrapper: Theme }
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
expect(getByTestId('Stack-Divider-1-Spacer-before')).toHaveStyle(expectedStyle)
|
|
206
|
+
expect(getByTestId('Stack-Divider-1-Spacer-after')).toHaveStyle(expectedStyle)
|
|
207
|
+
expect(getByTestId('Stack-Divider-2-Spacer-before')).toHaveStyle(expectedStyle)
|
|
208
|
+
expect(getByTestId('Stack-Divider-2-Spacer-after')).toHaveStyle(expectedStyle)
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
it('can pass props down to dividers', () => {
|
|
212
|
+
const tokens = { color: '#012345' }
|
|
213
|
+
|
|
214
|
+
const { getByTestId } = render(
|
|
215
|
+
<StackedContent divider={{ tokens, vertical: true }}>
|
|
216
|
+
<Typography>A</Typography>
|
|
217
|
+
<Typography>B</Typography>
|
|
218
|
+
<Typography>C</Typography>
|
|
219
|
+
</StackedContent>,
|
|
220
|
+
{ wrapper: Theme }
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
expect(getByTestId('Stack-Divider-1')).toHaveStyle({ borderRightColor: tokens.color })
|
|
224
|
+
expect(getByTestId('Stack-Divider-2')).toHaveStyle({ borderRightColor: tokens.color })
|
|
225
|
+
})
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
describe('getStackedContent (Boxes)', () => {
|
|
229
|
+
it('renders boxes around simple children', () => {
|
|
230
|
+
const { queryAllByTestId } = render(
|
|
231
|
+
<StackedContent box>
|
|
232
|
+
<Typography>A</Typography>
|
|
233
|
+
<Typography>B</Typography>
|
|
234
|
+
<Typography>C</Typography>
|
|
235
|
+
</StackedContent>,
|
|
236
|
+
{ wrapper: Theme }
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
expect(queryAllByTestId(/Stack-Box-\d$/)).toHaveLength(3)
|
|
240
|
+
expect(queryAllByTestId(/Stack-Divider/)).toHaveLength(0)
|
|
241
|
+
expect(queryAllByTestId(/Stack-Spacer/)).toHaveLength(0)
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
it('gives boxes spacing according to own space prop and spacing scale', () => {
|
|
245
|
+
const expectedSize = 8 // from __fixtures__/testTheme.js
|
|
246
|
+
const expectedStyle = {
|
|
247
|
+
paddingTop: expectedSize,
|
|
248
|
+
paddingLeft: expectedSize,
|
|
249
|
+
paddingBottom: expectedSize,
|
|
250
|
+
paddingRight: expectedSize
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const { getByTestId } = render(
|
|
254
|
+
<StackedContent space={2} box>
|
|
255
|
+
<Typography>A</Typography>
|
|
256
|
+
<Typography>B</Typography>
|
|
257
|
+
<Typography>C</Typography>
|
|
258
|
+
</StackedContent>,
|
|
259
|
+
{ wrapper: Theme }
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
expect(getByTestId('Stack-Box-0')).toHaveStyle(expectedStyle)
|
|
263
|
+
expect(getByTestId('Stack-Box-1')).toHaveStyle(expectedStyle)
|
|
264
|
+
expect(getByTestId('Stack-Box-2')).toHaveStyle(expectedStyle)
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
it('gives boxes spacing on specified sides only, if box props object is passed', () => {
|
|
268
|
+
const expectedSize = 8 // from __fixtures__/testTheme.js
|
|
269
|
+
const expectedStyle = {
|
|
270
|
+
paddingTop: expectedSize,
|
|
271
|
+
paddingLeft: expectedSize
|
|
272
|
+
}
|
|
273
|
+
const unexpectedStyle = {
|
|
274
|
+
paddingBottom: expectedSize,
|
|
275
|
+
paddingRight: expectedSize
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const { getByTestId } = render(
|
|
279
|
+
<StackedContent box={{ top: 2, left: 2 }}>
|
|
280
|
+
<Typography>A</Typography>
|
|
281
|
+
<Typography>B</Typography>
|
|
282
|
+
<Typography>C</Typography>
|
|
283
|
+
</StackedContent>,
|
|
284
|
+
{ wrapper: Theme }
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
expect(getByTestId('Stack-Box-0')).toHaveStyle(expectedStyle)
|
|
288
|
+
expect(getByTestId('Stack-Box-1')).toHaveStyle(expectedStyle)
|
|
289
|
+
expect(getByTestId('Stack-Box-2')).toHaveStyle(expectedStyle)
|
|
290
|
+
|
|
291
|
+
expect(getByTestId('Stack-Box-0')).not.toHaveStyle(unexpectedStyle)
|
|
292
|
+
expect(getByTestId('Stack-Box-1')).not.toHaveStyle(unexpectedStyle)
|
|
293
|
+
expect(getByTestId('Stack-Box-2')).not.toHaveStyle(unexpectedStyle)
|
|
294
|
+
})
|
|
295
|
+
})
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { fireEvent, render } from '@testing-library/react-native'
|
|
3
|
+
|
|
4
|
+
import { TextInput } from '../../src'
|
|
5
|
+
import Theme from '../../__fixtures__/Theme'
|
|
6
|
+
import Viewport from '../../__fixtures__/Viewport'
|
|
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
|
+
describe('TextInput', () => {
|
|
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', () => {
|
|
40
|
+
const { queryByText } = render(
|
|
41
|
+
<TextInput label="Test label content" tooltip="Test tooltip content" />,
|
|
42
|
+
{ wrapper: Wrapper }
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
// TODO: check for either the actual content or accessible text when the Tooltip is rendered
|
|
46
|
+
expect(queryByText('?')).toBeTruthy()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('triggers the interactive callbacks', () => {
|
|
50
|
+
const onFocus = jest.fn()
|
|
51
|
+
const onBlur = jest.fn()
|
|
52
|
+
const onMouseOver = jest.fn()
|
|
53
|
+
const onMouseOut = jest.fn()
|
|
54
|
+
|
|
55
|
+
const { getByA11yLabel } = render(
|
|
56
|
+
<TextInput
|
|
57
|
+
label="Input label"
|
|
58
|
+
onFocus={onFocus}
|
|
59
|
+
onBlur={onBlur}
|
|
60
|
+
onMouseOver={onMouseOver}
|
|
61
|
+
onMouseOut={onMouseOut}
|
|
62
|
+
/>,
|
|
63
|
+
{
|
|
64
|
+
wrapper: Wrapper
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const input = getByA11yLabel('Input label')
|
|
69
|
+
|
|
70
|
+
expect(onFocus).not.toHaveBeenCalled()
|
|
71
|
+
fireEvent(input, 'focus')
|
|
72
|
+
expect(onFocus).toHaveBeenCalledTimes(1)
|
|
73
|
+
|
|
74
|
+
expect(onBlur).not.toHaveBeenCalled()
|
|
75
|
+
fireEvent(input, 'blur')
|
|
76
|
+
expect(onBlur).toHaveBeenCalledTimes(1)
|
|
77
|
+
|
|
78
|
+
expect(onMouseOver).not.toHaveBeenCalled()
|
|
79
|
+
fireEvent(input, 'mouseOver')
|
|
80
|
+
expect(onMouseOver).toHaveBeenCalledTimes(1)
|
|
81
|
+
|
|
82
|
+
expect(onMouseOut).not.toHaveBeenCalled()
|
|
83
|
+
fireEvent(input, 'mouseOut')
|
|
84
|
+
expect(onMouseOut).toHaveBeenCalledTimes(1)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it("can't be edited when inactive", () => {
|
|
88
|
+
const { getByA11yLabel } = render(<TextInput label="Input label" inactive />, {
|
|
89
|
+
wrapper: Wrapper
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const input = getByA11yLabel('Input label')
|
|
93
|
+
|
|
94
|
+
expect(input).toHaveProp('editable', false)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('changes value when uncontrolled', () => {
|
|
98
|
+
const onChange = jest.fn()
|
|
99
|
+
|
|
100
|
+
const { getByA11yLabel } = render(<TextInput label="Input label" onChange={onChange} />, {
|
|
101
|
+
wrapper: Wrapper
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
const input = getByA11yLabel('Input label')
|
|
105
|
+
|
|
106
|
+
expect(onChange).not.toHaveBeenCalled()
|
|
107
|
+
fireEvent.changeText(input, 'new value')
|
|
108
|
+
expect(onChange).toHaveBeenCalledTimes(1)
|
|
109
|
+
expect(onChange).toHaveBeenLastCalledWith('new value')
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('changes value when controlled', () => {
|
|
113
|
+
const onChange = jest.fn()
|
|
114
|
+
|
|
115
|
+
const { getByA11yLabel } = render(
|
|
116
|
+
<TextInput label="Input label" onChange={onChange} value="initial value" />,
|
|
117
|
+
{
|
|
118
|
+
wrapper: Wrapper
|
|
119
|
+
}
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
const input = getByA11yLabel('Input label')
|
|
123
|
+
|
|
124
|
+
expect(onChange).not.toHaveBeenCalled()
|
|
125
|
+
fireEvent.changeText(input, 'new value')
|
|
126
|
+
expect(onChange).toHaveBeenCalledTimes(1)
|
|
127
|
+
expect(onChange).toHaveBeenLastCalledWith('new value')
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it("doesn't change value when readOnly", () => {
|
|
131
|
+
const onChange = jest.fn()
|
|
132
|
+
|
|
133
|
+
const { getByA11yLabel } = render(
|
|
134
|
+
<TextInput label="Input label" onChange={onChange} value="initial value" readOnly />,
|
|
135
|
+
{
|
|
136
|
+
wrapper: Wrapper
|
|
137
|
+
}
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
const input = getByA11yLabel('Input label')
|
|
141
|
+
|
|
142
|
+
expect(onChange).not.toHaveBeenCalled()
|
|
143
|
+
fireEvent.changeText(input, 'new value')
|
|
144
|
+
expect(onChange).not.toHaveBeenCalled()
|
|
145
|
+
})
|
|
146
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { renderHook } from '@testing-library/react-hooks'
|
|
2
|
+
import useUniqueId from '../../lib/utils/useUniqueId'
|
|
3
|
+
|
|
4
|
+
describe('useUniqueId hook', () => {
|
|
5
|
+
it('returns the same id for each re-render, but a different id for a new instance', () => {
|
|
6
|
+
const { result, rerender } = renderHook(() => useUniqueId('prefix'))
|
|
7
|
+
|
|
8
|
+
expect(result.current).toBe('prefix-1')
|
|
9
|
+
|
|
10
|
+
rerender()
|
|
11
|
+
|
|
12
|
+
expect(result.current).toBe('prefix-1')
|
|
13
|
+
|
|
14
|
+
// has to be done within the same test case, as we can't ensure order in which tests are being run in parallel
|
|
15
|
+
const { result: result2, rerender: rerender2 } = renderHook(() => useUniqueId('prefix'))
|
|
16
|
+
|
|
17
|
+
expect(result.current).toBe('prefix-1')
|
|
18
|
+
expect(result2.current).toBe('prefix-2')
|
|
19
|
+
|
|
20
|
+
// ensure that instances' rerendering doesn't affect one another
|
|
21
|
+
rerender2()
|
|
22
|
+
|
|
23
|
+
expect(result.current).toBe('prefix-1')
|
|
24
|
+
expect(result2.current).toBe('prefix-2')
|
|
25
|
+
|
|
26
|
+
rerender()
|
|
27
|
+
|
|
28
|
+
expect(result.current).toBe('prefix-1')
|
|
29
|
+
expect(result2.current).toBe('prefix-2')
|
|
30
|
+
})
|
|
31
|
+
})
|
package/lib/Box/Box.js
CHANGED
|
@@ -102,6 +102,7 @@ const Box = ({
|
|
|
102
102
|
variant,
|
|
103
103
|
tokens,
|
|
104
104
|
scroll,
|
|
105
|
+
testID,
|
|
105
106
|
...rest
|
|
106
107
|
}) => {
|
|
107
108
|
const a11y = a11yProps.select(rest);
|
|
@@ -117,11 +118,14 @@ const Box = ({
|
|
|
117
118
|
if (scroll) {
|
|
118
119
|
const scrollProps = typeof scroll === 'object' ? scroll : {};
|
|
119
120
|
scrollProps.contentContainerStyle = [styles, scrollProps.contentContainerStyle];
|
|
120
|
-
return /*#__PURE__*/React.createElement(ScrollView, Object.assign({}, scrollProps, a11y
|
|
121
|
+
return /*#__PURE__*/React.createElement(ScrollView, Object.assign({}, scrollProps, a11y, {
|
|
122
|
+
testID: testID
|
|
123
|
+
}), children);
|
|
121
124
|
}
|
|
122
125
|
|
|
123
126
|
return /*#__PURE__*/React.createElement(View, Object.assign({}, a11y, {
|
|
124
|
-
style: styles
|
|
127
|
+
style: styles,
|
|
128
|
+
testID: testID
|
|
125
129
|
}), children);
|
|
126
130
|
};
|
|
127
131
|
|
|
@@ -136,6 +140,7 @@ Box.propTypes = {
|
|
|
136
140
|
scroll: PropTypes.oneOfType([PropTypes.bool, ScrollView.propTypes ? PropTypes.shape(ScrollView.propTypes) : PropTypes.object]),
|
|
137
141
|
variant: variantProp.propType,
|
|
138
142
|
tokens: getTokensPropType('Box'),
|
|
143
|
+
testID: PropTypes.string,
|
|
139
144
|
children: PropTypes.node.isRequired
|
|
140
145
|
};
|
|
141
146
|
export default Box;
|
package/lib/Button/ButtonBase.js
CHANGED
|
@@ -19,6 +19,7 @@ const getOuterBorderOffset = ({
|
|
|
19
19
|
}) => outerBorderGap + outerBorderWidth;
|
|
20
20
|
|
|
21
21
|
const selectOuterContainerStyles = ({
|
|
22
|
+
alignSelf,
|
|
22
23
|
opacity,
|
|
23
24
|
outerBorderColor,
|
|
24
25
|
outerBorderWidth,
|
|
@@ -26,6 +27,7 @@ const selectOuterContainerStyles = ({
|
|
|
26
27
|
outerBorderRadius = 0,
|
|
27
28
|
outerBackgroundColor
|
|
28
29
|
}) => ({
|
|
30
|
+
alignSelf,
|
|
29
31
|
padding: outerBorderGap,
|
|
30
32
|
borderWidth: outerBorderWidth,
|
|
31
33
|
borderColor: outerBorderColor,
|
|
@@ -37,13 +39,7 @@ const selectOuterContainerStyles = ({
|
|
|
37
39
|
const selectOuterWidthStyles = ({
|
|
38
40
|
outerBorderGap,
|
|
39
41
|
outerBorderWidth,
|
|
40
|
-
width
|
|
41
|
-
// TODO: make margin the responsibility of a parent
|
|
42
|
-
// https://github.com/telus/universal-design-system/issues/525
|
|
43
|
-
marginTop = 0,
|
|
44
|
-
marginBottom = 0,
|
|
45
|
-
marginLeft = 0,
|
|
46
|
-
marginRight = 0
|
|
42
|
+
width
|
|
47
43
|
}) => {
|
|
48
44
|
// The inner container's bounding box is the bounding box of the button overall
|
|
49
45
|
// so this many device pixels will sit outside of the overall bounding box
|
|
@@ -52,22 +48,16 @@ const selectOuterWidthStyles = ({
|
|
|
52
48
|
outerBorderWidth
|
|
53
49
|
});
|
|
54
50
|
const widthStyles = {
|
|
55
|
-
|
|
56
|
-
marginBottom: marginBottom - outerBorderOffset,
|
|
57
|
-
marginLeft: marginLeft - outerBorderOffset,
|
|
58
|
-
marginRight: marginRight - outerBorderOffset
|
|
51
|
+
margin: 0 - outerBorderOffset
|
|
59
52
|
};
|
|
60
53
|
|
|
61
54
|
if (!width) {
|
|
62
55
|
return { ...widthStyles,
|
|
63
56
|
// Wrap content, stopping a flex parent's default align-items: stretch stretching focus ring beyond content
|
|
64
57
|
...Platform.select({
|
|
58
|
+
// width: fit-content isn't supported on Firefox; can't cascade props like CSS `width: fit-content; width: --moz-fit-content;`
|
|
65
59
|
web: {
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
// No fit-content or inline-block in RN. TODO: we might need to provide a prop to allow flex-end or center
|
|
69
|
-
native: {
|
|
70
|
-
alignSelf: 'flex-start'
|
|
60
|
+
display: 'inline-flex'
|
|
71
61
|
}
|
|
72
62
|
})
|
|
73
63
|
};
|
|
@@ -1,24 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
4
|
import ButtonBase from './ButtonBase';
|
|
5
|
+
import { StackWrap } from '../StackView';
|
|
5
6
|
import { useViewport } from '../ViewportProvider';
|
|
6
7
|
import { useThemeTokens } from '../ThemeProvider';
|
|
7
|
-
import { a11yProps, pressProps, variantProp, getTokensPropType } from '../utils/propTypes';
|
|
8
|
+
import { a11yProps, pressProps, variantProp, getTokensPropType, selectTokens } from '../utils/propTypes';
|
|
8
9
|
import { useMultipleInputValues } from '../utils/input';
|
|
9
10
|
|
|
10
|
-
const selectContainerStyles = ({
|
|
11
|
-
direction
|
|
12
|
-
}) => ({
|
|
13
|
-
flexDirection: direction
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const selectItemTokens = ({
|
|
17
|
-
gap
|
|
18
|
-
}, index) => ({
|
|
19
|
-
marginLeft: index && gap
|
|
20
|
-
});
|
|
21
|
-
|
|
22
11
|
const ButtonGroup = ({
|
|
23
12
|
variant,
|
|
24
13
|
buttonVariant = {},
|
|
@@ -41,7 +30,11 @@ const ButtonGroup = ({
|
|
|
41
30
|
const themeTokens = useThemeTokens('ButtonGroup', tokens, variant, {
|
|
42
31
|
viewport
|
|
43
32
|
});
|
|
44
|
-
const
|
|
33
|
+
const stackTokens = selectTokens('StackView', themeTokens);
|
|
34
|
+
const {
|
|
35
|
+
direction,
|
|
36
|
+
space
|
|
37
|
+
} = themeTokens;
|
|
45
38
|
const {
|
|
46
39
|
currentValues,
|
|
47
40
|
toggleOneValue
|
|
@@ -57,14 +50,15 @@ const ButtonGroup = ({
|
|
|
57
50
|
...rest
|
|
58
51
|
});
|
|
59
52
|
const itemA11yRole = a11y.accessibilityRole === 'radioGroup' ? 'radio' : 'checkbox';
|
|
60
|
-
return /*#__PURE__*/React.createElement(
|
|
61
|
-
|
|
62
|
-
|
|
53
|
+
return /*#__PURE__*/React.createElement(StackWrap, Object.assign({}, a11y, {
|
|
54
|
+
space: space,
|
|
55
|
+
direction: direction,
|
|
56
|
+
tokens: stackTokens
|
|
57
|
+
}), items.map(({
|
|
63
58
|
label,
|
|
64
59
|
id = label,
|
|
65
60
|
accessibilityLabel
|
|
66
61
|
}, index) => {
|
|
67
|
-
const itemTokens = selectItemTokens(themeTokens, index);
|
|
68
62
|
const isSelected = currentValues.includes(id); // Allow handlers to be passed down for blur, hover, focus, pressIn, etc
|
|
69
63
|
|
|
70
64
|
const pressHandlers = Object.fromEntries(Object.entries(pressProps.select(rest)).map(([key, handler]) => ({
|
|
@@ -100,8 +94,6 @@ const ButtonGroup = ({
|
|
|
100
94
|
})
|
|
101
95
|
}; // Ensure button is direct child of group as MacOS voiceover only applies "X of Y" to
|
|
102
96
|
// "radio" if it's a direct child of "radiogroup", even if aria-posinset etc exists
|
|
103
|
-
// See also: TODO: make margin the responsibility of a parent
|
|
104
|
-
// https://github.com/telus/universal-design-system/issues/525
|
|
105
97
|
|
|
106
98
|
return /*#__PURE__*/React.createElement(ButtonBase, Object.assign({
|
|
107
99
|
key: id
|
|
@@ -111,7 +103,6 @@ const ButtonGroup = ({
|
|
|
111
103
|
component: 'ButtonGroup',
|
|
112
104
|
...buttonVariant
|
|
113
105
|
},
|
|
114
|
-
tokens: itemTokens,
|
|
115
106
|
selected: isSelected,
|
|
116
107
|
inactive: inactive
|
|
117
108
|
}, itemA11y), label);
|