@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,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> = {}, shallowRendering = true) => {
14
- const renderer: any = shallowRendering ? shallow : mount;
15
- const wrapper: any = renderer(<GenericBlock {...(props as any)} />);
16
- return { props, wrapper };
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
- // 1. Test render via snapshot.
21
- describe('Snapshots and structure', () => {
22
- it('should render default', () => {
23
- const wrapper = shallow(
24
- <GenericBlock figure="figure" actions="actions">
25
- Content
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(wrapper.prop('gap')).toBe('big');
30
- expect(wrapper.prop('orientation')).toBe('horizontal');
31
-
32
- const figure = wrapper.find('.lumx-generic-block__figure');
33
- expect(figure).toHaveLength(1);
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
- const actions = wrapper.find('.lumx-generic-block__actions');
41
- expect(actions).toHaveLength(1);
38
+ expect(figure).not.toBeInTheDocument();
39
+ expect(actions).not.toBeInTheDocument();
42
40
  });
43
41
 
44
42
  it('should forward vAlign & hAlign', () => {
45
- const wrapper = shallow(
46
- <GenericBlock figure="figure" actions="actions" vAlign="left" hAlign="bottom">
47
- Content
48
- </GenericBlock>,
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 wrapper = shallow(
72
- <GenericBlock figure="Figure 1" figureProps={{ className: 'figure1', vAlign: 'left' }}>
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
- </GenericBlock>,
77
- );
73
+ ),
74
+ });
78
75
 
79
- const figure = wrapper.find('.lumx-generic-block__figure');
80
- expect(figure).toHaveClassName('figure1');
81
- expect(figure).toHaveClassName('figure2');
82
- expect(figure.prop('fillSpace')).toBe(true);
83
- expect(figure.prop('vAlign')).toBe('left');
84
- expect(figure).toHaveText('Figure 1Figure 2');
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(wrapper.find('.lumx-generic-block__content')).toHaveLength(0);
87
- expect(wrapper.find('.lumx-generic-block__actions')).toHaveLength(0);
83
+ expect(content).not.toBeInTheDocument();
84
+ expect(actions).not.toBeInTheDocument();
88
85
  });
89
86
 
90
87
  it('should combine content props', () => {
91
- const wrapper = shallow(
92
- <GenericBlock contentProps={{ className: 'content1', vAlign: 'left' }}>
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
- </GenericBlock>,
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
- const content = wrapper.find('.lumx-generic-block__content');
101
- expect(content).toHaveClassName('content1');
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 wrapper = shallow(
113
- <GenericBlock actions="Actions 1" actionsProps={{ className: 'actions1', vAlign: 'left' }}>
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
- </GenericBlock>,
118
- );
117
+ ),
118
+ });
119
119
 
120
- const actions = wrapper.find('.lumx-generic-block__actions');
121
- expect(actions).toHaveClassName('actions1');
122
- expect(actions).toHaveClassName('actions2');
123
- expect(actions.prop('fillSpace')).toBe(true);
124
- expect(actions.prop('vAlign')).toBe('left');
125
- expect(actions).toHaveText('Actions 1Actions 2');
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(wrapper.find('.lumx-generic-block__figure')).toHaveLength(0);
128
- expect(wrapper.find('.lumx-generic-block__content')).toHaveLength(0);
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
- shallow(
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
- commonTestsSuite(setup, { className: 'wrapper', prop: 'wrapper' }, { className: CLASSNAME });
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', defaultValue: 200 },
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, { ReactElement } from 'react';
1
+ import React from 'react';
2
2
 
3
- import { mount, shallow } from 'enzyme';
4
- import 'jest-enzyme';
5
- import { build, fake, oneOf } from 'test-data-bot';
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 = ({ ...propsOverride }: SetupProps = {}, shallowRendering = true) => {
18
+ const setup = (propsOverride: SetupProps = {}) => {
22
19
  const props: IconProps = {
23
20
  icon: 'mdiPlus',
24
21
  ...propsOverride,
25
22
  };
26
- const renderer: (el: ReactElement) => Wrapper = shallowRendering ? shallow : mount;
27
- const wrapper: Wrapper = renderer(<Icon {...props} />);
28
-
29
- return {
30
- i: wrapper.find('i'),
31
- path: wrapper.find('path'),
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
- // 1. Test render via snapshot (default states of component).
40
- describe('Snapshots and structure', () => {
41
- it('should render correctly', () => {
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).toExist();
46
- expect(i).toHaveClassName(CLASSNAME);
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).toExist();
49
- expect(path).toExist();
50
- });
40
+ expect(svg).toBeInTheDocument();
41
+ expect(svg).toHaveAttribute('aria-hidden', 'true');
42
+ expect(svg).not.toHaveAttribute('role');
51
43
 
52
- it('should render color & color variant', () => {
53
- const { wrapper } = setup({ color: ColorPalette.primary, colorVariant: ColorVariant.D1 });
54
- expect(wrapper).toMatchSnapshot();
44
+ expect(path).toBeInTheDocument();
45
+ expect(path).toHaveAttribute('d', props.icon);
55
46
  });
56
- });
57
47
 
58
- // 2. Test defaultProps value and important props custom values.
59
- describe('Props', () => {
60
- it("shouldn't use any default props", () => {
61
- const { i } = setup();
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
- ['color', 'size'].forEach((prop: string) => {
64
- expect(i).not.toHaveClassName(getBasicClass({ prefix: CLASSNAME, type: prop, value: '' }));
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
- it('should use the given props', () => {
69
- const modifiedPropsBuilder: () => SetupProps = build('props').fields({
70
- color: fake((fakeData: any) => fakeData.commerce.color()),
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
- const modifiedProps: SetupProps = modifiedPropsBuilder();
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
- const { i, path } = setup({ ...modifiedProps });
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
- Object.keys(modifiedProps).forEach((prop: string) => {
80
- if (prop === 'icon') {
81
- expect(path).toHaveProp('d', modifiedProps[prop]);
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
- // 3. Test events.
92
- // N/A
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
- // 4. Test conditions (i.e. things that display or not in the UI based on props).
95
- // N/A
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
- // 5. Test state.
98
- // N/A
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
- commonTestsSuite(setup, { className: 'i', prop: 'i' }, { className: CLASSNAME });
117
+ commonTestsSuiteRTL(setup, { baseClassName: CLASSNAME, forwardClassName: 'i', forwardAttributes: 'i' });
102
118
  });
@@ -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 { shallow } from 'enzyme';
4
- import 'jest-enzyme';
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
- const wrapper = shallow(<InlineList {...props} />);
11
- return { props, wrapper };
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 { wrapper } = setup({ children: ['Some text', 'Some other text'] });
18
- expect(wrapper).toHaveDisplayName('ul');
19
- expect(wrapper.prop('className')).toBe(InlineList.className);
20
- expect(wrapper.find('li')).toHaveLength(2);
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 { wrapper } = setup({ typography: 'body2', children: 'Some text' });
25
- expect(wrapper).toHaveClassName('lumx-typography-body2');
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 { wrapper } = setup({ color: 'blue', children: 'Some text' });
30
- expect(wrapper).toHaveClassName('lumx-color-font-blue-N');
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 { wrapper } = setup({ color: 'blue', colorVariant: 'D2', children: 'Some text' });
35
- expect(wrapper).toHaveClassName('lumx-color-font-blue-D2');
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
- commonTestsSuite(setup, { className: 'wrapper', prop: 'wrapper' }, { className: InlineList.className });
49
+ commonTestsSuiteRTL(setup, {
50
+ baseClassName: CLASSNAME,
51
+ forwardClassName: 'inlineList',
52
+ forwardAttributes: 'inlineList',
53
+ });
41
54
  });