@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.
Files changed (117) hide show
  1. package/_internal/ClickAwayProvider.js.map +1 -1
  2. package/_internal/types.d.ts +0 -2
  3. package/index.d.ts +2 -0
  4. package/index.js +347 -75
  5. package/index.js.map +1 -1
  6. package/package.json +23 -19
  7. package/src/components/autocomplete/Autocomplete.test.tsx +55 -142
  8. package/src/components/autocomplete/AutocompleteMultiple.test.tsx +37 -75
  9. package/src/components/autocomplete/__mockData__/index.ts +6 -1
  10. package/src/components/badge/Badge.test.tsx +20 -64
  11. package/src/components/button/Button.test.tsx +44 -121
  12. package/src/components/button/ButtonGroup.test.tsx +16 -39
  13. package/src/components/button/IconButton.stories.tsx +7 -0
  14. package/src/components/button/IconButton.test.tsx +37 -78
  15. package/src/components/button/IconButton.tsx +8 -1
  16. package/src/components/checkbox/Checkbox.test.tsx +62 -67
  17. package/src/components/chip/Chip.test.tsx +89 -139
  18. package/src/components/chip/ChipGroup.test.tsx +27 -10
  19. package/src/components/date-picker/DatePicker.test.tsx +15 -23
  20. package/src/components/date-picker/DatePickerControlled.test.tsx +24 -20
  21. package/src/components/date-picker/DatePickerField.test.tsx +43 -27
  22. package/src/components/dialog/Dialog.test.tsx +36 -35
  23. package/src/components/divider/Divider.test.tsx +23 -69
  24. package/src/components/dropdown/Dropdown.test.tsx +30 -61
  25. package/src/components/expansion-panel/ExpansionPanel.test.tsx +12 -8
  26. package/src/components/flag/Flag.test.tsx +28 -53
  27. package/src/components/generic-block/GenericBlock.test.tsx +93 -89
  28. package/src/components/grid-column/GridColumn.stories.tsx +3 -3
  29. package/src/components/icon/Icon.test.tsx +80 -64
  30. package/src/components/index.ts +0 -2
  31. package/src/components/inline-list/InlineList.test.tsx +30 -17
  32. package/src/components/input-helper/InputHelper.test.tsx +21 -81
  33. package/src/components/input-label/InputLabel.test.tsx +19 -61
  34. package/src/components/lightbox/Lightbox.test.tsx +3 -2
  35. package/src/components/link/Link.test.tsx +47 -31
  36. package/src/components/link-preview/LinkPreview.test.tsx +51 -51
  37. package/src/components/message/Message.test.tsx +31 -52
  38. package/src/components/mosaic/Mosaic.test.tsx +56 -72
  39. package/src/components/notification/Notification.test.tsx +51 -82
  40. package/src/components/popover/Popover.tsx +7 -9
  41. package/src/components/progress-tracker/ProgressTracker.test.tsx +20 -33
  42. package/src/components/progress-tracker/ProgressTrackerProvider.test.tsx +61 -36
  43. package/src/components/progress-tracker/ProgressTrackerStep.test.tsx +19 -109
  44. package/src/components/progress-tracker/ProgressTrackerStepPanel.test.tsx +21 -58
  45. package/src/components/progress-tracker/ProgressTrackerStepPanel.tsx +1 -1
  46. package/src/components/radio-button/RadioButton.test.tsx +78 -92
  47. package/src/components/radio-button/RadioGroup.test.tsx +13 -59
  48. package/src/components/select/Select.test.tsx +115 -284
  49. package/src/components/select/SelectMultiple.stories.tsx +105 -2
  50. package/src/components/select/SelectMultiple.test.tsx +126 -322
  51. package/src/components/select/WithSelectContext.tsx +10 -4
  52. package/src/components/side-navigation/SideNavigation.test.tsx +22 -35
  53. package/src/components/side-navigation/SideNavigationItem.test.tsx +72 -139
  54. package/src/components/switch/Switch.test.tsx +70 -149
  55. package/src/components/table/Table.test.tsx +2 -0
  56. package/src/components/table/TableBody.test.tsx +18 -8
  57. package/src/components/table/TableCell.test.tsx +34 -9
  58. package/src/components/table/TableHeader.test.tsx +18 -8
  59. package/src/components/table/TableRow.test.tsx +28 -8
  60. package/src/components/tabs/Tab.test.tsx +27 -96
  61. package/src/components/tabs/TabList.test.tsx +21 -56
  62. package/src/components/tabs/TabPanel.test.tsx +20 -55
  63. package/src/components/tabs/TabPanel.tsx +1 -1
  64. package/src/components/tabs/TabProvider.test.tsx +158 -37
  65. package/src/components/tabs/test-utils.ts +39 -0
  66. package/src/components/text-field/TextField.stories.tsx +14 -5
  67. package/src/components/text-field/TextField.test.tsx +54 -8
  68. package/src/components/text-field/TextField.tsx +49 -5
  69. package/src/components/tooltip/Tooltip.test.tsx +134 -75
  70. package/src/components/tooltip/useInjectTooltipRef.tsx +9 -2
  71. package/src/components/uploader/Uploader.test.tsx +60 -48
  72. package/src/components/user-block/UserBlock.test.tsx +69 -13
  73. package/src/hooks/useFocusTrap.ts +2 -2
  74. package/src/testing/utils/commonTestsSuiteRTL.ts +18 -8
  75. package/src/testing/utils/index.ts +0 -1
  76. package/src/utils/flattenChildren.ts +5 -0
  77. package/src/components/autocomplete/__snapshots__/Autocomplete.test.tsx.snap +0 -213
  78. package/src/components/autocomplete/__snapshots__/AutocompleteMultiple.test.tsx.snap +0 -88
  79. package/src/components/badge/__snapshots__/Badge.test.tsx.snap +0 -11
  80. package/src/components/button/ButtonRoot.test.tsx +0 -203
  81. package/src/components/button/__snapshots__/Button.test.tsx.snap +0 -96
  82. package/src/components/button/__snapshots__/ButtonGroup.test.tsx.snap +0 -22
  83. package/src/components/button/__snapshots__/ButtonRoot.test.tsx.snap +0 -160
  84. package/src/components/button/__snapshots__/IconButton.test.tsx.snap +0 -83
  85. package/src/components/checkbox/__snapshots__/Checkbox.test.tsx.snap +0 -141
  86. package/src/components/chip/__snapshots__/Chip.test.tsx.snap +0 -12
  87. package/src/components/chip/__snapshots__/ChipGroup.test.tsx.snap +0 -29
  88. package/src/components/date-picker/__snapshots__/DatePicker.test.tsx.snap +0 -22
  89. package/src/components/date-picker/__snapshots__/DatePickerControlled.test.tsx.snap +0 -597
  90. package/src/components/date-picker/__snapshots__/DatePickerField.test.tsx.snap +0 -43
  91. package/src/components/divider/__snapshots__/Divider.test.tsx.snap +0 -9
  92. package/src/components/dropdown/__snapshots__/Dropdown.test.tsx.snap +0 -35
  93. package/src/components/icon/__snapshots__/Icon.test.tsx.snap +0 -49
  94. package/src/components/input-helper/__snapshots__/InputHelper.test.tsx.snap +0 -9
  95. package/src/components/input-label/__snapshots__/InputLabel.test.tsx.snap +0 -10
  96. package/src/components/link/__snapshots__/Link.test.tsx.snap +0 -29
  97. package/src/components/message/__snapshots__/Message.test.tsx.snap +0 -15
  98. package/src/components/notification/__snapshots__/Notification.test.tsx.snap +0 -34
  99. package/src/components/progress-tracker/__snapshots__/ProgressTracker.test.tsx.snap +0 -41
  100. package/src/components/progress-tracker/__snapshots__/ProgressTrackerStep.test.tsx.snap +0 -141
  101. package/src/components/progress-tracker/__snapshots__/ProgressTrackerStepPanel.test.tsx.snap +0 -25
  102. package/src/components/radio-button/__snapshots__/RadioButton.test.tsx.snap +0 -113
  103. package/src/components/radio-button/__snapshots__/RadioGroup.test.tsx.snap +0 -26
  104. package/src/components/select/__snapshots__/Select.test.tsx.snap +0 -43
  105. package/src/components/select/__snapshots__/SelectMultiple.test.tsx.snap +0 -87
  106. package/src/components/side-navigation/__snapshots__/SideNavigation.test.tsx.snap +0 -7
  107. package/src/components/side-navigation/__snapshots__/SideNavigationItem.test.tsx.snap +0 -30
  108. package/src/components/switch/__snapshots__/Switch.test.tsx.snap +0 -179
  109. package/src/components/tabs/__snapshots__/Tab.test.tsx.snap +0 -62
  110. package/src/components/tabs/__snapshots__/TabList.test.tsx.snap +0 -22
  111. package/src/components/tabs/__snapshots__/TabPanel.test.tsx.snap +0 -25
  112. package/src/components/tabs/test.mocks.ts +0 -33
  113. package/src/components/text-field/__snapshots__/TextField.test.tsx.snap +0 -42
  114. package/src/components/tooltip/__snapshots__/Tooltip.test.tsx.snap +0 -233
  115. package/src/components/uploader/__snapshots__/Uploader.test.tsx.snap +0 -14
  116. package/src/testing/utils/commonTestsSuite.ts +0 -71
  117. package/src/utils/flattenChildren.test.tsx +0 -58
@@ -1,10 +1,11 @@
1
- import { mount, shallow } from 'enzyme';
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 { Wrapper } from '@lumx/react/testing/utils';
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> = {}, shallowRendering = true) => {
16
+ const setup = (propOverrides: Partial<ChipProps> = {}) => {
16
17
  const props = {
17
18
  ...propOverrides,
18
19
  };
19
- const renderer: (el: ReactElement) => Wrapper = shallowRendering ? shallow : mount;
20
- const wrapper = renderer(<Chip {...props} />);
21
-
22
- return {
23
- after: wrapper.find('.lumx-chip__after') as any,
24
- before: wrapper.find('.lumx-chip__before') as any,
25
- props,
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
- // 1. Test render via snapshot (default state of component).
32
- describe('Snapshot', () => {
33
- it('should render correctly Chip component', () => {
34
- const { wrapper } = setup();
35
- expect(wrapper).toMatchSnapshot();
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
- // 2. Test defaultProps value and important props custom values.
40
- // N/A.
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 mockOnClick = jest.fn();
45
- const mockOnAfterClick = jest.fn();
46
- const mockOnBeforeClick = jest.fn();
47
- const mockClickEvent = {
48
- stopPropagation: (): boolean => true,
49
- };
50
- const clearClickMocks = () => {
51
- [mockOnClick, mockOnAfterClick, mockOnBeforeClick].forEach((func) => func.mockClear());
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: mockOnAfterClick,
61
- onBeforeClick: mockOnBeforeClick,
62
- onClick: mockOnClick,
66
+ onAfterClick,
67
+ onBeforeClick,
68
+ onClick,
63
69
  });
64
70
 
65
- wrapper.simulate('click', mockClickEvent);
66
- expect(mockOnBeforeClick).not.toHaveBeenCalled();
71
+ await userEvent.click(chip);
72
+ expect(onBeforeClick).not.toHaveBeenCalled();
67
73
 
68
- clearClickMocks();
74
+ jest.clearAllMocks();
69
75
 
70
- after.simulate('click', mockClickEvent);
71
- expect(mockOnBeforeClick).not.toHaveBeenCalled();
76
+ await userEvent.click(after as any);
77
+ expect(onBeforeClick).not.toHaveBeenCalled();
72
78
 
73
- clearClickMocks();
79
+ jest.clearAllMocks();
74
80
 
75
- before.simulate('click', mockClickEvent);
76
- expect(mockOnBeforeClick).toHaveBeenCalled();
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, wrapper } = setup({
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: mockOnAfterClick,
84
- onBeforeClick: mockOnBeforeClick,
85
- onClick: mockOnClick,
89
+ onAfterClick,
90
+ onBeforeClick,
91
+ onClick,
86
92
  });
87
93
 
88
- wrapper.simulate('click');
89
- expect(mockOnClick).toHaveBeenCalled();
94
+ await userEvent.click(chip);
95
+ expect(onClick).toHaveBeenCalled();
90
96
 
91
- clearClickMocks();
97
+ jest.clearAllMocks();
92
98
 
93
- after.simulate('click');
94
- expect(mockOnClick).not.toHaveBeenCalled();
99
+ await userEvent.click(after as any);
100
+ expect(onClick).not.toHaveBeenCalled();
95
101
 
96
- clearClickMocks();
102
+ jest.clearAllMocks();
97
103
 
98
- before.simulate('click');
99
- expect(mockOnClick).not.toHaveBeenCalled();
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, wrapper } = setup({
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: mockOnAfterClick,
107
- onBeforeClick: mockOnBeforeClick,
108
- onClick: mockOnClick,
112
+ onAfterClick,
113
+ onBeforeClick,
114
+ onClick,
109
115
  });
110
116
 
111
- wrapper.simulate('click', mockClickEvent);
112
- expect(mockOnAfterClick).not.toHaveBeenCalled();
117
+ await userEvent.click(chip);
118
+ expect(onAfterClick).not.toHaveBeenCalled();
113
119
 
114
- clearClickMocks();
120
+ jest.clearAllMocks();
115
121
 
116
- after.simulate('click', mockClickEvent);
117
- expect(mockOnAfterClick).toHaveBeenCalled();
122
+ await userEvent.click(after as any);
123
+ expect(onAfterClick).toHaveBeenCalled();
118
124
 
119
- clearClickMocks();
125
+ jest.clearAllMocks();
120
126
 
121
- before.simulate('click', mockClickEvent);
122
- expect(mockOnAfterClick).not.toHaveBeenCalled();
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 onClick = jest.fn();
127
- const { after, before } = setup(
128
- {
129
- after: 'after',
130
- before: 'before',
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
- before.simulate('click', mockClickEvent);
138
+ await userEvent.click(before as any);
137
139
  expect(onClick).toHaveBeenCalled();
138
140
 
139
141
  onClick.mockClear();
140
142
 
141
- after.simulate('click', mockClickEvent);
143
+ await userEvent.click(after as any);
142
144
  expect(onClick).toHaveBeenCalled();
143
145
  });
144
146
  });
145
147
 
146
- // 4. Test conditions (i.e. things that display or not in the UI based on props).
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 { Chip } from './Chip';
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
- const wrapper = shallow(<ChipGroup {...props} />);
20
+ render(<ChipGroup {...props} />);
21
+ const chipGroup = getByClassName(document.body, CLASSNAME);
17
22
 
18
- return { props, wrapper };
23
+ return { props, chipGroup };
19
24
  };
20
25
 
21
26
  describe('<ChipGroup />', () => {
22
- // 1. Test render via snapshot (default state of component).
23
- describe('Snapshot', () => {
24
- it('should render correctly Chip Group component', () => {
25
- const { wrapper } = setup();
26
- expect(wrapper).toMatchSnapshot();
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, { ReactElement } from '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 { DatePicker } from './DatePicker';
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
- const mockedDate = new Date(
11
- new Date(1487721600).toLocaleString('en-US', {
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
- type SetupProps = Partial<DatePickerProps>;
11
+ const mockedDate = new Date(1487721600000);
12
+ Date.now = jest.fn(() => mockedDate.valueOf());
18
13
 
19
- const setup = ({ ...propsOverride }: SetupProps = {}, shallowRendering = true) => {
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
- const renderer: (el: ReactElement) => Wrapper = shallowRendering ? shallow : mount;
29
- const wrapper: Wrapper = renderer(<DatePicker {...props} />);
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
- describe('Snapshots and structure', () => {
36
- it('should render correctly', () => {
37
- const { wrapper } = setup();
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, { ReactElement } from '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';
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 = ({ ...propsOverride }: SetupProps = {}, shallowRendering = true) => {
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
- const renderer: (el: ReactElement) => Wrapper = shallowRendering ? shallow : mount;
32
- const wrapper: Wrapper = renderer(<DatePickerControlled {...props} />);
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
- describe('Snapshots and structure', () => {
39
- it('should render correctly', () => {
40
- const { wrapper } = setup();
41
- expect(wrapper).toMatchSnapshot();
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, { ReactElement } from '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';
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
- type SetupProps = Partial<DatePickerFieldProps>;
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
- const renderer: (el: ReactElement) => Wrapper = shallowRendering ? shallow : mount;
30
- const wrapper: Wrapper = renderer(<DatePickerField {...props} />);
31
-
32
- return { props, wrapper };
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
- describe('Snapshots and structure', () => {
37
- it('should render correctly', () => {
38
- const { wrapper } = setup();
39
- expect(wrapper).toMatchSnapshot();
40
- });
41
-
42
- it('should render correctly when passed a date object', () => {
43
- const { wrapper } = setup({ value: new Date('January 18, 1970') });
44
- expect(wrapper).toMatchSnapshot();
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
  });