@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,91 +0,0 @@
1
- import React from 'react'
2
- import { render } from '@testing-library/react-native'
3
- import { Text } from 'react-native'
4
-
5
- import Divider from '../../src/Divider'
6
- import Theme from '../../__fixtures__/Theme'
7
- import testTheme from '../../__fixtures__/testTheme'
8
-
9
- describe('Divider', () => {
10
- const testID = 'testID'
11
- const { width, color } = testTheme.components.Divider.tokens
12
- const { width: thickWidth } = testTheme.components.Divider.rules.find(
13
- (rule) => rule.if.weight === 'thick'
14
- ).tokens
15
-
16
- const horizontalStyles = {
17
- borderBottomColor: color,
18
- borderBottomWidth: width
19
- }
20
-
21
- const verticalStyles = {
22
- borderRightColor: color,
23
- borderRightWidth: width
24
- }
25
-
26
- const thickStyles = {
27
- borderBottomColor: color,
28
- borderBottomWidth: thickWidth
29
- }
30
-
31
- it('renders a horizontal line by default', () => {
32
- const { getByTestId } = render(
33
- <Theme>
34
- <Text>Before</Text>
35
- <Divider testID={testID} />
36
- <Text>After</Text>
37
- </Theme>
38
- )
39
- const divider = getByTestId(testID)
40
- expect(divider).toHaveStyle(horizontalStyles)
41
- expect(divider).not.toHaveStyle(verticalStyles)
42
- })
43
-
44
- it('renders space above and below a horizontal line if space prop is passed', () => {
45
- const expectedSize = 8 // from testTheme.js
46
-
47
- const { getByTestId } = render(
48
- <Theme>
49
- <Text>Before</Text>
50
- <Divider testID={testID} space={2} />
51
- <Text>After</Text>
52
- </Theme>
53
- )
54
- const before = getByTestId(`${testID}-Spacer-before`)
55
- expect(before).toHaveStyle({ height: expectedSize })
56
-
57
- const after = getByTestId(`${testID}-Spacer-after`)
58
- expect(after).toHaveStyle({ height: expectedSize })
59
- })
60
-
61
- it('renders space left and right of a vertical line if space prop is passed', () => {
62
- const expectedSize = 8 // from testTheme.js
63
-
64
- const { getByTestId } = render(
65
- <Theme>
66
- <Text>Before</Text>
67
- <Divider vertical testID={testID} space={2} />
68
- <Text>After</Text>
69
- </Theme>
70
- )
71
- const before = getByTestId(`${testID}-Spacer-before`)
72
- expect(before).toHaveStyle({ width: expectedSize })
73
-
74
- const after = getByTestId(`${testID}-Spacer-after`)
75
- expect(after).toHaveStyle({ width: expectedSize })
76
- })
77
-
78
- it('renders the correct styles for a given variant', () => {
79
- const { getByTestId } = render(
80
- <Theme>
81
- <Text>Before</Text>
82
- <Divider testID={testID} variant={{ weight: 'thick' }} />
83
- <Text>After</Text>
84
- </Theme>
85
- )
86
- const divider = getByTestId(testID)
87
- expect(divider).toHaveStyle(thickStyles)
88
- expect(divider).not.toHaveStyle(verticalStyles)
89
- expect(divider).not.toHaveStyle(horizontalStyles)
90
- })
91
- })
@@ -1,109 +0,0 @@
1
- import React from 'react'
2
- import { render, fireEvent } from '@testing-library/react-native'
3
-
4
- import { Accordion, ExpandCollapse, Typography } from '../../src'
5
- import Theme from '../../__fixtures__/Theme'
6
-
7
- describe('ExpandCollapse', () => {
8
- it('expands multiple groups when accordion = false', async () => {
9
- const { queryAllByA11yState, getByText } = render(
10
- <ExpandCollapse>
11
- {(expandProps) => (
12
- <>
13
- <ExpandCollapse.Panel
14
- {...expandProps}
15
- panelId="first"
16
- control={<Typography>First control</Typography>}
17
- >
18
- <Typography>First content</Typography>
19
- </ExpandCollapse.Panel>
20
- <ExpandCollapse.Panel
21
- {...expandProps}
22
- panelId="second"
23
- control={<Typography>Second control</Typography>}
24
- >
25
- <Typography>Second content</Typography>
26
- </ExpandCollapse.Panel>
27
- </>
28
- )}
29
- </ExpandCollapse>,
30
- {
31
- wrapper: Theme
32
- }
33
- )
34
- expect(queryAllByA11yState({ expanded: true }).length).toBe(0)
35
- await fireEvent.press(getByText('First control'))
36
- expect(queryAllByA11yState({ expanded: true }).length).toBe(1)
37
- await fireEvent.press(getByText('Second control'))
38
- expect(queryAllByA11yState({ expanded: true }).length).toBe(2)
39
- await fireEvent.press(getByText('Second control'))
40
- expect(queryAllByA11yState({ expanded: true }).length).toBe(1)
41
- })
42
-
43
- it("calls a panel's provided onPress function in addition to open/close", async () => {
44
- const panelId = 'group-id'
45
- const onPress = jest.fn()
46
-
47
- const { queryAllByA11yState, getByText } = render(
48
- <ExpandCollapse>
49
- {(expandProps) => (
50
- <ExpandCollapse.Panel
51
- {...expandProps}
52
- onPress={onPress}
53
- panelId={panelId}
54
- control={<Typography>First control</Typography>}
55
- >
56
- <Typography>First content</Typography>
57
- </ExpandCollapse.Panel>
58
- )}
59
- </ExpandCollapse>,
60
- {
61
- wrapper: Theme
62
- }
63
- )
64
- expect(onPress).toHaveBeenCalledTimes(0)
65
- expect(queryAllByA11yState({ expanded: true }).length).toBe(0)
66
-
67
- await fireEvent(getByText('First control'), 'press', { nativeEvent: 'example' })
68
- expect(queryAllByA11yState({ expanded: true }).length).toBe(1)
69
- expect(onPress).toHaveBeenCalledTimes(1)
70
- expect(onPress).toHaveBeenLastCalledWith(panelId, { nativeEvent: 'example' })
71
- })
72
- })
73
-
74
- describe('Accordion', () => {
75
- it('expands only one group', async () => {
76
- const { queryAllByA11yState, getByText } = render(
77
- <Accordion>
78
- {(expandProps) => (
79
- <>
80
- <Accordion.Panel
81
- {...expandProps}
82
- panelId="first"
83
- control={<Typography>First control</Typography>}
84
- >
85
- <Typography>First content</Typography>
86
- </Accordion.Panel>
87
- <Accordion.Panel
88
- {...expandProps}
89
- panelId="second"
90
- control={<Typography>Second control</Typography>}
91
- >
92
- <Typography>Second content</Typography>
93
- </Accordion.Panel>
94
- </>
95
- )}
96
- </Accordion>,
97
- {
98
- wrapper: Theme
99
- }
100
- )
101
- expect(queryAllByA11yState({ expanded: true }).length).toBe(0)
102
- await fireEvent.press(getByText('First control'))
103
- expect(queryAllByA11yState({ expanded: true }).length).toBe(1)
104
- await fireEvent.press(getByText('Second control'))
105
- expect(queryAllByA11yState({ expanded: true }).length).toBe(1)
106
- await fireEvent.press(getByText('Second control'))
107
- expect(queryAllByA11yState({ expanded: true }).length).toBe(0)
108
- })
109
- })
@@ -1,42 +0,0 @@
1
- import React from 'react'
2
- import { Text } from 'react-native'
3
- import { render } from '@testing-library/react-native'
4
-
5
- import Feedback from '../../src/Feedback'
6
- import Theme from '../../__fixtures__/Theme'
7
-
8
- describe('Feedback', () => {
9
- it('renders title', () => {
10
- const { queryByText } = render(<Feedback title="Test title" />, { wrapper: Theme })
11
-
12
- expect(queryByText('Test title')).toBeTruthy()
13
- })
14
-
15
- it('renders content when passed a string', () => {
16
- const { queryByText } = render(<Feedback>Test content</Feedback>, { wrapper: Theme })
17
-
18
- expect(queryByText('Test content')).toBeTruthy()
19
- })
20
-
21
- it('renders content when passed a React element', () => {
22
- const { queryByText } = render(
23
- <Feedback>
24
- <Text>Test content</Text>
25
- </Feedback>,
26
- { wrapper: Theme }
27
- )
28
-
29
- expect(queryByText('Test content')).toBeTruthy()
30
- })
31
-
32
- it("renders content with theme's style prop when passed a function", () => {
33
- const { getByText } = render(
34
- <Feedback>{({ textStyles }) => <Text style={textStyles}>Test content</Text>}</Feedback>,
35
- {
36
- wrapper: Theme
37
- }
38
- )
39
-
40
- expect(getByText('Test content')).toHaveStyle({ fontSize: 14 })
41
- })
42
- })
@@ -1,261 +0,0 @@
1
- import React from 'react'
2
- import { render } from '@testing-library/react-native'
3
- import { Text } from 'react-native'
4
- import { viewports } from '@telus-uds/system-constants'
5
-
6
- import FlexGrid from '../../src/FlexGrid'
7
- import Theme from '../../__fixtures__/Theme'
8
- import Viewport from '../../__fixtures__/Viewport'
9
-
10
- describe('FlexGrid.Col offsets', () => {
11
- const offsetLevels = {
12
- xs: 1,
13
- sm: 2,
14
- md: 3,
15
- lg: 4,
16
- xl: 5
17
- }
18
- const getOffsetStyle = (viewport) => ({ marginLeft: `${(offsetLevels[viewport] / 12) * 100}%` })
19
-
20
- it.each(
21
- // true here indicates offset styles should apply and follow the provided level for that prop
22
- // Align expected results like a table so they're easier to read
23
- /* prettier-ignore */ [
24
- ['xs', { xs: true, sm: false, md: false, lg: false, xl: false }],
25
- ['sm', { xs: true, sm: true, md: false, lg: false, xl: false }],
26
- ['md', { xs: true, sm: true, md: true, lg: false, xl: false }],
27
- ['lg', { xs: true, sm: true, md: true, lg: true, xl: false }],
28
- ['xl', { xs: true, sm: true, md: true, lg: true, xl: true }]
29
- ]
30
- )('applies styles from one offset prop at viewport "%s"', (viewport, expected) => {
31
- // Render flexgrids with one each of xsOffset={1}, smOffset={2} etc based on offsetLevels above
32
- const { getByText } = render(
33
- <Theme>
34
- <Viewport viewport={viewport}>
35
- <FlexGrid>
36
- {viewports.keys.map((offsetViewport) => {
37
- const propName = `${offsetViewport}Offset`
38
- const level = offsetLevels[offsetViewport]
39
- return (
40
- <FlexGrid.Col key={propName} {...{ [propName]: level }}>
41
- <Text>{propName}</Text>
42
- </FlexGrid.Col>
43
- )
44
- })}
45
- </FlexGrid>
46
- </Viewport>
47
- </Theme>
48
- )
49
- const expectIfOffsetExpected = (propViewport) => {
50
- const target = getByText(`${propViewport}Offset`).parent
51
- // eslint-disable-next-line jest/valid-expect
52
- return expected[propViewport] ? expect(target) : expect(target).not
53
- }
54
- expectIfOffsetExpected('xs').toHaveStyle(getOffsetStyle('xs'))
55
- expectIfOffsetExpected('sm').toHaveStyle(getOffsetStyle('sm'))
56
- expectIfOffsetExpected('md').toHaveStyle(getOffsetStyle('md'))
57
- expectIfOffsetExpected('lg').toHaveStyle(getOffsetStyle('lg'))
58
- expectIfOffsetExpected('xl').toHaveStyle(getOffsetStyle('xl'))
59
- })
60
- })
61
-
62
- describe('FlexGrid.Col sizes', () => {
63
- const sizeLevels = {
64
- xs: 1,
65
- sm: 2,
66
- md: 3,
67
- lg: 4,
68
- xl: 5
69
- }
70
- const getNumericSizeStyle = (viewport) => ({
71
- maxWidth: `${(sizeLevels[viewport] / 12) * 100}%`,
72
- flexBasis: `${(sizeLevels[viewport] / 12) * 100}%`
73
- })
74
-
75
- it.each(
76
- // true here indicates size styles should apply: following the provided level for that prop
77
- // Align expected results like a table so they're easier to read
78
- /* prettier-ignore */ [
79
- ['xs', { xs: true, sm: false, md: false, lg: false, xl: false }],
80
- ['sm', { xs: true, sm: true, md: false, lg: false, xl: false }],
81
- ['md', { xs: true, sm: true, md: true, lg: false, xl: false }],
82
- ['lg', { xs: true, sm: true, md: true, lg: true, xl: false }],
83
- ['xl', { xs: true, sm: true, md: true, lg: true, xl: true }]
84
- ]
85
- )('applies styles from one size prop at viewport "%s"', (viewport, expected) => {
86
- // Render flexgrids with one each of xs={1}, sm={2} etc based on sizeLevels above
87
- const { getByText } = render(
88
- <Theme>
89
- <Viewport viewport={viewport}>
90
- <FlexGrid>
91
- {viewports.keys.map((sizeViewport) => {
92
- const propName = sizeViewport
93
- const level = sizeLevels[sizeViewport]
94
- return (
95
- <FlexGrid.Col key={propName} {...{ [propName]: level }}>
96
- <Text>{propName}</Text>
97
- </FlexGrid.Col>
98
- )
99
- })}
100
- </FlexGrid>
101
- </Viewport>
102
- </Theme>
103
- )
104
-
105
- const expectIfSizeExpected = (propViewport) => {
106
- const target = getByText(propViewport).parent
107
- // eslint-disable-next-line jest/valid-expect
108
- return expected[propViewport] ? expect(target) : expect(target).not
109
- }
110
- expectIfSizeExpected('xs').toHaveStyle(getNumericSizeStyle('xs'))
111
- expectIfSizeExpected('sm').toHaveStyle(getNumericSizeStyle('sm'))
112
- expectIfSizeExpected('md').toHaveStyle(getNumericSizeStyle('md'))
113
- expectIfSizeExpected('lg').toHaveStyle(getNumericSizeStyle('lg'))
114
- expectIfSizeExpected('xl').toHaveStyle(getNumericSizeStyle('xl'))
115
- })
116
-
117
- it.each(
118
- // true here indicates size styles should apply: inheriting until level is passed as `true` resetting inheritance
119
- // Align expected results like a table so they're easier to read
120
- /* prettier-ignore */ [
121
- ['xs', { 'xs-md': true, 'xs-lg': true, 'xs-xl': true, 'sm-lg': false, 'sm-xl': false, 'md-xl': false }],
122
- ['sm', { 'xs-md': true, 'xs-lg': true, 'xs-xl': true, 'sm-lg': true, 'sm-xl': true, 'md-xl': false }],
123
- ['md', { 'xs-md': false, 'xs-lg': true, 'xs-xl': true, 'sm-lg': true, 'sm-xl': true, 'md-xl': true }],
124
- ['lg', { 'xs-md': false, 'xs-lg': false, 'xs-xl': true, 'sm-lg': false, 'sm-xl': true, 'md-xl': true }],
125
- ['xl', { 'xs-md': false, 'xs-lg': false, 'xs-xl': false, 'sm-lg': false, 'sm-xl': false, 'md-xl': false }]
126
- ]
127
- )('inherits size levels until a size prop is `true` at viewport "%s"', (viewport, expected) => {
128
- const { getByText } = render(
129
- <Theme>
130
- <Viewport viewport={viewport}>
131
- <FlexGrid>
132
- <FlexGrid.Col xs={sizeLevels.xs} md={true}>
133
- <Text>xs-md</Text>
134
- </FlexGrid.Col>
135
- <FlexGrid.Col xs={sizeLevels.xs} lg={true}>
136
- <Text>xs-lg</Text>
137
- </FlexGrid.Col>
138
- <FlexGrid.Col xs={sizeLevels.xs} xl={true}>
139
- <Text>xs-xl</Text>
140
- </FlexGrid.Col>
141
- <FlexGrid.Col sm={sizeLevels.sm} lg={true}>
142
- <Text>sm-lg</Text>
143
- </FlexGrid.Col>
144
- <FlexGrid.Col sm={sizeLevels.sm} xl={true}>
145
- <Text>sm-xl</Text>
146
- </FlexGrid.Col>
147
- <FlexGrid.Col md={sizeLevels.md} xl={true}>
148
- <Text>md-xl</Text>
149
- </FlexGrid.Col>
150
- </FlexGrid>
151
- </Viewport>
152
- </Theme>
153
- )
154
-
155
- const expectIfSizeExpected = (text) => {
156
- const target = getByText(text).parent
157
- // eslint-disable-next-line jest/valid-expect
158
- return expected[text] ? expect(target) : expect(target).not
159
- }
160
- expectIfSizeExpected('xs-md').toHaveStyle(getNumericSizeStyle('xs'))
161
- expectIfSizeExpected('xs-lg').toHaveStyle(getNumericSizeStyle('xs'))
162
- expectIfSizeExpected('xs-xl').toHaveStyle(getNumericSizeStyle('xs'))
163
- expectIfSizeExpected('sm-lg').toHaveStyle(getNumericSizeStyle('sm'))
164
- expectIfSizeExpected('sm-xl').toHaveStyle(getNumericSizeStyle('sm'))
165
- expectIfSizeExpected('md-xl').toHaveStyle(getNumericSizeStyle('md'))
166
- })
167
-
168
- // Testing special "hiding" case on passing xs, sm, md, lg, xl props as 0.
169
- // Should inherit like other values for these props, confirmed in:
170
- // https://github.com/telus/universal-design-system/pull/364#discussion_r671382300
171
- it.each(
172
- // true here indicates hiding styles should apply
173
- // Align expected results like a table so they're easier to read
174
- /* prettier-ignore */ [
175
- ['xs', { xs: true, sm: false, md: false, lg: false, xl: false }],
176
- ['sm', { xs: true, sm: true, md: false, lg: false, xl: false }],
177
- ['md', { xs: true, sm: true, md: true, lg: false, xl: false }],
178
- ['lg', { xs: true, sm: true, md: true, lg: true, xl: false }],
179
- ['xl', { xs: true, sm: true, md: true, lg: true, xl: true }]
180
- ]
181
- )('applies hiding styles from one prop at viewport "%s"', (viewport, expected) => {
182
- const hidingStyle = { display: 'none' }
183
-
184
- // Render flexgrids with one each of xs={0}, sm={0} etc based on sizeLevels above
185
- const { getByText } = render(
186
- <Theme>
187
- <Viewport viewport={viewport}>
188
- <FlexGrid>
189
- {viewports.keys.map((sizeViewport) => {
190
- const propName = sizeViewport
191
- return (
192
- <FlexGrid.Col key={propName} {...{ [propName]: 0 }}>
193
- <Text>{propName}</Text>
194
- </FlexGrid.Col>
195
- )
196
- })}
197
- </FlexGrid>
198
- </Viewport>
199
- </Theme>
200
- )
201
- const expectIfHidingExpected = (propViewport) => {
202
- const target = getByText(propViewport).parent
203
- // eslint-disable-next-line jest/valid-expect
204
- return expected[propViewport] ? expect(target) : expect(target).not
205
- }
206
- expectIfHidingExpected('xs').toHaveStyle(hidingStyle)
207
- expectIfHidingExpected('sm').toHaveStyle(hidingStyle)
208
- expectIfHidingExpected('md').toHaveStyle(hidingStyle)
209
- expectIfHidingExpected('lg').toHaveStyle(hidingStyle)
210
- expectIfHidingExpected('xl').toHaveStyle(hidingStyle)
211
- })
212
- })
213
-
214
- describe('FlexGrid.Col horizontalAlign', () => {
215
- const alignRightStyle = { textAlign: 'right' }
216
-
217
- it.each(
218
- // true here indicates offset styles should apply and follow the provided level for that prop
219
- // Align expected results like a table so they're easier to read
220
- /* prettier-ignore */ [
221
- ['xs', { xs: true, sm: false, md: false, lg: false, xl: false }],
222
- ['sm', { xs: true, sm: true, md: false, lg: false, xl: false }],
223
- ['md', { xs: true, sm: true, md: true, lg: false, xl: false }],
224
- ['lg', { xs: true, sm: true, md: true, lg: true, xl: false }],
225
- ['xl', { xs: true, sm: true, md: true, lg: true, xl: true }]
226
- ]
227
- )('applies right align from one horizontalAlign value at viewport "%s"', (viewport, expected) => {
228
- // Render flexgrids with horizontalAlign={{ xs: 'right' }}, horizontalAlign={{ sm: 'right' }}, etc
229
- const { getByText } = render(
230
- <Theme>
231
- <Viewport viewport={viewport}>
232
- <FlexGrid>
233
- {viewports.keys.map((alignViewport) => {
234
- return (
235
- <FlexGrid.Col
236
- key={alignViewport}
237
- horizontalAlign={{
238
- [alignViewport]: 'right'
239
- }}
240
- >
241
- <Text>{alignViewport}</Text>
242
- </FlexGrid.Col>
243
- )
244
- })}
245
- </FlexGrid>
246
- </Viewport>
247
- </Theme>
248
- )
249
-
250
- const expectIfAlignExpected = (propViewport) => {
251
- const target = getByText(propViewport).parent
252
- // eslint-disable-next-line jest/valid-expect
253
- return expected[propViewport] ? expect(target) : expect(target).not
254
- }
255
- expectIfAlignExpected('xs').toHaveStyle(alignRightStyle)
256
- expectIfAlignExpected('sm').toHaveStyle(alignRightStyle)
257
- expectIfAlignExpected('md').toHaveStyle(alignRightStyle)
258
- expectIfAlignExpected('lg').toHaveStyle(alignRightStyle)
259
- expectIfAlignExpected('xl').toHaveStyle(alignRightStyle)
260
- })
261
- })
@@ -1,136 +0,0 @@
1
- import React from 'react'
2
- import { render } from '@testing-library/react-native'
3
- import { Text } from 'react-native'
4
- import { viewports } from '@telus-uds/system-constants'
5
-
6
- import FlexGrid from '../../src/FlexGrid'
7
- import applyInheritance from '../../src/FlexGrid/helpers'
8
- import Theme from '../../__fixtures__/Theme'
9
- import Viewport from '../../__fixtures__/Viewport'
10
-
11
- const contents = (
12
- <FlexGrid.Col>
13
- <FlexGrid.Row>
14
- <Text>Some text</Text>
15
- </FlexGrid.Row>
16
- </FlexGrid.Col>
17
- )
18
-
19
- // Keep these on one line, wrapping some makes them harder to read
20
- /* prettier-ignore */
21
- describe('FlexGrid applyInheritance', () => {
22
- it('fills undefined values with last defined value', () => {
23
- expect(applyInheritance([1, undefined, undefined, undefined, undefined])).toEqual([1, 1, 1, 1, 1])
24
- expect(applyInheritance([1, 2, undefined, undefined, undefined])).toEqual([1, 2, 2, 2, 2])
25
- expect(applyInheritance([1, 2, 3, undefined, undefined])).toEqual([1, 2, 3, 3, 3])
26
- expect(applyInheritance([1, 2, 3, 4, undefined])).toEqual([1, 2, 3, 4, 4])
27
- })
28
-
29
- it("doesn't change an array's values where everything is defined", () => {
30
- expect(applyInheritance([1, 2, 3, 4, 5])).toEqual([1, 2, 3, 4, 5])
31
- })
32
-
33
- it("doesn't change an array's values where nothing is defined", () => {
34
- expect(applyInheritance([undefined, undefined, undefined, undefined, undefined])).toEqual([undefined, undefined, undefined, undefined, undefined])
35
- })
36
-
37
- // TODO: check implementation, see if it really needs to return undefined for [0] and '' for others
38
- it("doesn't change undefined values before the first defined value", () => {
39
- expect(applyInheritance([undefined, 1, 2, 3, 4])).toEqual([undefined, 1, 2, 3, 4])
40
- expect(applyInheritance([undefined, undefined, 1, 2, 3])).toEqual([undefined, undefined, 1, 2, 3])
41
- expect(applyInheritance([undefined, undefined, undefined, 1, 2])).toEqual([undefined, undefined, undefined, 1, 2])
42
- expect(applyInheritance([undefined, undefined, undefined, undefined, 1])).toEqual([undefined, undefined, undefined, undefined, 1])
43
- })
44
-
45
- it('fills undefined values after any defined value while leaving those before', () => {
46
- expect(applyInheritance([undefined, 1, undefined, 2, undefined])).toEqual([undefined, 1, 1, 2, 2])
47
- expect(applyInheritance([undefined, undefined, 1, undefined, 2])).toEqual([undefined, undefined, 1, 1, 2])
48
- expect(applyInheritance([undefined, undefined, undefined, 1, undefined])).toEqual([undefined, undefined, undefined, 1, 1])
49
- })
50
- })
51
-
52
- describe('FlexGrid', () => {
53
- it('Sets style correctly if outsideGutter is passed', () => {
54
- const withID = 'with-outsideGutter'
55
- const withoutID = 'without-outsideGutter'
56
-
57
- const withStyle = { width: '100%' }
58
-
59
- const withoutStyle = { marginHorizontal: -16 }
60
-
61
- const { getByTestId } = render(
62
- <Theme>
63
- <Viewport>
64
- <FlexGrid outsideGutter={true} testID={withID}>
65
- {contents}
66
- </FlexGrid>
67
- <FlexGrid outsideGutter={false} testID={withoutID}>
68
- {contents}
69
- </FlexGrid>
70
- </Viewport>
71
- </Theme>
72
- )
73
-
74
- expect(getByTestId(withID)).toHaveStyle(withStyle)
75
- expect(getByTestId(withoutID)).toHaveStyle(withoutStyle)
76
-
77
- expect(getByTestId(withID)).not.toHaveStyle(withoutStyle)
78
- expect(getByTestId(withoutID)).not.toHaveStyle(withStyle)
79
- })
80
-
81
- it.each(Array.from(viewports.map.entries()))(
82
- `applies correct limitWidth styles at viewport "%s"`,
83
- (viewport, breakpoint) => {
84
- const testID = 'testID'
85
- const { getByTestId } = render(
86
- <Theme>
87
- <Viewport viewport={viewport}>
88
- <FlexGrid limitWidth testID={testID}>
89
- {contents}
90
- </FlexGrid>
91
- </Viewport>
92
- </Theme>
93
- )
94
- if (viewport !== viewports.xs) {
95
- expect(typeof breakpoint).toBe('number')
96
- expect(breakpoint).toBeGreaterThan(0)
97
- expect(getByTestId(testID)).toHaveStyle({ maxWidth: breakpoint })
98
- } else {
99
- expect(getByTestId(testID)).not.toHaveStyle({ maxWidth: breakpoint })
100
- }
101
- }
102
- )
103
-
104
- it.each(
105
- // Align expected results like a table so they're easier to read
106
- /* prettier-ignore */ [
107
- ['xs', { xs: 'column-reverse', sm: 'column', md: 'column', lg: 'column', xl: 'column' }],
108
- ['sm', { xs: 'column-reverse', sm: 'column-reverse', md: 'column', lg: 'column', xl: 'column' }],
109
- ['md', { xs: 'column-reverse', sm: 'column-reverse', md: 'column-reverse', lg: 'column', xl: 'column' }],
110
- ['lg', { xs: 'column-reverse', sm: 'column-reverse', md: 'column-reverse', lg: 'column-reverse', xl: 'column' }],
111
- ['xl', { xs: 'column-reverse', sm: 'column-reverse', md: 'column-reverse', lg: 'column-reverse', xl: 'column-reverse' }]
112
- ]
113
- )('applies correct column order for each reverse prop at viewport "%s"', (viewport, expected) => {
114
- // Render flexgrids for each of xsReverse, smReverse, mdReverse etc etc
115
- const { getByTestId } = render(
116
- <Theme>
117
- <Viewport viewport={viewport}>
118
- {viewports.keys.map((reverseViewport) => {
119
- const propName = `${reverseViewport}Reverse`
120
- return (
121
- <FlexGrid key={propName} testID={propName} {...{ [propName]: true }}>
122
- {contents}
123
- </FlexGrid>
124
- )
125
- })}
126
- </Viewport>
127
- </Theme>
128
- )
129
-
130
- expect(getByTestId('xsReverse')).toHaveStyle({ flexDirection: expected.xs })
131
- expect(getByTestId('smReverse')).toHaveStyle({ flexDirection: expected.sm })
132
- expect(getByTestId('mdReverse')).toHaveStyle({ flexDirection: expected.md })
133
- expect(getByTestId('lgReverse')).toHaveStyle({ flexDirection: expected.lg })
134
- expect(getByTestId('xlReverse')).toHaveStyle({ flexDirection: expected.xl })
135
- })
136
- })