@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,8 +1,9 @@
|
|
|
1
1
|
import React, { createRef } from 'react';
|
|
2
|
-
import { mount, shallow } from 'enzyme';
|
|
3
|
-
import 'jest-enzyme';
|
|
4
|
-
import { commonTestsSuite } from '@lumx/react/testing/utils';
|
|
5
2
|
|
|
3
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
4
|
+
import { render } from '@testing-library/react';
|
|
5
|
+
|
|
6
|
+
import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
6
7
|
import { GenericBlock, GenericBlockProps } from '.';
|
|
7
8
|
|
|
8
9
|
const CLASSNAME = GenericBlock.className as string;
|
|
@@ -10,122 +11,121 @@ const CLASSNAME = GenericBlock.className as string;
|
|
|
10
11
|
/**
|
|
11
12
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
12
13
|
*/
|
|
13
|
-
const setup = (props: Partial<GenericBlockProps> = {}
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
14
|
+
const setup = (props: Partial<GenericBlockProps> = {}) => {
|
|
15
|
+
render(<GenericBlock {...(props as any)} />);
|
|
16
|
+
const genericBlock = getByClassName(document.body, CLASSNAME);
|
|
17
|
+
const figure = queryByClassName(genericBlock, 'lumx-generic-block__figure');
|
|
18
|
+
const content = queryByClassName(genericBlock, 'lumx-generic-block__content');
|
|
19
|
+
const actions = queryByClassName(genericBlock, 'lumx-generic-block__actions');
|
|
20
|
+
return { props, genericBlock, figure, content, actions };
|
|
17
21
|
};
|
|
18
22
|
|
|
19
23
|
describe(`<${GenericBlock.displayName}>`, () => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
</GenericBlock>,
|
|
24
|
+
describe('Props', () => {
|
|
25
|
+
it('should render content', () => {
|
|
26
|
+
const { genericBlock, content, figure, actions } = setup({ children: 'Content' });
|
|
27
|
+
expect(genericBlock).toBeInTheDocument();
|
|
28
|
+
expect(genericBlock.className).toMatchInlineSnapshot(
|
|
29
|
+
`"lumx-generic-block lumx-flex-box lumx-flex-box--orientation-horizontal lumx-flex-box--gap-big"`,
|
|
27
30
|
);
|
|
28
31
|
|
|
29
|
-
expect(
|
|
30
|
-
expect(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const content = wrapper.find('.lumx-generic-block__content');
|
|
36
|
-
expect(content).toHaveLength(1);
|
|
37
|
-
expect(content.prop('fillSpace')).toBe(true);
|
|
38
|
-
expect(content.prop('orientation')).toBe('vertical');
|
|
32
|
+
expect(content).toBeInTheDocument();
|
|
33
|
+
expect(content).toHaveTextContent('Content');
|
|
34
|
+
expect(content?.className).toMatchInlineSnapshot(
|
|
35
|
+
`"lumx-generic-block__content lumx-flex-box lumx-flex-box--orientation-vertical lumx-flex-box--fill-space"`,
|
|
36
|
+
);
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
expect(actions).
|
|
38
|
+
expect(figure).not.toBeInTheDocument();
|
|
39
|
+
expect(actions).not.toBeInTheDocument();
|
|
42
40
|
});
|
|
43
41
|
|
|
44
42
|
it('should forward vAlign & hAlign', () => {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
const { genericBlock, figure, content, actions } = setup({
|
|
44
|
+
children: 'Content',
|
|
45
|
+
figure: 'Figure',
|
|
46
|
+
actions: 'Actions',
|
|
47
|
+
vAlign: 'left',
|
|
48
|
+
hAlign: 'bottom',
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
expect(genericBlock?.className).toMatchInlineSnapshot(
|
|
52
|
+
`"lumx-generic-block lumx-flex-box lumx-flex-box--orientation-horizontal lumx-flex-box--v-align-left lumx-flex-box--h-align-bottom lumx-flex-box--gap-big"`,
|
|
53
|
+
);
|
|
54
|
+
expect(figure?.className).toMatchInlineSnapshot(
|
|
55
|
+
`"lumx-generic-block__figure lumx-flex-box lumx-flex-box--orientation-horizontal lumx-flex-box--v-align-left lumx-flex-box--h-align-bottom"`,
|
|
56
|
+
);
|
|
57
|
+
expect(content?.className).toMatchInlineSnapshot(
|
|
58
|
+
`"lumx-generic-block__content lumx-flex-box lumx-flex-box--orientation-vertical lumx-flex-box--v-align-left lumx-flex-box--h-align-bottom lumx-flex-box--fill-space"`,
|
|
59
|
+
);
|
|
60
|
+
expect(actions?.className).toMatchInlineSnapshot(
|
|
61
|
+
`"lumx-generic-block__actions lumx-flex-box lumx-flex-box--orientation-horizontal lumx-flex-box--v-align-left lumx-flex-box--h-align-bottom"`,
|
|
49
62
|
);
|
|
50
|
-
|
|
51
|
-
expect(wrapper.prop('vAlign')).toBe('left');
|
|
52
|
-
expect(wrapper.prop('hAlign')).toBe('bottom');
|
|
53
|
-
|
|
54
|
-
const figure = wrapper.find('.lumx-generic-block__figure');
|
|
55
|
-
expect(figure).toHaveLength(1);
|
|
56
|
-
expect(figure.prop('vAlign')).toBe('left');
|
|
57
|
-
expect(figure.prop('hAlign')).toBe('bottom');
|
|
58
|
-
|
|
59
|
-
const content = wrapper.find('.lumx-generic-block__content');
|
|
60
|
-
expect(content).toHaveLength(1);
|
|
61
|
-
expect(content.prop('vAlign')).toBe('left');
|
|
62
|
-
expect(content.prop('hAlign')).toBe('bottom');
|
|
63
|
-
|
|
64
|
-
const actions = wrapper.find('.lumx-generic-block__actions');
|
|
65
|
-
expect(actions).toHaveLength(1);
|
|
66
|
-
expect(actions.prop('vAlign')).toBe('left');
|
|
67
|
-
expect(actions.prop('hAlign')).toBe('bottom');
|
|
68
63
|
});
|
|
69
64
|
|
|
70
65
|
it('should combine figure props', () => {
|
|
71
|
-
const
|
|
72
|
-
|
|
66
|
+
const { figure, content, actions } = setup({
|
|
67
|
+
figure: 'Figure 1',
|
|
68
|
+
figureProps: { className: 'figure1', vAlign: 'left' },
|
|
69
|
+
children: (
|
|
73
70
|
<GenericBlock.Figure className="figure2" fillSpace>
|
|
74
71
|
Figure 2
|
|
75
72
|
</GenericBlock.Figure>
|
|
76
|
-
|
|
77
|
-
);
|
|
73
|
+
),
|
|
74
|
+
});
|
|
78
75
|
|
|
79
|
-
|
|
80
|
-
expect(figure).
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
expect(figure).
|
|
76
|
+
// Merged class names
|
|
77
|
+
expect(figure?.className).toMatchInlineSnapshot(
|
|
78
|
+
`"figure1 figure2 lumx-generic-block__figure lumx-flex-box lumx-flex-box--orientation-horizontal lumx-flex-box--v-align-left lumx-flex-box--fill-space"`,
|
|
79
|
+
);
|
|
80
|
+
// Merged content
|
|
81
|
+
expect(figure).toHaveTextContent('Figure 1Figure 2');
|
|
85
82
|
|
|
86
|
-
expect(
|
|
87
|
-
expect(
|
|
83
|
+
expect(content).not.toBeInTheDocument();
|
|
84
|
+
expect(actions).not.toBeInTheDocument();
|
|
88
85
|
});
|
|
89
86
|
|
|
90
87
|
it('should combine content props', () => {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
Content 1
|
|
94
|
-
<GenericBlock.Content className="content2" fillSpace>
|
|
88
|
+
const { figure, content, actions } = setup({
|
|
89
|
+
children: [
|
|
90
|
+
'Content 1',
|
|
91
|
+
<GenericBlock.Content key="content" className="content2" fillSpace>
|
|
95
92
|
Content 2
|
|
96
|
-
</GenericBlock.Content
|
|
97
|
-
|
|
93
|
+
</GenericBlock.Content>,
|
|
94
|
+
],
|
|
95
|
+
contentProps: { className: 'content1', vAlign: 'left' },
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Merged class names
|
|
99
|
+
expect(content?.className).toMatchInlineSnapshot(
|
|
100
|
+
`"content1 content2 lumx-generic-block__content lumx-flex-box lumx-flex-box--orientation-vertical lumx-flex-box--v-align-left lumx-flex-box--fill-space"`,
|
|
98
101
|
);
|
|
102
|
+
// Merged content
|
|
103
|
+
expect(content).toHaveTextContent('Content 2Content 1');
|
|
99
104
|
|
|
100
|
-
|
|
101
|
-
expect(
|
|
102
|
-
expect(content).toHaveClassName('content2');
|
|
103
|
-
expect(content.prop('fillSpace')).toBe(true);
|
|
104
|
-
expect(content.prop('vAlign')).toBe('left');
|
|
105
|
-
expect(content).toHaveText('Content 2Content 1');
|
|
106
|
-
|
|
107
|
-
expect(wrapper.find('.lumx-generic-block__figure')).toHaveLength(0);
|
|
108
|
-
expect(wrapper.find('.lumx-generic-block__actions')).toHaveLength(0);
|
|
105
|
+
expect(figure).not.toBeInTheDocument();
|
|
106
|
+
expect(actions).not.toBeInTheDocument();
|
|
109
107
|
});
|
|
110
108
|
|
|
111
109
|
it('should combine actions props', () => {
|
|
112
|
-
const
|
|
113
|
-
|
|
110
|
+
const { figure, content, actions } = setup({
|
|
111
|
+
actions: 'Actions 1',
|
|
112
|
+
actionsProps: { className: 'actions1', vAlign: 'left' },
|
|
113
|
+
children: (
|
|
114
114
|
<GenericBlock.Actions className="actions2" fillSpace>
|
|
115
115
|
Actions 2
|
|
116
116
|
</GenericBlock.Actions>
|
|
117
|
-
|
|
118
|
-
);
|
|
117
|
+
),
|
|
118
|
+
});
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
expect(actions).
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
expect(actions).
|
|
120
|
+
// Merged class names
|
|
121
|
+
expect(actions?.className).toMatchInlineSnapshot(
|
|
122
|
+
`"actions1 actions2 lumx-generic-block__actions lumx-flex-box lumx-flex-box--orientation-horizontal lumx-flex-box--v-align-left lumx-flex-box--fill-space"`,
|
|
123
|
+
);
|
|
124
|
+
// Merged content
|
|
125
|
+
expect(actions).toHaveTextContent('Actions 1Actions 2');
|
|
126
126
|
|
|
127
|
-
expect(
|
|
128
|
-
expect(
|
|
127
|
+
expect(content).not.toBeInTheDocument();
|
|
128
|
+
expect(figure).not.toBeInTheDocument();
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
it('should forward refs', () => {
|
|
@@ -133,7 +133,7 @@ describe(`<${GenericBlock.displayName}>`, () => {
|
|
|
133
133
|
const figureRef = createRef<HTMLDivElement>();
|
|
134
134
|
const contentRef = createRef<HTMLDivElement>();
|
|
135
135
|
const actionsRef = createRef<HTMLDivElement>();
|
|
136
|
-
|
|
136
|
+
render(
|
|
137
137
|
<GenericBlock ref={rootRef}>
|
|
138
138
|
<GenericBlock.Figure ref={figureRef} />
|
|
139
139
|
<GenericBlock.Content ref={contentRef} />
|
|
@@ -148,5 +148,9 @@ describe(`<${GenericBlock.displayName}>`, () => {
|
|
|
148
148
|
});
|
|
149
149
|
|
|
150
150
|
// Common tests suite.
|
|
151
|
-
|
|
151
|
+
commonTestsSuiteRTL(setup, {
|
|
152
|
+
baseClassName: CLASSNAME,
|
|
153
|
+
forwardClassName: 'genericBlock',
|
|
154
|
+
forwardAttributes: 'genericBlock',
|
|
155
|
+
});
|
|
152
156
|
});
|
|
@@ -14,7 +14,7 @@ const gapSizes: Array<GridColumnProps['gap']> = [Size.tiny, Size.regular, Size.b
|
|
|
14
14
|
const getItems = (nb: number) =>
|
|
15
15
|
range(nb).map((key) => (
|
|
16
16
|
// eslint-disable-next-line react/jsx-key
|
|
17
|
-
<div style={genericBlockStyle}>
|
|
17
|
+
<div key={key} style={genericBlockStyle}>
|
|
18
18
|
<h2>Column {key}</h2>
|
|
19
19
|
<p>{loremIpsum('tiny')}</p>
|
|
20
20
|
</div>
|
|
@@ -26,7 +26,7 @@ export default {
|
|
|
26
26
|
argTypes: {
|
|
27
27
|
nbItems: { control: 'number', min: 0 },
|
|
28
28
|
gap: getSelectArgType(gapSizes),
|
|
29
|
-
itemMinWidth: { control: 'number'
|
|
29
|
+
itemMinWidth: { control: 'number' },
|
|
30
30
|
maxColumns: { control: 'number' },
|
|
31
31
|
},
|
|
32
32
|
args: GridColumn.defaultProps,
|
|
@@ -42,5 +42,5 @@ export const Default = {};
|
|
|
42
42
|
* Grid column with max 4 columns (responsive)
|
|
43
43
|
*/
|
|
44
44
|
export const Columns = {
|
|
45
|
-
args: { maxColumns: 4 },
|
|
45
|
+
args: { maxColumns: 4, itemMinWidth: 200 },
|
|
46
46
|
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import '
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { mdiCheck, mdiPlus } from '@lumx/icons';
|
|
8
|
-
import { ColorPalette, ColorVariant, Size } from '@lumx/react';
|
|
9
|
-
import { commonTestsSuite, Wrapper } from '@lumx/react/testing/utils';
|
|
10
|
-
import { getBasicClass } from '@lumx/react/utils/className';
|
|
3
|
+
import { mdiAlertCircle } from '@lumx/icons';
|
|
4
|
+
import { ColorPalette, ColorVariant, Size, Theme } from '@lumx/react';
|
|
5
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
11
6
|
|
|
7
|
+
import { getByClassName, getByTagName } from '@lumx/react/testing/utils/queries';
|
|
8
|
+
import { render } from '@testing-library/react';
|
|
12
9
|
import { Icon, IconProps } from './Icon';
|
|
13
10
|
|
|
14
11
|
const CLASSNAME = Icon.className as string;
|
|
@@ -18,85 +15,104 @@ type SetupProps = Partial<IconProps>;
|
|
|
18
15
|
/**
|
|
19
16
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
20
17
|
*/
|
|
21
|
-
const setup = (
|
|
18
|
+
const setup = (propsOverride: SetupProps = {}) => {
|
|
22
19
|
const props: IconProps = {
|
|
23
20
|
icon: 'mdiPlus',
|
|
24
21
|
...propsOverride,
|
|
25
22
|
};
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
svg: wrapper.find('svg'),
|
|
33
|
-
props,
|
|
34
|
-
wrapper,
|
|
35
|
-
};
|
|
23
|
+
render(<Icon {...props} />);
|
|
24
|
+
const i = getByClassName(document.body, CLASSNAME);
|
|
25
|
+
const svg = getByTagName(i, 'svg');
|
|
26
|
+
const path = getByTagName(svg, 'path');
|
|
27
|
+
|
|
28
|
+
return { i, svg, path, props };
|
|
36
29
|
};
|
|
37
30
|
|
|
38
31
|
describe(`<${Icon.displayName}>`, () => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const { i, path, svg, wrapper } = setup();
|
|
43
|
-
expect(wrapper).toMatchSnapshot();
|
|
32
|
+
describe('Props', () => {
|
|
33
|
+
it('should render default', () => {
|
|
34
|
+
const { i, svg, path, props } = setup();
|
|
44
35
|
|
|
45
|
-
expect(i).
|
|
46
|
-
expect(i).
|
|
36
|
+
expect(i).toBeInTheDocument();
|
|
37
|
+
expect(i).toHaveClass(CLASSNAME);
|
|
38
|
+
expect(i?.className).toMatchInlineSnapshot(`"lumx-icon lumx-icon--no-shape lumx-icon--path"`);
|
|
47
39
|
|
|
48
|
-
expect(svg).
|
|
49
|
-
expect(
|
|
50
|
-
|
|
40
|
+
expect(svg).toBeInTheDocument();
|
|
41
|
+
expect(svg).toHaveAttribute('aria-hidden', 'true');
|
|
42
|
+
expect(svg).not.toHaveAttribute('role');
|
|
51
43
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
expect(wrapper).toMatchSnapshot();
|
|
44
|
+
expect(path).toBeInTheDocument();
|
|
45
|
+
expect(path).toHaveAttribute('d', props.icon);
|
|
55
46
|
});
|
|
56
|
-
});
|
|
57
47
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
it('should adapt svg with alternate text', () => {
|
|
49
|
+
const { svg, props } = setup({ alt: 'Alternate text' });
|
|
50
|
+
expect(svg).toHaveAttribute('aria-label', props.alt);
|
|
51
|
+
expect(svg).not.toHaveAttribute('aria-hidden');
|
|
52
|
+
expect(svg).toHaveAttribute('role');
|
|
53
|
+
});
|
|
62
54
|
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
describe('size', () => {
|
|
56
|
+
it('should render size', () => {
|
|
57
|
+
const { i } = setup({ size: Size.s });
|
|
58
|
+
expect(i).toHaveClass('lumx-icon--size-s');
|
|
65
59
|
});
|
|
66
|
-
});
|
|
67
60
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
icon: oneOf(mdiPlus, mdiCheck),
|
|
72
|
-
size: oneOf(...Object.values(Size)),
|
|
61
|
+
it('should adapt xxs size with hasShape', () => {
|
|
62
|
+
const { i } = setup({ hasShape: true, size: Size.xxs });
|
|
63
|
+
expect(i).toHaveClass('lumx-icon--size-s');
|
|
73
64
|
});
|
|
74
65
|
|
|
75
|
-
|
|
66
|
+
it('should adapt xs size with hasShape', () => {
|
|
67
|
+
const { i } = setup({ hasShape: true, size: Size.xs });
|
|
68
|
+
expect(i).toHaveClass('lumx-icon--size-s');
|
|
69
|
+
});
|
|
76
70
|
|
|
77
|
-
|
|
71
|
+
it('should adapt xxl size with hasShape', () => {
|
|
72
|
+
const { i } = setup({ hasShape: true, size: Size.xxl });
|
|
73
|
+
expect(i).toHaveClass('lumx-icon--size-xl');
|
|
74
|
+
});
|
|
78
75
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
} else {
|
|
83
|
-
expect(i).toHaveClassName(
|
|
84
|
-
getBasicClass({ prefix: CLASSNAME, type: prop, value: modifiedProps[prop] }),
|
|
85
|
-
);
|
|
86
|
-
}
|
|
76
|
+
it('should add default size with hasShape', () => {
|
|
77
|
+
const { i } = setup({ hasShape: true });
|
|
78
|
+
expect(i).toHaveClass('lumx-icon--size-m');
|
|
87
79
|
});
|
|
88
80
|
});
|
|
89
|
-
});
|
|
90
81
|
|
|
91
|
-
|
|
92
|
-
|
|
82
|
+
describe('color', () => {
|
|
83
|
+
it('should render color and color variant', () => {
|
|
84
|
+
const { i } = setup({
|
|
85
|
+
color: ColorPalette.primary,
|
|
86
|
+
colorVariant: ColorVariant.D1,
|
|
87
|
+
});
|
|
88
|
+
expect(i).toHaveClass('lumx-icon--color-primary lumx-icon--color-variant-D1');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should improve yellow icon color contrast with alert circle icon', () => {
|
|
92
|
+
const { i } = setup({
|
|
93
|
+
color: ColorPalette.yellow,
|
|
94
|
+
icon: mdiAlertCircle,
|
|
95
|
+
});
|
|
96
|
+
expect(i).toHaveClass('lumx-icon--color-yellow lumx-icon--has-dark-layer');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should set a default color on dark theme', () => {
|
|
100
|
+
const { i } = setup({ theme: Theme.dark });
|
|
101
|
+
expect(i).toHaveClass('lumx-icon--color-light lumx-icon--theme-dark');
|
|
102
|
+
});
|
|
93
103
|
|
|
94
|
-
|
|
95
|
-
|
|
104
|
+
it('should set a default color on has shape', () => {
|
|
105
|
+
const { i } = setup({ hasShape: true });
|
|
106
|
+
expect(i).toHaveClass('lumx-icon--color-dark lumx-icon--has-shape');
|
|
107
|
+
});
|
|
96
108
|
|
|
97
|
-
|
|
98
|
-
|
|
109
|
+
it('should set a default color variant on has shape & dark color', () => {
|
|
110
|
+
const { i } = setup({ color: ColorPalette.dark, hasShape: true });
|
|
111
|
+
expect(i).toHaveClass('lumx-icon--color-variant-L2 lumx-icon--color-dark lumx-icon--has-shape');
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
99
115
|
|
|
100
116
|
// Common tests suite.
|
|
101
|
-
|
|
117
|
+
commonTestsSuiteRTL(setup, { baseClassName: CLASSNAME, forwardClassName: 'i', forwardAttributes: 'i' });
|
|
102
118
|
});
|
package/src/components/index.ts
CHANGED
|
@@ -146,8 +146,6 @@ export type Typography = TypographyInterface | TypographyCustom;
|
|
|
146
146
|
export const AspectRatio = {
|
|
147
147
|
/** Intrinsic content ratio. */
|
|
148
148
|
original: 'original',
|
|
149
|
-
/** Ratio 3:1 */
|
|
150
|
-
panoramic: 'panoramic',
|
|
151
149
|
/** Ratio 16:9 */
|
|
152
150
|
wide: 'wide',
|
|
153
151
|
/** Ratio 3:2 */
|
|
@@ -1,41 +1,54 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import '
|
|
5
|
-
|
|
6
|
-
import { commonTestsSuite } from '@lumx/react/testing/utils';
|
|
3
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
4
|
+
import { render, screen, within } from '@testing-library/react';
|
|
5
|
+
import { queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
7
6
|
import { InlineList, InlineListProps } from '.';
|
|
8
7
|
|
|
8
|
+
const CLASSNAME = InlineList.className as string;
|
|
9
|
+
|
|
9
10
|
const setup = (props: Partial<InlineListProps> = {}) => {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
render(<InlineList {...props} />);
|
|
12
|
+
const inlineList = queryByClassName(document.body, CLASSNAME);
|
|
13
|
+
return { props, inlineList };
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
describe(`<${InlineList.displayName}>`, () => {
|
|
15
17
|
describe('Snapshots and structure', () => {
|
|
16
18
|
it('should render default', () => {
|
|
17
|
-
const {
|
|
18
|
-
|
|
19
|
-
expect(
|
|
20
|
-
|
|
19
|
+
const { inlineList } = setup({ children: ['Some text', 'Some other text'] });
|
|
20
|
+
|
|
21
|
+
expect(inlineList).toBeInTheDocument();
|
|
22
|
+
|
|
23
|
+
const list = screen.getByRole('list');
|
|
24
|
+
expect(list).toBeInTheDocument();
|
|
25
|
+
|
|
26
|
+
const listItems = within(list).queryAllByRole('listitem');
|
|
27
|
+
expect(listItems.length).toBe(2);
|
|
28
|
+
expect(listItems[0]).toHaveTextContent('Some text');
|
|
29
|
+
expect(listItems[1]).toHaveTextContent('Some other text');
|
|
21
30
|
});
|
|
22
31
|
|
|
23
32
|
it('should render with typography', () => {
|
|
24
|
-
const {
|
|
25
|
-
expect(
|
|
33
|
+
const { inlineList } = setup({ typography: 'body2', children: 'Some text' });
|
|
34
|
+
expect(inlineList).toHaveClass('lumx-typography-body2');
|
|
26
35
|
});
|
|
27
36
|
|
|
28
37
|
it('should render with color', () => {
|
|
29
|
-
const {
|
|
30
|
-
expect(
|
|
38
|
+
const { inlineList } = setup({ color: 'blue', children: 'Some text' });
|
|
39
|
+
expect(inlineList).toHaveClass('lumx-color-font-blue-N');
|
|
31
40
|
});
|
|
32
41
|
|
|
33
42
|
it('should render with color and variant', () => {
|
|
34
|
-
const {
|
|
35
|
-
expect(
|
|
43
|
+
const { inlineList } = setup({ color: 'blue', colorVariant: 'D2', children: 'Some text' });
|
|
44
|
+
expect(inlineList).toHaveClass('lumx-color-font-blue-D2');
|
|
36
45
|
});
|
|
37
46
|
});
|
|
38
47
|
|
|
39
48
|
// Common tests suite.
|
|
40
|
-
|
|
49
|
+
commonTestsSuiteRTL(setup, {
|
|
50
|
+
baseClassName: CLASSNAME,
|
|
51
|
+
forwardClassName: 'inlineList',
|
|
52
|
+
forwardAttributes: 'inlineList',
|
|
53
|
+
});
|
|
41
54
|
});
|