@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,69 +1,70 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { commonTestsSuite, Wrapper } from '@lumx/react/testing/utils';
|
|
1
|
+
import React from 'react';
|
|
3
2
|
|
|
4
|
-
import {
|
|
5
|
-
import '
|
|
6
|
-
import
|
|
3
|
+
import { Dialog, DialogProps } from '@lumx/react/components/dialog/Dialog';
|
|
4
|
+
import { queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
5
|
+
import { render, screen } from '@testing-library/react';
|
|
6
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
7
|
+
import userEvent from '@testing-library/user-event';
|
|
7
8
|
|
|
8
9
|
const CLASSNAME = Dialog.className as string;
|
|
9
10
|
|
|
10
|
-
// Mock out the useIntersectionObserver hook since it can't work with Jest/Enzyme.
|
|
11
|
-
jest.mock('@lumx/react/hooks/useIntersectionObserver', () => ({
|
|
12
|
-
useIntersectionObserver: () => new Map(),
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
|
-
type SetupProps = Partial<DialogProps>;
|
|
16
|
-
|
|
17
11
|
/**
|
|
18
12
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
19
13
|
*/
|
|
20
|
-
const setup = (
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return { props, wrapper, dialog };
|
|
14
|
+
const setup = (props: Partial<DialogProps> = {}) => {
|
|
15
|
+
render(<Dialog isOpen {...props} />);
|
|
16
|
+
const dialog = queryByClassName(document.body, CLASSNAME);
|
|
17
|
+
const container = dialog && queryByClassName(dialog, `${CLASSNAME}__container`);
|
|
18
|
+
return { props, dialog, container };
|
|
27
19
|
};
|
|
28
20
|
|
|
29
21
|
describe(`<${Dialog.displayName}>`, () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
it('should render default', () => {
|
|
23
|
+
const { dialog, container } = setup();
|
|
24
|
+
expect(dialog).toBeInTheDocument();
|
|
25
|
+
expect(container).toBe(screen.queryByRole('dialog'));
|
|
26
|
+
expect(container).toHaveAttribute('aria-modal', 'true');
|
|
27
|
+
});
|
|
33
28
|
|
|
34
|
-
|
|
29
|
+
describe('Events', () => {
|
|
30
|
+
it('should trigger `onClose` when pressing `escape` key', async () => {
|
|
35
31
|
const onClose = jest.fn();
|
|
36
|
-
setup({ isOpen: true, onClose }
|
|
32
|
+
setup({ isOpen: true, onClose });
|
|
37
33
|
|
|
38
|
-
|
|
34
|
+
await userEvent.keyboard('[Escape]');
|
|
39
35
|
expect(onClose).toHaveBeenCalled();
|
|
40
36
|
});
|
|
41
37
|
|
|
42
|
-
it('should not trigger `onClose` when pressing any other key', () => {
|
|
38
|
+
it('should not trigger `onClose` when pressing any other key', async () => {
|
|
43
39
|
const onClose = jest.fn();
|
|
44
|
-
setup({ isOpen: true, onClose }
|
|
40
|
+
setup({ isOpen: true, onClose });
|
|
45
41
|
|
|
46
|
-
|
|
42
|
+
await userEvent.keyboard('a');
|
|
47
43
|
expect(onClose).not.toHaveBeenCalled();
|
|
48
44
|
});
|
|
49
45
|
|
|
50
|
-
it('should not trigger `onClose` when pressing `escape` key with `preventAutoClose` set to `true`', () => {
|
|
46
|
+
it('should not trigger `onClose` when pressing `escape` key with `preventAutoClose` set to `true`', async () => {
|
|
51
47
|
const onClose = jest.fn();
|
|
52
|
-
setup({ isOpen: true, onClose, preventAutoClose: true }
|
|
48
|
+
setup({ isOpen: true, onClose, preventAutoClose: true });
|
|
53
49
|
|
|
54
|
-
|
|
50
|
+
await userEvent.keyboard('[Escape]');
|
|
55
51
|
expect(onClose).not.toHaveBeenCalled();
|
|
56
52
|
});
|
|
57
53
|
|
|
58
|
-
it('should not trigger `onClose` when pressing `escape` key with `preventCloseOnEscape` set to `true`', () => {
|
|
54
|
+
it('should not trigger `onClose` when pressing `escape` key with `preventCloseOnEscape` set to `true`', async () => {
|
|
59
55
|
const onClose = jest.fn();
|
|
60
|
-
setup({ isOpen: true, onClose, preventCloseOnEscape: true }
|
|
56
|
+
setup({ isOpen: true, onClose, preventCloseOnEscape: true });
|
|
61
57
|
|
|
62
|
-
|
|
58
|
+
await userEvent.keyboard('[Escape]');
|
|
63
59
|
expect(onClose).not.toHaveBeenCalled();
|
|
64
60
|
});
|
|
65
61
|
});
|
|
66
62
|
|
|
67
63
|
// Common tests suite.
|
|
68
|
-
|
|
64
|
+
commonTestsSuiteRTL(setup, {
|
|
65
|
+
baseClassName: CLASSNAME,
|
|
66
|
+
forwardAttributes: 'dialog',
|
|
67
|
+
forwardRef: 'dialog',
|
|
68
|
+
forwardClassName: 'dialog',
|
|
69
|
+
});
|
|
69
70
|
});
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import 'jest-enzyme';
|
|
5
|
-
|
|
6
|
-
import { commonTestsSuite, Wrapper } from '@lumx/react/testing/utils';
|
|
7
|
-
import { getBasicClass } from '@lumx/react/utils/className';
|
|
3
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
8
4
|
|
|
9
5
|
import { Theme } from '@lumx/react';
|
|
6
|
+
import { render, screen } from '@testing-library/react';
|
|
10
7
|
import { Divider, DividerProps } from './Divider';
|
|
11
8
|
|
|
12
|
-
const DEFAULT_PROPS = Divider.defaultProps as any;
|
|
13
9
|
const CLASSNAME = Divider.className as string;
|
|
14
10
|
|
|
15
11
|
type SetupProps = Partial<DividerProps>;
|
|
@@ -17,77 +13,35 @@ type SetupProps = Partial<DividerProps>;
|
|
|
17
13
|
/**
|
|
18
14
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
19
15
|
*/
|
|
20
|
-
const setup = (
|
|
21
|
-
const props: DividerProps = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const renderer: (el: ReactElement) => Wrapper = shallowRendering ? shallow : mount;
|
|
26
|
-
const wrapper: Wrapper = renderer(<Divider {...props} />);
|
|
16
|
+
const setup = (propsOverride: SetupProps = {}) => {
|
|
17
|
+
const props: DividerProps = { ...propsOverride };
|
|
18
|
+
|
|
19
|
+
render(<Divider {...props} />);
|
|
20
|
+
const divider = screen.queryByRole('separator');
|
|
27
21
|
|
|
28
|
-
return {
|
|
29
|
-
hr: wrapper.find('hr'),
|
|
30
|
-
props,
|
|
31
|
-
wrapper,
|
|
32
|
-
};
|
|
22
|
+
return { props, divider };
|
|
33
23
|
};
|
|
34
24
|
|
|
35
25
|
describe(`<${Divider.displayName}>`, () => {
|
|
36
|
-
// 1. Test render via snapshot (default states of component).
|
|
37
|
-
describe('Snapshots and structure', () => {
|
|
38
|
-
it('should render correctly', () => {
|
|
39
|
-
const { hr, wrapper } = setup();
|
|
40
|
-
expect(wrapper).toMatchSnapshot();
|
|
41
|
-
|
|
42
|
-
expect(hr).toExist();
|
|
43
|
-
expect(hr).toHaveClassName(CLASSNAME);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// 2. Test defaultProps value and important props custom values.
|
|
48
26
|
describe('Props', () => {
|
|
49
|
-
it('should
|
|
50
|
-
const {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
getBasicClass({ prefix: CLASSNAME, type: prop, value: DEFAULT_PROPS[prop] }),
|
|
55
|
-
);
|
|
56
|
-
});
|
|
27
|
+
it('should render default', () => {
|
|
28
|
+
const { divider } = setup();
|
|
29
|
+
expect(divider).toBeInTheDocument();
|
|
30
|
+
expect(divider).toHaveClass(CLASSNAME);
|
|
31
|
+
expect(divider).toHaveClass(`${CLASSNAME}--theme-light`);
|
|
57
32
|
});
|
|
58
33
|
|
|
59
|
-
it('should
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
[testedProp]: Theme.dark,
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const { hr } = setup(modifiedProps);
|
|
66
|
-
|
|
67
|
-
expect(hr).toHaveClassName(
|
|
68
|
-
getBasicClass({ prefix: CLASSNAME, type: testedProp, value: modifiedProps[testedProp] }),
|
|
69
|
-
);
|
|
70
|
-
expect(hr).not.toHaveClassName(
|
|
71
|
-
getBasicClass({ prefix: CLASSNAME, type: testedProp, value: DEFAULT_PROPS[testedProp] }),
|
|
72
|
-
);
|
|
34
|
+
it('should render dark Theme', () => {
|
|
35
|
+
const { divider } = setup({ theme: Theme.dark });
|
|
36
|
+
expect(divider).toHaveClass(`${CLASSNAME}--theme-dark`);
|
|
73
37
|
});
|
|
74
38
|
});
|
|
75
39
|
|
|
76
|
-
// 3. Test events.
|
|
77
|
-
describe('Events', () => {
|
|
78
|
-
// Nothing to do here.
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// 4. Test conditions (i.e. things that display or not in the UI based on props).
|
|
82
|
-
describe('Conditions', () => {
|
|
83
|
-
// Nothing to do here.
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// 5. Test state.
|
|
87
|
-
describe('State', () => {
|
|
88
|
-
// Nothing to do here.
|
|
89
|
-
});
|
|
90
|
-
|
|
91
40
|
// Common tests suite.
|
|
92
|
-
|
|
41
|
+
commonTestsSuiteRTL(setup, {
|
|
42
|
+
baseClassName: CLASSNAME,
|
|
43
|
+
forwardClassName: 'divider',
|
|
44
|
+
forwardAttributes: 'divider',
|
|
45
|
+
forwardRef: 'divider',
|
|
46
|
+
});
|
|
93
47
|
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import '
|
|
5
|
-
|
|
6
|
-
import { commonTestsSuite, Wrapper } from '@lumx/react/testing/utils';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
import { queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
7
5
|
|
|
6
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
7
|
+
import userEvent from '@testing-library/user-event';
|
|
8
8
|
import { Dropdown, DropdownProps } from './Dropdown';
|
|
9
9
|
|
|
10
10
|
const CLASSNAME = Dropdown.className as string;
|
|
@@ -12,7 +12,7 @@ const CLASSNAME = Dropdown.className as string;
|
|
|
12
12
|
/**
|
|
13
13
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
14
14
|
*/
|
|
15
|
-
const setup = (
|
|
15
|
+
const setup = (propsOverride: Partial<DropdownProps> = {}) => {
|
|
16
16
|
const anchorRef = React.createRef<HTMLButtonElement>();
|
|
17
17
|
const props: DropdownProps = {
|
|
18
18
|
anchorRef,
|
|
@@ -20,78 +20,47 @@ const setup = ({ ...propsOverride }: Partial<DropdownProps> = {}, shallowRenderi
|
|
|
20
20
|
isOpen: true,
|
|
21
21
|
...propsOverride,
|
|
22
22
|
};
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
return {
|
|
26
|
-
props,
|
|
27
|
-
wrapper,
|
|
28
|
-
};
|
|
23
|
+
render(<Dropdown {...props} />);
|
|
24
|
+
const dropDown = queryByClassName(document.body, CLASSNAME);
|
|
25
|
+
return { props, dropDown };
|
|
29
26
|
};
|
|
30
27
|
|
|
31
28
|
describe(`<${Dropdown.displayName}>`, () => {
|
|
32
|
-
// 1. Test render via snapshot (default states of component).
|
|
33
|
-
describe('Snapshots and structure', () => {
|
|
34
|
-
it('should render correctly', () => {
|
|
35
|
-
const { wrapper } = setup();
|
|
36
|
-
expect(wrapper).toMatchSnapshot();
|
|
37
|
-
expect(wrapper).toHaveClassName(CLASSNAME);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// 3. Test events.
|
|
42
29
|
describe('Events', () => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
document.body.addEventListener = jest.fn((type, cb) => {
|
|
50
|
-
(eventListeners as any)[type] = cb;
|
|
30
|
+
it('should trigger `onClose` when pressing `escape` key', async () => {
|
|
31
|
+
const onClose = jest.fn();
|
|
32
|
+
setup({
|
|
33
|
+
closeOnEscape: true,
|
|
34
|
+
onClose,
|
|
35
|
+
isOpen: true,
|
|
51
36
|
});
|
|
52
|
-
eventListeners = {};
|
|
53
|
-
onClose.mockClear();
|
|
54
|
-
});
|
|
55
37
|
|
|
56
|
-
|
|
57
|
-
setup(
|
|
58
|
-
{
|
|
59
|
-
closeOnEscape: true,
|
|
60
|
-
onClose,
|
|
61
|
-
isOpen: true,
|
|
62
|
-
},
|
|
63
|
-
false,
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
eventListeners.keydown?.({ key: 'Escape' });
|
|
38
|
+
await userEvent.keyboard('[Escape]');
|
|
67
39
|
expect(onClose).toHaveBeenCalled();
|
|
68
40
|
});
|
|
69
41
|
|
|
70
|
-
it('should not trigger `onClose` when pressing any other key', () => {
|
|
71
|
-
|
|
42
|
+
it('should not trigger `onClose` when pressing any other key', async () => {
|
|
43
|
+
const onClose = jest.fn();
|
|
44
|
+
setup({ isOpen: true, onClose, closeOnEscape: true });
|
|
72
45
|
|
|
73
|
-
|
|
46
|
+
await userEvent.keyboard('a');
|
|
74
47
|
expect(onClose).not.toHaveBeenCalled();
|
|
75
48
|
});
|
|
76
49
|
|
|
77
|
-
it('should not trigger `onClose` when pressing `escape` key with `closeOnEscape` set to `false`', () => {
|
|
78
|
-
|
|
50
|
+
it('should not trigger `onClose` when pressing `escape` key with `closeOnEscape` set to `false`', async () => {
|
|
51
|
+
const onClose = jest.fn();
|
|
52
|
+
setup({ isOpen: true, onClose, closeOnEscape: false });
|
|
79
53
|
|
|
80
|
-
|
|
54
|
+
await userEvent.keyboard('[Escape]');
|
|
81
55
|
expect(onClose).not.toHaveBeenCalled();
|
|
82
56
|
});
|
|
83
57
|
});
|
|
84
58
|
|
|
85
|
-
// 4. Test conditions (i.e. things that display or not in the UI based on props).
|
|
86
|
-
describe('Conditions', () => {
|
|
87
|
-
// Nothing to do here.
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// 5. Test state.
|
|
91
|
-
describe('State', () => {
|
|
92
|
-
// Nothing to do here.
|
|
93
|
-
});
|
|
94
|
-
|
|
95
59
|
// Common tests suite.
|
|
96
|
-
|
|
60
|
+
commonTestsSuiteRTL(setup, {
|
|
61
|
+
baseClassName: CLASSNAME,
|
|
62
|
+
forwardClassName: 'dropDown',
|
|
63
|
+
forwardAttributes: 'dropDown',
|
|
64
|
+
forwardRef: 'dropDown',
|
|
65
|
+
});
|
|
97
66
|
});
|
|
@@ -4,17 +4,16 @@ import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
|
4
4
|
import { queryByRole, render } from '@testing-library/react';
|
|
5
5
|
import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
6
6
|
import userEvent from '@testing-library/user-event';
|
|
7
|
+
|
|
7
8
|
import { ExpansionPanel, ExpansionPanelProps } from '.';
|
|
8
9
|
|
|
9
10
|
const CLASSNAME = ExpansionPanel.className as string;
|
|
10
11
|
|
|
11
|
-
type SetupProps = Partial<ExpansionPanelProps>;
|
|
12
|
-
|
|
13
12
|
/**
|
|
14
13
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
15
14
|
*/
|
|
16
|
-
const setup = (propsOverride:
|
|
17
|
-
const props
|
|
15
|
+
const setup = (propsOverride: Partial<ExpansionPanelProps> = {}) => {
|
|
16
|
+
const props = {
|
|
18
17
|
toggleButtonProps: { label: 'Toggle' },
|
|
19
18
|
...propsOverride,
|
|
20
19
|
};
|
|
@@ -76,9 +75,9 @@ describe(`<${ExpansionPanel.displayName}>`, () => {
|
|
|
76
75
|
});
|
|
77
76
|
|
|
78
77
|
describe('Events', () => {
|
|
79
|
-
const onOpen
|
|
80
|
-
const onClose
|
|
81
|
-
const onToggleOpen
|
|
78
|
+
const onOpen = jest.fn();
|
|
79
|
+
const onClose = jest.fn();
|
|
80
|
+
const onToggleOpen = jest.fn();
|
|
82
81
|
|
|
83
82
|
beforeEach(onOpen.mockClear);
|
|
84
83
|
beforeEach(onClose.mockClear);
|
|
@@ -112,5 +111,10 @@ describe(`<${ExpansionPanel.displayName}>`, () => {
|
|
|
112
111
|
});
|
|
113
112
|
|
|
114
113
|
// Common tests suite.
|
|
115
|
-
commonTestsSuiteRTL(setup, {
|
|
114
|
+
commonTestsSuiteRTL(setup, {
|
|
115
|
+
baseClassName: CLASSNAME,
|
|
116
|
+
forwardClassName: 'element',
|
|
117
|
+
forwardAttributes: 'element',
|
|
118
|
+
forwardRef: 'element',
|
|
119
|
+
});
|
|
116
120
|
});
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import 'jest-enzyme';
|
|
3
|
-
import React, { ReactElement } from 'react';
|
|
1
|
+
import React from 'react';
|
|
4
2
|
|
|
5
3
|
import { ColorPalette, Theme } from '@lumx/react';
|
|
6
4
|
import { mdiAbTesting } from '@lumx/icons';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
6
|
+
import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
7
|
+
import { render } from '@testing-library/react';
|
|
9
8
|
|
|
10
9
|
import { Flag, FlagProps } from './Flag';
|
|
11
10
|
|
|
@@ -14,66 +13,42 @@ const CLASSNAME = Flag.className as string;
|
|
|
14
13
|
/**
|
|
15
14
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
16
15
|
*/
|
|
17
|
-
const setup = (propOverrides: Partial<FlagProps> = {}
|
|
18
|
-
const props = {
|
|
19
|
-
label: 'default',
|
|
20
|
-
...propOverrides,
|
|
21
|
-
};
|
|
22
|
-
const renderer: (el: ReactElement) => Wrapper = shallowRendering ? shallow : mount;
|
|
23
|
-
const wrapper = renderer(<Flag {...props} />);
|
|
16
|
+
const setup = (propOverrides: Partial<FlagProps> = {}) => {
|
|
17
|
+
const props = { label: 'default', ...propOverrides };
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
19
|
+
render(<Flag {...props} />);
|
|
20
|
+
const flag = getByClassName(document.body, CLASSNAME);
|
|
21
|
+
const icon = queryByClassName(flag, `${CLASSNAME}__icon`);
|
|
22
|
+
|
|
23
|
+
return { props, flag, icon };
|
|
30
24
|
};
|
|
31
25
|
|
|
32
26
|
describe(`<${Flag.displayName} />`, () => {
|
|
33
|
-
describe('
|
|
34
|
-
it('should
|
|
35
|
-
const {
|
|
36
|
-
|
|
37
|
-
expect(
|
|
38
|
-
expect(
|
|
27
|
+
describe('Props', () => {
|
|
28
|
+
it('should render default', () => {
|
|
29
|
+
const { flag, icon } = setup();
|
|
30
|
+
expect(flag).toBeInTheDocument();
|
|
31
|
+
expect(flag).toHaveClass(CLASSNAME);
|
|
32
|
+
expect(flag).toHaveClass(`${CLASSNAME}--color-dark`);
|
|
33
|
+
expect(icon).not.toBeInTheDocument();
|
|
39
34
|
});
|
|
40
35
|
|
|
41
|
-
it('should
|
|
42
|
-
const {
|
|
43
|
-
expect(
|
|
44
|
-
getBasicClass({
|
|
45
|
-
prefix: CLASSNAME,
|
|
46
|
-
type: 'color',
|
|
47
|
-
value: ColorPalette.dark,
|
|
48
|
-
}),
|
|
49
|
-
);
|
|
36
|
+
it('should render icon', () => {
|
|
37
|
+
const { icon } = setup({ icon: mdiAbTesting });
|
|
38
|
+
expect(icon).toBeInTheDocument();
|
|
50
39
|
});
|
|
51
40
|
|
|
52
|
-
it('should
|
|
53
|
-
const {
|
|
54
|
-
expect(
|
|
55
|
-
getBasicClass({
|
|
56
|
-
prefix: CLASSNAME,
|
|
57
|
-
type: 'color',
|
|
58
|
-
value: ColorPalette.light,
|
|
59
|
-
}),
|
|
60
|
-
);
|
|
41
|
+
it('should render dark theme', () => {
|
|
42
|
+
const { flag } = setup({ theme: Theme.dark });
|
|
43
|
+
expect(flag).toHaveClass(`${CLASSNAME}--color-light`);
|
|
61
44
|
});
|
|
62
45
|
|
|
63
|
-
it('should
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
expect(wrapper).toHaveClassName(
|
|
68
|
-
getBasicClass({
|
|
69
|
-
prefix: CLASSNAME,
|
|
70
|
-
type: 'color',
|
|
71
|
-
value: color,
|
|
72
|
-
}),
|
|
73
|
-
);
|
|
46
|
+
it('should render custom color', () => {
|
|
47
|
+
const { flag } = setup({ color: ColorPalette.red });
|
|
48
|
+
expect(flag).toHaveClass(`${CLASSNAME}--color-red`);
|
|
74
49
|
});
|
|
75
50
|
});
|
|
76
51
|
|
|
77
52
|
// Common tests suite.
|
|
78
|
-
|
|
53
|
+
commonTestsSuiteRTL(setup, { baseClassName: CLASSNAME, forwardClassName: 'flag', forwardAttributes: 'flag' });
|
|
79
54
|
});
|