@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
package/package.json
CHANGED
|
@@ -7,35 +7,41 @@
|
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@juggle/resize-observer": "^3.2.0",
|
|
10
|
-
"@lumx/core": "^3.3.1
|
|
11
|
-
"@lumx/icons": "^3.3.1
|
|
10
|
+
"@lumx/core": "^3.3.1",
|
|
11
|
+
"@lumx/icons": "^3.3.1",
|
|
12
12
|
"@popperjs/core": "^2.5.4",
|
|
13
13
|
"body-scroll-lock": "^3.1.5",
|
|
14
14
|
"classnames": "^2.2.6",
|
|
15
|
-
"react-is": "
|
|
15
|
+
"react-is": ">=16.13.0",
|
|
16
16
|
"react-popper": "^2.2.4",
|
|
17
17
|
"uid": "^2.0.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@babel/core": "^7.
|
|
20
|
+
"@babel/core": "^7.18.13",
|
|
21
21
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
22
22
|
"@babel/plugin-proposal-export-default-from": "^7.18.10",
|
|
23
23
|
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
|
|
24
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.
|
|
24
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.18.9",
|
|
25
25
|
"@babel/plugin-proposal-optional-chaining": "^7.18.9",
|
|
26
26
|
"@babel/plugin-proposal-private-methods": "^7.18.6",
|
|
27
27
|
"@babel/plugin-proposal-private-property-in-object": "^7.18.6",
|
|
28
|
-
"@babel/preset-env": "^7.
|
|
28
|
+
"@babel/preset-env": "^7.18.10",
|
|
29
29
|
"@babel/preset-react": "^7.18.6",
|
|
30
30
|
"@babel/preset-typescript": "^7.18.6",
|
|
31
31
|
"@rollup/plugin-commonjs": "^15.0.0",
|
|
32
32
|
"@rollup/plugin-node-resolve": "9.0.0",
|
|
33
|
+
"@storybook/addon-a11y": "^7.0.20",
|
|
34
|
+
"@storybook/addon-essentials": "^7.0.20",
|
|
35
|
+
"@storybook/addon-interactions": "^7.0.20",
|
|
36
|
+
"@storybook/blocks": "^7.0.20",
|
|
37
|
+
"@storybook/react": "^7.0.20",
|
|
38
|
+
"@storybook/react-vite": "^7.0.20",
|
|
39
|
+
"@storybook/testing-library": "^0.0.14-next.2",
|
|
33
40
|
"@testing-library/jest-dom": "^5.16.4",
|
|
34
41
|
"@testing-library/react": "^12.1.2",
|
|
35
42
|
"@testing-library/user-event": "^14.4.3",
|
|
36
43
|
"@types/body-scroll-lock": "^2.6.1",
|
|
37
44
|
"@types/classnames": "^2.2.9",
|
|
38
|
-
"@types/enzyme": "^3.10.12",
|
|
39
45
|
"@types/jest": "^29.2.1",
|
|
40
46
|
"@types/lodash": "^4.14.149",
|
|
41
47
|
"@types/react": "^16.9.11",
|
|
@@ -46,17 +52,14 @@
|
|
|
46
52
|
"babel-loader": "^8.0.6",
|
|
47
53
|
"chromatic": "^6.0.6",
|
|
48
54
|
"core-js": "^3.6.4",
|
|
49
|
-
"enzyme": "^3.11.0",
|
|
50
|
-
"enzyme-adapter-react-16": "^1.15.4",
|
|
51
|
-
"enzyme-to-json": "^3.5.0",
|
|
52
55
|
"focus-visible": "^5.0.2",
|
|
53
56
|
"glob": "^7.1.6",
|
|
54
57
|
"install-peers-cli": "^2.2.0",
|
|
55
58
|
"is-ci": "^2.0.0",
|
|
56
59
|
"jest": "29.1.2",
|
|
57
60
|
"jest-environment-jsdom": "29.1.2",
|
|
58
|
-
"
|
|
59
|
-
"react-dom": "
|
|
61
|
+
"react": "^17.0.2",
|
|
62
|
+
"react-dom": "^17.0.2",
|
|
60
63
|
"rollup": "2.26.10",
|
|
61
64
|
"rollup-plugin-analyzer": "^3.3.0",
|
|
62
65
|
"rollup-plugin-babel": "^4.4.0",
|
|
@@ -66,9 +69,11 @@
|
|
|
66
69
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
67
70
|
"rollup-plugin-ts-paths-resolve": "^1.3.0",
|
|
68
71
|
"rollup-plugin-typescript-paths": "^1.2.2",
|
|
69
|
-
"
|
|
72
|
+
"storybook": "^7.0.20",
|
|
70
73
|
"tsconfig-paths-webpack-plugin": "^3.3.0",
|
|
71
74
|
"typescript": "^4.1.2",
|
|
75
|
+
"vite": "^4.2.1",
|
|
76
|
+
"vite-tsconfig-paths": "^4.0.7",
|
|
72
77
|
"yargs": "^15.4.1",
|
|
73
78
|
"yarn": "^1.19.1"
|
|
74
79
|
},
|
|
@@ -76,8 +81,8 @@
|
|
|
76
81
|
"lodash": "4.17.21",
|
|
77
82
|
"moment": ">= 2",
|
|
78
83
|
"moment-range": "^4.0.2",
|
|
79
|
-
"react": "
|
|
80
|
-
"react-dom": "
|
|
84
|
+
"react": ">= 16.13.0",
|
|
85
|
+
"react-dom": ">= 16.13.0"
|
|
81
86
|
},
|
|
82
87
|
"description": "The official LumApps Design System (LumX) for React applications",
|
|
83
88
|
"engines": {
|
|
@@ -108,10 +113,9 @@
|
|
|
108
113
|
"build": "rollup -c",
|
|
109
114
|
"prepare": "install-peers || exit 0",
|
|
110
115
|
"test": "jest --config jest/index.js --coverage --notify --passWithNoTests --detectOpenHandles --runInBand",
|
|
111
|
-
"storybook": "
|
|
112
|
-
"
|
|
113
|
-
"build:storybook": "cd storybook && ./build"
|
|
116
|
+
"start:storybook": "storybook dev -p 9000",
|
|
117
|
+
"build:storybook": "storybook build"
|
|
114
118
|
},
|
|
115
119
|
"sideEffects": false,
|
|
116
|
-
"version": "3.3.1
|
|
120
|
+
"version": "3.3.1"
|
|
117
121
|
}
|
|
@@ -1,181 +1,94 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import '
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import { Autocomplete, AutocompleteProps } from './Autocomplete';
|
|
3
|
+
import { Dropdown, List, ListItem, Size, TextField } from '@lumx/react';
|
|
4
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
5
|
+
import { getByClassName, getByTagName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
6
|
+
import { render } from '@testing-library/react';
|
|
7
|
+
import userEvent from '@testing-library/user-event';
|
|
9
8
|
|
|
10
9
|
import { CITIES as suggestions } from './__mockData__';
|
|
10
|
+
import { Autocomplete, AutocompleteProps } from './Autocomplete';
|
|
11
11
|
|
|
12
12
|
const CLASSNAME = Autocomplete.className as string;
|
|
13
13
|
|
|
14
|
-
type SetupProps = Partial<AutocompleteProps>;
|
|
15
|
-
|
|
16
|
-
interface Suggestion {
|
|
17
|
-
id: string;
|
|
18
|
-
text: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
14
|
/**
|
|
22
15
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
23
16
|
*/
|
|
24
|
-
const setup = (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
17
|
+
const setup = (props: Partial<AutocompleteProps> = {}) => {
|
|
18
|
+
render(
|
|
19
|
+
<Autocomplete {...(props as any)}>
|
|
20
|
+
<List>
|
|
21
|
+
{suggestions.map((suggestion) => (
|
|
22
|
+
<ListItem size={Size.tiny} key={suggestion.id}>
|
|
23
|
+
<div>{suggestion.text}</div>
|
|
24
|
+
</ListItem>
|
|
25
|
+
))}
|
|
26
|
+
</List>
|
|
27
|
+
</Autocomplete>,
|
|
28
|
+
);
|
|
29
|
+
const autocomplete = getByClassName(document.body, CLASSNAME);
|
|
30
|
+
const textField = getByClassName(autocomplete, TextField.className as string);
|
|
31
|
+
const getDropdown = () => queryByClassName(document.body, Dropdown.className as string);
|
|
32
|
+
const inputNative = getByTagName(autocomplete, 'input');
|
|
33
|
+
return { props, textField, getDropdown, autocomplete, inputNative };
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
describe(`<${Autocomplete.displayName}>`, () => {
|
|
37
|
-
// 1. Test render via snapshot (default states of component).
|
|
38
|
-
describe('Snapshots and structure', () => {
|
|
39
|
-
// Here is an example of a basic rendering check, with snapshot.
|
|
40
|
-
|
|
41
|
-
it('should render correctly', () => {
|
|
42
|
-
const { wrapper, textField, dropdown } = setup({
|
|
43
|
-
children: (
|
|
44
|
-
<List isClickable>
|
|
45
|
-
{suggestions.map((suggestion: Suggestion) => (
|
|
46
|
-
<ListItem size={Size.tiny} key={suggestion.id}>
|
|
47
|
-
<div>{suggestion.text}</div>
|
|
48
|
-
</ListItem>
|
|
49
|
-
))}
|
|
50
|
-
</List>
|
|
51
|
-
),
|
|
52
|
-
label: 'Field label',
|
|
53
|
-
isOpen: true,
|
|
54
|
-
isRequired: true,
|
|
55
|
-
onChange: jest.fn(),
|
|
56
|
-
value: '',
|
|
57
|
-
});
|
|
58
|
-
expect(wrapper).toMatchSnapshot();
|
|
59
|
-
|
|
60
|
-
expect(wrapper).toExist();
|
|
61
|
-
|
|
62
|
-
expect(wrapper).toHaveClassName(CLASSNAME);
|
|
63
|
-
|
|
64
|
-
expect(textField).toHaveLength(1);
|
|
65
|
-
expect(dropdown).toHaveLength(1);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// 2. Test defaultProps value and important props custom values.
|
|
70
37
|
describe('Props', () => {
|
|
71
|
-
it('should
|
|
72
|
-
const {
|
|
38
|
+
it('should render default', () => {
|
|
39
|
+
const { autocomplete, textField, getDropdown } = setup();
|
|
73
40
|
|
|
74
|
-
expect(
|
|
41
|
+
expect(autocomplete.className).toMatchInlineSnapshot(`"lumx-autocomplete"`);
|
|
42
|
+
expect(textField).toBeInTheDocument();
|
|
43
|
+
expect(getDropdown()).not.toBeInTheDocument();
|
|
75
44
|
});
|
|
76
45
|
|
|
77
|
-
it('should render
|
|
78
|
-
const {
|
|
79
|
-
|
|
80
|
-
<List isClickable>
|
|
81
|
-
{suggestions.map((suggestion: Suggestion) => (
|
|
82
|
-
<ListItem size={Size.tiny} key={suggestion.id}>
|
|
83
|
-
<div>{suggestion.text}</div>
|
|
84
|
-
</ListItem>
|
|
85
|
-
))}
|
|
86
|
-
</List>
|
|
87
|
-
),
|
|
88
|
-
isOpen: false,
|
|
89
|
-
onChange: jest.fn(),
|
|
90
|
-
value: '',
|
|
91
|
-
});
|
|
92
|
-
expect(wrapper).toMatchSnapshot();
|
|
93
|
-
|
|
94
|
-
expect(wrapper).toExist();
|
|
95
|
-
|
|
96
|
-
expect(wrapper).toHaveClassName(CLASSNAME);
|
|
46
|
+
it('should render open', () => {
|
|
47
|
+
const { getDropdown } = setup({ isOpen: true });
|
|
48
|
+
expect(getDropdown()).toBeInTheDocument();
|
|
97
49
|
});
|
|
98
50
|
});
|
|
99
51
|
|
|
100
|
-
// 3. Test events.
|
|
101
52
|
describe('Events', () => {
|
|
102
|
-
it('should trigger the onChange callback when there is a change on the Text Field', () => {
|
|
53
|
+
it('should trigger the onChange callback when there is a change on the Text Field', async () => {
|
|
54
|
+
const name = 'autocomplete-name';
|
|
103
55
|
const onChange = jest.fn();
|
|
104
|
-
const {
|
|
105
|
-
|
|
106
|
-
<List isClickable>
|
|
107
|
-
{suggestions.map((suggestion: Suggestion) => (
|
|
108
|
-
<ListItem size={Size.tiny} key={suggestion.id}>
|
|
109
|
-
<div>{suggestion.text}</div>
|
|
110
|
-
</ListItem>
|
|
111
|
-
))}
|
|
112
|
-
</List>
|
|
113
|
-
),
|
|
114
|
-
isOpen: false,
|
|
56
|
+
const { inputNative } = setup({
|
|
57
|
+
name,
|
|
115
58
|
onChange,
|
|
116
|
-
value: '',
|
|
117
59
|
});
|
|
118
60
|
|
|
119
|
-
|
|
61
|
+
await userEvent.tab();
|
|
62
|
+
expect(inputNative).toHaveFocus();
|
|
63
|
+
await userEvent.keyboard('a');
|
|
120
64
|
|
|
121
|
-
|
|
65
|
+
// (text, name, event)
|
|
66
|
+
expect(onChange).toHaveBeenCalledWith('a', name, expect.any(Object));
|
|
122
67
|
});
|
|
123
68
|
|
|
124
|
-
it('should trigger the onFocus callback when the text field is focused
|
|
69
|
+
it('should trigger the onFocus/onBlur callback when the text field is focused and blurred', async () => {
|
|
125
70
|
const onFocus = jest.fn();
|
|
126
|
-
const { textField } = setup({
|
|
127
|
-
children: (
|
|
128
|
-
<List isClickable>
|
|
129
|
-
{suggestions.map((suggestion: Suggestion) => (
|
|
130
|
-
<ListItem size={Size.tiny} key={suggestion.id}>
|
|
131
|
-
<div>{suggestion.text}</div>
|
|
132
|
-
</ListItem>
|
|
133
|
-
))}
|
|
134
|
-
</List>
|
|
135
|
-
),
|
|
136
|
-
isOpen: false,
|
|
137
|
-
onFocus,
|
|
138
|
-
value: '',
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
textField.simulate('focus');
|
|
142
|
-
|
|
143
|
-
expect(onFocus).toHaveBeenCalled();
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('should trigger the onBlur callback when the Text Field loses focus', () => {
|
|
147
71
|
const onBlur = jest.fn();
|
|
148
|
-
const {
|
|
149
|
-
|
|
150
|
-
<List isClickable>
|
|
151
|
-
{suggestions.map((suggestion: Suggestion) => (
|
|
152
|
-
<ListItem size={Size.tiny} key={suggestion.id}>
|
|
153
|
-
<div>{suggestion.text}</div>
|
|
154
|
-
</ListItem>
|
|
155
|
-
))}
|
|
156
|
-
</List>
|
|
157
|
-
),
|
|
158
|
-
isOpen: false,
|
|
72
|
+
const { inputNative } = setup({
|
|
73
|
+
onFocus,
|
|
159
74
|
onBlur,
|
|
160
|
-
value: '',
|
|
161
75
|
});
|
|
162
76
|
|
|
163
|
-
|
|
77
|
+
await userEvent.tab();
|
|
78
|
+
expect(inputNative).toHaveFocus();
|
|
79
|
+
expect(onFocus).toHaveBeenCalled();
|
|
164
80
|
|
|
81
|
+
await userEvent.tab();
|
|
82
|
+
expect(inputNative).not.toHaveFocus();
|
|
165
83
|
expect(onBlur).toHaveBeenCalled();
|
|
166
84
|
});
|
|
167
85
|
});
|
|
168
86
|
|
|
169
|
-
// 4. Test conditions (i.e. things that display or not in the UI based on props).
|
|
170
|
-
describe('Conditions', () => {
|
|
171
|
-
// Nothing to do here.
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
// 5. Test state.
|
|
175
|
-
describe('State', () => {
|
|
176
|
-
// Nothing to do here.
|
|
177
|
-
});
|
|
178
|
-
|
|
179
87
|
// Common tests suite.
|
|
180
|
-
|
|
88
|
+
commonTestsSuiteRTL(setup, {
|
|
89
|
+
baseClassName: CLASSNAME,
|
|
90
|
+
forwardClassName: 'autocomplete',
|
|
91
|
+
forwardAttributes: 'autocomplete',
|
|
92
|
+
forwardRef: 'autocomplete',
|
|
93
|
+
});
|
|
181
94
|
});
|
|
@@ -1,94 +1,56 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import '
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import { commonTestsSuite, Wrapper } from '@lumx/react/testing/utils';
|
|
8
|
-
import { AutocompleteMultiple, AutocompleteMultipleProps } from './AutocompleteMultiple';
|
|
3
|
+
import { Dropdown, List, ListItem, Size, TextField } from '@lumx/react';
|
|
4
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
5
|
+
import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
6
|
+
import { render } from '@testing-library/react';
|
|
9
7
|
|
|
10
8
|
import { CITIES as suggestions } from './__mockData__';
|
|
9
|
+
import { AutocompleteMultiple, AutocompleteMultipleProps } from './AutocompleteMultiple';
|
|
11
10
|
|
|
12
11
|
const CLASSNAME = AutocompleteMultiple.className as string;
|
|
13
12
|
|
|
14
|
-
type SetupProps = Partial<AutocompleteMultipleProps>;
|
|
15
|
-
|
|
16
|
-
interface Suggestion {
|
|
17
|
-
id: string;
|
|
18
|
-
text: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
const setup = (props: Partial<AutocompleteMultipleProps> = {}) => {
|
|
17
|
+
render(
|
|
18
|
+
<AutocompleteMultiple {...(props as any)}>
|
|
19
|
+
<List>
|
|
20
|
+
{suggestions.map((suggestion) => (
|
|
21
|
+
<ListItem size={Size.tiny} key={suggestion.id}>
|
|
22
|
+
<div>{suggestion.text}</div>
|
|
23
|
+
</ListItem>
|
|
24
|
+
))}
|
|
25
|
+
</List>
|
|
26
|
+
</AutocompleteMultiple>,
|
|
27
|
+
);
|
|
28
|
+
const autocompleteMultiple = getByClassName(document.body, CLASSNAME);
|
|
29
|
+
const textField = getByClassName(autocompleteMultiple, TextField.className as string);
|
|
30
|
+
const getDropdown = () => queryByClassName(document.body, Dropdown.className as string);
|
|
31
|
+
return { props, autocompleteMultiple, textField, getDropdown };
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
describe(`<${AutocompleteMultiple.displayName}>`, () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// Here is an example of a basic rendering check, with snapshot.
|
|
36
|
-
|
|
37
|
-
it('should render correctly', () => {
|
|
38
|
-
const { wrapper } = setup({
|
|
39
|
-
children: (
|
|
40
|
-
<List isClickable>
|
|
41
|
-
{suggestions.map((suggestion: Suggestion) => (
|
|
42
|
-
<ListItem size={Size.tiny} key={suggestion.id}>
|
|
43
|
-
<div>{suggestion.text}</div>
|
|
44
|
-
</ListItem>
|
|
45
|
-
))}
|
|
46
|
-
</List>
|
|
47
|
-
),
|
|
48
|
-
chips: [
|
|
49
|
-
{
|
|
50
|
-
id: 'lyon',
|
|
51
|
-
text: 'Lyon',
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
id: 'montevideo',
|
|
55
|
-
text: 'Montevideo',
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
label: 'Field label',
|
|
59
|
-
isOpen: true,
|
|
60
|
-
isRequired: true,
|
|
61
|
-
onChange: jest.fn(),
|
|
62
|
-
value: '',
|
|
63
|
-
});
|
|
64
|
-
expect(wrapper).toMatchSnapshot();
|
|
65
|
-
|
|
66
|
-
expect(wrapper).toExist();
|
|
35
|
+
it('should render default', () => {
|
|
36
|
+
const { autocompleteMultiple, textField, getDropdown } = setup({});
|
|
67
37
|
|
|
68
|
-
|
|
69
|
-
|
|
38
|
+
expect(autocompleteMultiple).toBeInTheDocument();
|
|
39
|
+
expect(autocompleteMultiple.className).toMatchInlineSnapshot(`"lumx-autocomplete-multiple lumx-autocomplete"`);
|
|
40
|
+
expect(textField).toBeInTheDocument();
|
|
41
|
+
expect(getDropdown()).not.toBeInTheDocument();
|
|
70
42
|
});
|
|
71
43
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// 3. Test events.
|
|
78
|
-
describe('Events', () => {
|
|
79
|
-
// Nothing to do here.
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// 4. Test conditions (i.e. things that display or not in the UI based on props).
|
|
83
|
-
describe('Conditions', () => {
|
|
84
|
-
// Nothing to do here.
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// 5. Test state.
|
|
88
|
-
describe('State', () => {
|
|
89
|
-
// Nothing to do here.
|
|
44
|
+
it('should render open', () => {
|
|
45
|
+
const { getDropdown } = setup({ isOpen: true });
|
|
46
|
+
expect(getDropdown()).toBeInTheDocument();
|
|
90
47
|
});
|
|
91
48
|
|
|
92
49
|
// Common tests suite.
|
|
93
|
-
|
|
50
|
+
commonTestsSuiteRTL(setup, {
|
|
51
|
+
baseClassName: CLASSNAME,
|
|
52
|
+
forwardClassName: 'autocompleteMultiple',
|
|
53
|
+
forwardRef: 'autocompleteMultiple',
|
|
54
|
+
forwardAttributes: 'autocompleteMultiple',
|
|
55
|
+
});
|
|
94
56
|
});
|
|
@@ -1,91 +1,47 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import '
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import { getBasicClass } from '@lumx/react/utils/className';
|
|
8
|
-
|
|
9
|
-
import { Theme } from '@lumx/react';
|
|
3
|
+
import { ColorPalette } from '@lumx/react';
|
|
4
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
5
|
+
import { getByClassName } from '@lumx/react/testing/utils/queries';
|
|
6
|
+
import { render } from '@testing-library/react';
|
|
10
7
|
import { Badge, BadgeProps } from './Badge';
|
|
11
8
|
|
|
12
|
-
const DEFAULT_PROPS = Badge.defaultProps as any;
|
|
13
9
|
const CLASSNAME = Badge.className as string;
|
|
14
10
|
|
|
15
11
|
/**
|
|
16
12
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
17
13
|
*/
|
|
18
|
-
const setup = (
|
|
14
|
+
const setup = (propsOverride: Partial<BadgeProps> = {}) => {
|
|
19
15
|
const props: BadgeProps = {
|
|
20
16
|
children: <span>30</span>,
|
|
21
17
|
...propsOverride,
|
|
22
18
|
};
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
badge: wrapper.find(`div`),
|
|
28
|
-
props,
|
|
29
|
-
wrapper,
|
|
30
|
-
};
|
|
19
|
+
render(<Badge {...props} />);
|
|
20
|
+
const badge = getByClassName(document.body, CLASSNAME);
|
|
21
|
+
return { badge, props };
|
|
31
22
|
};
|
|
32
23
|
|
|
33
24
|
describe(`<${Badge.displayName}>`, () => {
|
|
34
|
-
// 1. Test render via snapshot (default states of component).
|
|
35
|
-
describe('Snapshots and structure', () => {
|
|
36
|
-
it('should render correctly', () => {
|
|
37
|
-
const { wrapper, badge } = setup();
|
|
38
|
-
expect(wrapper).toMatchSnapshot();
|
|
39
|
-
|
|
40
|
-
expect(badge).toExist();
|
|
41
|
-
expect(wrapper).toHaveClassName(CLASSNAME);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// 2. Test defaultProps value and important props custom values.
|
|
46
25
|
describe('Props', () => {
|
|
47
26
|
it('should use default props', () => {
|
|
48
27
|
const { badge } = setup();
|
|
49
28
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
getBasicClass({ prefix: CLASSNAME, type: prop, value: DEFAULT_PROPS[prop] }),
|
|
53
|
-
);
|
|
54
|
-
});
|
|
29
|
+
expect(badge.className).toMatchInlineSnapshot(`"lumx-badge lumx-badge--color-primary"`);
|
|
30
|
+
expect(badge).toHaveTextContent(/30/);
|
|
55
31
|
});
|
|
56
32
|
|
|
57
|
-
it('should
|
|
58
|
-
const
|
|
59
|
-
const modifiedProps: Partial<BadgeProps> = {
|
|
60
|
-
[testedProp]: Theme.dark,
|
|
61
|
-
};
|
|
33
|
+
it('should render color', () => {
|
|
34
|
+
const { badge } = setup({ color: ColorPalette.red });
|
|
62
35
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
expect(badge).toHaveClassName(
|
|
66
|
-
getBasicClass({ prefix: CLASSNAME, type: testedProp, value: modifiedProps[testedProp] }),
|
|
67
|
-
);
|
|
68
|
-
expect(badge).not.toHaveClassName(
|
|
69
|
-
getBasicClass({ prefix: CLASSNAME, type: testedProp, value: DEFAULT_PROPS[testedProp] }),
|
|
70
|
-
);
|
|
36
|
+
expect(badge).toHaveClass('lumx-badge--color-red');
|
|
71
37
|
});
|
|
72
38
|
});
|
|
73
39
|
|
|
74
|
-
// 3. Test events.
|
|
75
|
-
describe('Events', () => {
|
|
76
|
-
// Nothing to do here.
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
// 4. Test conditions (i.e. things that display or not in the UI based on props).
|
|
80
|
-
describe('Conditions', () => {
|
|
81
|
-
// Nothing to do here.
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// 5. Test state.
|
|
85
|
-
describe('State', () => {
|
|
86
|
-
// Nothing to do here.
|
|
87
|
-
});
|
|
88
|
-
|
|
89
40
|
// Common tests suite.
|
|
90
|
-
|
|
41
|
+
commonTestsSuiteRTL(setup, {
|
|
42
|
+
baseClassName: CLASSNAME,
|
|
43
|
+
forwardClassName: 'badge',
|
|
44
|
+
forwardAttributes: 'badge',
|
|
45
|
+
forwardRef: 'badge',
|
|
46
|
+
});
|
|
91
47
|
});
|