@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,128 +1,38 @@
1
- import { commonTestsSuite, Wrapper } from '@lumx/react/testing/utils';
2
- import { getBasicClass } from '@lumx/react/utils/className';
1
+ import React from 'react';
3
2
 
4
- import { mount, shallow } from 'enzyme';
5
- import 'jest-enzyme';
6
- import React, { ReactElement } from 'react';
3
+ import { render, screen } from '@testing-library/react';
4
+ import { getByClassName } from '@lumx/react/testing/utils/queries';
5
+ import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
7
6
 
8
- import { setupTabProviderMocks } from '../tabs/test.mocks';
9
7
  import { ProgressTrackerStep, ProgressTrackerStepProps } from './ProgressTrackerStep';
10
8
 
11
9
  const CLASSNAME = ProgressTrackerStep.className as string;
12
10
 
13
- // Mock useTabProviderContext.
14
- jest.mock('../tabs/state', () => {
15
- const state = jest.requireActual('../tabs/state');
16
- return { ...state, useTabProviderContext: jest.fn(), useTabProviderContextState: jest.fn() };
17
- });
18
-
19
11
  type SetupProps = Partial<ProgressTrackerStepProps>;
20
12
 
21
13
  /**
22
14
  * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
23
15
  */
24
- const setup = ({ ...propsOverride }: SetupProps = {}, shallowRendering = true) => {
25
- const props: ProgressTrackerStepProps = { label: 'Test Step Label', ...propsOverride };
26
- const renderer: (el: ReactElement) => Wrapper = shallowRendering ? shallow : mount;
27
- const wrapper: Wrapper = renderer(<ProgressTrackerStep {...props} />);
16
+ const setup = (propsOverride: SetupProps = {}) => {
17
+ const props = { label: 'Test Step Label', ...propsOverride };
18
+ render(<ProgressTrackerStep {...props} />);
19
+ const progressTrackerStep = getByClassName(document.body, CLASSNAME);
28
20
 
29
- return { props, wrapper };
21
+ return { props, progressTrackerStep };
30
22
  };
31
23
 
32
24
  describe(`<${ProgressTrackerStep.displayName}>`, () => {
33
- // 1. Test render via snapshot (default states of component).
34
- describe('Snapshots and structure', () => {
35
- it('should render', () => {
36
- setupTabProviderMocks({ index: 1 });
37
- const { wrapper } = setup({});
38
- expect(wrapper).toMatchSnapshot();
39
- expect(wrapper).toHaveClassName(CLASSNAME);
40
- });
41
-
42
- it('should render active state', () => {
43
- setupTabProviderMocks({ index: 3, isActive: true });
44
- const { wrapper } = setup({});
45
- expect(wrapper).toMatchSnapshot();
46
- });
47
-
48
- it('should render complete state', () => {
49
- setupTabProviderMocks({ index: 3, isComplete: true });
50
- const { wrapper } = setup({});
51
- expect(wrapper).toMatchSnapshot();
52
- });
53
-
54
- it('should render erroneous state', () => {
55
- setupTabProviderMocks({ index: 3, hasError: true });
56
- const { wrapper } = setup({});
57
- expect(wrapper).toMatchSnapshot();
58
- });
59
-
60
- it('should render active erroneous state', () => {
61
- setupTabProviderMocks({ index: 3, isActive: true, hasError: true });
62
- const { wrapper } = setup({});
63
- expect(wrapper).toMatchSnapshot();
64
- });
65
- });
66
-
67
- // 2. Test defaultProps value and important props custom values.
68
- describe('Props', () => {
69
- it('should use the given props to add classes', () => {
70
- setupTabProviderMocks();
71
- const props: any = {
72
- isActive: true,
73
- hasError: true,
74
- isComplete: true,
75
- };
76
- const { wrapper } = setup(props);
77
-
78
- Object.keys(props).forEach((prop) => {
79
- expect(wrapper).toHaveClassName(getBasicClass({ prefix: CLASSNAME, type: prop, value: props[prop] }));
80
- });
81
- });
82
- });
83
-
84
- // 3. Test events.
85
- describe('Events', () => {
86
- it('should trigger `onChange` when focused if the provider is configured to do so', () => {
87
- const { changeToTab } = setupTabProviderMocks({ shouldActivateOnFocus: true });
88
- const { wrapper } = setup({}, false);
89
-
90
- wrapper.simulate('focus');
91
- expect(changeToTab).toHaveBeenCalledTimes(1);
92
- });
93
-
94
- it('should trigger `onChange` when clicked', () => {
95
- const { changeToTab } = setupTabProviderMocks();
96
- const { wrapper } = setup({}, false);
97
-
98
- wrapper.simulate('click');
99
- expect(changeToTab).toHaveBeenCalledTimes(1);
100
- });
101
-
102
- it('should trigger `onChange` when pressing `enter`', () => {
103
- const { changeToTab } = setupTabProviderMocks();
104
- const { wrapper } = setup({}, false);
105
-
106
- wrapper.simulate('keypress', { key: 'Enter' });
107
- expect(changeToTab).toHaveBeenCalledTimes(1);
108
- });
109
-
110
- it('should not trigger `onChange` when pressing any other key', () => {
111
- const { changeToTab } = setupTabProviderMocks();
112
- const { wrapper } = setup({}, false);
113
-
114
- wrapper.simulate('keypress', { key: 'a' });
115
- expect(changeToTab).not.toHaveBeenCalled();
116
- });
25
+ it('should render default', () => {
26
+ const label = 'Step';
27
+ const { progressTrackerStep } = setup({ label });
28
+ expect(progressTrackerStep).toBe(screen.queryByRole('tab', { name: label }));
117
29
  });
118
30
 
119
31
  // Common tests suite.
120
- commonTestsSuite(
121
- (...args: any[]) => {
122
- setupTabProviderMocks();
123
- return setup(...args);
124
- },
125
- { className: 'wrapper', prop: 'wrapper' },
126
- { className: CLASSNAME },
127
- );
32
+ commonTestsSuiteRTL(setup, {
33
+ baseClassName: CLASSNAME,
34
+ forwardClassName: 'progressTrackerStep',
35
+ forwardAttributes: 'progressTrackerStep',
36
+ forwardRef: 'progressTrackerStep',
37
+ });
128
38
  });
@@ -1,73 +1,36 @@
1
- import { commonTestsSuite, Wrapper } from '@lumx/react/testing/utils';
2
- import { mount, shallow } from 'enzyme';
3
- import 'jest-enzyme';
4
- import React, { ReactElement } from 'react';
5
- import { setupTabProviderMocks } from '../tabs/test.mocks';
6
- import { ProgressTrackerStepPanel, ProgressTrackerStepPanelProps } from './ProgressTrackerStepPanel';
1
+ import React from 'react';
7
2
 
8
- const CLASSNAME = ProgressTrackerStepPanel.className as string;
3
+ import { render, screen } from '@testing-library/react';
4
+ import { getByClassName } from '@lumx/react/testing/utils/queries';
9
5
 
10
- // Mock useTabProviderContext.
11
- jest.mock('../tabs/state', () => {
12
- const state = jest.requireActual('../tabs/state');
13
- return { ...state, useTabProviderContext: jest.fn(), useTabProviderContextState: jest.fn() };
14
- });
6
+ import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
7
+ import { ProgressTrackerStepPanel, ProgressTrackerStepPanelProps } from './ProgressTrackerStepPanel';
15
8
 
16
- type SetupProps = Partial<ProgressTrackerStepPanelProps>;
9
+ const CLASSNAME = ProgressTrackerStepPanel.className as string;
17
10
 
18
11
  /**
19
12
  * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
20
13
  */
21
- const setup = ({ ...propsOverride }: SetupProps = {}, shallowRendering = true) => {
22
- const props: ProgressTrackerStepPanelProps = { ...propsOverride, children: 'Tab panel content' };
23
- const renderer: (el: ReactElement) => Wrapper = shallowRendering ? shallow : mount;
24
- const wrapper: Wrapper = renderer(<ProgressTrackerStepPanel {...props} />);
14
+ const setup = (propsOverride: Partial<ProgressTrackerStepPanelProps> = {}) => {
15
+ const props = { ...propsOverride, children: 'Tab panel content' };
16
+ render(<ProgressTrackerStepPanel {...props} />);
17
+ const progressTrackerStepPanel = getByClassName(document.body, CLASSNAME);
25
18
 
26
- return { props, wrapper };
19
+ return { props, progressTrackerStepPanel };
27
20
  };
28
21
 
29
22
  describe(`<${ProgressTrackerStepPanel.displayName}>`, () => {
30
- // 1. Test render via snapshot (default states of component).
31
- describe('Snapshots and structure', () => {
32
- it('should render correctly', () => {
33
- setupTabProviderMocks({ index: 1 });
34
- const { wrapper } = setup();
35
- expect(wrapper).toMatchSnapshot();
36
- expect(wrapper).toHaveClassName(CLASSNAME);
37
- });
38
-
39
- it('should render isActive state', () => {
40
- setupTabProviderMocks({ index: 2, isActive: true });
41
- const { wrapper } = setup();
42
- expect(wrapper).toMatchSnapshot();
43
- });
44
-
45
- it('should not render children when not active and lazy', () => {
46
- setupTabProviderMocks({ isLazy: true, isActive: false });
47
- const { wrapper } = setup();
48
- expect(wrapper.find('div').props().children).toBeFalsy();
49
- });
50
-
51
- it('should render children when active and lazy', () => {
52
- setupTabProviderMocks({ isLazy: true, isActive: true });
53
- const { wrapper } = setup();
54
- expect(wrapper.find('div').props().children).toBeTruthy();
55
- });
56
-
57
- it('should render children when not active and not lazy', () => {
58
- setupTabProviderMocks({ isActive: false, isLazy: false });
59
- const { wrapper } = setup();
60
- expect(wrapper.find('div').props().children).toBeTruthy();
61
- });
23
+ it('should render default', () => {
24
+ const content = 'Content';
25
+ const { progressTrackerStepPanel } = setup({ children: content });
26
+ expect(progressTrackerStepPanel).toBe(screen.queryByRole('tabpanel'));
62
27
  });
63
28
 
64
29
  // Common tests suite.
65
- commonTestsSuite(
66
- (...args: any[]) => {
67
- setupTabProviderMocks();
68
- return setup(...args);
69
- },
70
- { className: 'wrapper', prop: 'wrapper' },
71
- { className: CLASSNAME },
72
- );
30
+ commonTestsSuiteRTL(setup, {
31
+ baseClassName: CLASSNAME,
32
+ forwardClassName: 'progressTrackerStepPanel',
33
+ forwardRef: 'progressTrackerStepPanel',
34
+ forwardAttributes: 'progressTrackerStepPanel',
35
+ });
73
36
  });
@@ -54,7 +54,7 @@ export const ProgressTrackerStepPanel: Comp<ProgressTrackerStepPanelProps, HTMLD
54
54
  id={state?.tabPanelId}
55
55
  className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, isActive }))}
56
56
  role="tabpanel"
57
- tabIndex={0}
57
+ tabIndex={isActive ? 0 : -1}
58
58
  aria-labelledby={state?.tabId}
59
59
  >
60
60
  {(!state?.isLazy || isActive) && children}
@@ -1,13 +1,11 @@
1
- import React, { InputHTMLAttributes, LabelHTMLAttributes, ReactElement } from 'react';
1
+ import React from 'react';
2
2
 
3
- import { mount, shallow } from 'enzyme';
4
- import 'jest-enzyme';
3
+ import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
4
+ import { getByClassName, getByTagName, queryByClassName } from '@lumx/react/testing/utils/queries';
5
+ import { render } from '@testing-library/react';
6
+ import userEvent from '@testing-library/user-event';
5
7
 
6
- import { commonTestsSuite, Wrapper } from '@lumx/react/testing/utils';
7
- import { getBasicClass } from '@lumx/react/utils/className';
8
-
9
- import { Theme } from '@lumx/react';
10
- import { RadioButton, RadioButtonProps } from './RadioButton';
8
+ import { RadioButton, RadioButtonProps } from '.';
11
9
 
12
10
  const CLASSNAME = RadioButton.className as string;
13
11
 
@@ -16,108 +14,96 @@ type SetupProps = Partial<RadioButtonProps>;
16
14
  /**
17
15
  * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
18
16
  */
19
- const setup = (propsOverride: SetupProps = {}, shallowRendering = true) => {
17
+ const setup = (propsOverride: SetupProps = {}) => {
20
18
  const props: any = { id: 'fixedId', ...propsOverride };
21
- const renderer: (el: ReactElement) => Wrapper = shallowRendering ? shallow : mount;
22
- const wrapper: Wrapper = renderer(<RadioButton {...props} />);
23
-
24
- return {
25
- helper: wrapper.find(`.${CLASSNAME}__helper`),
26
- input: wrapper.find(`input`),
27
- label: wrapper.find(`.${CLASSNAME}__label`),
28
- props,
29
- wrapper,
30
- };
19
+ render(<RadioButton {...props} />);
20
+
21
+ const radioButton = getByClassName(document.body, CLASSNAME);
22
+ const helper = queryByClassName(radioButton, `${CLASSNAME}__helper`);
23
+ const label = queryByClassName(radioButton, `${CLASSNAME}__label`);
24
+ const input = getByTagName(radioButton, 'input');
25
+ return { radioButton, helper, label, input, props };
31
26
  };
32
27
 
33
28
  describe(`<${RadioButton.displayName}>`, () => {
34
- // 1. Test render via snapshot (default states of component).
35
- describe('Snapshots and structure', () => {
36
- it('should render defaults', () => {
37
- const { wrapper, input, helper } = setup({});
38
- expect(wrapper).toMatchSnapshot();
39
-
40
- expect(wrapper).toExist();
41
-
42
- expect(input).toExist();
43
- const inputProps: InputHTMLAttributes<HTMLInputElement> = input.props();
44
- expect(inputProps.checked).toBeFalsy();
45
- expect(inputProps.disabled).toBeFalsy();
46
-
47
- expect(helper).not.toExist();
29
+ describe('Props', () => {
30
+ it('should render correctly', () => {
31
+ const { radioButton, input, label, helper } = setup();
32
+ expect(radioButton).toBeInTheDocument();
33
+ expect(radioButton).toHaveClass(CLASSNAME);
34
+ expect(radioButton).not.toHaveClass('lumx-radio-button--is-disabled');
35
+ expect(radioButton).toHaveClass('lumx-radio-button--is-unchecked');
36
+
37
+ expect(label).not.toBeInTheDocument();
38
+ expect(helper).not.toBeInTheDocument();
39
+
40
+ expect(input).toBeInTheDocument();
41
+ expect(input).not.toBeChecked();
42
+ expect(input).not.toBeDisabled();
48
43
  });
49
44
 
50
- it('should render checked, disabled & id', () => {
51
- const props = {
52
- isChecked: true,
45
+ it('should render disabled and checked', () => {
46
+ const { radioButton, input } = setup({
53
47
  isDisabled: true,
54
- id: 'inputID',
55
- };
56
- const { wrapper, input } = setup(props);
57
- expect(wrapper).toMatchSnapshot();
58
-
59
- const inputProps: InputHTMLAttributes<HTMLInputElement> = input.props();
60
- expect(inputProps.checked).toBe(true);
61
- expect(inputProps.disabled).toBe(true);
62
- expect(inputProps.id).toEqual(props.id);
48
+ isChecked: true,
49
+ });
50
+ expect(radioButton).toHaveClass('lumx-radio-button--is-disabled');
51
+ expect(radioButton).toHaveClass('lumx-radio-button--is-checked');
52
+
53
+ expect(input).toBeChecked();
54
+ expect(input).toBeDisabled();
63
55
  });
64
56
 
65
- it('should render label & helper', () => {
66
- const props = {
67
- helper: 'Helper',
68
- label: 'Label',
69
- };
70
- const { wrapper, label, helper, input } = setup(props as Partial<RadioButtonProps>);
71
- expect(wrapper).toMatchSnapshot();
72
-
73
- expect(input).toExist();
74
- const inputProps: InputHTMLAttributes<HTMLInputElement> = input.props();
75
- expect(inputProps.checked).toBeFalsy();
76
- expect(inputProps.disabled).toBeFalsy();
77
-
78
- expect(label).toExist();
79
- expect(label.contains(props.label)).toBe(true);
80
- const labelProps: LabelHTMLAttributes<HTMLLabelElement> = label.props();
81
- expect(labelProps.htmlFor).toEqual(inputProps.id);
82
-
83
- expect(helper).toExist();
84
- expect(helper.contains(props.helper)).toBe(true);
57
+ it('should render helper and label', () => {
58
+ const id = 'radioButton1';
59
+ const { props, helper, label, input } = setup({
60
+ id,
61
+ helper: 'Test helper',
62
+ label: 'Test label',
63
+ });
64
+
65
+ expect(helper).toBeInTheDocument();
66
+ expect(helper).toHaveTextContent(props.helper);
67
+ expect(helper).toHaveAttribute('id');
68
+
69
+ expect(label).toBeInTheDocument();
70
+ expect(label).toHaveTextContent(props.label);
71
+ expect(label).toHaveAttribute('for', id);
72
+
73
+ expect(input).toHaveAttribute('id', id);
74
+ expect(input).toHaveAttribute('aria-describedby', helper?.id);
85
75
  });
86
- });
87
76
 
88
- // 2. Test defaultProps value and important props custom values.
89
- describe('Props', () => {
90
- it('should use props for classes', () => {
91
- const props = {
92
- isChecked: true,
93
- isDisabled: true,
94
- theme: Theme.dark,
95
- };
96
- const { wrapper } = setup(props as RadioButtonProps);
97
-
98
- expect(wrapper).toHaveClassName(CLASSNAME);
99
- expect(wrapper).toHaveClassName(getBasicClass({ prefix: CLASSNAME, type: 'isDisabled', value: true }));
100
- expect(wrapper).toHaveClassName(getBasicClass({ prefix: CLASSNAME, type: 'isChecked', value: true }));
101
- expect(wrapper).not.toHaveClassName(getBasicClass({ prefix: CLASSNAME, type: 'isUnchecked', value: true }));
102
- expect(wrapper).toHaveClassName(getBasicClass({ prefix: CLASSNAME, type: 'theme', value: props.theme }));
77
+ it('should forward input props', () => {
78
+ const { props, input } = setup({
79
+ inputProps: {
80
+ 'aria-labelledby': 'labelledby-id',
81
+ },
82
+ });
83
+
84
+ expect(input).toHaveAttribute('aria-labelledby', props.inputProps['aria-labelledby']);
103
85
  });
104
86
  });
105
87
 
106
- // 3. Test events.
107
88
  describe('Events', () => {
108
- // Nothing to do here.
109
- });
89
+ const onChange = jest.fn();
110
90
 
111
- // 4. Test conditions (i.e. things that display or not in the UI based on props).
112
- describe('Conditions', () => {
113
- // Nothing to do here.
114
- });
91
+ it('should trigger `onChange` when radioButton is clicked', async () => {
92
+ const value = 'value';
93
+ const name = 'name';
94
+ const { input } = setup({ checked: false, onChange, value, name });
95
+ expect(input).not.toBeChecked();
96
+
97
+ await userEvent.click(input);
115
98
 
116
- // 5. Test state.
117
- describe('State', () => {
118
- // Nothing to do here.
99
+ expect(onChange).toHaveBeenCalledWith(value, name, expect.any(Object));
100
+ });
119
101
  });
120
102
 
121
103
  // Common tests suite.
122
- commonTestsSuite(setup, { prop: 'wrapper', className: 'wrapper' }, { className: CLASSNAME });
104
+ commonTestsSuiteRTL(setup, {
105
+ baseClassName: CLASSNAME,
106
+ forwardClassName: 'radioButton',
107
+ forwardAttributes: 'radioButton',
108
+ });
123
109
  });
@@ -1,11 +1,9 @@
1
- import React, { ReactElement } from 'react';
1
+ import React from 'react';
2
2
 
3
- import { mount, shallow } from 'enzyme';
4
- import 'jest-enzyme';
3
+ import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
5
4
 
6
- import { Wrapper, commonTestsSuite } from '@lumx/react/testing/utils';
7
-
8
- import { RadioButton } from '@lumx/react';
5
+ import { render } from '@testing-library/react';
6
+ import { queryByClassName } from '@lumx/react/testing/utils/queries';
9
7
  import { RadioGroup, RadioGroupProps } from './RadioGroup';
10
8
 
11
9
  const CLASSNAME = RadioGroup.className as string;
@@ -15,63 +13,19 @@ type SetupProps = Partial<RadioGroupProps>;
15
13
  /**
16
14
  * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
17
15
  */
18
- const setup = (propsOverride: SetupProps = {}, shallowRendering = true) => {
16
+ const setup = (propsOverride: SetupProps = {}) => {
19
17
  const props: any = { ...propsOverride };
20
- const renderer: (el: ReactElement) => Wrapper = shallowRendering ? shallow : mount;
21
- const wrapper = renderer(<RadioGroup {...props} />);
18
+ render(<RadioGroup {...props} />);
22
19
 
23
- return {
24
- props,
25
- radioButtons: wrapper.find('RadioButton'),
26
- wrapper,
27
- };
20
+ const radioGroup = queryByClassName(document.body, CLASSNAME);
21
+ return { props, radioGroup };
28
22
  };
29
23
 
30
24
  describe(`<${RadioGroup.displayName}>`, () => {
31
- // 1. Test render via snapshot (default states of component).
32
- describe('Snapshots and structure', () => {
33
- it('should render defaults', () => {
34
- const { wrapper } = setup();
35
- expect(wrapper).toMatchSnapshot();
36
-
37
- expect(wrapper).toExist();
38
- expect(wrapper).toHaveClassName(CLASSNAME);
39
- });
40
-
41
- it('should render with radio button children', () => {
42
- const { wrapper, radioButtons } = setup({
43
- children: [
44
- <RadioButton key={0} isChecked label="Label 1" />,
45
- <RadioButton key={1} isChecked={false} label="Label 2" />,
46
- ],
47
- });
48
- expect(wrapper).toMatchSnapshot();
49
-
50
- expect(radioButtons).toExist();
51
- expect(radioButtons.length).toBe(2);
52
- });
53
- });
54
-
55
- // 2. Test defaultProps value and important props custom values.
56
- describe('Props', () => {
57
- // Nothing to do here.
58
- });
59
-
60
- // 3. Test events.
61
- describe('Events', () => {
62
- // Nothing to do here
63
- });
64
-
65
- // 4. Test conditions (i.e. things that display or not in the UI based on props).
66
- describe('Conditions', () => {
67
- // Nothing to do here.
68
- });
69
-
70
- // 5. Test state.
71
- describe('State', () => {
72
- // Nothing to do here.
73
- });
74
-
75
25
  // Common tests suite.
76
- commonTestsSuite(setup, { prop: 'wrapper', className: 'wrapper' }, { className: CLASSNAME });
26
+ commonTestsSuiteRTL(setup, {
27
+ baseClassName: CLASSNAME,
28
+ forwardClassName: 'radioGroup',
29
+ forwardAttributes: 'radioGroup',
30
+ });
77
31
  });