@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,10 +1,11 @@
|
|
|
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
|
-
import {
|
|
4
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
7
5
|
import { getBasicClass } from '@lumx/react/utils/className';
|
|
6
|
+
import { render } from '@testing-library/react';
|
|
7
|
+
import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
8
|
+
import userEvent from '@testing-library/user-event';
|
|
8
9
|
import { Chip, ChipProps } from './Chip';
|
|
9
10
|
|
|
10
11
|
const CLASSNAME = Chip.className as string;
|
|
@@ -12,188 +13,137 @@ const CLASSNAME = Chip.className as string;
|
|
|
12
13
|
/**
|
|
13
14
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
14
15
|
*/
|
|
15
|
-
const setup = (propOverrides: Partial<ChipProps> = {}
|
|
16
|
+
const setup = (propOverrides: Partial<ChipProps> = {}) => {
|
|
16
17
|
const props = {
|
|
17
18
|
...propOverrides,
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
wrapper,
|
|
27
|
-
};
|
|
20
|
+
|
|
21
|
+
render(<Chip {...props} />);
|
|
22
|
+
const chip = getByClassName(document.body, CLASSNAME);
|
|
23
|
+
const before = queryByClassName(chip, `${CLASSNAME}__before`);
|
|
24
|
+
const after = queryByClassName(chip, `${CLASSNAME}__after`);
|
|
25
|
+
|
|
26
|
+
return { props, chip, before, after };
|
|
28
27
|
};
|
|
29
28
|
|
|
30
29
|
describe('<Chip />', () => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
expect(
|
|
30
|
+
describe('Props', () => {
|
|
31
|
+
it('should render default', () => {
|
|
32
|
+
const { chip } = setup({ children: 'Chip text' });
|
|
33
|
+
expect(chip).toBeInTheDocument();
|
|
34
|
+
expect(chip).toHaveTextContent('Chip text');
|
|
35
|
+
expect(chip.className).toMatchInlineSnapshot(
|
|
36
|
+
`"lumx-chip lumx-chip--color-dark lumx-chip--size-m lumx-chip--is-unselected"`,
|
|
37
|
+
);
|
|
36
38
|
});
|
|
37
|
-
});
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
it('should render dark theme', () => {
|
|
41
|
+
const { chip } = setup({ theme: Theme.dark });
|
|
42
|
+
expect(chip).toHaveClass('lumx-chip--color-light');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should render clickable', () => {
|
|
46
|
+
const onClick = jest.fn();
|
|
47
|
+
const { chip } = setup({ children: 'Chip text', onClick });
|
|
48
|
+
expect(chip).toHaveAttribute('role', 'button');
|
|
49
|
+
expect(chip.className).toMatchInlineSnapshot(
|
|
50
|
+
`"lumx-chip lumx-chip--is-clickable lumx-chip--color-dark lumx-chip--size-m lumx-chip--is-unselected"`,
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
41
54
|
|
|
42
|
-
// 3. Test events.
|
|
43
55
|
describe('Events', () => {
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
beforeEach(() => clearClickMocks);
|
|
55
|
-
|
|
56
|
-
it('should trigger onBeforeClick only when clicking on the "before" element', () => {
|
|
57
|
-
const { after, before, wrapper } = setup({
|
|
56
|
+
const onClick = jest.fn();
|
|
57
|
+
const onAfterClick = jest.fn();
|
|
58
|
+
const onBeforeClick = jest.fn();
|
|
59
|
+
|
|
60
|
+
beforeEach(jest.clearAllMocks);
|
|
61
|
+
|
|
62
|
+
it('should trigger onBeforeClick only when clicking on the "before" element', async () => {
|
|
63
|
+
const { after, before, chip } = setup({
|
|
58
64
|
after: 'after',
|
|
59
65
|
before: 'before',
|
|
60
|
-
onAfterClick
|
|
61
|
-
onBeforeClick
|
|
62
|
-
onClick
|
|
66
|
+
onAfterClick,
|
|
67
|
+
onBeforeClick,
|
|
68
|
+
onClick,
|
|
63
69
|
});
|
|
64
70
|
|
|
65
|
-
|
|
66
|
-
expect(
|
|
71
|
+
await userEvent.click(chip);
|
|
72
|
+
expect(onBeforeClick).not.toHaveBeenCalled();
|
|
67
73
|
|
|
68
|
-
|
|
74
|
+
jest.clearAllMocks();
|
|
69
75
|
|
|
70
|
-
|
|
71
|
-
expect(
|
|
76
|
+
await userEvent.click(after as any);
|
|
77
|
+
expect(onBeforeClick).not.toHaveBeenCalled();
|
|
72
78
|
|
|
73
|
-
|
|
79
|
+
jest.clearAllMocks();
|
|
74
80
|
|
|
75
|
-
|
|
76
|
-
expect(
|
|
81
|
+
await userEvent.click(before as any);
|
|
82
|
+
expect(onBeforeClick).toHaveBeenCalled();
|
|
77
83
|
});
|
|
78
84
|
|
|
79
|
-
it('should trigger onClick when clicking on the label area', () => {
|
|
80
|
-
const { after, before,
|
|
85
|
+
it('should trigger onClick when clicking on the label area', async () => {
|
|
86
|
+
const { after, before, chip } = setup({
|
|
81
87
|
after: 'after',
|
|
82
88
|
before: 'before',
|
|
83
|
-
onAfterClick
|
|
84
|
-
onBeforeClick
|
|
85
|
-
onClick
|
|
89
|
+
onAfterClick,
|
|
90
|
+
onBeforeClick,
|
|
91
|
+
onClick,
|
|
86
92
|
});
|
|
87
93
|
|
|
88
|
-
|
|
89
|
-
expect(
|
|
94
|
+
await userEvent.click(chip);
|
|
95
|
+
expect(onClick).toHaveBeenCalled();
|
|
90
96
|
|
|
91
|
-
|
|
97
|
+
jest.clearAllMocks();
|
|
92
98
|
|
|
93
|
-
|
|
94
|
-
expect(
|
|
99
|
+
await userEvent.click(after as any);
|
|
100
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
95
101
|
|
|
96
|
-
|
|
102
|
+
jest.clearAllMocks();
|
|
97
103
|
|
|
98
|
-
|
|
99
|
-
expect(
|
|
104
|
+
await userEvent.click(before as any);
|
|
105
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
100
106
|
});
|
|
101
107
|
|
|
102
|
-
it('should trigger onAfterClick only when clicking on the "after" element', () => {
|
|
103
|
-
const { after, before,
|
|
108
|
+
it('should trigger onAfterClick only when clicking on the "after" element', async () => {
|
|
109
|
+
const { after, before, chip } = setup({
|
|
104
110
|
after: 'after',
|
|
105
111
|
before: 'before',
|
|
106
|
-
onAfterClick
|
|
107
|
-
onBeforeClick
|
|
108
|
-
onClick
|
|
112
|
+
onAfterClick,
|
|
113
|
+
onBeforeClick,
|
|
114
|
+
onClick,
|
|
109
115
|
});
|
|
110
116
|
|
|
111
|
-
|
|
112
|
-
expect(
|
|
117
|
+
await userEvent.click(chip);
|
|
118
|
+
expect(onAfterClick).not.toHaveBeenCalled();
|
|
113
119
|
|
|
114
|
-
|
|
120
|
+
jest.clearAllMocks();
|
|
115
121
|
|
|
116
|
-
|
|
117
|
-
expect(
|
|
122
|
+
await userEvent.click(after as any);
|
|
123
|
+
expect(onAfterClick).toHaveBeenCalled();
|
|
118
124
|
|
|
119
|
-
|
|
125
|
+
jest.clearAllMocks();
|
|
120
126
|
|
|
121
|
-
|
|
122
|
-
expect(
|
|
127
|
+
await userEvent.click(before as any);
|
|
128
|
+
expect(onAfterClick).not.toHaveBeenCalled();
|
|
123
129
|
});
|
|
124
130
|
|
|
125
|
-
it('should not stop propagation when clicking on a "before"or "after" element without an event handler', () => {
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
onClick,
|
|
132
|
-
},
|
|
133
|
-
false,
|
|
134
|
-
);
|
|
131
|
+
it('should not stop propagation when clicking on a "before" or "after" element without an event handler', async () => {
|
|
132
|
+
const { after, before } = setup({
|
|
133
|
+
after: 'after',
|
|
134
|
+
before: 'before',
|
|
135
|
+
onClick,
|
|
136
|
+
});
|
|
135
137
|
|
|
136
|
-
|
|
138
|
+
await userEvent.click(before as any);
|
|
137
139
|
expect(onClick).toHaveBeenCalled();
|
|
138
140
|
|
|
139
141
|
onClick.mockClear();
|
|
140
142
|
|
|
141
|
-
|
|
143
|
+
await userEvent.click(after as any);
|
|
142
144
|
expect(onClick).toHaveBeenCalled();
|
|
143
145
|
});
|
|
144
146
|
});
|
|
145
147
|
|
|
146
|
-
|
|
147
|
-
describe('Conditions', () => {
|
|
148
|
-
it('should have an extra class on the "before" element if it is clickable', () => {
|
|
149
|
-
let { before } = setup({ before: 'before 1' });
|
|
150
|
-
expect(before).toHaveLength(1);
|
|
151
|
-
expect(before.hasClass('lumx-chip__before--is-clickable')).toEqual(false);
|
|
152
|
-
|
|
153
|
-
({ before } = setup({ before: 'before 2', onBeforeClick: (): boolean => true }));
|
|
154
|
-
expect(before).toHaveLength(1);
|
|
155
|
-
expect(before.hasClass('lumx-chip__before--is-clickable')).toEqual(true);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('should have an extra class on the "after" element if it is clickable', () => {
|
|
159
|
-
let { after } = setup({ after: 'after 1' });
|
|
160
|
-
expect(after).toHaveLength(1);
|
|
161
|
-
expect(after.hasClass('lumx-chip__after--is-clickable')).toEqual(false);
|
|
162
|
-
|
|
163
|
-
({ after } = setup({ after: 'after 2', onAfterClick: (): boolean => true }));
|
|
164
|
-
expect(after).toHaveLength(1);
|
|
165
|
-
expect(after.hasClass('lumx-chip__after--is-clickable')).toEqual(true);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('should have correct default color', () => {
|
|
169
|
-
const { wrapper } = setup({});
|
|
170
|
-
expect(wrapper).toHaveClassName(
|
|
171
|
-
getBasicClass({
|
|
172
|
-
prefix: CLASSNAME,
|
|
173
|
-
type: 'color',
|
|
174
|
-
value: ColorPalette.dark,
|
|
175
|
-
}),
|
|
176
|
-
);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('should switch color with theme', () => {
|
|
180
|
-
const { wrapper } = setup({ theme: Theme.dark });
|
|
181
|
-
expect(wrapper).toHaveClassName(
|
|
182
|
-
getBasicClass({
|
|
183
|
-
prefix: CLASSNAME,
|
|
184
|
-
type: 'color',
|
|
185
|
-
value: ColorPalette.light,
|
|
186
|
-
}),
|
|
187
|
-
);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('should use color over the theme', () => {
|
|
191
|
-
const color = ColorPalette.red;
|
|
192
|
-
const { wrapper } = setup({ theme: Theme.dark, color });
|
|
193
|
-
expect(wrapper).toHaveClassName(getBasicClass({ prefix: CLASSNAME, type: 'color', value: color }));
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
// 5. Test state.
|
|
198
|
-
// N/A.
|
|
148
|
+
commonTestsSuiteRTL(setup, { baseClassName: CLASSNAME, forwardClassName: 'chip', forwardAttributes: 'chip' });
|
|
199
149
|
});
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { shallow } from 'enzyme';
|
|
2
|
-
import 'jest-enzyme';
|
|
3
1
|
import React from 'react';
|
|
4
2
|
|
|
5
|
-
import {
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
import { getByClassName } from '@lumx/react/testing/utils/queries';
|
|
5
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
6
|
+
import { Alignment } from '@lumx/react';
|
|
6
7
|
import { ChipGroup, ChipGroupProps } from './ChipGroup';
|
|
8
|
+
import { Chip } from './Chip';
|
|
9
|
+
|
|
10
|
+
const CLASSNAME = ChipGroup.className as string;
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
@@ -13,17 +17,30 @@ const setup = (propOverrides: Partial<ChipGroupProps> = {}) => {
|
|
|
13
17
|
children: [<Chip key="1">Chip 1</Chip>, <Chip key="2">Chip 2</Chip>, <Chip key="3">Chip 3</Chip>],
|
|
14
18
|
...propOverrides,
|
|
15
19
|
};
|
|
16
|
-
|
|
20
|
+
render(<ChipGroup {...props} />);
|
|
21
|
+
const chipGroup = getByClassName(document.body, CLASSNAME);
|
|
17
22
|
|
|
18
|
-
return { props,
|
|
23
|
+
return { props, chipGroup };
|
|
19
24
|
};
|
|
20
25
|
|
|
21
26
|
describe('<ChipGroup />', () => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
expect(
|
|
27
|
+
describe('Props', () => {
|
|
28
|
+
it('should render default', () => {
|
|
29
|
+
const { chipGroup } = setup();
|
|
30
|
+
expect(chipGroup).toBeInTheDocument();
|
|
31
|
+
expect(chipGroup).toHaveClass(CLASSNAME);
|
|
32
|
+
expect(chipGroup).toHaveClass(`${CLASSNAME}--align-left`);
|
|
27
33
|
});
|
|
34
|
+
|
|
35
|
+
it('should render with align', () => {
|
|
36
|
+
const { chipGroup } = setup({ align: Alignment.right });
|
|
37
|
+
expect(chipGroup).toHaveClass(`${CLASSNAME}--align-right`);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
commonTestsSuiteRTL(setup, {
|
|
42
|
+
baseClassName: CLASSNAME,
|
|
43
|
+
forwardClassName: 'chipGroup',
|
|
44
|
+
forwardAttributes: 'chipGroup',
|
|
28
45
|
});
|
|
29
46
|
});
|
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { mount, shallow } from 'enzyme';
|
|
4
|
-
import 'jest-enzyme';
|
|
5
|
-
|
|
6
|
-
import { Wrapper } from '@lumx/react/testing/utils';
|
|
7
3
|
import { DatePickerProps } from '@lumx/react';
|
|
8
|
-
import {
|
|
4
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
5
|
+
import { getByClassName } from '@lumx/react/testing/utils/queries';
|
|
6
|
+
import { render } from '@testing-library/react';
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
timeZone: 'America/Toronto',
|
|
13
|
-
}),
|
|
14
|
-
);
|
|
15
|
-
Date.now = jest.fn(() => mockedDate.valueOf());
|
|
8
|
+
import { DatePicker } from '.';
|
|
9
|
+
import { CLASSNAME } from './constants';
|
|
16
10
|
|
|
17
|
-
|
|
11
|
+
const mockedDate = new Date(1487721600000);
|
|
12
|
+
Date.now = jest.fn(() => mockedDate.valueOf());
|
|
18
13
|
|
|
19
|
-
const setup = (
|
|
14
|
+
const setup = (propsOverride: Partial<DatePickerProps> = {}) => {
|
|
20
15
|
const props: DatePickerProps = {
|
|
21
16
|
locale: 'fr',
|
|
22
17
|
onChange: jest.fn(),
|
|
@@ -25,17 +20,14 @@ const setup = ({ ...propsOverride }: SetupProps = {}, shallowRendering = true) =
|
|
|
25
20
|
previousButtonProps: { label: 'Previous month' },
|
|
26
21
|
...propsOverride,
|
|
27
22
|
};
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
return { props, wrapper };
|
|
23
|
+
render(<DatePicker {...props} />);
|
|
24
|
+
const datePicker = getByClassName(document.body, CLASSNAME);
|
|
25
|
+
return { props, datePicker };
|
|
32
26
|
};
|
|
33
27
|
|
|
34
28
|
describe(`<${DatePicker.displayName}>`, () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
expect(wrapper).toMatchSnapshot();
|
|
39
|
-
});
|
|
29
|
+
commonTestsSuiteRTL(setup, {
|
|
30
|
+
baseClassName: CLASSNAME,
|
|
31
|
+
forwardRef: 'datePicker',
|
|
40
32
|
});
|
|
41
33
|
});
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import '
|
|
5
|
-
|
|
6
|
-
import { Wrapper } from '@lumx/react/testing/utils';
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
5
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
7
6
|
|
|
8
7
|
import { DatePickerControlled, DatePickerControlledProps } from './DatePickerControlled';
|
|
8
|
+
import { CLASSNAME } from './constants';
|
|
9
9
|
|
|
10
|
-
const mockedDate = new Date(
|
|
11
|
-
new Date(1487721600).toLocaleString('en-US', {
|
|
12
|
-
timeZone: 'America/Toronto',
|
|
13
|
-
}),
|
|
14
|
-
);
|
|
10
|
+
const mockedDate = new Date(1487721600000);
|
|
15
11
|
Date.now = jest.fn(() => mockedDate.valueOf());
|
|
16
12
|
|
|
17
13
|
type SetupProps = Partial<DatePickerControlledProps>;
|
|
18
14
|
|
|
19
|
-
const setup = (
|
|
15
|
+
const setup = (propsOverride: SetupProps = {}) => {
|
|
20
16
|
const props: DatePickerControlledProps = {
|
|
21
17
|
locale: 'fr',
|
|
22
18
|
onChange: jest.fn(),
|
|
@@ -28,17 +24,25 @@ const setup = ({ ...propsOverride }: SetupProps = {}, shallowRendering = true) =
|
|
|
28
24
|
previousButtonProps: { label: 'Previous month' },
|
|
29
25
|
...propsOverride,
|
|
30
26
|
};
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
return { props, wrapper };
|
|
27
|
+
render(<DatePickerControlled {...props} />);
|
|
28
|
+
const datePickerControlled = getByClassName(document.body, CLASSNAME);
|
|
29
|
+
return { props, datePickerControlled };
|
|
35
30
|
};
|
|
36
31
|
|
|
37
32
|
describe(`<${DatePickerControlled.displayName}>`, () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
33
|
+
it('should render', () => {
|
|
34
|
+
const { datePickerControlled } = setup();
|
|
35
|
+
expect(datePickerControlled).toBeInTheDocument();
|
|
36
|
+
|
|
37
|
+
const month = queryByClassName(datePickerControlled, `${CLASSNAME}__month`);
|
|
38
|
+
expect(month).toHaveTextContent('février 2017');
|
|
39
|
+
|
|
40
|
+
const selected = queryByClassName(datePickerControlled, `${CLASSNAME}__month-day--is-selected`);
|
|
41
|
+
expect(selected).toBe(screen.queryByRole('button', { name: '22' }));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
commonTestsSuiteRTL(setup, {
|
|
45
|
+
baseClassName: CLASSNAME,
|
|
46
|
+
forwardRef: 'datePickerControlled',
|
|
43
47
|
});
|
|
44
48
|
});
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import '
|
|
5
|
-
|
|
6
|
-
import {
|
|
3
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
|
+
import { getByClassName, getByTagName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
6
|
+
import { TextField } from '@lumx/react';
|
|
7
7
|
|
|
8
|
+
import userEvent from '@testing-library/user-event';
|
|
8
9
|
import { DatePickerField, DatePickerFieldProps } from './DatePickerField';
|
|
10
|
+
import { CLASSNAME } from './constants';
|
|
9
11
|
|
|
10
|
-
const mockedDate = new Date(
|
|
11
|
-
new Date(1487721600).toLocaleString('en-US', {
|
|
12
|
-
timeZone: 'America/Toronto',
|
|
13
|
-
}),
|
|
14
|
-
);
|
|
12
|
+
const mockedDate = new Date(1487721600000);
|
|
15
13
|
Date.now = jest.fn(() => mockedDate.valueOf());
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const setup = ({ ...propsOverride }: SetupProps = {}, shallowRendering = true) => {
|
|
15
|
+
const setup = (propsOverride: Partial<DatePickerFieldProps> = {}) => {
|
|
20
16
|
const props: DatePickerFieldProps = {
|
|
21
17
|
label: 'DatePickerField',
|
|
22
18
|
locale: 'fr',
|
|
@@ -26,22 +22,42 @@ const setup = ({ ...propsOverride }: SetupProps = {}, shallowRendering = true) =
|
|
|
26
22
|
previousButtonProps: { label: 'Previous month' },
|
|
27
23
|
...propsOverride,
|
|
28
24
|
};
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
render(<DatePickerField {...props} />);
|
|
26
|
+
const textField = getByClassName(document.body, TextField.className as string);
|
|
27
|
+
const inputNative = getByTagName(textField, 'input');
|
|
28
|
+
const getDatePicker = () => queryByClassName(document.body, CLASSNAME);
|
|
29
|
+
return { props, textField, inputNative, getDatePicker };
|
|
33
30
|
};
|
|
34
31
|
|
|
35
32
|
describe(`<${DatePickerField.displayName}>`, () => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
it('should render', () => {
|
|
34
|
+
const { inputNative, props } = setup();
|
|
35
|
+
expect(inputNative).toBe(screen.queryByRole('textbox', { name: props.label }));
|
|
36
|
+
expect(inputNative).toHaveValue('22 février 2017');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should open on click', async () => {
|
|
40
|
+
const { getDatePicker, inputNative } = setup();
|
|
41
|
+
expect(getDatePicker()).not.toBeInTheDocument();
|
|
42
|
+
|
|
43
|
+
await userEvent.click(inputNative);
|
|
44
|
+
expect(getDatePicker()).toBeInTheDocument();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should open on Enter pressed', async () => {
|
|
48
|
+
const { getDatePicker, inputNative } = setup();
|
|
49
|
+
expect(getDatePicker()).not.toBeInTheDocument();
|
|
50
|
+
|
|
51
|
+
await userEvent.tab();
|
|
52
|
+
expect(inputNative).toHaveFocus();
|
|
53
|
+
await userEvent.keyboard('[Enter]');
|
|
54
|
+
expect(getDatePicker()).toBeInTheDocument();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
commonTestsSuiteRTL(setup, {
|
|
58
|
+
baseClassName: TextField.className as string,
|
|
59
|
+
forwardRef: 'textField',
|
|
60
|
+
forwardAttributes: 'inputNative',
|
|
61
|
+
forwardClassName: 'textField',
|
|
46
62
|
});
|
|
47
63
|
});
|