@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
|
@@ -41,17 +41,38 @@ describe('Divider', () => {
|
|
|
41
41
|
expect(divider).not.toHaveStyle(verticalStyles)
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
it('renders a
|
|
44
|
+
it('renders space above and below a horizontal line if space prop is passed', () => {
|
|
45
|
+
const expectedSize = 8 // from testTheme.js
|
|
46
|
+
|
|
45
47
|
const { getByTestId } = render(
|
|
46
48
|
<Theme>
|
|
47
49
|
<Text>Before</Text>
|
|
48
|
-
<Divider
|
|
50
|
+
<Divider testID={testID} space={2} />
|
|
49
51
|
<Text>After</Text>
|
|
50
52
|
</Theme>
|
|
51
53
|
)
|
|
52
|
-
const
|
|
53
|
-
expect(
|
|
54
|
-
|
|
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 })
|
|
55
76
|
})
|
|
56
77
|
|
|
57
78
|
it('renders the correct styles for a given variant', () => {
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
})
|
|
@@ -48,6 +48,7 @@ describe('FlexGrid.Col offsets', () => {
|
|
|
48
48
|
)
|
|
49
49
|
const expectIfOffsetExpected = (propViewport) => {
|
|
50
50
|
const target = getByText(`${propViewport}Offset`).parent
|
|
51
|
+
// eslint-disable-next-line jest/valid-expect
|
|
51
52
|
return expected[propViewport] ? expect(target) : expect(target).not
|
|
52
53
|
}
|
|
53
54
|
expectIfOffsetExpected('xs').toHaveStyle(getOffsetStyle('xs'))
|
|
@@ -103,6 +104,7 @@ describe('FlexGrid.Col sizes', () => {
|
|
|
103
104
|
|
|
104
105
|
const expectIfSizeExpected = (propViewport) => {
|
|
105
106
|
const target = getByText(propViewport).parent
|
|
107
|
+
// eslint-disable-next-line jest/valid-expect
|
|
106
108
|
return expected[propViewport] ? expect(target) : expect(target).not
|
|
107
109
|
}
|
|
108
110
|
expectIfSizeExpected('xs').toHaveStyle(getNumericSizeStyle('xs'))
|
|
@@ -152,6 +154,7 @@ describe('FlexGrid.Col sizes', () => {
|
|
|
152
154
|
|
|
153
155
|
const expectIfSizeExpected = (text) => {
|
|
154
156
|
const target = getByText(text).parent
|
|
157
|
+
// eslint-disable-next-line jest/valid-expect
|
|
155
158
|
return expected[text] ? expect(target) : expect(target).not
|
|
156
159
|
}
|
|
157
160
|
expectIfSizeExpected('xs-md').toHaveStyle(getNumericSizeStyle('xs'))
|
|
@@ -196,6 +199,7 @@ describe('FlexGrid.Col sizes', () => {
|
|
|
196
199
|
)
|
|
197
200
|
const expectIfHidingExpected = (propViewport) => {
|
|
198
201
|
const target = getByText(propViewport).parent
|
|
202
|
+
// eslint-disable-next-line jest/valid-expect
|
|
199
203
|
return expected[propViewport] ? expect(target) : expect(target).not
|
|
200
204
|
}
|
|
201
205
|
expectIfHidingExpected('xs').toHaveStyle(hidingStyle)
|
|
@@ -244,6 +248,7 @@ describe('FlexGrid.Col horizontalAlign', () => {
|
|
|
244
248
|
|
|
245
249
|
const expectIfAlignExpected = (propViewport) => {
|
|
246
250
|
const target = getByText(propViewport).parent
|
|
251
|
+
// eslint-disable-next-line jest/valid-expect
|
|
247
252
|
return expected[propViewport] ? expect(target) : expect(target).not
|
|
248
253
|
}
|
|
249
254
|
expectIfAlignExpected('xs').toHaveStyle(alignRightStyle)
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { render, fireEvent } from '@testing-library/react-native'
|
|
3
|
+
|
|
4
|
+
import { Pagination } 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('Pagination', () => {
|
|
16
|
+
it('truncates the number of rendered elements', () => {
|
|
17
|
+
const { getByText } = render(
|
|
18
|
+
<Pagination tokens={{ truncateAbove: 3 }}>
|
|
19
|
+
<Pagination.PageButton onPress={() => {}} />
|
|
20
|
+
<Pagination.PageButton onPress={() => {}} />
|
|
21
|
+
<Pagination.PageButton onPress={() => {}} />
|
|
22
|
+
<Pagination.PageButton onPress={() => {}} />
|
|
23
|
+
<Pagination.PageButton onPress={() => {}} />
|
|
24
|
+
</Pagination>,
|
|
25
|
+
{
|
|
26
|
+
wrapper: Wrapper
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
expect(() => getByText('1')).not.toThrow()
|
|
31
|
+
expect(() => getByText('2')).not.toThrow()
|
|
32
|
+
expect(() => getByText('...')).not.toThrow()
|
|
33
|
+
expect(() => getByText('3')).toThrow()
|
|
34
|
+
expect(() => getByText('4')).toThrow()
|
|
35
|
+
expect(() => getByText('5')).not.toThrow()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('renders the "Next Page" button when applicable', () => {
|
|
39
|
+
const { getByA11yLabel } = render(
|
|
40
|
+
<Pagination>
|
|
41
|
+
<Pagination.PageButton onPress={() => {}} isActive />
|
|
42
|
+
<Pagination.PageButton onPress={() => {}} />
|
|
43
|
+
</Pagination>,
|
|
44
|
+
{
|
|
45
|
+
wrapper: Wrapper
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
expect(() => getByA11yLabel(/next/)).not.toThrow()
|
|
50
|
+
expect(() => getByA11yLabel(/previous/)).toThrow()
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('renders the "Previous Page" button when applicable', () => {
|
|
54
|
+
const { getByA11yLabel } = render(
|
|
55
|
+
<Pagination>
|
|
56
|
+
<Pagination.PageButton onPress={() => {}} />
|
|
57
|
+
<Pagination.PageButton onPress={() => {}} isActive />
|
|
58
|
+
</Pagination>,
|
|
59
|
+
{
|
|
60
|
+
wrapper: Wrapper
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
expect(() => getByA11yLabel(/next/)).toThrow()
|
|
65
|
+
expect(() => getByA11yLabel(/previous/)).not.toThrow()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('uses correct copy', () => {
|
|
69
|
+
const { getByA11yLabel } = render(
|
|
70
|
+
<Pagination copy="fr">
|
|
71
|
+
<Pagination.PageButton onPress={() => {}} isActive />
|
|
72
|
+
</Pagination>,
|
|
73
|
+
{
|
|
74
|
+
wrapper: Wrapper
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
expect(() => getByA11yLabel(/page actuelle/)).not.toThrow()
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
describe('Pagination Page Button', () => {
|
|
82
|
+
it('triggers the onPress callback when pressed', () => {
|
|
83
|
+
const onPress = jest.fn()
|
|
84
|
+
|
|
85
|
+
const { getByA11yLabel } = render(
|
|
86
|
+
<Pagination>
|
|
87
|
+
<Pagination.PageButton onPress={() => {}} isActive />
|
|
88
|
+
<Pagination.PageButton onPress={onPress} />
|
|
89
|
+
</Pagination>,
|
|
90
|
+
{
|
|
91
|
+
wrapper: Wrapper
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
expect(onPress).not.toHaveBeenCalled()
|
|
96
|
+
|
|
97
|
+
fireEvent.press(getByA11yLabel('Go to page number 2'))
|
|
98
|
+
|
|
99
|
+
expect(onPress).toHaveBeenCalledTimes(1)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('renders a link and passes down hrefAttrs', () => {
|
|
103
|
+
const { getByA11yLabel } = render(
|
|
104
|
+
<Pagination>
|
|
105
|
+
<Pagination.PageButton onPress={() => {}} isActive />
|
|
106
|
+
<Pagination.PageButton href="test-url" hrefAttrs={{ target: '_blank' }} />
|
|
107
|
+
</Pagination>,
|
|
108
|
+
{
|
|
109
|
+
wrapper: Wrapper
|
|
110
|
+
}
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
const button = getByA11yLabel('Go to page number 2')
|
|
114
|
+
|
|
115
|
+
expect(button).toHaveProp('accessibilityRole', 'link')
|
|
116
|
+
expect(button).toHaveProp('href', 'test-url')
|
|
117
|
+
expect(button).toHaveProp('target', '_blank')
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
describe('Pagination Side Button', () => {
|
|
122
|
+
it('triggers the onPress event of the item next to the active one', () => {
|
|
123
|
+
const onPress = jest.fn()
|
|
124
|
+
|
|
125
|
+
const { getByA11yLabel } = render(
|
|
126
|
+
<Pagination>
|
|
127
|
+
<Pagination.PageButton onPress={() => {}} isActive />
|
|
128
|
+
<Pagination.PageButton onPress={onPress} />
|
|
129
|
+
</Pagination>,
|
|
130
|
+
{
|
|
131
|
+
wrapper: Wrapper
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
expect(onPress).not.toHaveBeenCalled()
|
|
136
|
+
|
|
137
|
+
fireEvent.press(getByA11yLabel(/next/))
|
|
138
|
+
|
|
139
|
+
expect(onPress).toHaveBeenCalledTimes(1)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('renders a link with href props of the item next to the active one', () => {
|
|
143
|
+
const { getByA11yLabel } = render(
|
|
144
|
+
<Pagination>
|
|
145
|
+
<Pagination.PageButton onPress={() => {}} isActive />
|
|
146
|
+
<Pagination.PageButton href="test-url" hrefAttrs={{ target: '_blank' }} />
|
|
147
|
+
</Pagination>,
|
|
148
|
+
{
|
|
149
|
+
wrapper: Wrapper
|
|
150
|
+
}
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
const button = getByA11yLabel(/next/)
|
|
154
|
+
|
|
155
|
+
expect(button).toHaveProp('accessibilityRole', 'link')
|
|
156
|
+
expect(button).toHaveProp('href', 'test-url')
|
|
157
|
+
expect(button).toHaveProp('target', '_blank')
|
|
158
|
+
})
|
|
159
|
+
})
|
|
160
|
+
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { render } from '@testing-library/react-native'
|
|
3
|
+
|
|
4
|
+
import { Spacer } from '../../src'
|
|
5
|
+
import Theme from '../../__fixtures__/Theme'
|
|
6
|
+
|
|
7
|
+
const testID = 'spacer'
|
|
8
|
+
|
|
9
|
+
describe('Spacer', () => {
|
|
10
|
+
it('has smallest size from spacing scale by default', () => {
|
|
11
|
+
const expectedSize = 4 // from __fixtures__/testTheme.js
|
|
12
|
+
const { getByTestId } = render(<Spacer testID={testID} />, { wrapper: Theme })
|
|
13
|
+
expect(getByTestId(testID)).toHaveStyle({
|
|
14
|
+
height: expectedSize
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('has size from spacing scale if space prop passed', () => {
|
|
19
|
+
const expectedSize = 8 // from __fixtures__/testTheme.js
|
|
20
|
+
const { getByTestId } = render(<Spacer space={2} testID={testID} />, { wrapper: Theme })
|
|
21
|
+
expect(getByTestId(testID)).toHaveStyle({
|
|
22
|
+
height: expectedSize
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('has no size if 0 passed in', () => {
|
|
27
|
+
const expectedSize = 0
|
|
28
|
+
const { getByTestId } = render(<Spacer space={0} testID={testID} />, { wrapper: Theme })
|
|
29
|
+
expect(getByTestId(testID)).toHaveStyle({
|
|
30
|
+
height: expectedSize
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
describe('Spacer (row)', () => {
|
|
36
|
+
it('has smallest size from spacing scale by default', () => {
|
|
37
|
+
const expectedSize = 4 // from __fixtures__/testTheme.js
|
|
38
|
+
const { getByTestId } = render(<Spacer testID={testID} direction="row" />, { wrapper: Theme })
|
|
39
|
+
expect(getByTestId(testID)).toHaveStyle({
|
|
40
|
+
width: expectedSize
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('has size from spacing scale if space prop passed', () => {
|
|
45
|
+
const expectedSize = 8 // from __fixtures__/testTheme.js
|
|
46
|
+
const { getByTestId } = render(<Spacer space={2} testID={testID} direction="row" />, {
|
|
47
|
+
wrapper: Theme
|
|
48
|
+
})
|
|
49
|
+
expect(getByTestId(testID)).toHaveStyle({
|
|
50
|
+
width: expectedSize
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('has no size if 0 passed in', () => {
|
|
55
|
+
const expectedSize = 0
|
|
56
|
+
const { getByTestId } = render(<Spacer space={0} testID={testID} direction="row" />, {
|
|
57
|
+
wrapper: Theme
|
|
58
|
+
})
|
|
59
|
+
expect(getByTestId(testID)).toHaveStyle({
|
|
60
|
+
width: expectedSize
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
})
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { View } from 'react-native'
|
|
3
|
+
import { render } from '@testing-library/react-native'
|
|
4
|
+
|
|
5
|
+
import { Spacer, StackView, Typography } from '../../src'
|
|
6
|
+
import Theme from '../../__fixtures__/Theme'
|
|
7
|
+
import testTheme from '../../__fixtures__/testTheme'
|
|
8
|
+
|
|
9
|
+
const getFirstAncestorAboveType = (element, ComponentType) => {
|
|
10
|
+
if (element.type === ComponentType) return element.parent
|
|
11
|
+
if (element.parent) return getFirstAncestorAboveType(element.parent, ComponentType)
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('StackView', () => {
|
|
16
|
+
it('renders separators and children as direct children of a flex column by default', () => {
|
|
17
|
+
const expectedStyle = { flexDirection: 'column' }
|
|
18
|
+
|
|
19
|
+
const { getByTestId } = render(
|
|
20
|
+
<StackView space={2}>
|
|
21
|
+
<Typography>A</Typography>
|
|
22
|
+
<Typography>B</Typography>
|
|
23
|
+
</StackView>,
|
|
24
|
+
{ wrapper: Theme }
|
|
25
|
+
)
|
|
26
|
+
const parent = getFirstAncestorAboveType(getByTestId('Stack-Spacer-1'), Spacer)
|
|
27
|
+
expect(parent.type).toBe('View')
|
|
28
|
+
expect(parent).toHaveStyle(expectedStyle)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('renders separators and children as direct children of a flex column if direction is "column-reverse"', () => {
|
|
32
|
+
const expectedStyle = { flexDirection: 'column-reverse' }
|
|
33
|
+
|
|
34
|
+
const { getByTestId } = render(
|
|
35
|
+
<StackView direction="column-reverse" space={2}>
|
|
36
|
+
<Typography>A</Typography>
|
|
37
|
+
<Typography>B</Typography>
|
|
38
|
+
</StackView>,
|
|
39
|
+
{ wrapper: Theme }
|
|
40
|
+
)
|
|
41
|
+
const parent = getFirstAncestorAboveType(getByTestId('Stack-Spacer-1'), Spacer)
|
|
42
|
+
expect(parent.type).toBe('View')
|
|
43
|
+
expect(parent).toHaveStyle(expectedStyle)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('renders separators and children as direct children of a flex row if direction is "row"', () => {
|
|
47
|
+
const expectedStyle = { flexDirection: 'row' }
|
|
48
|
+
|
|
49
|
+
const { getByTestId } = render(
|
|
50
|
+
<StackView direction="row" space={2}>
|
|
51
|
+
<Typography>A</Typography>
|
|
52
|
+
<Typography>B</Typography>
|
|
53
|
+
</StackView>,
|
|
54
|
+
{ wrapper: Theme }
|
|
55
|
+
)
|
|
56
|
+
const parent = getFirstAncestorAboveType(getByTestId('Stack-Spacer-1'), Spacer)
|
|
57
|
+
expect(parent.type).toBe('View')
|
|
58
|
+
expect(parent).toHaveStyle(expectedStyle)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('renders separators and children as direct children of a flex row if direction is "row-reverse"', () => {
|
|
62
|
+
const expectedStyle = { flexDirection: 'row-reverse' }
|
|
63
|
+
|
|
64
|
+
const { getByTestId } = render(
|
|
65
|
+
<StackView direction="row-reverse" space={2}>
|
|
66
|
+
<Typography>A</Typography>
|
|
67
|
+
<Typography>B</Typography>
|
|
68
|
+
</StackView>,
|
|
69
|
+
{ wrapper: Theme }
|
|
70
|
+
)
|
|
71
|
+
const parent = getFirstAncestorAboveType(getByTestId('Stack-Spacer-1'), Spacer)
|
|
72
|
+
expect(parent.type).toBe('View')
|
|
73
|
+
expect(parent).toHaveStyle(expectedStyle)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('renders separators and children as direct children of parent if "inherit" is set', () => {
|
|
77
|
+
// Some arbitrary custom style we apply to the parent
|
|
78
|
+
const expectedStyle = { color: '#012345', flexBasis: 12345 }
|
|
79
|
+
|
|
80
|
+
const { getByTestId } = render(
|
|
81
|
+
<View style={expectedStyle}>
|
|
82
|
+
<StackView inherit>
|
|
83
|
+
<Typography>A</Typography>
|
|
84
|
+
<Typography>B</Typography>
|
|
85
|
+
</StackView>
|
|
86
|
+
</View>,
|
|
87
|
+
{ wrapper: Theme }
|
|
88
|
+
)
|
|
89
|
+
const parent = getFirstAncestorAboveType(getByTestId('Stack-Spacer-1'), Spacer)
|
|
90
|
+
// Expect an empty StackView fiber node with no styles of its own
|
|
91
|
+
expect(parent.type).toBe(StackView)
|
|
92
|
+
expect(parent).not.toHaveStyle({ flexDirection: 'column' })
|
|
93
|
+
expect(parent).not.toHaveStyle({ flexDirection: 'row' })
|
|
94
|
+
|
|
95
|
+
// Expect next parent to be a rendered View with styles
|
|
96
|
+
const renderedParent = getFirstAncestorAboveType(parent, StackView)
|
|
97
|
+
expect(renderedParent.type).toBe('View')
|
|
98
|
+
expect(renderedParent).toHaveStyle(expectedStyle)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('renders horizontal dividers by default', () => {
|
|
102
|
+
const expectedSize = 4 // from __fixtures__/testTheme.js
|
|
103
|
+
const expectedStyle = { height: expectedSize }
|
|
104
|
+
const { color } = testTheme.components.Divider.tokens
|
|
105
|
+
|
|
106
|
+
const { getByTestId } = render(
|
|
107
|
+
<StackView divider>
|
|
108
|
+
<Typography>A</Typography>
|
|
109
|
+
<Typography>B</Typography>
|
|
110
|
+
<Typography>C</Typography>
|
|
111
|
+
</StackView>,
|
|
112
|
+
{ wrapper: Theme }
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
expect(getByTestId('Stack-Divider-1')).toHaveStyle({ borderBottomColor: color })
|
|
116
|
+
expect(getByTestId('Stack-Divider-2')).toHaveStyle({ borderBottomColor: color })
|
|
117
|
+
|
|
118
|
+
expect(getByTestId('Stack-Divider-1')).not.toHaveStyle({ borderRightColor: color })
|
|
119
|
+
expect(getByTestId('Stack-Divider-2')).not.toHaveStyle({ borderRightColor: color })
|
|
120
|
+
|
|
121
|
+
expect(getByTestId('Stack-Divider-1-Spacer-before')).toHaveStyle(expectedStyle)
|
|
122
|
+
expect(getByTestId('Stack-Divider-1-Spacer-after')).toHaveStyle(expectedStyle)
|
|
123
|
+
expect(getByTestId('Stack-Divider-2-Spacer-before')).toHaveStyle(expectedStyle)
|
|
124
|
+
expect(getByTestId('Stack-Divider-2-Spacer-after')).toHaveStyle(expectedStyle)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('renders horizontal dividers if direction is "column-reverse"', () => {
|
|
128
|
+
const expectedSize = 4 // from __fixtures__/testTheme.js
|
|
129
|
+
const expectedStyle = { height: expectedSize }
|
|
130
|
+
const { color } = testTheme.components.Divider.tokens
|
|
131
|
+
|
|
132
|
+
const { getByTestId } = render(
|
|
133
|
+
<StackView direction="column-reverse" divider>
|
|
134
|
+
<Typography>A</Typography>
|
|
135
|
+
<Typography>B</Typography>
|
|
136
|
+
<Typography>C</Typography>
|
|
137
|
+
</StackView>,
|
|
138
|
+
{ wrapper: Theme }
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
expect(getByTestId('Stack-Divider-1')).toHaveStyle({ borderBottomColor: color })
|
|
142
|
+
expect(getByTestId('Stack-Divider-2')).toHaveStyle({ borderBottomColor: color })
|
|
143
|
+
|
|
144
|
+
expect(getByTestId('Stack-Divider-1')).not.toHaveStyle({ borderRightColor: color })
|
|
145
|
+
expect(getByTestId('Stack-Divider-2')).not.toHaveStyle({ borderRightColor: color })
|
|
146
|
+
|
|
147
|
+
expect(getByTestId('Stack-Divider-1-Spacer-before')).toHaveStyle(expectedStyle)
|
|
148
|
+
expect(getByTestId('Stack-Divider-1-Spacer-after')).toHaveStyle(expectedStyle)
|
|
149
|
+
expect(getByTestId('Stack-Divider-2-Spacer-before')).toHaveStyle(expectedStyle)
|
|
150
|
+
expect(getByTestId('Stack-Divider-2-Spacer-after')).toHaveStyle(expectedStyle)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('renders vertical dividers if direction is "row"', () => {
|
|
154
|
+
const { color } = testTheme.components.Divider.tokens
|
|
155
|
+
const expectedSize = 4 // from __fixtures__/testTheme.js
|
|
156
|
+
const expectedStyle = { width: expectedSize }
|
|
157
|
+
|
|
158
|
+
const { getByTestId } = render(
|
|
159
|
+
<StackView divider direction="row">
|
|
160
|
+
<Typography>A</Typography>
|
|
161
|
+
<Typography>B</Typography>
|
|
162
|
+
<Typography>C</Typography>
|
|
163
|
+
</StackView>,
|
|
164
|
+
{ wrapper: Theme }
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
expect(getByTestId('Stack-Divider-1')).not.toHaveStyle({ borderBottomColor: color })
|
|
168
|
+
expect(getByTestId('Stack-Divider-2')).not.toHaveStyle({ borderBottomColor: color })
|
|
169
|
+
|
|
170
|
+
expect(getByTestId('Stack-Divider-1')).toHaveStyle({ borderRightColor: color })
|
|
171
|
+
expect(getByTestId('Stack-Divider-2')).toHaveStyle({ borderRightColor: color })
|
|
172
|
+
|
|
173
|
+
expect(getByTestId('Stack-Divider-1-Spacer-before')).toHaveStyle(expectedStyle)
|
|
174
|
+
expect(getByTestId('Stack-Divider-1-Spacer-after')).toHaveStyle(expectedStyle)
|
|
175
|
+
expect(getByTestId('Stack-Divider-2-Spacer-before')).toHaveStyle(expectedStyle)
|
|
176
|
+
expect(getByTestId('Stack-Divider-2-Spacer-after')).toHaveStyle(expectedStyle)
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it('renders vertical dividers if direction is "row-reverse"', () => {
|
|
180
|
+
const { color } = testTheme.components.Divider.tokens
|
|
181
|
+
const expectedSize = 4 // from __fixtures__/testTheme.js
|
|
182
|
+
const expectedStyle = { width: expectedSize }
|
|
183
|
+
|
|
184
|
+
const { getByTestId } = render(
|
|
185
|
+
<StackView divider direction="row-reverse">
|
|
186
|
+
<Typography>A</Typography>
|
|
187
|
+
<Typography>B</Typography>
|
|
188
|
+
<Typography>C</Typography>
|
|
189
|
+
</StackView>,
|
|
190
|
+
{ wrapper: Theme }
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
expect(getByTestId('Stack-Divider-1')).not.toHaveStyle({ borderBottomColor: color })
|
|
194
|
+
expect(getByTestId('Stack-Divider-2')).not.toHaveStyle({ borderBottomColor: color })
|
|
195
|
+
|
|
196
|
+
expect(getByTestId('Stack-Divider-1')).toHaveStyle({ borderRightColor: color })
|
|
197
|
+
expect(getByTestId('Stack-Divider-2')).toHaveStyle({ borderRightColor: color })
|
|
198
|
+
|
|
199
|
+
expect(getByTestId('Stack-Divider-1-Spacer-before')).toHaveStyle(expectedStyle)
|
|
200
|
+
expect(getByTestId('Stack-Divider-1-Spacer-after')).toHaveStyle(expectedStyle)
|
|
201
|
+
expect(getByTestId('Stack-Divider-2-Spacer-before')).toHaveStyle(expectedStyle)
|
|
202
|
+
expect(getByTestId('Stack-Divider-2-Spacer-after')).toHaveStyle(expectedStyle)
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
it('renders row spacers if direction is "row"', () => {
|
|
206
|
+
const expectedSize = 8 // from __fixtures__/testTheme.js
|
|
207
|
+
|
|
208
|
+
const { getByTestId } = render(
|
|
209
|
+
<StackView direction="row" space={2}>
|
|
210
|
+
<Typography>A</Typography>
|
|
211
|
+
<Typography>B</Typography>
|
|
212
|
+
<Typography>C</Typography>
|
|
213
|
+
</StackView>,
|
|
214
|
+
{ wrapper: Theme }
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
expect(getByTestId('Stack-Spacer-1')).not.toHaveStyle({ height: expectedSize })
|
|
218
|
+
expect(getByTestId('Stack-Spacer-2')).not.toHaveStyle({ height: expectedSize })
|
|
219
|
+
|
|
220
|
+
expect(getByTestId('Stack-Spacer-1')).toHaveStyle({ width: expectedSize })
|
|
221
|
+
expect(getByTestId('Stack-Spacer-2')).toHaveStyle({ width: expectedSize })
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
it('renders row spacers if direction is "row-reverse"', () => {
|
|
225
|
+
const expectedSize = 8 // from __fixtures__/testTheme.js
|
|
226
|
+
|
|
227
|
+
const { getByTestId } = render(
|
|
228
|
+
<StackView direction="row-reverse" space={2}>
|
|
229
|
+
<Typography>A</Typography>
|
|
230
|
+
<Typography>B</Typography>
|
|
231
|
+
<Typography>C</Typography>
|
|
232
|
+
</StackView>,
|
|
233
|
+
{ wrapper: Theme }
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
expect(getByTestId('Stack-Spacer-1')).not.toHaveStyle({ height: expectedSize })
|
|
237
|
+
expect(getByTestId('Stack-Spacer-2')).not.toHaveStyle({ height: expectedSize })
|
|
238
|
+
|
|
239
|
+
expect(getByTestId('Stack-Spacer-1')).toHaveStyle({ width: expectedSize })
|
|
240
|
+
expect(getByTestId('Stack-Spacer-2')).toHaveStyle({ width: expectedSize })
|
|
241
|
+
})
|
|
242
|
+
})
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { render } from '@testing-library/react-native'
|
|
3
|
+
|
|
4
|
+
import { StackWrap, Typography } from '../../src'
|
|
5
|
+
import Theme from '../../__fixtures__/Theme'
|
|
6
|
+
|
|
7
|
+
describe('StackWrap', () => {
|
|
8
|
+
it('renders no spacers (because they would wrap badly)', () => {
|
|
9
|
+
const { queryAllByTestId } = render(
|
|
10
|
+
<StackWrap space={2}>
|
|
11
|
+
<Typography>A</Typography>
|
|
12
|
+
<Typography>B</Typography>
|
|
13
|
+
<Typography>C</Typography>
|
|
14
|
+
</StackWrap>,
|
|
15
|
+
{ wrapper: Theme }
|
|
16
|
+
)
|
|
17
|
+
expect(queryAllByTestId(/Spacer/)).toHaveLength(0)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('puts a `gap` between lines which may be different to `space` between items', () => {
|
|
21
|
+
// This test unavoidably hangs on some implementation details,
|
|
22
|
+
// which isn't ideal, but it does test something a user would see.
|
|
23
|
+
const expectedStyle = { paddingBottom: 8, paddingRight: 4 }
|
|
24
|
+
|
|
25
|
+
const { getByTestId } = render(
|
|
26
|
+
<StackWrap space={1} gap={2}>
|
|
27
|
+
<Typography>A</Typography>
|
|
28
|
+
<Typography>B</Typography>
|
|
29
|
+
</StackWrap>,
|
|
30
|
+
{ wrapper: Theme }
|
|
31
|
+
)
|
|
32
|
+
expect(getByTestId('Stack-Box-1')).toHaveStyle(expectedStyle)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('accepts accessibility props on the container responsible for wrapping content', () => {
|
|
36
|
+
const expectedStyle = { flexWrap: 'wrap' }
|
|
37
|
+
|
|
38
|
+
const { getByRole } = render(
|
|
39
|
+
<StackWrap accessibilityRole="radiogroup">
|
|
40
|
+
<Typography>A</Typography>
|
|
41
|
+
<Typography>B</Typography>
|
|
42
|
+
</StackWrap>,
|
|
43
|
+
{ wrapper: Theme }
|
|
44
|
+
)
|
|
45
|
+
expect(getByRole('radiogroup')).toHaveStyle(expectedStyle)
|
|
46
|
+
})
|
|
47
|
+
})
|