@lumx/react 3.3.1-alpha.0 → 3.3.1
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/_internal/ClickAwayProvider.js.map +1 -1
- package/_internal/types.d.ts +0 -2
- package/index.d.ts +2 -0
- package/index.js +347 -75
- package/index.js.map +1 -1
- package/package.json +23 -19
- package/src/components/autocomplete/Autocomplete.test.tsx +55 -142
- package/src/components/autocomplete/AutocompleteMultiple.test.tsx +37 -75
- package/src/components/autocomplete/__mockData__/index.ts +6 -1
- package/src/components/badge/Badge.test.tsx +20 -64
- package/src/components/button/Button.test.tsx +44 -121
- package/src/components/button/ButtonGroup.test.tsx +16 -39
- package/src/components/button/IconButton.stories.tsx +7 -0
- package/src/components/button/IconButton.test.tsx +37 -78
- package/src/components/button/IconButton.tsx +8 -1
- package/src/components/checkbox/Checkbox.test.tsx +62 -67
- package/src/components/chip/Chip.test.tsx +89 -139
- package/src/components/chip/ChipGroup.test.tsx +27 -10
- package/src/components/date-picker/DatePicker.test.tsx +15 -23
- package/src/components/date-picker/DatePickerControlled.test.tsx +24 -20
- package/src/components/date-picker/DatePickerField.test.tsx +43 -27
- package/src/components/dialog/Dialog.test.tsx +36 -35
- package/src/components/divider/Divider.test.tsx +23 -69
- package/src/components/dropdown/Dropdown.test.tsx +30 -61
- package/src/components/expansion-panel/ExpansionPanel.test.tsx +12 -8
- package/src/components/flag/Flag.test.tsx +28 -53
- package/src/components/generic-block/GenericBlock.test.tsx +93 -89
- package/src/components/grid-column/GridColumn.stories.tsx +3 -3
- package/src/components/icon/Icon.test.tsx +80 -64
- package/src/components/index.ts +0 -2
- package/src/components/inline-list/InlineList.test.tsx +30 -17
- package/src/components/input-helper/InputHelper.test.tsx +21 -81
- package/src/components/input-label/InputLabel.test.tsx +19 -61
- package/src/components/lightbox/Lightbox.test.tsx +3 -2
- package/src/components/link/Link.test.tsx +47 -31
- package/src/components/link-preview/LinkPreview.test.tsx +51 -51
- package/src/components/message/Message.test.tsx +31 -52
- package/src/components/mosaic/Mosaic.test.tsx +56 -72
- package/src/components/notification/Notification.test.tsx +51 -82
- package/src/components/popover/Popover.tsx +7 -9
- package/src/components/progress-tracker/ProgressTracker.test.tsx +20 -33
- package/src/components/progress-tracker/ProgressTrackerProvider.test.tsx +61 -36
- package/src/components/progress-tracker/ProgressTrackerStep.test.tsx +19 -109
- package/src/components/progress-tracker/ProgressTrackerStepPanel.test.tsx +21 -58
- package/src/components/progress-tracker/ProgressTrackerStepPanel.tsx +1 -1
- package/src/components/radio-button/RadioButton.test.tsx +78 -92
- package/src/components/radio-button/RadioGroup.test.tsx +13 -59
- package/src/components/select/Select.test.tsx +115 -284
- package/src/components/select/SelectMultiple.stories.tsx +105 -2
- package/src/components/select/SelectMultiple.test.tsx +126 -322
- package/src/components/select/WithSelectContext.tsx +10 -4
- package/src/components/side-navigation/SideNavigation.test.tsx +22 -35
- package/src/components/side-navigation/SideNavigationItem.test.tsx +72 -139
- package/src/components/switch/Switch.test.tsx +70 -149
- package/src/components/table/Table.test.tsx +2 -0
- package/src/components/table/TableBody.test.tsx +18 -8
- package/src/components/table/TableCell.test.tsx +34 -9
- package/src/components/table/TableHeader.test.tsx +18 -8
- package/src/components/table/TableRow.test.tsx +28 -8
- package/src/components/tabs/Tab.test.tsx +27 -96
- package/src/components/tabs/TabList.test.tsx +21 -56
- package/src/components/tabs/TabPanel.test.tsx +20 -55
- package/src/components/tabs/TabPanel.tsx +1 -1
- package/src/components/tabs/TabProvider.test.tsx +158 -37
- package/src/components/tabs/test-utils.ts +39 -0
- package/src/components/text-field/TextField.stories.tsx +14 -5
- package/src/components/text-field/TextField.test.tsx +54 -8
- package/src/components/text-field/TextField.tsx +49 -5
- package/src/components/tooltip/Tooltip.test.tsx +134 -75
- package/src/components/tooltip/useInjectTooltipRef.tsx +9 -2
- package/src/components/uploader/Uploader.test.tsx +60 -48
- package/src/components/user-block/UserBlock.test.tsx +69 -13
- package/src/hooks/useFocusTrap.ts +2 -2
- package/src/testing/utils/commonTestsSuiteRTL.ts +18 -8
- package/src/testing/utils/index.ts +0 -1
- package/src/utils/flattenChildren.ts +5 -0
- package/src/components/autocomplete/__snapshots__/Autocomplete.test.tsx.snap +0 -213
- package/src/components/autocomplete/__snapshots__/AutocompleteMultiple.test.tsx.snap +0 -88
- package/src/components/badge/__snapshots__/Badge.test.tsx.snap +0 -11
- package/src/components/button/ButtonRoot.test.tsx +0 -203
- package/src/components/button/__snapshots__/Button.test.tsx.snap +0 -96
- package/src/components/button/__snapshots__/ButtonGroup.test.tsx.snap +0 -22
- package/src/components/button/__snapshots__/ButtonRoot.test.tsx.snap +0 -160
- package/src/components/button/__snapshots__/IconButton.test.tsx.snap +0 -83
- package/src/components/checkbox/__snapshots__/Checkbox.test.tsx.snap +0 -141
- package/src/components/chip/__snapshots__/Chip.test.tsx.snap +0 -12
- package/src/components/chip/__snapshots__/ChipGroup.test.tsx.snap +0 -29
- package/src/components/date-picker/__snapshots__/DatePicker.test.tsx.snap +0 -22
- package/src/components/date-picker/__snapshots__/DatePickerControlled.test.tsx.snap +0 -597
- package/src/components/date-picker/__snapshots__/DatePickerField.test.tsx.snap +0 -43
- package/src/components/divider/__snapshots__/Divider.test.tsx.snap +0 -9
- package/src/components/dropdown/__snapshots__/Dropdown.test.tsx.snap +0 -35
- package/src/components/icon/__snapshots__/Icon.test.tsx.snap +0 -49
- package/src/components/input-helper/__snapshots__/InputHelper.test.tsx.snap +0 -9
- package/src/components/input-label/__snapshots__/InputLabel.test.tsx.snap +0 -10
- package/src/components/link/__snapshots__/Link.test.tsx.snap +0 -29
- package/src/components/message/__snapshots__/Message.test.tsx.snap +0 -15
- package/src/components/notification/__snapshots__/Notification.test.tsx.snap +0 -34
- package/src/components/progress-tracker/__snapshots__/ProgressTracker.test.tsx.snap +0 -41
- package/src/components/progress-tracker/__snapshots__/ProgressTrackerStep.test.tsx.snap +0 -141
- package/src/components/progress-tracker/__snapshots__/ProgressTrackerStepPanel.test.tsx.snap +0 -25
- package/src/components/radio-button/__snapshots__/RadioButton.test.tsx.snap +0 -113
- package/src/components/radio-button/__snapshots__/RadioGroup.test.tsx.snap +0 -26
- package/src/components/select/__snapshots__/Select.test.tsx.snap +0 -43
- package/src/components/select/__snapshots__/SelectMultiple.test.tsx.snap +0 -87
- package/src/components/side-navigation/__snapshots__/SideNavigation.test.tsx.snap +0 -7
- package/src/components/side-navigation/__snapshots__/SideNavigationItem.test.tsx.snap +0 -30
- package/src/components/switch/__snapshots__/Switch.test.tsx.snap +0 -179
- package/src/components/tabs/__snapshots__/Tab.test.tsx.snap +0 -62
- package/src/components/tabs/__snapshots__/TabList.test.tsx.snap +0 -22
- package/src/components/tabs/__snapshots__/TabPanel.test.tsx.snap +0 -25
- package/src/components/tabs/test.mocks.ts +0 -33
- package/src/components/text-field/__snapshots__/TextField.test.tsx.snap +0 -42
- package/src/components/tooltip/__snapshots__/Tooltip.test.tsx.snap +0 -233
- package/src/components/uploader/__snapshots__/Uploader.test.tsx.snap +0 -14
- package/src/testing/utils/commonTestsSuite.ts +0 -71
- package/src/utils/flattenChildren.test.tsx +0 -58
|
@@ -1,175 +1,108 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import '
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
import { commonTestsSuite, Wrapper } from '@lumx/react/testing/utils';
|
|
8
|
-
import { getBasicClass } from '@lumx/react/utils/className';
|
|
9
|
-
|
|
10
|
-
import { mdiAccount } from '@lumx/icons';
|
|
3
|
+
import { getAllByClassName, queryAllByClassName } from '@lumx/react/testing/utils/queries';
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
11
6
|
|
|
12
7
|
import { SideNavigationItem, SideNavigationItemProps } from './SideNavigationItem';
|
|
13
8
|
|
|
14
|
-
const DEFAULT_PROPS = SideNavigationItem.defaultProps as any;
|
|
15
9
|
const CLASSNAME = SideNavigationItem.className as string;
|
|
16
10
|
|
|
17
|
-
|
|
11
|
+
const toggleButtonProps = { label: 'Toggle' };
|
|
18
12
|
|
|
19
13
|
/**
|
|
20
14
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
21
15
|
*/
|
|
22
|
-
const setup = (
|
|
23
|
-
const props:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
const renderer: (el: ReactElement) => Wrapper = shallowRendering ? shallow : mount;
|
|
28
|
-
const wrapper: Wrapper = renderer(<SideNavigationItem {...props} />);
|
|
29
|
-
|
|
16
|
+
const setup = (propsOverride: Partial<SideNavigationItemProps> = {}) => {
|
|
17
|
+
const props = { label: 'Label', toggleButtonProps, ...propsOverride };
|
|
18
|
+
render(<SideNavigationItem {...props} />);
|
|
19
|
+
const sideNavigation = getAllByClassName(document.body, CLASSNAME)[0];
|
|
30
20
|
return {
|
|
31
|
-
chevron:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
chevron: queryAllByClassName(sideNavigation, `${CLASSNAME}__chevron`)[0] || null,
|
|
22
|
+
toggle: queryAllByClassName(sideNavigation, `${CLASSNAME}__toggle`)[0] || null,
|
|
23
|
+
children: queryAllByClassName(sideNavigation, `${CLASSNAME}__children`)[0] || null,
|
|
24
|
+
icon: queryAllByClassName(sideNavigation, `${CLASSNAME}__icon`)[0],
|
|
25
|
+
label: queryAllByClassName(sideNavigation, `${CLASSNAME}__link span`)[0],
|
|
26
|
+
link: queryAllByClassName(sideNavigation, `${CLASSNAME}__link`)[0],
|
|
36
27
|
props,
|
|
37
|
-
|
|
38
|
-
wrapper,
|
|
28
|
+
sideNavigation,
|
|
39
29
|
};
|
|
40
30
|
};
|
|
41
31
|
|
|
42
32
|
describe(`<${SideNavigationItem.displayName}>`, () => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const { root, wrapper } = setup();
|
|
49
|
-
expect(wrapper).toMatchSnapshot();
|
|
33
|
+
it('should render default', () => {
|
|
34
|
+
const label = 'Side navigation item';
|
|
35
|
+
const { sideNavigation, link } = setup({ label });
|
|
36
|
+
expect(sideNavigation).toBeInTheDocument();
|
|
37
|
+
expect(sideNavigation).toBe(screen.queryByRole('listitem'));
|
|
50
38
|
|
|
51
|
-
|
|
52
|
-
expect(root).toHaveClassName(CLASSNAME);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should render correctly with split actions', () => {
|
|
56
|
-
const { root, wrapper } = setup({ linkProps: { href: 'http://toto.com' }, onClick: () => null });
|
|
57
|
-
expect(wrapper).toMatchSnapshot();
|
|
58
|
-
|
|
59
|
-
expect(root).toExist();
|
|
60
|
-
expect(root).toHaveClassName(CLASSNAME);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should unmount children by default when closed', () => {
|
|
64
|
-
const { children } = setup({
|
|
65
|
-
children: <SideNavigationItem label="Child 1" toggleButtonProps={{ label: 'Toggle' }} />,
|
|
66
|
-
});
|
|
67
|
-
expect(children).not.toExist();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should keep children in DOM when closed and with closeMode="hide"', () => {
|
|
71
|
-
const { children } = setup({
|
|
72
|
-
closeMode: 'hide',
|
|
73
|
-
children: <SideNavigationItem key="1" label="Child 1" toggleButtonProps={{ label: 'Toggle' }} />,
|
|
74
|
-
});
|
|
75
|
-
expect(children).toExist();
|
|
76
|
-
});
|
|
39
|
+
expect(link).toBeInTheDocument();
|
|
77
40
|
});
|
|
78
41
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const { root } = setup();
|
|
85
|
-
|
|
86
|
-
const propNames = without(Object.keys(DEFAULT_PROPS), 'closeMode');
|
|
87
|
-
for (const prop of propNames) {
|
|
88
|
-
const className = getBasicClass({ prefix: CLASSNAME, type: prop, value: DEFAULT_PROPS[prop] });
|
|
89
|
-
if (className) {
|
|
90
|
-
expect(root).toHaveClassName(className);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
});
|
|
42
|
+
it('should render a link', () => {
|
|
43
|
+
const label = 'Side navigation item';
|
|
44
|
+
const { props, link } = setup({ linkProps: { href: 'https://example.com' }, label });
|
|
45
|
+
expect(link).toBe(screen.queryByRole('link', { name: label }));
|
|
46
|
+
expect(link).toHaveAttribute('href', props.linkProps?.href);
|
|
94
47
|
});
|
|
95
48
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
expect(onClick).toHaveBeenCalled();
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
// 4. Test conditions (i.e. things that display or not in the UI based on props).
|
|
110
|
-
describe('Conditions', () => {
|
|
111
|
-
// Here is an example of children types check.
|
|
112
|
-
|
|
113
|
-
const items = [
|
|
114
|
-
<SideNavigationItem key="a" label="a" toggleButtonProps={{ label: 'Toggle' }} />,
|
|
115
|
-
<SideNavigationItem key="b" label="b" toggleButtonProps={{ label: 'Toggle' }} />,
|
|
116
|
-
];
|
|
117
|
-
|
|
118
|
-
it('should hide chevron when no children are passed', () => {
|
|
119
|
-
const { chevron } = setup({
|
|
120
|
-
children: [],
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
expect(chevron).not.toExist();
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('should show chevron when children are passed', () => {
|
|
127
|
-
const { chevron } = setup({
|
|
128
|
-
children: items,
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
expect(chevron).toExist();
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('should hide children when children are passed and isOpen is false', () => {
|
|
135
|
-
const { children } = setup({
|
|
136
|
-
children: items,
|
|
137
|
-
isOpen: false,
|
|
49
|
+
describe('children', () => {
|
|
50
|
+
it('should render with children closed', () => {
|
|
51
|
+
const label = 'Side navigation item';
|
|
52
|
+
const { chevron, link, children } = setup({
|
|
53
|
+
label,
|
|
54
|
+
children: [
|
|
55
|
+
<SideNavigationItem key="1" label="Child 1" toggleButtonProps={toggleButtonProps} />,
|
|
56
|
+
<SideNavigationItem key="3" label="Child 2" toggleButtonProps={toggleButtonProps} />,
|
|
57
|
+
],
|
|
138
58
|
});
|
|
139
|
-
|
|
140
|
-
expect(
|
|
59
|
+
expect(link).toHaveTextContent(label);
|
|
60
|
+
expect(chevron).toBeInTheDocument();
|
|
61
|
+
expect(children).not.toBeInTheDocument();
|
|
141
62
|
});
|
|
142
63
|
|
|
143
|
-
it('should
|
|
144
|
-
const
|
|
145
|
-
|
|
64
|
+
it('should render with children opened', () => {
|
|
65
|
+
const label = 'Side navigation item';
|
|
66
|
+
const { chevron, link, children } = setup({
|
|
67
|
+
label,
|
|
146
68
|
isOpen: true,
|
|
69
|
+
children: [
|
|
70
|
+
<SideNavigationItem key="1" label="Child 1" toggleButtonProps={toggleButtonProps} />,
|
|
71
|
+
<SideNavigationItem key="3" label="Child 2" toggleButtonProps={toggleButtonProps} />,
|
|
72
|
+
],
|
|
147
73
|
});
|
|
148
|
-
|
|
149
|
-
expect(
|
|
74
|
+
expect(link).toHaveTextContent(label);
|
|
75
|
+
expect(chevron).toBeInTheDocument();
|
|
76
|
+
expect(children).toBeInTheDocument();
|
|
150
77
|
});
|
|
78
|
+
});
|
|
151
79
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
80
|
+
describe('children and link', () => {
|
|
81
|
+
it('should render with children and link', () => {
|
|
82
|
+
const label = 'Side navigation item';
|
|
83
|
+
const { props, toggle, link } = setup({
|
|
84
|
+
label,
|
|
85
|
+
linkProps: { href: 'https://example.com' },
|
|
86
|
+
children: [
|
|
87
|
+
<SideNavigationItem key="1" label="Child 1" toggleButtonProps={toggleButtonProps} />,
|
|
88
|
+
<SideNavigationItem key="3" label="Child 2" toggleButtonProps={toggleButtonProps} />,
|
|
89
|
+
],
|
|
155
90
|
});
|
|
156
91
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
it('should add props to link when provided', () => {
|
|
161
|
-
const { link } = setup({
|
|
162
|
-
linkProps: {
|
|
163
|
-
href: '/',
|
|
164
|
-
},
|
|
165
|
-
});
|
|
92
|
+
// Link
|
|
93
|
+
expect(link).toBe(screen.queryByRole('link', { name: label }));
|
|
94
|
+
expect(link).toHaveAttribute('href', props.linkProps?.href);
|
|
166
95
|
|
|
167
|
-
|
|
96
|
+
// Toggle button
|
|
97
|
+
expect(toggle).toBe(screen.queryByRole('button', { name: toggleButtonProps.label }));
|
|
168
98
|
});
|
|
169
99
|
});
|
|
170
100
|
|
|
171
|
-
// 5. Test state => no state
|
|
172
|
-
|
|
173
101
|
// Common tests suite.
|
|
174
|
-
|
|
102
|
+
commonTestsSuiteRTL(setup, {
|
|
103
|
+
baseClassName: CLASSNAME,
|
|
104
|
+
forwardClassName: 'sideNavigation',
|
|
105
|
+
forwardAttributes: 'sideNavigation',
|
|
106
|
+
forwardRef: 'sideNavigation',
|
|
107
|
+
});
|
|
175
108
|
});
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import '
|
|
5
|
-
import {
|
|
3
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
4
|
+
import { render } from '@testing-library/react';
|
|
5
|
+
import { getByClassName, getByTagName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
6
|
+
import userEvent from '@testing-library/user-event/';
|
|
6
7
|
|
|
7
|
-
import without from 'lodash/without';
|
|
8
|
-
|
|
9
|
-
import { Wrapper, commonTestsSuite } from '@lumx/react/testing/utils';
|
|
10
|
-
import { getBasicClass } from '@lumx/react/utils/className';
|
|
11
|
-
|
|
12
|
-
import { Theme, Alignment } from '@lumx/react';
|
|
13
8
|
import { Switch, SwitchProps } from './Switch';
|
|
14
9
|
|
|
15
|
-
const DEFAULT_PROPS = Switch.defaultProps as any;
|
|
16
10
|
const CLASSNAME = Switch.className as string;
|
|
17
11
|
|
|
18
12
|
type SetupProps = Partial<SwitchProps>;
|
|
@@ -20,170 +14,97 @@ type SetupProps = Partial<SwitchProps>;
|
|
|
20
14
|
/**
|
|
21
15
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
22
16
|
*/
|
|
23
|
-
const setup = (
|
|
24
|
-
const props
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
root: wrapper.find('div').first(),
|
|
34
|
-
|
|
35
|
-
input: wrapper.find('input'),
|
|
36
|
-
inputWrapper: wrapper.find(`.${CLASSNAME}__input-wrapper`),
|
|
37
|
-
|
|
38
|
-
content: wrapper.find(`.${CLASSNAME}__content`),
|
|
39
|
-
helper: wrapper.find(`.${CLASSNAME}__helper`),
|
|
40
|
-
label: wrapper.find(`.${CLASSNAME}__label`),
|
|
41
|
-
|
|
42
|
-
props,
|
|
43
|
-
wrapper,
|
|
44
|
-
};
|
|
17
|
+
const setup = (propsOverride: SetupProps = {}) => {
|
|
18
|
+
const props = { ...propsOverride };
|
|
19
|
+
render(<Switch {...props} />);
|
|
20
|
+
const switchWrapper = getByClassName(document.body, CLASSNAME);
|
|
21
|
+
const input = getByTagName(switchWrapper, 'input');
|
|
22
|
+
const helper = queryByClassName(switchWrapper, `${CLASSNAME}__helper`);
|
|
23
|
+
const label = queryByClassName(switchWrapper, `${CLASSNAME}__label`);
|
|
24
|
+
return { switchWrapper, input, helper, label, props };
|
|
45
25
|
};
|
|
46
26
|
|
|
47
27
|
jest.mock('uid', () => ({ uid: () => 'uid' }));
|
|
48
28
|
|
|
49
29
|
describe(`<${Switch.displayName}>`, () => {
|
|
50
|
-
// 1. Test render via snapshot (default states of component).
|
|
51
|
-
describe('Snapshots and structure', () => {
|
|
52
|
-
it('should render correctly without any label', () => {
|
|
53
|
-
const { root, inputWrapper, input, content, wrapper } = setup();
|
|
54
|
-
expect(wrapper).toMatchSnapshot();
|
|
55
|
-
|
|
56
|
-
expect(root).toExist();
|
|
57
|
-
expect(root).toHaveClassName(CLASSNAME);
|
|
58
|
-
|
|
59
|
-
expect(inputWrapper).toExist();
|
|
60
|
-
expect(input).toExist();
|
|
61
|
-
|
|
62
|
-
expect(content).not.toExist();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should render correctly with only a `label`', () => {
|
|
66
|
-
const props: SetupProps = { children: 'Label' };
|
|
67
|
-
const { root, inputWrapper, input, content, helper, label, wrapper } = setup(props);
|
|
68
|
-
expect(wrapper).toMatchSnapshot();
|
|
69
|
-
|
|
70
|
-
expect(root).toExist();
|
|
71
|
-
expect(root).toHaveClassName(CLASSNAME);
|
|
72
|
-
|
|
73
|
-
expect(inputWrapper).toExist();
|
|
74
|
-
expect(input).toExist();
|
|
75
|
-
|
|
76
|
-
expect(content).toExist();
|
|
77
|
-
expect(label).toExist();
|
|
78
|
-
expect(helper).not.toExist();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should render correctly with a `label` and a `helper`', () => {
|
|
82
|
-
const props: SetupProps = { children: 'Label', helper: 'Helper' };
|
|
83
|
-
const { root, inputWrapper, input, content, helper, label, wrapper } = setup(props);
|
|
84
|
-
expect(wrapper).toMatchSnapshot();
|
|
85
|
-
|
|
86
|
-
expect(root).toExist();
|
|
87
|
-
expect(root).toHaveClassName(CLASSNAME);
|
|
88
|
-
|
|
89
|
-
expect(inputWrapper).toExist();
|
|
90
|
-
expect(input).toExist();
|
|
91
|
-
|
|
92
|
-
expect(content).toExist();
|
|
93
|
-
expect(label).toExist();
|
|
94
|
-
expect(helper).toExist();
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// 2. Test defaultProps value and important props custom values.
|
|
99
30
|
describe('Props', () => {
|
|
100
|
-
it('should
|
|
101
|
-
const {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
31
|
+
it('should render correctly', () => {
|
|
32
|
+
const { switchWrapper, input, label, helper } = setup();
|
|
33
|
+
expect(switchWrapper).toBeInTheDocument();
|
|
34
|
+
expect(switchWrapper).toHaveClass(CLASSNAME);
|
|
35
|
+
expect(switchWrapper).not.toHaveClass('lumx-switch--is-disabled');
|
|
36
|
+
expect(switchWrapper).toHaveClass('lumx-switch--is-unchecked');
|
|
37
|
+
|
|
38
|
+
expect(label).not.toBeInTheDocument();
|
|
39
|
+
expect(helper).not.toBeInTheDocument();
|
|
40
|
+
|
|
41
|
+
expect(input).toBeInTheDocument();
|
|
42
|
+
expect(input).toHaveAttribute('role', 'switch');
|
|
43
|
+
expect(input).not.toBeChecked();
|
|
44
|
+
expect(input).not.toBeDisabled();
|
|
114
45
|
});
|
|
115
46
|
|
|
116
|
-
it('should
|
|
117
|
-
const
|
|
47
|
+
it('should render disabled and checked', () => {
|
|
48
|
+
const { switchWrapper, input } = setup({
|
|
49
|
+
isDisabled: true,
|
|
118
50
|
isChecked: true,
|
|
119
|
-
position: oneOf(...without(Object.values(Alignment), DEFAULT_PROPS.position)),
|
|
120
|
-
theme: oneOf(...without(Object.values(Theme), DEFAULT_PROPS.theme)),
|
|
121
51
|
});
|
|
52
|
+
expect(switchWrapper).toHaveClass('lumx-switch--is-disabled');
|
|
53
|
+
expect(switchWrapper).toHaveClass('lumx-switch--is-checked');
|
|
122
54
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const { root } = setup({ ...modifiedProps });
|
|
126
|
-
|
|
127
|
-
Object.keys(modifiedProps).forEach((prop: string) => {
|
|
128
|
-
if (prop === 'checked') {
|
|
129
|
-
if (modifiedProps[prop]) {
|
|
130
|
-
expect(root).toHaveClassName(
|
|
131
|
-
getBasicClass({ prefix: CLASSNAME, type: prop, value: modifiedProps[prop] }),
|
|
132
|
-
);
|
|
133
|
-
} else {
|
|
134
|
-
expect(root).toHaveClassName(
|
|
135
|
-
getBasicClass({ prefix: CLASSNAME, type: 'unchecked', value: true }),
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
} else {
|
|
139
|
-
expect(root).toHaveClassName(
|
|
140
|
-
getBasicClass({ prefix: CLASSNAME, type: prop, value: modifiedProps[prop] }),
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
55
|
+
expect(input).toBeChecked();
|
|
56
|
+
expect(input).toBeDisabled();
|
|
144
57
|
});
|
|
145
58
|
|
|
146
|
-
it('should
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
59
|
+
it('should render helper and label', () => {
|
|
60
|
+
const id = 'switchWrapper1';
|
|
61
|
+
const { props, helper, label, input } = setup({
|
|
62
|
+
id,
|
|
63
|
+
helper: 'Test helper',
|
|
64
|
+
children: 'Test label',
|
|
151
65
|
});
|
|
152
66
|
|
|
153
|
-
expect(
|
|
154
|
-
|
|
155
|
-
|
|
67
|
+
expect(helper).toBeInTheDocument();
|
|
68
|
+
expect(helper).toHaveTextContent(props.helper as string);
|
|
69
|
+
expect(helper).toHaveAttribute('id');
|
|
156
70
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
71
|
+
expect(label).toBeInTheDocument();
|
|
72
|
+
expect(label).toHaveTextContent(props.children);
|
|
73
|
+
expect(label).toHaveAttribute('for', id);
|
|
160
74
|
|
|
161
|
-
|
|
162
|
-
|
|
75
|
+
expect(input).toHaveAttribute('id', id);
|
|
76
|
+
expect(input).toHaveAttribute('aria-describedby', helper?.id);
|
|
163
77
|
});
|
|
164
78
|
|
|
165
|
-
it('should
|
|
166
|
-
const { input } = setup({
|
|
79
|
+
it('should forward input props', () => {
|
|
80
|
+
const { props, input } = setup({
|
|
81
|
+
inputProps: { 'aria-labelledby': 'labelledby-id' },
|
|
82
|
+
});
|
|
167
83
|
|
|
168
|
-
input.
|
|
169
|
-
expect(onChange).toHaveBeenCalled();
|
|
84
|
+
expect(input).toHaveAttribute('aria-labelledby', props.inputProps?.['aria-labelledby']);
|
|
170
85
|
});
|
|
171
86
|
});
|
|
172
87
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
it('should not display the `helper` if no `label` is given', () => {
|
|
176
|
-
const props: SetupProps = { helper: 'Helper' };
|
|
177
|
-
const { content, wrapper } = setup(props);
|
|
178
|
-
expect(wrapper).toMatchSnapshot();
|
|
88
|
+
describe('Events', () => {
|
|
89
|
+
const onChange = jest.fn();
|
|
179
90
|
|
|
180
|
-
|
|
91
|
+
it('should trigger `onChange` when switchWrapper is clicked', async () => {
|
|
92
|
+
const value = 'value';
|
|
93
|
+
const name = 'name';
|
|
94
|
+
const { input } = setup({ checked: false, onChange, value, name });
|
|
95
|
+
expect(input).not.toBeChecked();
|
|
96
|
+
|
|
97
|
+
await userEvent.click(input);
|
|
98
|
+
|
|
99
|
+
expect(onChange).toHaveBeenCalledWith(true, value, name, expect.any(Object));
|
|
181
100
|
});
|
|
182
101
|
});
|
|
183
102
|
|
|
184
|
-
// 5. Test state.
|
|
185
|
-
// N/A
|
|
186
|
-
|
|
187
103
|
// Common tests suite.
|
|
188
|
-
|
|
104
|
+
commonTestsSuiteRTL(setup, {
|
|
105
|
+
baseClassName: CLASSNAME,
|
|
106
|
+
forwardClassName: 'switchWrapper',
|
|
107
|
+
forwardAttributes: 'switchWrapper',
|
|
108
|
+
forwardRef: 'switchWrapper',
|
|
109
|
+
});
|
|
189
110
|
});
|
|
@@ -3,6 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
4
4
|
import { queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
5
5
|
import { render } from '@testing-library/react';
|
|
6
|
+
|
|
6
7
|
import { Table, TableProps } from './Table';
|
|
7
8
|
|
|
8
9
|
const CLASSNAME = Table.className as string;
|
|
@@ -19,5 +20,6 @@ describe(`<${Table.displayName}>`, () => {
|
|
|
19
20
|
baseClassName: CLASSNAME,
|
|
20
21
|
forwardClassName: 'table',
|
|
21
22
|
forwardAttributes: 'table',
|
|
23
|
+
forwardRef: 'table',
|
|
22
24
|
});
|
|
23
25
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import '
|
|
4
|
-
import {
|
|
2
|
+
|
|
3
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
4
|
+
import { render } from '@testing-library/react';
|
|
5
|
+
import { queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
5
6
|
|
|
6
7
|
import { TableBody, TableBodyProps } from './TableBody';
|
|
7
8
|
|
|
@@ -10,13 +11,22 @@ const CLASSNAME = TableBody.className as string;
|
|
|
10
11
|
/**
|
|
11
12
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
12
13
|
*/
|
|
13
|
-
const setup = (props: Partial<TableBodyProps> = {}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const setup = (props: Partial<TableBodyProps> = {}) => {
|
|
15
|
+
render(
|
|
16
|
+
<table>
|
|
17
|
+
<TableBody {...(props as any)} />
|
|
18
|
+
</table>,
|
|
19
|
+
);
|
|
20
|
+
const tableBody = queryByClassName(document.body, CLASSNAME);
|
|
21
|
+
return { props, tableBody };
|
|
17
22
|
};
|
|
18
23
|
|
|
19
24
|
describe(`<${TableBody.displayName}>`, () => {
|
|
20
25
|
// Common tests suite.
|
|
21
|
-
|
|
26
|
+
commonTestsSuiteRTL(setup, {
|
|
27
|
+
baseClassName: CLASSNAME,
|
|
28
|
+
forwardClassName: 'tableBody',
|
|
29
|
+
forwardAttributes: 'tableBody',
|
|
30
|
+
forwardRef: 'tableBody',
|
|
31
|
+
});
|
|
22
32
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import '
|
|
4
|
-
import {
|
|
2
|
+
|
|
3
|
+
import { queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
5
6
|
|
|
6
7
|
import { TableCell, TableCellProps } from './TableCell';
|
|
7
8
|
|
|
@@ -10,14 +11,38 @@ const CLASSNAME = TableCell.className as string;
|
|
|
10
11
|
/**
|
|
11
12
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
12
13
|
*/
|
|
13
|
-
const setup = (props: Partial<TableCellProps> = {}
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const setup = (props: Partial<TableCellProps> = {}) => {
|
|
15
|
+
const Parent = props?.variant === 'head' ? 'thead' : 'tbody';
|
|
16
|
+
render(
|
|
17
|
+
<table>
|
|
18
|
+
<Parent>
|
|
19
|
+
<tr>
|
|
20
|
+
<TableCell {...(props as any)} />
|
|
21
|
+
</tr>
|
|
22
|
+
</Parent>
|
|
23
|
+
</table>,
|
|
24
|
+
);
|
|
25
|
+
const tableCell = queryByClassName(document.body, CLASSNAME);
|
|
26
|
+
return { props, tableCell };
|
|
18
27
|
};
|
|
19
28
|
|
|
20
29
|
describe(`<${TableCell.displayName}>`, () => {
|
|
30
|
+
it('should render default', () => {
|
|
31
|
+
const content = 'Content';
|
|
32
|
+
const { tableCell } = setup({ children: content });
|
|
33
|
+
expect(tableCell).toBe(screen.queryByRole('cell', { name: content }));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should render header variant', () => {
|
|
37
|
+
const content = 'Content';
|
|
38
|
+
const { tableCell } = setup({ children: content, variant: 'head' });
|
|
39
|
+
expect(tableCell).toBe(screen.queryByRole('columnheader', { name: content }));
|
|
40
|
+
});
|
|
41
|
+
|
|
21
42
|
// Common tests suite.
|
|
22
|
-
|
|
43
|
+
commonTestsSuiteRTL(setup, {
|
|
44
|
+
baseClassName: CLASSNAME,
|
|
45
|
+
forwardClassName: 'tableCell',
|
|
46
|
+
forwardAttributes: 'tableCell',
|
|
47
|
+
});
|
|
23
48
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import '
|
|
4
|
-
import {
|
|
2
|
+
|
|
3
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
4
|
+
import { render } from '@testing-library/react';
|
|
5
|
+
import { queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
5
6
|
|
|
6
7
|
import { TableHeader, TableHeaderProps } from './TableHeader';
|
|
7
8
|
|
|
@@ -10,13 +11,22 @@ const CLASSNAME = TableHeader.className as string;
|
|
|
10
11
|
/**
|
|
11
12
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
12
13
|
*/
|
|
13
|
-
const setup = (props:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const setup = (props: TableHeaderProps = {}) => {
|
|
15
|
+
render(
|
|
16
|
+
<table>
|
|
17
|
+
<TableHeader {...props} />
|
|
18
|
+
</table>,
|
|
19
|
+
);
|
|
20
|
+
const tableHeader = queryByClassName(document.body, CLASSNAME);
|
|
21
|
+
return { props, tableHeader };
|
|
17
22
|
};
|
|
18
23
|
|
|
19
24
|
describe(`<${TableHeader.displayName}>`, () => {
|
|
20
25
|
// Common tests suite.
|
|
21
|
-
|
|
26
|
+
commonTestsSuiteRTL(setup, {
|
|
27
|
+
baseClassName: CLASSNAME,
|
|
28
|
+
forwardClassName: 'tableHeader',
|
|
29
|
+
forwardAttributes: 'tableHeader',
|
|
30
|
+
forwardRef: 'tableHeader',
|
|
31
|
+
});
|
|
22
32
|
});
|