@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,128 +1,38 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getBasicClass } from '@lumx/react/utils/className';
|
|
1
|
+
import React from 'react';
|
|
3
2
|
|
|
4
|
-
import {
|
|
5
|
-
import '
|
|
6
|
-
import
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import { getByClassName } from '@lumx/react/testing/utils/queries';
|
|
5
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
7
6
|
|
|
8
|
-
import { setupTabProviderMocks } from '../tabs/test.mocks';
|
|
9
7
|
import { ProgressTrackerStep, ProgressTrackerStepProps } from './ProgressTrackerStep';
|
|
10
8
|
|
|
11
9
|
const CLASSNAME = ProgressTrackerStep.className as string;
|
|
12
10
|
|
|
13
|
-
// Mock useTabProviderContext.
|
|
14
|
-
jest.mock('../tabs/state', () => {
|
|
15
|
-
const state = jest.requireActual('../tabs/state');
|
|
16
|
-
return { ...state, useTabProviderContext: jest.fn(), useTabProviderContextState: jest.fn() };
|
|
17
|
-
});
|
|
18
|
-
|
|
19
11
|
type SetupProps = Partial<ProgressTrackerStepProps>;
|
|
20
12
|
|
|
21
13
|
/**
|
|
22
14
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
23
15
|
*/
|
|
24
|
-
const setup = (
|
|
25
|
-
const props
|
|
26
|
-
|
|
27
|
-
const
|
|
16
|
+
const setup = (propsOverride: SetupProps = {}) => {
|
|
17
|
+
const props = { label: 'Test Step Label', ...propsOverride };
|
|
18
|
+
render(<ProgressTrackerStep {...props} />);
|
|
19
|
+
const progressTrackerStep = getByClassName(document.body, CLASSNAME);
|
|
28
20
|
|
|
29
|
-
return { props,
|
|
21
|
+
return { props, progressTrackerStep };
|
|
30
22
|
};
|
|
31
23
|
|
|
32
24
|
describe(`<${ProgressTrackerStep.displayName}>`, () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const { wrapper } = setup({});
|
|
38
|
-
expect(wrapper).toMatchSnapshot();
|
|
39
|
-
expect(wrapper).toHaveClassName(CLASSNAME);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should render active state', () => {
|
|
43
|
-
setupTabProviderMocks({ index: 3, isActive: true });
|
|
44
|
-
const { wrapper } = setup({});
|
|
45
|
-
expect(wrapper).toMatchSnapshot();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should render complete state', () => {
|
|
49
|
-
setupTabProviderMocks({ index: 3, isComplete: true });
|
|
50
|
-
const { wrapper } = setup({});
|
|
51
|
-
expect(wrapper).toMatchSnapshot();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should render erroneous state', () => {
|
|
55
|
-
setupTabProviderMocks({ index: 3, hasError: true });
|
|
56
|
-
const { wrapper } = setup({});
|
|
57
|
-
expect(wrapper).toMatchSnapshot();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should render active erroneous state', () => {
|
|
61
|
-
setupTabProviderMocks({ index: 3, isActive: true, hasError: true });
|
|
62
|
-
const { wrapper } = setup({});
|
|
63
|
-
expect(wrapper).toMatchSnapshot();
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// 2. Test defaultProps value and important props custom values.
|
|
68
|
-
describe('Props', () => {
|
|
69
|
-
it('should use the given props to add classes', () => {
|
|
70
|
-
setupTabProviderMocks();
|
|
71
|
-
const props: any = {
|
|
72
|
-
isActive: true,
|
|
73
|
-
hasError: true,
|
|
74
|
-
isComplete: true,
|
|
75
|
-
};
|
|
76
|
-
const { wrapper } = setup(props);
|
|
77
|
-
|
|
78
|
-
Object.keys(props).forEach((prop) => {
|
|
79
|
-
expect(wrapper).toHaveClassName(getBasicClass({ prefix: CLASSNAME, type: prop, value: props[prop] }));
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// 3. Test events.
|
|
85
|
-
describe('Events', () => {
|
|
86
|
-
it('should trigger `onChange` when focused if the provider is configured to do so', () => {
|
|
87
|
-
const { changeToTab } = setupTabProviderMocks({ shouldActivateOnFocus: true });
|
|
88
|
-
const { wrapper } = setup({}, false);
|
|
89
|
-
|
|
90
|
-
wrapper.simulate('focus');
|
|
91
|
-
expect(changeToTab).toHaveBeenCalledTimes(1);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('should trigger `onChange` when clicked', () => {
|
|
95
|
-
const { changeToTab } = setupTabProviderMocks();
|
|
96
|
-
const { wrapper } = setup({}, false);
|
|
97
|
-
|
|
98
|
-
wrapper.simulate('click');
|
|
99
|
-
expect(changeToTab).toHaveBeenCalledTimes(1);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should trigger `onChange` when pressing `enter`', () => {
|
|
103
|
-
const { changeToTab } = setupTabProviderMocks();
|
|
104
|
-
const { wrapper } = setup({}, false);
|
|
105
|
-
|
|
106
|
-
wrapper.simulate('keypress', { key: 'Enter' });
|
|
107
|
-
expect(changeToTab).toHaveBeenCalledTimes(1);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('should not trigger `onChange` when pressing any other key', () => {
|
|
111
|
-
const { changeToTab } = setupTabProviderMocks();
|
|
112
|
-
const { wrapper } = setup({}, false);
|
|
113
|
-
|
|
114
|
-
wrapper.simulate('keypress', { key: 'a' });
|
|
115
|
-
expect(changeToTab).not.toHaveBeenCalled();
|
|
116
|
-
});
|
|
25
|
+
it('should render default', () => {
|
|
26
|
+
const label = 'Step';
|
|
27
|
+
const { progressTrackerStep } = setup({ label });
|
|
28
|
+
expect(progressTrackerStep).toBe(screen.queryByRole('tab', { name: label }));
|
|
117
29
|
});
|
|
118
30
|
|
|
119
31
|
// Common tests suite.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
{ className: CLASSNAME },
|
|
127
|
-
);
|
|
32
|
+
commonTestsSuiteRTL(setup, {
|
|
33
|
+
baseClassName: CLASSNAME,
|
|
34
|
+
forwardClassName: 'progressTrackerStep',
|
|
35
|
+
forwardAttributes: 'progressTrackerStep',
|
|
36
|
+
forwardRef: 'progressTrackerStep',
|
|
37
|
+
});
|
|
128
38
|
});
|
|
@@ -1,73 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { mount, shallow } from 'enzyme';
|
|
3
|
-
import 'jest-enzyme';
|
|
4
|
-
import React, { ReactElement } from 'react';
|
|
5
|
-
import { setupTabProviderMocks } from '../tabs/test.mocks';
|
|
6
|
-
import { ProgressTrackerStepPanel, ProgressTrackerStepPanelProps } from './ProgressTrackerStepPanel';
|
|
1
|
+
import React from 'react';
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import { getByClassName } from '@lumx/react/testing/utils/queries';
|
|
9
5
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const state = jest.requireActual('../tabs/state');
|
|
13
|
-
return { ...state, useTabProviderContext: jest.fn(), useTabProviderContextState: jest.fn() };
|
|
14
|
-
});
|
|
6
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
7
|
+
import { ProgressTrackerStepPanel, ProgressTrackerStepPanelProps } from './ProgressTrackerStepPanel';
|
|
15
8
|
|
|
16
|
-
|
|
9
|
+
const CLASSNAME = ProgressTrackerStepPanel.className as string;
|
|
17
10
|
|
|
18
11
|
/**
|
|
19
12
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
20
13
|
*/
|
|
21
|
-
const setup = (
|
|
22
|
-
const props
|
|
23
|
-
|
|
24
|
-
const
|
|
14
|
+
const setup = (propsOverride: Partial<ProgressTrackerStepPanelProps> = {}) => {
|
|
15
|
+
const props = { ...propsOverride, children: 'Tab panel content' };
|
|
16
|
+
render(<ProgressTrackerStepPanel {...props} />);
|
|
17
|
+
const progressTrackerStepPanel = getByClassName(document.body, CLASSNAME);
|
|
25
18
|
|
|
26
|
-
return { props,
|
|
19
|
+
return { props, progressTrackerStepPanel };
|
|
27
20
|
};
|
|
28
21
|
|
|
29
22
|
describe(`<${ProgressTrackerStepPanel.displayName}>`, () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const { wrapper } = setup();
|
|
35
|
-
expect(wrapper).toMatchSnapshot();
|
|
36
|
-
expect(wrapper).toHaveClassName(CLASSNAME);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should render isActive state', () => {
|
|
40
|
-
setupTabProviderMocks({ index: 2, isActive: true });
|
|
41
|
-
const { wrapper } = setup();
|
|
42
|
-
expect(wrapper).toMatchSnapshot();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should not render children when not active and lazy', () => {
|
|
46
|
-
setupTabProviderMocks({ isLazy: true, isActive: false });
|
|
47
|
-
const { wrapper } = setup();
|
|
48
|
-
expect(wrapper.find('div').props().children).toBeFalsy();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should render children when active and lazy', () => {
|
|
52
|
-
setupTabProviderMocks({ isLazy: true, isActive: true });
|
|
53
|
-
const { wrapper } = setup();
|
|
54
|
-
expect(wrapper.find('div').props().children).toBeTruthy();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should render children when not active and not lazy', () => {
|
|
58
|
-
setupTabProviderMocks({ isActive: false, isLazy: false });
|
|
59
|
-
const { wrapper } = setup();
|
|
60
|
-
expect(wrapper.find('div').props().children).toBeTruthy();
|
|
61
|
-
});
|
|
23
|
+
it('should render default', () => {
|
|
24
|
+
const content = 'Content';
|
|
25
|
+
const { progressTrackerStepPanel } = setup({ children: content });
|
|
26
|
+
expect(progressTrackerStepPanel).toBe(screen.queryByRole('tabpanel'));
|
|
62
27
|
});
|
|
63
28
|
|
|
64
29
|
// Common tests suite.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
{ className: CLASSNAME },
|
|
72
|
-
);
|
|
30
|
+
commonTestsSuiteRTL(setup, {
|
|
31
|
+
baseClassName: CLASSNAME,
|
|
32
|
+
forwardClassName: 'progressTrackerStepPanel',
|
|
33
|
+
forwardRef: 'progressTrackerStepPanel',
|
|
34
|
+
forwardAttributes: 'progressTrackerStepPanel',
|
|
35
|
+
});
|
|
73
36
|
});
|
|
@@ -54,7 +54,7 @@ export const ProgressTrackerStepPanel: Comp<ProgressTrackerStepPanelProps, HTMLD
|
|
|
54
54
|
id={state?.tabPanelId}
|
|
55
55
|
className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, isActive }))}
|
|
56
56
|
role="tabpanel"
|
|
57
|
-
tabIndex={0}
|
|
57
|
+
tabIndex={isActive ? 0 : -1}
|
|
58
58
|
aria-labelledby={state?.tabId}
|
|
59
59
|
>
|
|
60
60
|
{(!state?.isLazy || isActive) && children}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import '
|
|
3
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
4
|
+
import { getByClassName, getByTagName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
5
|
+
import { render } from '@testing-library/react';
|
|
6
|
+
import userEvent from '@testing-library/user-event';
|
|
5
7
|
|
|
6
|
-
import {
|
|
7
|
-
import { getBasicClass } from '@lumx/react/utils/className';
|
|
8
|
-
|
|
9
|
-
import { Theme } from '@lumx/react';
|
|
10
|
-
import { RadioButton, RadioButtonProps } from './RadioButton';
|
|
8
|
+
import { RadioButton, RadioButtonProps } from '.';
|
|
11
9
|
|
|
12
10
|
const CLASSNAME = RadioButton.className as string;
|
|
13
11
|
|
|
@@ -16,108 +14,96 @@ type SetupProps = Partial<RadioButtonProps>;
|
|
|
16
14
|
/**
|
|
17
15
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
18
16
|
*/
|
|
19
|
-
const setup = (propsOverride: SetupProps = {}
|
|
17
|
+
const setup = (propsOverride: SetupProps = {}) => {
|
|
20
18
|
const props: any = { id: 'fixedId', ...propsOverride };
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
props,
|
|
29
|
-
wrapper,
|
|
30
|
-
};
|
|
19
|
+
render(<RadioButton {...props} />);
|
|
20
|
+
|
|
21
|
+
const radioButton = getByClassName(document.body, CLASSNAME);
|
|
22
|
+
const helper = queryByClassName(radioButton, `${CLASSNAME}__helper`);
|
|
23
|
+
const label = queryByClassName(radioButton, `${CLASSNAME}__label`);
|
|
24
|
+
const input = getByTagName(radioButton, 'input');
|
|
25
|
+
return { radioButton, helper, label, input, props };
|
|
31
26
|
};
|
|
32
27
|
|
|
33
28
|
describe(`<${RadioButton.displayName}>`, () => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
expect(
|
|
39
|
-
|
|
40
|
-
expect(
|
|
41
|
-
|
|
42
|
-
expect(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
expect(
|
|
46
|
-
|
|
47
|
-
expect(
|
|
29
|
+
describe('Props', () => {
|
|
30
|
+
it('should render correctly', () => {
|
|
31
|
+
const { radioButton, input, label, helper } = setup();
|
|
32
|
+
expect(radioButton).toBeInTheDocument();
|
|
33
|
+
expect(radioButton).toHaveClass(CLASSNAME);
|
|
34
|
+
expect(radioButton).not.toHaveClass('lumx-radio-button--is-disabled');
|
|
35
|
+
expect(radioButton).toHaveClass('lumx-radio-button--is-unchecked');
|
|
36
|
+
|
|
37
|
+
expect(label).not.toBeInTheDocument();
|
|
38
|
+
expect(helper).not.toBeInTheDocument();
|
|
39
|
+
|
|
40
|
+
expect(input).toBeInTheDocument();
|
|
41
|
+
expect(input).not.toBeChecked();
|
|
42
|
+
expect(input).not.toBeDisabled();
|
|
48
43
|
});
|
|
49
44
|
|
|
50
|
-
it('should render
|
|
51
|
-
const
|
|
52
|
-
isChecked: true,
|
|
45
|
+
it('should render disabled and checked', () => {
|
|
46
|
+
const { radioButton, input } = setup({
|
|
53
47
|
isDisabled: true,
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
expect(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
expect(
|
|
61
|
-
expect(inputProps.disabled).toBe(true);
|
|
62
|
-
expect(inputProps.id).toEqual(props.id);
|
|
48
|
+
isChecked: true,
|
|
49
|
+
});
|
|
50
|
+
expect(radioButton).toHaveClass('lumx-radio-button--is-disabled');
|
|
51
|
+
expect(radioButton).toHaveClass('lumx-radio-button--is-checked');
|
|
52
|
+
|
|
53
|
+
expect(input).toBeChecked();
|
|
54
|
+
expect(input).toBeDisabled();
|
|
63
55
|
});
|
|
64
56
|
|
|
65
|
-
it('should render
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
expect(
|
|
74
|
-
|
|
75
|
-
expect(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
expect(label).
|
|
79
|
-
expect(label
|
|
80
|
-
|
|
81
|
-
expect(
|
|
82
|
-
|
|
83
|
-
expect(helper).toExist();
|
|
84
|
-
expect(helper.contains(props.helper)).toBe(true);
|
|
57
|
+
it('should render helper and label', () => {
|
|
58
|
+
const id = 'radioButton1';
|
|
59
|
+
const { props, helper, label, input } = setup({
|
|
60
|
+
id,
|
|
61
|
+
helper: 'Test helper',
|
|
62
|
+
label: 'Test label',
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
expect(helper).toBeInTheDocument();
|
|
66
|
+
expect(helper).toHaveTextContent(props.helper);
|
|
67
|
+
expect(helper).toHaveAttribute('id');
|
|
68
|
+
|
|
69
|
+
expect(label).toBeInTheDocument();
|
|
70
|
+
expect(label).toHaveTextContent(props.label);
|
|
71
|
+
expect(label).toHaveAttribute('for', id);
|
|
72
|
+
|
|
73
|
+
expect(input).toHaveAttribute('id', id);
|
|
74
|
+
expect(input).toHaveAttribute('aria-describedby', helper?.id);
|
|
85
75
|
});
|
|
86
|
-
});
|
|
87
76
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const { wrapper } = setup(props as RadioButtonProps);
|
|
97
|
-
|
|
98
|
-
expect(wrapper).toHaveClassName(CLASSNAME);
|
|
99
|
-
expect(wrapper).toHaveClassName(getBasicClass({ prefix: CLASSNAME, type: 'isDisabled', value: true }));
|
|
100
|
-
expect(wrapper).toHaveClassName(getBasicClass({ prefix: CLASSNAME, type: 'isChecked', value: true }));
|
|
101
|
-
expect(wrapper).not.toHaveClassName(getBasicClass({ prefix: CLASSNAME, type: 'isUnchecked', value: true }));
|
|
102
|
-
expect(wrapper).toHaveClassName(getBasicClass({ prefix: CLASSNAME, type: 'theme', value: props.theme }));
|
|
77
|
+
it('should forward input props', () => {
|
|
78
|
+
const { props, input } = setup({
|
|
79
|
+
inputProps: {
|
|
80
|
+
'aria-labelledby': 'labelledby-id',
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
expect(input).toHaveAttribute('aria-labelledby', props.inputProps['aria-labelledby']);
|
|
103
85
|
});
|
|
104
86
|
});
|
|
105
87
|
|
|
106
|
-
// 3. Test events.
|
|
107
88
|
describe('Events', () => {
|
|
108
|
-
|
|
109
|
-
});
|
|
89
|
+
const onChange = jest.fn();
|
|
110
90
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
91
|
+
it('should trigger `onChange` when radioButton 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);
|
|
115
98
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
// Nothing to do here.
|
|
99
|
+
expect(onChange).toHaveBeenCalledWith(value, name, expect.any(Object));
|
|
100
|
+
});
|
|
119
101
|
});
|
|
120
102
|
|
|
121
103
|
// Common tests suite.
|
|
122
|
-
|
|
104
|
+
commonTestsSuiteRTL(setup, {
|
|
105
|
+
baseClassName: CLASSNAME,
|
|
106
|
+
forwardClassName: 'radioButton',
|
|
107
|
+
forwardAttributes: 'radioButton',
|
|
108
|
+
});
|
|
123
109
|
});
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import 'jest-enzyme';
|
|
3
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
5
4
|
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import { RadioButton } from '@lumx/react';
|
|
5
|
+
import { render } from '@testing-library/react';
|
|
6
|
+
import { queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
9
7
|
import { RadioGroup, RadioGroupProps } from './RadioGroup';
|
|
10
8
|
|
|
11
9
|
const CLASSNAME = RadioGroup.className as string;
|
|
@@ -15,63 +13,19 @@ type SetupProps = Partial<RadioGroupProps>;
|
|
|
15
13
|
/**
|
|
16
14
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
17
15
|
*/
|
|
18
|
-
const setup = (propsOverride: SetupProps = {}
|
|
16
|
+
const setup = (propsOverride: SetupProps = {}) => {
|
|
19
17
|
const props: any = { ...propsOverride };
|
|
20
|
-
|
|
21
|
-
const wrapper = renderer(<RadioGroup {...props} />);
|
|
18
|
+
render(<RadioGroup {...props} />);
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
radioButtons: wrapper.find('RadioButton'),
|
|
26
|
-
wrapper,
|
|
27
|
-
};
|
|
20
|
+
const radioGroup = queryByClassName(document.body, CLASSNAME);
|
|
21
|
+
return { props, radioGroup };
|
|
28
22
|
};
|
|
29
23
|
|
|
30
24
|
describe(`<${RadioGroup.displayName}>`, () => {
|
|
31
|
-
// 1. Test render via snapshot (default states of component).
|
|
32
|
-
describe('Snapshots and structure', () => {
|
|
33
|
-
it('should render defaults', () => {
|
|
34
|
-
const { wrapper } = setup();
|
|
35
|
-
expect(wrapper).toMatchSnapshot();
|
|
36
|
-
|
|
37
|
-
expect(wrapper).toExist();
|
|
38
|
-
expect(wrapper).toHaveClassName(CLASSNAME);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should render with radio button children', () => {
|
|
42
|
-
const { wrapper, radioButtons } = setup({
|
|
43
|
-
children: [
|
|
44
|
-
<RadioButton key={0} isChecked label="Label 1" />,
|
|
45
|
-
<RadioButton key={1} isChecked={false} label="Label 2" />,
|
|
46
|
-
],
|
|
47
|
-
});
|
|
48
|
-
expect(wrapper).toMatchSnapshot();
|
|
49
|
-
|
|
50
|
-
expect(radioButtons).toExist();
|
|
51
|
-
expect(radioButtons.length).toBe(2);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// 2. Test defaultProps value and important props custom values.
|
|
56
|
-
describe('Props', () => {
|
|
57
|
-
// Nothing to do here.
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// 3. Test events.
|
|
61
|
-
describe('Events', () => {
|
|
62
|
-
// Nothing to do here
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// 4. Test conditions (i.e. things that display or not in the UI based on props).
|
|
66
|
-
describe('Conditions', () => {
|
|
67
|
-
// Nothing to do here.
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
// 5. Test state.
|
|
71
|
-
describe('State', () => {
|
|
72
|
-
// Nothing to do here.
|
|
73
|
-
});
|
|
74
|
-
|
|
75
25
|
// Common tests suite.
|
|
76
|
-
|
|
26
|
+
commonTestsSuiteRTL(setup, {
|
|
27
|
+
baseClassName: CLASSNAME,
|
|
28
|
+
forwardClassName: 'radioGroup',
|
|
29
|
+
forwardAttributes: 'radioGroup',
|
|
30
|
+
});
|
|
77
31
|
});
|