@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,14 +1,13 @@
|
|
|
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
|
|
|
5
|
+
import { render } from '@testing-library/react';
|
|
6
|
+
import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
7
|
+
import userEvent from '@testing-library/user-event';
|
|
8
|
+
import { mdiPlus } from '@lumx/icons';
|
|
9
9
|
import { Uploader, UploaderProps } from './Uploader';
|
|
10
10
|
|
|
11
|
-
const DEFAULT_PROPS = Uploader.defaultProps as any;
|
|
12
11
|
const CLASSNAME = Uploader.className as string;
|
|
13
12
|
|
|
14
13
|
type SetupProps = Partial<UploaderProps>;
|
|
@@ -16,72 +15,85 @@ type SetupProps = Partial<UploaderProps>;
|
|
|
16
15
|
/**
|
|
17
16
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
18
17
|
*/
|
|
19
|
-
const setup = (propsOverride: SetupProps = {}
|
|
18
|
+
const setup = (propsOverride: SetupProps = {}) => {
|
|
20
19
|
const props: any = { ...propsOverride };
|
|
21
|
-
const renderer: (el: ReactElement) => Wrapper = shallowRendering ? shallow : mount;
|
|
22
|
-
const wrapper: Wrapper = renderer(<Uploader {...props} />);
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
render(<Uploader {...props} />);
|
|
22
|
+
const uploader = getByClassName(document.body, CLASSNAME);
|
|
23
|
+
const label = queryByClassName(uploader, `${CLASSNAME}__label`);
|
|
24
|
+
const icon = queryByClassName(uploader, `${CLASSNAME}__icon`);
|
|
25
|
+
|
|
26
|
+
return { props, uploader, label, icon };
|
|
25
27
|
};
|
|
26
28
|
|
|
27
29
|
describe(`<${Uploader.displayName}>`, () => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
describe('Props', () => {
|
|
31
|
+
it('should render default', () => {
|
|
32
|
+
const { uploader } = setup();
|
|
33
|
+
|
|
34
|
+
expect(uploader).toHaveClass(CLASSNAME);
|
|
35
|
+
expect(uploader).toHaveClass('lumx-uploader--aspect-ratio-horizontal');
|
|
36
|
+
expect(uploader).toHaveClass('lumx-uploader--size-xl');
|
|
37
|
+
expect(uploader).toHaveClass('lumx-uploader--theme-light');
|
|
38
|
+
expect(uploader).toHaveClass('lumx-uploader--variant-square');
|
|
39
|
+
});
|
|
31
40
|
|
|
32
|
-
it('should render
|
|
33
|
-
const {
|
|
34
|
-
expect(
|
|
41
|
+
it('should render icon', () => {
|
|
42
|
+
const { icon } = setup({ icon: mdiPlus });
|
|
43
|
+
expect(icon).toBeInTheDocument();
|
|
44
|
+
});
|
|
35
45
|
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
it('should render label', () => {
|
|
47
|
+
const { label } = setup({ label: 'Label' });
|
|
48
|
+
expect(label).toBeInTheDocument();
|
|
49
|
+
expect(label).toHaveTextContent('Label');
|
|
38
50
|
});
|
|
39
|
-
});
|
|
40
51
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
it('should render variant circle', () => {
|
|
53
|
+
const { uploader } = setup({
|
|
54
|
+
variant: 'circle',
|
|
55
|
+
// Ratio should be ignored
|
|
56
|
+
aspectRatio: 'vertical',
|
|
57
|
+
});
|
|
44
58
|
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
expect(uploader).toHaveClass(CLASSNAME);
|
|
60
|
+
expect(uploader).toHaveClass('lumx-uploader--aspect-ratio-square');
|
|
61
|
+
expect(uploader).toHaveClass('lumx-uploader--size-xl');
|
|
62
|
+
expect(uploader).toHaveClass('lumx-uploader--theme-light');
|
|
63
|
+
expect(uploader).toHaveClass('lumx-uploader--variant-circle');
|
|
64
|
+
});
|
|
47
65
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
66
|
+
it('should render variant rounded', () => {
|
|
67
|
+
const { uploader } = setup({ variant: 'rounded' });
|
|
68
|
+
|
|
69
|
+
expect(uploader).toHaveClass(CLASSNAME);
|
|
70
|
+
expect(uploader).toHaveClass('lumx-uploader--aspect-ratio-horizontal');
|
|
71
|
+
expect(uploader).toHaveClass('lumx-uploader--size-xl');
|
|
72
|
+
expect(uploader).toHaveClass('lumx-uploader--theme-light');
|
|
73
|
+
expect(uploader).toHaveClass('lumx-uploader--variant-rounded');
|
|
53
74
|
});
|
|
54
75
|
});
|
|
55
76
|
|
|
56
|
-
// 3. Test events.
|
|
57
77
|
describe('Events', () => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const onClick: jest.Mock = jest.fn();
|
|
78
|
+
const onClick = jest.fn();
|
|
61
79
|
|
|
62
80
|
beforeEach(() => {
|
|
63
81
|
onClick.mockClear();
|
|
64
82
|
});
|
|
65
83
|
|
|
66
|
-
it('should trigger `onClick` when clicked', () => {
|
|
67
|
-
const {
|
|
84
|
+
it('should trigger `onClick` when clicked', async () => {
|
|
85
|
+
const { uploader } = setup({ onClick });
|
|
68
86
|
|
|
69
|
-
|
|
87
|
+
await userEvent.click(uploader);
|
|
70
88
|
|
|
71
89
|
expect(onClick).toHaveBeenCalled();
|
|
72
90
|
});
|
|
73
91
|
});
|
|
74
92
|
|
|
75
|
-
// 4. Test conditions (i.e. things that display or not in the UI based on props).
|
|
76
|
-
describe('Conditions', () => {
|
|
77
|
-
// Nothing to do here.
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
// 5. Test state.
|
|
81
|
-
describe('State', () => {
|
|
82
|
-
// Nothing to do here.
|
|
83
|
-
});
|
|
84
|
-
|
|
85
93
|
// Common tests suite.
|
|
86
|
-
|
|
94
|
+
commonTestsSuiteRTL(setup, {
|
|
95
|
+
baseClassName: CLASSNAME,
|
|
96
|
+
forwardClassName: 'uploader',
|
|
97
|
+
forwardAttributes: 'uploader',
|
|
98
|
+
});
|
|
87
99
|
});
|
|
@@ -1,9 +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 { render, within } from '@testing-library/react';
|
|
5
|
+
import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
6
|
+
import { Thumbnail } from '@lumx/react';
|
|
7
|
+
import userEvent from '@testing-library/user-event';
|
|
5
8
|
|
|
6
|
-
import { commonTestsSuite, Wrapper } from '@lumx/react/testing/utils';
|
|
7
9
|
import { UserBlock, UserBlockProps } from './UserBlock';
|
|
8
10
|
|
|
9
11
|
const CLASSNAME = UserBlock.className as string;
|
|
@@ -11,24 +13,78 @@ const CLASSNAME = UserBlock.className as string;
|
|
|
11
13
|
/**
|
|
12
14
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
13
15
|
*/
|
|
14
|
-
const setup = (
|
|
16
|
+
const setup = (propsOverride: Partial<UserBlockProps> = {}) => {
|
|
15
17
|
const props: UserBlockProps = { ...propsOverride };
|
|
16
|
-
const renderer: (el: ReactElement) => Wrapper = shallowRendering ? shallow : mount;
|
|
17
|
-
const wrapper: Wrapper = renderer(<UserBlock {...props} />);
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
render(<UserBlock {...props} />);
|
|
20
|
+
const userBlock = getByClassName(document.body, CLASSNAME);
|
|
21
|
+
const name = queryByClassName(userBlock, `${CLASSNAME}__name`);
|
|
22
|
+
const avatar = queryByClassName(userBlock, `${CLASSNAME}__avatar`);
|
|
23
|
+
const thumbnail = avatar && queryByClassName(avatar, Thumbnail.className as string);
|
|
24
|
+
const fields = queryByClassName(userBlock, `${CLASSNAME}__fields`);
|
|
25
|
+
|
|
26
|
+
return { props, userBlock, name, avatar, thumbnail, fields };
|
|
20
27
|
};
|
|
21
28
|
|
|
22
29
|
describe(`<${UserBlock.displayName}>`, () => {
|
|
23
|
-
|
|
24
|
-
describe('Snapshots and structure', () => {
|
|
30
|
+
describe('Props', () => {
|
|
25
31
|
it('should forward name props', () => {
|
|
26
|
-
const {
|
|
32
|
+
const { name } = setup({ name: 'John Doe', nameProps: { 'data-custom-attribute': true } });
|
|
33
|
+
|
|
34
|
+
expect(name).toHaveAttribute('data-custom-attribute');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should render button', async () => {
|
|
38
|
+
const onClick = jest.fn();
|
|
39
|
+
const { name, thumbnail } = setup({
|
|
40
|
+
onClick,
|
|
41
|
+
name: 'John Doe',
|
|
42
|
+
avatarProps: { image: 'profile-picture.jpg' },
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Button name
|
|
46
|
+
expect(name?.tagName).toBe('BUTTON');
|
|
47
|
+
await userEvent.click(name as any);
|
|
48
|
+
expect(onClick).toHaveBeenCalled();
|
|
49
|
+
|
|
50
|
+
// Button thumbnail (but excluded from tab stops)
|
|
51
|
+
expect(thumbnail?.tagName).toBe('BUTTON');
|
|
52
|
+
expect(thumbnail?.tabIndex).toBe(-1);
|
|
53
|
+
onClick.mockClear();
|
|
54
|
+
await userEvent.click(thumbnail as any);
|
|
55
|
+
expect(onClick).toHaveBeenCalled();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should render link', async () => {
|
|
59
|
+
const { props, name, thumbnail } = setup({
|
|
60
|
+
linkProps: { href: 'https://example.com' },
|
|
61
|
+
name: 'John Doe',
|
|
62
|
+
avatarProps: { image: 'profile-picture.jpg' },
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Link name
|
|
66
|
+
expect(name?.tagName).toBe('A');
|
|
67
|
+
expect(name).toHaveAttribute('href', props.linkProps?.href);
|
|
27
68
|
|
|
28
|
-
|
|
69
|
+
// Link thumbnail (but excluded from tab stops)
|
|
70
|
+
expect(thumbnail?.tagName).toBe('A');
|
|
71
|
+
expect(thumbnail?.tabIndex).toBe(-1);
|
|
72
|
+
expect(thumbnail).toHaveAttribute('href', props.linkProps?.href);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should render fields', () => {
|
|
76
|
+
const { fields } = setup({ fields: ['Field 1', 'Field 2'] });
|
|
77
|
+
expect(fields).toBeInTheDocument();
|
|
78
|
+
expect(within(fields as any).getByText('Field 1')).toBeInTheDocument();
|
|
79
|
+
expect(within(fields as any).getByText('Field 2')).toBeInTheDocument();
|
|
29
80
|
});
|
|
30
81
|
});
|
|
31
82
|
|
|
32
83
|
// Common tests suite.
|
|
33
|
-
|
|
84
|
+
commonTestsSuiteRTL(setup, {
|
|
85
|
+
baseClassName: CLASSNAME,
|
|
86
|
+
forwardClassName: 'userBlock',
|
|
87
|
+
forwardAttributes: 'userBlock',
|
|
88
|
+
forwardRef: 'userBlock',
|
|
89
|
+
});
|
|
34
90
|
});
|
|
@@ -72,10 +72,10 @@ export function useFocusTrap(focusZoneElement: HTMLElement | Falsy, focusElement
|
|
|
72
72
|
// SETUP:
|
|
73
73
|
if (focusElement && focusZoneElement.contains(focusElement)) {
|
|
74
74
|
// Focus the given element.
|
|
75
|
-
focusElement.focus();
|
|
75
|
+
focusElement.focus({ preventScroll: true });
|
|
76
76
|
} else {
|
|
77
77
|
// Focus the first focusable element in the zone.
|
|
78
|
-
getFirstAndLastFocusable(focusZoneElement).first?.focus();
|
|
78
|
+
getFirstAndLastFocusable(focusZoneElement).first?.focus({ preventScroll: true });
|
|
79
79
|
}
|
|
80
80
|
FOCUS_TRAPS.register(focusTrap);
|
|
81
81
|
|
|
@@ -2,6 +2,7 @@ import isEmpty from 'lodash/isEmpty';
|
|
|
2
2
|
|
|
3
3
|
import { GenericProps } from '@lumx/react/utils/type';
|
|
4
4
|
import { queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
5
|
+
import React from 'react';
|
|
5
6
|
|
|
6
7
|
interface CommonSetup {
|
|
7
8
|
props: GenericProps;
|
|
@@ -11,9 +12,10 @@ interface Options<S extends CommonSetup> {
|
|
|
11
12
|
baseClassName: string;
|
|
12
13
|
forwardClassName?: keyof S;
|
|
13
14
|
forwardAttributes?: keyof S;
|
|
15
|
+
forwardRef?: keyof S;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
type SetupFunction<S extends CommonSetup> = (props?: GenericProps) => S
|
|
18
|
+
type SetupFunction<S extends CommonSetup> = (props?: GenericProps) => S | Promise<S>;
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Common tests on components
|
|
@@ -24,31 +26,39 @@ export function commonTestsSuiteRTL<S extends CommonSetup>(setup: SetupFunction<
|
|
|
24
26
|
if (isEmpty(options)) {
|
|
25
27
|
return;
|
|
26
28
|
}
|
|
27
|
-
const { baseClassName, forwardClassName, forwardAttributes } = options;
|
|
29
|
+
const { baseClassName, forwardClassName, forwardAttributes, forwardRef } = options;
|
|
28
30
|
describe('Common tests suite', () => {
|
|
29
|
-
it('should render with base class name', () => {
|
|
30
|
-
setup();
|
|
31
|
+
it('should render with base class name', async () => {
|
|
32
|
+
await setup();
|
|
31
33
|
expect(queryByClassName(document.body, baseClassName)).toBeInTheDocument();
|
|
32
34
|
});
|
|
33
35
|
|
|
34
36
|
if (forwardClassName) {
|
|
35
|
-
it('should forward any CSS class', () => {
|
|
37
|
+
it('should forward any CSS class', async () => {
|
|
36
38
|
const modifiedProps = {
|
|
37
39
|
className: 'component component--is-tested',
|
|
38
40
|
};
|
|
39
|
-
const wrappers = setup(modifiedProps);
|
|
41
|
+
const wrappers = await setup(modifiedProps);
|
|
40
42
|
expect(wrappers[forwardClassName]).toHaveClass(modifiedProps.className);
|
|
41
43
|
});
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
if (forwardAttributes) {
|
|
45
|
-
it('should forward any other prop', () => {
|
|
47
|
+
it('should forward any other prop', async () => {
|
|
46
48
|
const modifiedProps = {
|
|
47
49
|
winter: 'is coming',
|
|
48
50
|
};
|
|
49
|
-
const wrappers = setup(modifiedProps);
|
|
51
|
+
const wrappers = await setup(modifiedProps);
|
|
50
52
|
expect(wrappers[forwardAttributes]).toHaveAttribute('winter', modifiedProps.winter);
|
|
51
53
|
});
|
|
52
54
|
}
|
|
55
|
+
|
|
56
|
+
if (forwardRef) {
|
|
57
|
+
it('should forward ref', async () => {
|
|
58
|
+
const ref = React.createRef();
|
|
59
|
+
const wrappers = await setup({ ref });
|
|
60
|
+
expect(ref.current).toBe(wrappers[forwardRef]);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
53
63
|
});
|
|
54
64
|
}
|
|
@@ -8,6 +8,11 @@ import { isFragment } from 'react-is';
|
|
|
8
8
|
*
|
|
9
9
|
* @param children React nodes to flatten.
|
|
10
10
|
* @return Flattened react nodes.
|
|
11
|
+
* @deprecated This function was used to develop keyboard navigation in the List component,
|
|
12
|
+
* but we will replace this with a better method that does not require to hack the children inspection
|
|
13
|
+
*
|
|
14
|
+
* TODO: remove List keyboard navigation once we have provided alternative component (Menu, Combobox, etc.),
|
|
15
|
+
* remove this function and then remove react-is from the dependencies
|
|
11
16
|
*/
|
|
12
17
|
export function flattenChildren(children: ReactNode) {
|
|
13
18
|
function recur(nodes: ReactNode, keys: Key[] = []) {
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`<Autocomplete> Props should render correctly when the dropdown is closed 1`] = `
|
|
4
|
-
<div
|
|
5
|
-
className="lumx-autocomplete"
|
|
6
|
-
>
|
|
7
|
-
<TextField
|
|
8
|
-
inputRef={[Function]}
|
|
9
|
-
onChange={[MockFunction]}
|
|
10
|
-
textFieldRef={
|
|
11
|
-
{
|
|
12
|
-
"current": null,
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
theme="light"
|
|
16
|
-
type="text"
|
|
17
|
-
value=""
|
|
18
|
-
/>
|
|
19
|
-
<Dropdown
|
|
20
|
-
anchorRef={
|
|
21
|
-
{
|
|
22
|
-
"current": null,
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
closeOnClick={false}
|
|
26
|
-
closeOnClickAway={true}
|
|
27
|
-
closeOnEscape={true}
|
|
28
|
-
fitToAnchorWidth={true}
|
|
29
|
-
fitWithinViewportHeight={true}
|
|
30
|
-
focusAnchorOnClose={true}
|
|
31
|
-
isOpen={false}
|
|
32
|
-
placement="bottom-start"
|
|
33
|
-
shouldFocusOnOpen={false}
|
|
34
|
-
>
|
|
35
|
-
<List
|
|
36
|
-
isClickable={true}
|
|
37
|
-
tabIndex={-1}
|
|
38
|
-
>
|
|
39
|
-
<ListItem
|
|
40
|
-
key="losangeles"
|
|
41
|
-
size="tiny"
|
|
42
|
-
>
|
|
43
|
-
<div>
|
|
44
|
-
Los Angeles
|
|
45
|
-
</div>
|
|
46
|
-
</ListItem>
|
|
47
|
-
<ListItem
|
|
48
|
-
key="sanfrancisco"
|
|
49
|
-
size="tiny"
|
|
50
|
-
>
|
|
51
|
-
<div>
|
|
52
|
-
San Francisco
|
|
53
|
-
</div>
|
|
54
|
-
</ListItem>
|
|
55
|
-
<ListItem
|
|
56
|
-
key="paris"
|
|
57
|
-
size="tiny"
|
|
58
|
-
>
|
|
59
|
-
<div>
|
|
60
|
-
Paris
|
|
61
|
-
</div>
|
|
62
|
-
</ListItem>
|
|
63
|
-
<ListItem
|
|
64
|
-
key="montpellier"
|
|
65
|
-
size="tiny"
|
|
66
|
-
>
|
|
67
|
-
<div>
|
|
68
|
-
Montpellier
|
|
69
|
-
</div>
|
|
70
|
-
</ListItem>
|
|
71
|
-
<ListItem
|
|
72
|
-
key="bordeaux"
|
|
73
|
-
size="tiny"
|
|
74
|
-
>
|
|
75
|
-
<div>
|
|
76
|
-
Bordeaux
|
|
77
|
-
</div>
|
|
78
|
-
</ListItem>
|
|
79
|
-
<ListItem
|
|
80
|
-
key="toulouse"
|
|
81
|
-
size="tiny"
|
|
82
|
-
>
|
|
83
|
-
<div>
|
|
84
|
-
Toulouse
|
|
85
|
-
</div>
|
|
86
|
-
</ListItem>
|
|
87
|
-
<ListItem
|
|
88
|
-
key="lyon"
|
|
89
|
-
size="tiny"
|
|
90
|
-
>
|
|
91
|
-
<div>
|
|
92
|
-
Lyon
|
|
93
|
-
</div>
|
|
94
|
-
</ListItem>
|
|
95
|
-
<ListItem
|
|
96
|
-
key="montevideo"
|
|
97
|
-
size="tiny"
|
|
98
|
-
>
|
|
99
|
-
<div>
|
|
100
|
-
Montevideo
|
|
101
|
-
</div>
|
|
102
|
-
</ListItem>
|
|
103
|
-
</List>
|
|
104
|
-
</Dropdown>
|
|
105
|
-
</div>
|
|
106
|
-
`;
|
|
107
|
-
|
|
108
|
-
exports[`<Autocomplete> Snapshots and structure should render correctly 1`] = `
|
|
109
|
-
<div
|
|
110
|
-
className="lumx-autocomplete"
|
|
111
|
-
>
|
|
112
|
-
<TextField
|
|
113
|
-
inputRef={[Function]}
|
|
114
|
-
isRequired={true}
|
|
115
|
-
label="Field label"
|
|
116
|
-
onChange={[MockFunction]}
|
|
117
|
-
textFieldRef={
|
|
118
|
-
{
|
|
119
|
-
"current": null,
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
theme="light"
|
|
123
|
-
type="text"
|
|
124
|
-
value=""
|
|
125
|
-
/>
|
|
126
|
-
<Dropdown
|
|
127
|
-
anchorRef={
|
|
128
|
-
{
|
|
129
|
-
"current": null,
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
closeOnClick={false}
|
|
133
|
-
closeOnClickAway={true}
|
|
134
|
-
closeOnEscape={true}
|
|
135
|
-
fitToAnchorWidth={true}
|
|
136
|
-
fitWithinViewportHeight={true}
|
|
137
|
-
focusAnchorOnClose={true}
|
|
138
|
-
isOpen={true}
|
|
139
|
-
placement="bottom-start"
|
|
140
|
-
shouldFocusOnOpen={false}
|
|
141
|
-
>
|
|
142
|
-
<List
|
|
143
|
-
isClickable={true}
|
|
144
|
-
tabIndex={-1}
|
|
145
|
-
>
|
|
146
|
-
<ListItem
|
|
147
|
-
key="losangeles"
|
|
148
|
-
size="tiny"
|
|
149
|
-
>
|
|
150
|
-
<div>
|
|
151
|
-
Los Angeles
|
|
152
|
-
</div>
|
|
153
|
-
</ListItem>
|
|
154
|
-
<ListItem
|
|
155
|
-
key="sanfrancisco"
|
|
156
|
-
size="tiny"
|
|
157
|
-
>
|
|
158
|
-
<div>
|
|
159
|
-
San Francisco
|
|
160
|
-
</div>
|
|
161
|
-
</ListItem>
|
|
162
|
-
<ListItem
|
|
163
|
-
key="paris"
|
|
164
|
-
size="tiny"
|
|
165
|
-
>
|
|
166
|
-
<div>
|
|
167
|
-
Paris
|
|
168
|
-
</div>
|
|
169
|
-
</ListItem>
|
|
170
|
-
<ListItem
|
|
171
|
-
key="montpellier"
|
|
172
|
-
size="tiny"
|
|
173
|
-
>
|
|
174
|
-
<div>
|
|
175
|
-
Montpellier
|
|
176
|
-
</div>
|
|
177
|
-
</ListItem>
|
|
178
|
-
<ListItem
|
|
179
|
-
key="bordeaux"
|
|
180
|
-
size="tiny"
|
|
181
|
-
>
|
|
182
|
-
<div>
|
|
183
|
-
Bordeaux
|
|
184
|
-
</div>
|
|
185
|
-
</ListItem>
|
|
186
|
-
<ListItem
|
|
187
|
-
key="toulouse"
|
|
188
|
-
size="tiny"
|
|
189
|
-
>
|
|
190
|
-
<div>
|
|
191
|
-
Toulouse
|
|
192
|
-
</div>
|
|
193
|
-
</ListItem>
|
|
194
|
-
<ListItem
|
|
195
|
-
key="lyon"
|
|
196
|
-
size="tiny"
|
|
197
|
-
>
|
|
198
|
-
<div>
|
|
199
|
-
Lyon
|
|
200
|
-
</div>
|
|
201
|
-
</ListItem>
|
|
202
|
-
<ListItem
|
|
203
|
-
key="montevideo"
|
|
204
|
-
size="tiny"
|
|
205
|
-
>
|
|
206
|
-
<div>
|
|
207
|
-
Montevideo
|
|
208
|
-
</div>
|
|
209
|
-
</ListItem>
|
|
210
|
-
</List>
|
|
211
|
-
</Dropdown>
|
|
212
|
-
</div>
|
|
213
|
-
`;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`<AutocompleteMultiple> Snapshots and structure should render correctly 1`] = `
|
|
4
|
-
<Autocomplete
|
|
5
|
-
anchorToInput={false}
|
|
6
|
-
chips={[]}
|
|
7
|
-
className="lumx-autocomplete-multiple"
|
|
8
|
-
closeOnClick={false}
|
|
9
|
-
closeOnClickAway={true}
|
|
10
|
-
closeOnEscape={true}
|
|
11
|
-
isOpen={true}
|
|
12
|
-
isRequired={true}
|
|
13
|
-
label="Field label"
|
|
14
|
-
onChange={[MockFunction]}
|
|
15
|
-
shouldFocusOnClose={false}
|
|
16
|
-
value=""
|
|
17
|
-
>
|
|
18
|
-
<List
|
|
19
|
-
isClickable={true}
|
|
20
|
-
tabIndex={-1}
|
|
21
|
-
>
|
|
22
|
-
<ListItem
|
|
23
|
-
key="losangeles"
|
|
24
|
-
size="tiny"
|
|
25
|
-
>
|
|
26
|
-
<div>
|
|
27
|
-
Los Angeles
|
|
28
|
-
</div>
|
|
29
|
-
</ListItem>
|
|
30
|
-
<ListItem
|
|
31
|
-
key="sanfrancisco"
|
|
32
|
-
size="tiny"
|
|
33
|
-
>
|
|
34
|
-
<div>
|
|
35
|
-
San Francisco
|
|
36
|
-
</div>
|
|
37
|
-
</ListItem>
|
|
38
|
-
<ListItem
|
|
39
|
-
key="paris"
|
|
40
|
-
size="tiny"
|
|
41
|
-
>
|
|
42
|
-
<div>
|
|
43
|
-
Paris
|
|
44
|
-
</div>
|
|
45
|
-
</ListItem>
|
|
46
|
-
<ListItem
|
|
47
|
-
key="montpellier"
|
|
48
|
-
size="tiny"
|
|
49
|
-
>
|
|
50
|
-
<div>
|
|
51
|
-
Montpellier
|
|
52
|
-
</div>
|
|
53
|
-
</ListItem>
|
|
54
|
-
<ListItem
|
|
55
|
-
key="bordeaux"
|
|
56
|
-
size="tiny"
|
|
57
|
-
>
|
|
58
|
-
<div>
|
|
59
|
-
Bordeaux
|
|
60
|
-
</div>
|
|
61
|
-
</ListItem>
|
|
62
|
-
<ListItem
|
|
63
|
-
key="toulouse"
|
|
64
|
-
size="tiny"
|
|
65
|
-
>
|
|
66
|
-
<div>
|
|
67
|
-
Toulouse
|
|
68
|
-
</div>
|
|
69
|
-
</ListItem>
|
|
70
|
-
<ListItem
|
|
71
|
-
key="lyon"
|
|
72
|
-
size="tiny"
|
|
73
|
-
>
|
|
74
|
-
<div>
|
|
75
|
-
Lyon
|
|
76
|
-
</div>
|
|
77
|
-
</ListItem>
|
|
78
|
-
<ListItem
|
|
79
|
-
key="montevideo"
|
|
80
|
-
size="tiny"
|
|
81
|
-
>
|
|
82
|
-
<div>
|
|
83
|
-
Montevideo
|
|
84
|
-
</div>
|
|
85
|
-
</ListItem>
|
|
86
|
-
</List>
|
|
87
|
-
</Autocomplete>
|
|
88
|
-
`;
|