@telus-uds/components-base 0.0.2-prerelease.1 → 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 +36 -0
- package/__fixtures__/testTheme.js +264 -84
- package/__tests__/Box/Box.test.jsx +81 -58
- package/__tests__/Card/Card.test.jsx +63 -0
- package/__tests__/Divider/Divider.test.jsx +26 -5
- package/__tests__/Feedback/Feedback.test.jsx +42 -0
- package/__tests__/FlexGrid/Col.test.jsx +5 -0
- package/__tests__/Pagination/Pagination.test.jsx +160 -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__/ThemeProvider/useThemeTokens.test.jsx +5 -3
- package/__tests__/utils/spacing.test.jsx +273 -0
- package/__tests__/utils/useUniqueId.test.js +31 -0
- package/babel.config.json +8 -0
- package/jest.config.js +7 -6
- package/lib/A11yInfoProvider/index.js +2 -2
- package/lib/A11yText/index.js +1 -3
- package/lib/ActivityIndicator/Spinner.web.js +3 -5
- package/lib/Box/Box.js +117 -82
- package/lib/Button/Button.js +1 -3
- package/lib/Button/ButtonBase.js +9 -21
- package/lib/Button/ButtonGroup.js +14 -25
- package/lib/Button/ButtonLink.js +1 -3
- package/lib/Card/Card.js +103 -0
- package/lib/Card/index.js +2 -0
- package/lib/Divider/Divider.js +40 -4
- package/lib/ExpandCollapse/Accordion.js +1 -3
- package/lib/ExpandCollapse/Control.js +3 -5
- package/lib/ExpandCollapse/Panel.js +2 -4
- package/lib/Feedback/Feedback.js +110 -0
- package/lib/Feedback/index.js +2 -0
- package/lib/FlexGrid/Col/Col.js +3 -5
- package/lib/FlexGrid/FlexGrid.js +1 -3
- package/lib/FlexGrid/Row/Row.js +1 -3
- package/lib/FlexGrid/providers/GutterContext.js +1 -1
- 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/ChevronLink.js +1 -3
- package/lib/Link/Link.js +1 -3
- package/lib/Link/LinkBase.js +11 -7
- package/lib/Link/TextButton.js +1 -3
- package/lib/Pagination/PageButton.js +85 -0
- package/lib/Pagination/Pagination.js +118 -0
- package/lib/Pagination/SideButton.js +108 -0
- package/lib/Pagination/dictionary.js +18 -0
- package/lib/Pagination/index.js +2 -0
- package/lib/Pagination/useCopy.js +10 -0
- package/lib/Pagination/usePagination.js +70 -0
- package/lib/SideNav/Item.js +4 -6
- package/lib/SideNav/ItemsGroup.js +11 -11
- package/lib/SideNav/SideNav.js +2 -4
- 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/ThemeProvider/ThemeProvider.js +2 -2
- package/lib/ThemeProvider/useThemeTokens.js +34 -6
- package/lib/ThemeProvider/utils/theme-tokens.js +37 -9
- package/lib/ToggleSwitch/ToggleSwitch.js +17 -47
- package/lib/Typography/Typography.js +1 -7
- package/lib/ViewportProvider/index.js +1 -1
- package/lib/index.js +8 -1
- package/lib/utils/index.js +2 -1
- package/lib/utils/input.js +3 -1
- package/lib/utils/propTypes.js +103 -8
- package/lib/utils/spacing/index.js +2 -0
- package/lib/utils/spacing/useSpacingScale.js +102 -0
- package/lib/utils/spacing/utils.js +32 -0
- package/lib/utils/useUniqueId.js +12 -0
- package/package.json +6 -9
- package/release-context.json +4 -4
- package/src/Box/Box.jsx +117 -80
- package/src/Button/ButtonBase.jsx +8 -21
- package/src/Button/ButtonGroup.jsx +13 -17
- package/src/Card/Card.jsx +101 -0
- package/src/Card/index.js +3 -0
- package/src/Divider/Divider.jsx +38 -3
- package/src/ExpandCollapse/Control.jsx +2 -3
- package/src/Feedback/Feedback.jsx +99 -0
- package/src/Feedback/index.js +3 -0
- package/src/FlexGrid/Col/Col.jsx +4 -2
- 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/Pagination/PageButton.jsx +80 -0
- package/src/Pagination/Pagination.jsx +135 -0
- package/src/Pagination/SideButton.jsx +93 -0
- package/src/Pagination/dictionary.js +18 -0
- package/src/Pagination/index.js +3 -0
- package/src/Pagination/useCopy.js +7 -0
- package/src/Pagination/usePagination.js +69 -0
- package/src/SideNav/Item.jsx +3 -3
- package/src/SideNav/ItemsGroup.jsx +11 -13
- 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/ThemeProvider/useThemeTokens.js +34 -7
- package/src/ThemeProvider/utils/theme-tokens.js +37 -8
- package/src/ToggleSwitch/ToggleSwitch.jsx +23 -43
- package/src/Typography/Typography.jsx +0 -4
- package/src/index.js +8 -1
- package/src/utils/index.js +1 -0
- package/src/utils/input.js +2 -1
- package/src/utils/propTypes.js +105 -16
- package/src/utils/spacing/index.js +3 -0
- package/src/utils/spacing/useSpacingScale.js +93 -0
- package/src/utils/spacing/utils.js +28 -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 +46 -17
- 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 +62 -0
- 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 -3
- package/stories/Link/TextButton.stories.jsx +24 -3
- package/stories/Pagination/Pagination.stories.jsx +64 -0
- 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 +113 -13
- package/babel.config.js +0 -3
|
@@ -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
|
+
})
|
|
@@ -291,9 +291,11 @@ describe('useThemeTokens', () => {
|
|
|
291
291
|
})
|
|
292
292
|
})
|
|
293
293
|
|
|
294
|
+
// Simulate a scenario where a parent component passes tokens to a child component.
|
|
295
|
+
// Imagine a component that contains a button and wants to tell it what colour to be when pressed.
|
|
294
296
|
it('overrides default theme tokens using passed-in tokens function', () => {
|
|
295
|
-
// ExtendedComponent is
|
|
296
|
-
// setting
|
|
297
|
+
// ExtendedComponent is a parent to TestComponent and passes it additional theming rules,
|
|
298
|
+
// setting child TestComponent's colour to lilac when child's state is "off", and red when "on".
|
|
297
299
|
const getTokensByExtendedRules = getHookResult(() =>
|
|
298
300
|
useThemeTokensCallback('ExtendedComponent')
|
|
299
301
|
)
|
|
@@ -301,7 +303,7 @@ describe('useThemeTokens', () => {
|
|
|
301
303
|
// If the extending component uses different naming to its inner component, we need to map names
|
|
302
304
|
const selectInnerTokens = ({ innerColour }) => ({ colour: innerColour })
|
|
303
305
|
const tokensFn = (innerAppearances) =>
|
|
304
|
-
selectInnerTokens(getTokensByExtendedRules({
|
|
306
|
+
selectInnerTokens(getTokensByExtendedRules({ innerOn: innerAppearances.on }))
|
|
305
307
|
|
|
306
308
|
const on = { on: true }
|
|
307
309
|
|