@innovaccer/design-system 2.3.0 → 2.4.0-0

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 (87) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/core/components/atoms/backdrop/Backdrop.tsx +11 -1
  3. package/core/components/atoms/button/Button.tsx +60 -44
  4. package/core/components/atoms/button/__stories__/IconButtonGroup.story.tsx +4 -4
  5. package/core/components/atoms/button/__stories__/IconButtonSecondary.story.tsx +1 -1
  6. package/core/components/atoms/button/__tests__/Button.test.tsx +36 -1
  7. package/core/components/atoms/dropdown/DropdownList.tsx +1 -0
  8. package/core/components/atoms/dropdown/Loading.tsx +9 -9
  9. package/core/components/atoms/dropdown/__stories__/Options.tsx +2 -0
  10. package/core/components/atoms/dropdown/__tests__/Dropdown.test.tsx +12 -1
  11. package/core/components/atoms/dropdown/__tests__/Loading.test.tsx +66 -0
  12. package/core/components/atoms/dropdown/__tests__/Option.test.tsx +204 -0
  13. package/core/components/atoms/dropdown/option/CheckboxOption.tsx +1 -0
  14. package/core/components/atoms/dropdown/option/IconOption.tsx +3 -1
  15. package/core/components/atoms/dropdown/option/IconWithMetaOption.tsx +3 -1
  16. package/core/components/atoms/dropdown/option/index.tsx +7 -1
  17. package/core/components/molecules/dialog/__tests__/__snapshots__/Dialog.test.tsx.snap +13 -0
  18. package/core/components/molecules/emptyState/__stories__/assets/pageNotLoaded.png +0 -0
  19. package/core/components/molecules/emptyState/__stories__/variants/noContentAvailable.story.tsx +26 -0
  20. package/core/components/molecules/emptyState/__stories__/variants/{smallSizeWithButton.story.tsx → noSearchResults.story.tsx} +2 -2
  21. package/core/components/molecules/emptyState/__stories__/variants/{largeSize.story.tsx → pageNotLoaded.story.tsx} +3 -3
  22. package/core/components/molecules/fileList/FileIcon.tsx +10 -2
  23. package/core/components/molecules/fileList/FileListItem.tsx +7 -3
  24. package/core/components/molecules/fileList/__stories__/__common__/fileListExample.tsx +1 -0
  25. package/core/components/molecules/fileList/__tests__/FileList.test.tsx +115 -0
  26. package/core/components/molecules/fileList/__tests__/__snapshots__/FileList.test.tsx.snap +232 -0
  27. package/core/components/molecules/inputMask/InputMask.tsx +2 -5
  28. package/core/components/molecules/inputMask/__tests__/InputMask.test.tsx +128 -0
  29. package/core/components/molecules/inputMask/__tests__/__snapshots__/InputMask.test.tsx.snap +39 -0
  30. package/core/components/molecules/modal/Modal.tsx +7 -5
  31. package/core/components/molecules/modal/__tests__/__snapshots__/Modal.test.tsx.snap +18 -0
  32. package/core/components/molecules/sidesheet/Sidesheet.tsx +5 -3
  33. package/core/components/molecules/sidesheet/__tests__/__snapshots__/Sidesheet.test.tsx.snap +2 -0
  34. package/core/components/organisms/calendar/Calendar.tsx +66 -22
  35. package/core/components/organisms/calendar/__stories__/variants/withEvents.story.tsx +45 -0
  36. package/core/components/organisms/calendar/__tests__/Calendar.test.tsx +10 -0
  37. package/core/components/organisms/calendar/__tests__/__snapshots__/Calendar.test.tsx.snap +1096 -1096
  38. package/core/components/organisms/calendar/config.ts +2 -2
  39. package/core/components/organisms/calendar/types.ts +1 -0
  40. package/core/components/organisms/datePicker/DatePicker.tsx +23 -9
  41. package/core/components/organisms/datePicker/__tests__/{DatePicker.tsx → DatePicker.test.tsx} +16 -1
  42. package/core/components/organisms/datePicker/__tests__/__snapshots__/DatePicker.test.tsx.snap +2257 -0
  43. package/core/components/organisms/dateRangePicker/__tests__/__snapshots__/DateRangePicker.test.tsx.snap +2552 -2550
  44. package/core/components/organisms/inlineMessage/InlineMessage.tsx +75 -0
  45. package/core/components/organisms/inlineMessage/__stories__/Default.story.tsx +18 -0
  46. package/core/components/organisms/inlineMessage/__stories__/Error.story.tsx +19 -0
  47. package/core/components/organisms/inlineMessage/__stories__/Info.story.tsx +19 -0
  48. package/core/components/organisms/inlineMessage/__stories__/Success.story.tsx +19 -0
  49. package/core/components/organisms/inlineMessage/__stories__/Warning.story.tsx +18 -0
  50. package/core/components/organisms/inlineMessage/__stories__/variants/InlineMessageWithinTable.story.tsx +139 -0
  51. package/core/components/organisms/inlineMessage/__tests__/InlineMessage.test.tsx +91 -0
  52. package/core/components/organisms/inlineMessage/__tests__/__snapshots__/InlineMessage.test.tsx.snap +139 -0
  53. package/core/components/organisms/inlineMessage/index.tsx +1 -0
  54. package/core/components/organisms/timePicker/__tests__/__snapshots__/TimePicker.test.tsx.snap +8 -0
  55. package/core/index.tsx +2 -0
  56. package/core/index.type.tsx +1 -0
  57. package/core/utils/__tests__/__snapshots__/TS.test.tsx.snap +485 -466
  58. package/css/dist/index.css +72 -8
  59. package/css/dist/index.css.map +1 -1
  60. package/css/src/components/calendar.css +37 -5
  61. package/css/src/components/card.css +1 -1
  62. package/css/src/components/chipInput.css +2 -2
  63. package/css/src/components/editableChipInput.css +2 -1
  64. package/css/src/components/inlineMessage.css +29 -0
  65. package/dist/core/components/atoms/backdrop/Backdrop.d.ts +1 -0
  66. package/dist/core/components/atoms/button/Button.d.ts +1 -0
  67. package/dist/core/components/atoms/popperWrapper/PopperWrapper.d.ts +28 -27
  68. package/dist/core/components/organisms/calendar/Calendar.d.ts +6 -1
  69. package/dist/core/components/organisms/calendar/types.d.ts +3 -0
  70. package/dist/core/components/organisms/inlineMessage/InlineMessage.d.ts +15 -0
  71. package/dist/core/components/organisms/inlineMessage/index.d.ts +1 -0
  72. package/dist/core/index.d.ts +1 -0
  73. package/dist/core/index.type.d.ts +1 -0
  74. package/dist/index.esm.js +189 -66
  75. package/dist/index.js +201 -80
  76. package/dist/index.js.map +1 -1
  77. package/dist/index.umd.js +1 -1
  78. package/dist/index.umd.js.br +0 -0
  79. package/dist/index.umd.js.gz +0 -0
  80. package/dts.config.js +13 -0
  81. package/package.json +4 -2
  82. package/types/innovaccer-design-system/index.d.ts +39 -0
  83. package/types/innovaccer-design-system/innovaccer-design-system-tests.ts +0 -0
  84. package/types/innovaccer-design-system/tsconfig.json +23 -0
  85. package/types/innovaccer-design-system/tslint.json +1 -0
  86. package/core/components/molecules/emptyState/__stories__/variants/smallSizeWithoutButton.story.tsx +0 -21
  87. package/core/components/organisms/datePicker/__tests__/__snapshots__/DatePicker.tsx.snap +0 -2164
package/CHANGELOG.md CHANGED
@@ -1,3 +1,38 @@
1
+ ## 2.4.0-0 (2021-09-17)
2
+
3
+ ### Highlights
4
+ NA
5
+
6
+ ### Breaking changes
7
+ NA
8
+
9
+ ### Migration guide
10
+ NA
11
+
12
+ ### Deprecations
13
+ NA
14
+
15
+ ### Features
16
+ * Automated the process of types bundling (21f435b0)
17
+ * A new InlineMessage Component has been added (f852b2a8)
18
+ * Added the events indicator on given date in Calendar Component (4714efa2)
19
+ * A Chip has been added to Datepicker Component to select today's date (ee9e47e0)
20
+ * Tooltip in Icon Button Component has been added (f9f14233)
21
+ ### Fixes
22
+ * Removes the events type Array from Calendar Component (41abf4ef)
23
+ * zIndex for Backdrop Component has been fixed (055edb09)
24
+ * Border radius of Card Component has been fixed (c113a568)
25
+ * New Stories has been added to EmptyState Component and updated the existing story (af83ea74)
26
+ * Height of the Input field has been fixed when focus in EditableChipInput Component (bbb4f256)
27
+ ### Improvements
28
+ * Added test cases for InputMask Component (e0f37b99)
29
+ * Added test cases for FileList Component (b36a44f1)
30
+ * Added test cases for Dropdown Component options and loading state (1cb98e93)
31
+ ### Documentation
32
+ NA
33
+
34
+ -------------------
35
+
1
36
  ## 2.3.0 (2021-09-10)
2
37
 
3
38
  ### Highlights
@@ -10,6 +10,10 @@ export interface BackdropProps extends BaseProps {
10
10
  * Handles open/close state
11
11
  */
12
12
  open: boolean;
13
+ /**
14
+ * Specify zIndex Value
15
+ */
16
+ zIndex?: number;
13
17
  }
14
18
 
15
19
  export const Backdrop: React.FC<BackdropProps> = (props) => {
@@ -61,7 +65,13 @@ export const Backdrop: React.FC<BackdropProps> = (props) => {
61
65
  }, [props.open]);
62
66
 
63
67
  const BackdropElement = ReactDOM.createPortal(
64
- <div data-test="DesignSystem-Backdrop" data-layer={true} {...baseProps} className={classes} />,
68
+ <div
69
+ data-test="DesignSystem-Backdrop"
70
+ data-layer={true}
71
+ {...baseProps}
72
+ className={classes}
73
+ style={{ zIndex: props.zIndex }}
74
+ />,
65
75
  document.body
66
76
  );
67
77
 
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { Text, Icon, Spinner } from '@/index';
2
+ import { Text, Icon, Spinner, Tooltip } from '@/index';
3
3
  import classNames from 'classnames';
4
4
  import { BaseProps, BaseHtmlProps } from '@/utils/types';
5
5
 
@@ -46,6 +46,10 @@ export interface ButtonProps extends BaseProps, BaseHtmlProps<HTMLButtonElement>
46
46
  * Material icon name
47
47
  */
48
48
  icon?: string;
49
+ /**
50
+ * Adds title to `Button` when only icon is present
51
+ */
52
+ tooltip?: string;
49
53
  /**
50
54
  * Align icon left or right
51
55
  * @default "left"
@@ -105,6 +109,7 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>((props, r
105
109
  loading,
106
110
  disabled,
107
111
  className,
112
+ tooltip,
108
113
  ...rest
109
114
  } = props;
110
115
 
@@ -124,50 +129,61 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>((props, r
124
129
  [`Button-icon--${iconAlign}`]: children && iconAlign,
125
130
  });
126
131
 
132
+ const ButtonElement = () => {
133
+ return (
134
+ <button
135
+ data-test="DesignSystem-Button"
136
+ ref={ref}
137
+ type={type}
138
+ className={buttonClass}
139
+ disabled={disabled || loading}
140
+ tabIndex={tabIndex}
141
+ {...rest}
142
+ >
143
+ {loading ? (
144
+ <>
145
+ <Spinner
146
+ size="small"
147
+ appearance={appearance === 'basic' || appearance === 'transparent' ? 'secondary' : 'white'}
148
+ data-test="DesignSystem-Button--Spinner"
149
+ className="Button-spinner"
150
+ />
151
+ <Text className="Button-text Button-text--hidden">{children || ''}</Text>
152
+ </>
153
+ ) : (
154
+ <>
155
+ {icon && (
156
+ <div className={iconClass}>
157
+ <Icon
158
+ data-test="DesignSystem-Button--Icon"
159
+ name={icon}
160
+ appearance={
161
+ disabled
162
+ ? 'disabled'
163
+ : appearance === 'basic' || appearance === 'transparent'
164
+ ? selected
165
+ ? 'info'
166
+ : 'default'
167
+ : 'white'
168
+ }
169
+ size={largeIcon && !children ? sizeMapping[size] + 4 : sizeMapping[size]}
170
+ />
171
+ </div>
172
+ )}
173
+ {children}
174
+ </>
175
+ )}
176
+ </button>
177
+ );
178
+ }
179
+
127
180
  return (
128
- <button
129
- data-test="DesignSystem-Button"
130
- ref={ref}
131
- type={type}
132
- className={buttonClass}
133
- disabled={disabled || loading}
134
- tabIndex={tabIndex}
135
- {...rest}
136
- >
137
- {loading ? (
138
- <>
139
- <Spinner
140
- size="small"
141
- appearance={appearance === 'basic' || appearance === 'transparent' ? 'secondary' : 'white'}
142
- data-test="DesignSystem-Button--Spinner"
143
- className="Button-spinner"
144
- />
145
- <Text className="Button-text Button-text--hidden">{children || ''}</Text>
146
- </>
147
- ) : (
148
- <>
149
- {icon && (
150
- <div className={iconClass}>
151
- <Icon
152
- data-test="DesignSystem-Button--Icon"
153
- name={icon}
154
- appearance={
155
- disabled
156
- ? 'disabled'
157
- : appearance === 'basic' || appearance === 'transparent'
158
- ? selected
159
- ? 'info'
160
- : 'default'
161
- : 'white'
162
- }
163
- size={largeIcon && !children ? sizeMapping[size] + 4 : sizeMapping[size]}
164
- />
165
- </div>
166
- )}
167
- {children}
168
- </>
169
- )}
170
- </button>
181
+ icon && tooltip && !children ?
182
+ <Tooltip tooltip={tooltip}>
183
+ <ButtonElement />
184
+ </Tooltip>
185
+ :
186
+ <ButtonElement />
171
187
  );
172
188
  });
173
189
 
@@ -2,10 +2,10 @@ import * as React from 'react';
2
2
  import Button from '@/components/atoms/button';
3
3
 
4
4
  export const iconButtonGroup = () => (
5
- <div className="d-flex">
6
- <Button size="tiny" icon="content_copy" className="mr-2" />
7
- <Button size="tiny" icon="content_paste" className="mr-2" />
8
- <Button size="tiny" icon="delete" />
5
+ <div className="d-inline-flex">
6
+ <Button size="tiny" icon="content_copy " className="mr-2" tooltip="Copy" />
7
+ <Button size="tiny" icon="content_paste" className="mr-2" tooltip="Paste" />
8
+ <Button size="tiny" icon="delete" tooltip="Delete" />
9
9
  </div>
10
10
  );
11
11
 
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import Button from '../Button';
3
3
 
4
- export const iconButton = () => <Button appearance="basic" icon="keyboard_arrow_right" />;
4
+ export const iconButton = () => <Button appearance="basic" icon="keyboard_arrow_right" tooltip="Next in rank" />;
5
5
 
6
6
  export default {
7
7
  title: 'Components/Button/Icon Button',
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { render } from '@testing-library/react';
2
+ import { render, fireEvent, screen } from '@testing-library/react';
3
3
  import { Button } from '@/index';
4
4
  import { ButtonProps as Props } from '@/index.type';
5
5
  import { testHelper, filterUndefined, valueHelper, testMessageHelper } from '@/utils/testHelper';
@@ -232,3 +232,38 @@ describe('Button component with icon', () => {
232
232
  });
233
233
  });
234
234
  });
235
+
236
+ describe('Button component with Tooltip', () => {
237
+
238
+ it('check for tooltip attribute', () => {
239
+ const { getByTestId } = render(
240
+ <Button appearance="basic" icon="keyboard_arrow_right" tooltip="Next in rank" />
241
+ );
242
+
243
+ fireEvent.mouseEnter(getByTestId('DesignSystem-Button'));
244
+ expect(getByTestId('DesignSystem-Popover')).toBeInTheDocument();
245
+ });
246
+
247
+ it('check for tooltip when children is given', () => {
248
+ render(
249
+ <Button
250
+ appearance="basic"
251
+ icon="keyboard_arrow_right"
252
+ tooltip="Next in rank"
253
+ >
254
+ Click Me
255
+ </Button>
256
+ );
257
+
258
+ const TooltipComponent = screen.queryByText('DesignSystem-Popover');
259
+ expect(TooltipComponent).not.toBeInTheDocument();
260
+ });
261
+
262
+ it('check for tooltip when icon is not given', () => {
263
+ render(
264
+ <Button appearance="basic" tooltip="Next in rank" />
265
+ );
266
+ const TooltipComponent = screen.queryByText('DesignSystem-Popover');
267
+ expect(TooltipComponent).not.toBeInTheDocument();
268
+ });
269
+ });
@@ -623,6 +623,7 @@ const DropdownList = (props: OptionsProps) => {
623
623
  customStyle={popoverStyle}
624
624
  position={alignmentMapping[align]}
625
625
  {...popoverOptions}
626
+ data-test="DesignSystem-Dropdown--Popover"
626
627
  >
627
628
  {(withSearch || props.async) && renderSearch()}
628
629
  {renderDropdownSection()}
@@ -7,31 +7,31 @@ const Loading = (props: any) => {
7
7
 
8
8
  switch (loadingType) {
9
9
  case 'DEFAULT':
10
- return <PlaceholderParagraph length={'large'} />;
10
+ return <PlaceholderParagraph length={'large'} data-test="DesignSystem-Dropdown--PlaceholderParagraph" />;
11
11
  case 'WITH_ICON':
12
12
  return (
13
- <Placeholder withImage={true} round={true}>
13
+ <Placeholder withImage={true} round={true} data-test="DesignSystem-Dropdown--Placeholder">
14
14
  <PlaceholderParagraph length="large" />
15
15
  </Placeholder>
16
16
  );
17
17
  case 'WITH_META':
18
18
  return (
19
- <Placeholder withImage={false}>
20
- <PlaceholderParagraph length="large" />
21
- <PlaceholderParagraph length="medium" size="xxs" />
19
+ <Placeholder withImage={false} data-test="DesignSystem-Dropdown--Placeholder">
20
+ <PlaceholderParagraph length="large" data-test="DesignSystem-Dropdown--PlaceholderParagraph" />
21
+ <PlaceholderParagraph length="medium" size="xxs" data-test="DesignSystem-Dropdown--PlaceholderParagraph" />
22
22
  </Placeholder>
23
23
  );
24
24
  case 'WITH_CHECKBOX':
25
25
  return (
26
- <Placeholder withImage={true}>
26
+ <Placeholder withImage={true} data-test="DesignSystem-Dropdown--Placeholder">
27
27
  <PlaceholderParagraph length="large" />
28
28
  </Placeholder>
29
29
  );
30
30
  case 'ICON_WITH_META':
31
31
  return (
32
- <Placeholder withImage={true} round={true} imageSize={'medium'}>
33
- <PlaceholderParagraph length="large" />
34
- <PlaceholderParagraph length="medium" size="xxs" />
32
+ <Placeholder withImage={true} round={true} imageSize={'medium'} data-test="DesignSystem-Dropdown--Placeholder">
33
+ <PlaceholderParagraph length="large" data-test="DesignSystem-Dropdown--PlaceholderParagraph" />
34
+ <PlaceholderParagraph length="medium" size="xxs" data-test="DesignSystem-Dropdown--PlaceholderParagraph" />
35
35
  </Placeholder>
36
36
  );
37
37
  }
@@ -19,6 +19,8 @@ for (let i = 1; i <= 10; i++) {
19
19
  disabledStoryOptions.push({
20
20
  label: `Option ${i}`,
21
21
  value: `Option ${i}`,
22
+ icon: 'events',
23
+ subInfo: 'subInfo',
22
24
  disabled: i === 2,
23
25
  });
24
26
  }
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { render } from '@testing-library/react';
2
+ import { render, fireEvent } from '@testing-library/react';
3
3
  import { testHelper, filterUndefined, valueHelper, testMessageHelper } from '@/utils/testHelper';
4
4
  import { Dropdown } from '@/index';
5
5
  import { DropdownProps as Props } from '@/index.type';
@@ -27,6 +27,7 @@ for (let i = 1; i <= 10; i++) {
27
27
  }
28
28
 
29
29
  const FunctionValue = jest.fn();
30
+ const trigger = 'DesignSystem-DropdownTrigger';
30
31
 
31
32
  describe('Dropdown component', () => {
32
33
  const mapper: Record<string, any> = {
@@ -246,3 +247,13 @@ describe('Dropdown component', () => {
246
247
 
247
248
  testHelper(mapper, testFunc);
248
249
  });
250
+
251
+ describe('renders dropdown', () => {
252
+ it('renders popover', () => {
253
+ const { getByTestId } = render(<Dropdown options={storyOptions} />);
254
+ const dropdownTrigger = getByTestId(trigger);
255
+ fireEvent.click(dropdownTrigger);
256
+
257
+ expect(getByTestId('DesignSystem-Popover')).toBeInTheDocument();
258
+ });
259
+ });
@@ -0,0 +1,66 @@
1
+ import * as React from 'react';
2
+ import { render, fireEvent } from '@testing-library/react';
3
+ import { Dropdown } from '@/index';
4
+
5
+ import { storyOptions, iconOptions, subInfoOptions, iconWithSubinfoOptions } from '../__stories__/Options';
6
+
7
+ const FunctionValue = jest.fn();
8
+ const trigger = 'DesignSystem-DropdownTrigger';
9
+
10
+ describe('renders loading states', () => {
11
+ it('DEFAULT options', () => {
12
+ const { getAllByTestId, getByTestId } = render(<Dropdown options={storyOptions} loading={true} />);
13
+ const dropdownTrigger = getByTestId(trigger);
14
+ fireEvent.click(dropdownTrigger);
15
+
16
+ expect(getAllByTestId('DesignSystem-Dropdown--PlaceholderParagraph')).toHaveLength(storyOptions.length);
17
+ });
18
+
19
+ it('WITH_ICON options', () => {
20
+ const { getAllByTestId, getByTestId } = render(
21
+ <Dropdown options={iconOptions} loading={true} optionType="WITH_ICON" />
22
+ );
23
+ const dropdownTrigger = getByTestId(trigger);
24
+ fireEvent.click(dropdownTrigger);
25
+
26
+ expect(getAllByTestId('DesignSystem-Dropdown--Placeholder')).toHaveLength(iconOptions.length);
27
+ expect(getAllByTestId('DesignSystem-Placeholder--Image')).toHaveLength(iconOptions.length);
28
+ });
29
+
30
+ it('WITH_META options', () => {
31
+ const { getAllByTestId, queryByTestId, getByTestId } = render(
32
+ <Dropdown options={subInfoOptions} loading={true} optionType="WITH_META" />
33
+ );
34
+ const dropdownTrigger = getByTestId(trigger);
35
+ fireEvent.click(dropdownTrigger);
36
+
37
+ expect(getAllByTestId('DesignSystem-Dropdown--Placeholder')).toHaveLength(subInfoOptions.length);
38
+ expect(queryByTestId('DesignSystem-Placeholder--Image')).not.toBeInTheDocument();
39
+ expect(getAllByTestId('DesignSystem-Dropdown--PlaceholderParagraph')).toHaveLength(subInfoOptions.length * 2);
40
+ });
41
+
42
+ it('ICON_WITH_META options', () => {
43
+ const { getAllByTestId, getByTestId } = render(
44
+ <Dropdown options={iconWithSubinfoOptions} loading={true} optionType="ICON_WITH_META" />
45
+ );
46
+ const dropdownTrigger = getByTestId(trigger);
47
+ fireEvent.click(dropdownTrigger);
48
+
49
+ expect(getAllByTestId('DesignSystem-Dropdown--Placeholder')).toHaveLength(iconWithSubinfoOptions.length);
50
+ expect(getAllByTestId('DesignSystem-Placeholder--Image')).toHaveLength(iconWithSubinfoOptions.length);
51
+ expect(getAllByTestId('DesignSystem-Dropdown--PlaceholderParagraph')).toHaveLength(
52
+ iconWithSubinfoOptions.length * 2
53
+ );
54
+ });
55
+
56
+ it('WITH_CHECKBOX options', () => {
57
+ const { getAllByTestId, getByTestId } = render(
58
+ <Dropdown options={storyOptions} loading={true} withCheckbox={true} />
59
+ );
60
+ const dropdownTrigger = getByTestId(trigger);
61
+ fireEvent.click(dropdownTrigger);
62
+
63
+ expect(getAllByTestId('DesignSystem-Dropdown--Placeholder')).toHaveLength(storyOptions.length);
64
+ expect(getAllByTestId('DesignSystem-Placeholder--Image')).toHaveLength(storyOptions.length);
65
+ });
66
+ });
@@ -0,0 +1,204 @@
1
+ import * as React from 'react';
2
+ import { render, fireEvent } from '@testing-library/react';
3
+ import { Dropdown } from '@/index';
4
+
5
+ import {
6
+ storyOptions,
7
+ iconOptions,
8
+ subInfoOptions,
9
+ disabledStoryOptions,
10
+ iconWithSubinfoOptions,
11
+ } from '../__stories__/Options';
12
+
13
+ const FunctionValue = jest.fn();
14
+ const trigger = 'DesignSystem-DropdownTrigger';
15
+
16
+ describe('renders different options', () => {
17
+ it('renders DEFAULT options', () => {
18
+ const { getAllByTestId, getByTestId } = render(<Dropdown options={storyOptions} />);
19
+ const dropdownTrigger = getByTestId(trigger);
20
+ fireEvent.click(dropdownTrigger);
21
+ expect(getAllByTestId('DesignSystem-DropdownOption--DEFAULT')).toHaveLength(storyOptions.length);
22
+ expect(getAllByTestId('DesignSystem-DropdownOption--DEFAULT')[0].textContent).toMatch(storyOptions[0].label);
23
+ });
24
+
25
+ it('renders WITH_ICON options', () => {
26
+ const { getAllByTestId, getByTestId } = render(<Dropdown options={iconOptions} optionType="WITH_ICON" />);
27
+ const dropdownTrigger = getByTestId(trigger);
28
+ fireEvent.click(dropdownTrigger);
29
+ expect(getAllByTestId('DesignSystem-DropdownOption--WITH_ICON')).toHaveLength(iconOptions.length);
30
+ expect(getAllByTestId('DesignSystem-DropdownOption--WITH_ICON')[0].textContent).toMatch(iconOptions[0].label);
31
+ expect(getAllByTestId('DesignSystem-DropdownOption--WITH_ICON--Icon')[0].textContent).toMatch(iconOptions[0].icon);
32
+ });
33
+
34
+ it('renders WITH_META options', () => {
35
+ const { getAllByTestId, getByTestId } = render(<Dropdown options={subInfoOptions} optionType="WITH_META" />);
36
+ const dropdownTrigger = getByTestId(trigger);
37
+ fireEvent.click(dropdownTrigger);
38
+ expect(getAllByTestId('DesignSystem-DropdownOption--WITH_META')).toHaveLength(subInfoOptions.length);
39
+ expect(getAllByTestId('DesignSystem-DropdownOption--WITH_META')[0].textContent).toMatch(subInfoOptions[0].label);
40
+ expect(getAllByTestId('DesignSystem-DropdownOption--WITH_META--Meta')[0].textContent).toMatch(
41
+ subInfoOptions[0].subInfo
42
+ );
43
+ });
44
+
45
+ it('renders WITH_CHECKBOX options', () => {
46
+ const { getAllByTestId, getByTestId } = render(<Dropdown options={storyOptions} withCheckbox={true} />);
47
+ const dropdownTrigger = getByTestId(trigger);
48
+ fireEvent.click(dropdownTrigger);
49
+ expect(getAllByTestId('DesignSystem-DropdownOption--WITH_CHECKBOX')).toHaveLength(storyOptions.length);
50
+ expect(getAllByTestId('DesignSystem-DropdownOption--WITH_CHECKBOX')[0].textContent).toMatch(storyOptions[0].label);
51
+ });
52
+
53
+ it('renders ICON_WITH_META options', () => {
54
+ const { getAllByTestId, getByTestId } = render(
55
+ <Dropdown options={iconWithSubinfoOptions} optionType="ICON_WITH_META" />
56
+ );
57
+ const dropdownTrigger = getByTestId(trigger);
58
+ fireEvent.click(dropdownTrigger);
59
+ expect(getAllByTestId('DesignSystem-DropdownOption--ICON_WITH_META')).toHaveLength(iconWithSubinfoOptions.length);
60
+ expect(getAllByTestId('DesignSystem-DropdownOption--ICON_WITH_META')[0].textContent).toMatch(
61
+ iconWithSubinfoOptions[0].label
62
+ );
63
+ expect(getAllByTestId('DesignSystem-DropdownOption--ICON_WITH_META--Icon')[0].textContent).toMatch(
64
+ iconWithSubinfoOptions[0].icon
65
+ );
66
+ expect(getAllByTestId('DesignSystem-DropdownOption--ICON_WITH_META')[0].textContent).toMatch(
67
+ iconWithSubinfoOptions[0].subInfo
68
+ );
69
+ });
70
+ });
71
+
72
+ describe('renders custom option', () => {
73
+ it('custom option renderer', () => {
74
+ const { getAllByTestId, getByTestId } = render(<Dropdown options={storyOptions} optionRenderer={FunctionValue} />);
75
+ const dropdownTrigger = getByTestId(trigger);
76
+ fireEvent.click(dropdownTrigger);
77
+ expect(getAllByTestId('DesignSystem-DropdownOption--Custom')).toHaveLength(storyOptions.length);
78
+ expect(getAllByTestId('DesignSystem-DropdownOption--Custom')[0]).toHaveClass('OptionWrapper');
79
+ expect(FunctionValue).toHaveBeenCalled();
80
+ });
81
+ });
82
+
83
+ describe('dropdown with prop: truncateOption', () => {
84
+ it('wraps option', () => {
85
+ const { getAllByTestId, getByTestId } = render(<Dropdown options={storyOptions} truncateOption={false} />);
86
+ const dropdownTrigger = getByTestId(trigger);
87
+ fireEvent.click(dropdownTrigger);
88
+ expect(getAllByTestId('DesignSystem-Text')[0]).toHaveClass('Option-text--wrap');
89
+ });
90
+ });
91
+
92
+ describe('renders option with meta list', () => {
93
+ it('metalist option', () => {
94
+ const { getByTestId } = render(
95
+ <Dropdown
96
+ options={[
97
+ {
98
+ optionType: 'WITH_META',
99
+ label: 'Option',
100
+ value: 'Option',
101
+ subInfo: {
102
+ list: [
103
+ { icon: 'assessment', label: 'Meta data' },
104
+ { icon: 'assessment', label: 'Meta data' },
105
+ ],
106
+ seperator: true,
107
+ },
108
+ },
109
+ ]}
110
+ />
111
+ );
112
+ const dropdownTrigger = getByTestId(trigger);
113
+ fireEvent.click(dropdownTrigger);
114
+
115
+ expect(getByTestId('DesignSystem-DropdownOption--WITH_META--MetaList')).toBeInTheDocument();
116
+ });
117
+ });
118
+
119
+ describe('renders active option', () => {
120
+ it('without checkbox', () => {
121
+ const { getAllByTestId, getByTestId } = render(<Dropdown options={storyOptions} />);
122
+ const dropdownTrigger = getByTestId(trigger);
123
+ fireEvent.click(dropdownTrigger);
124
+
125
+ const option = getAllByTestId('DesignSystem-DropdownOption--DEFAULT')[0];
126
+ fireEvent.mouseEnter(option);
127
+ expect(option).toHaveClass('Option--active');
128
+ });
129
+
130
+ it('with checkbox', () => {
131
+ const { getAllByTestId, getByTestId } = render(<Dropdown options={storyOptions} withCheckbox={true} />);
132
+ const dropdownTrigger = getByTestId(trigger);
133
+ fireEvent.click(dropdownTrigger);
134
+
135
+ const option = getAllByTestId('DesignSystem-DropdownOption--WITH_CHECKBOX')[0];
136
+ fireEvent.mouseEnter(option);
137
+ expect(option).toHaveClass('Option-checkbox--active');
138
+ });
139
+ });
140
+
141
+ describe('renders selected option', () => {
142
+ it('with DEFAULT option', () => {
143
+ const { getAllByTestId, getByTestId } = render(<Dropdown options={storyOptions} />);
144
+ const dropdownTrigger = getByTestId(trigger);
145
+ fireEvent.click(dropdownTrigger);
146
+
147
+ const selectedOption = getAllByTestId('DesignSystem-DropdownOption--DEFAULT')[0];
148
+ fireEvent.click(selectedOption);
149
+ expect(selectedOption).toHaveClass('Option--selected');
150
+ });
151
+
152
+ it('WITH_ICON options', () => {
153
+ const { getAllByTestId, getByTestId } = render(<Dropdown options={iconOptions} optionType="WITH_ICON" />);
154
+ const dropdownTrigger = getByTestId(trigger);
155
+ fireEvent.click(dropdownTrigger);
156
+
157
+ const selectedOption = getAllByTestId('DesignSystem-DropdownOption--WITH_ICON')[0];
158
+ fireEvent.click(selectedOption);
159
+ expect(selectedOption).toHaveClass('Option--selected');
160
+ });
161
+
162
+ it('WITH_META options', () => {
163
+ const { getAllByTestId, getByTestId } = render(<Dropdown options={disabledStoryOptions} optionType="WITH_META" />);
164
+ const dropdownTrigger = getByTestId(trigger);
165
+ fireEvent.click(dropdownTrigger);
166
+
167
+ const selectedOption = getAllByTestId('DesignSystem-DropdownOption--WITH_META')[0];
168
+ fireEvent.click(selectedOption);
169
+ expect(selectedOption).toHaveClass('Option--selected');
170
+ });
171
+ });
172
+
173
+ describe('renders disabled option', () => {
174
+ it('with DEFAULT option', () => {
175
+ const { getAllByTestId, getByTestId } = render(<Dropdown options={disabledStoryOptions} />);
176
+ const dropdownTrigger = getByTestId(trigger);
177
+ fireEvent.click(dropdownTrigger);
178
+ expect(getAllByTestId('DesignSystem-DropdownOption--DEFAULT')[1]).toHaveClass('Option--disabled');
179
+ expect(getAllByTestId('DesignSystem-Text')[1]).toHaveClass('Text--disabled');
180
+ });
181
+
182
+ it('WITH_CHECKBOX option', () => {
183
+ const { getAllByTestId, getByTestId } = render(<Dropdown options={disabledStoryOptions} withCheckbox={true} />);
184
+ const dropdownTrigger = getByTestId(trigger);
185
+ fireEvent.click(dropdownTrigger);
186
+ expect(getAllByTestId('DesignSystem-DropdownOption--WITH_CHECKBOX')[1]).toHaveAttribute('data-disabled');
187
+ });
188
+
189
+ it('WITH_ICON options', () => {
190
+ const { getAllByTestId, getByTestId } = render(<Dropdown options={disabledStoryOptions} optionType="WITH_ICON" />);
191
+ const dropdownTrigger = getByTestId(trigger);
192
+ fireEvent.click(dropdownTrigger);
193
+ expect(getAllByTestId('DesignSystem-Text')[1]).toHaveClass('Text--disabled');
194
+ expect(getAllByTestId('DesignSystem-DropdownOption--WITH_ICON--Icon')[1]).toHaveClass('Icon--disabled');
195
+ });
196
+
197
+ it('WITH_META options', () => {
198
+ const { getAllByTestId, getByTestId } = render(<Dropdown options={disabledStoryOptions} optionType="WITH_META" />);
199
+ const dropdownTrigger = getByTestId(trigger);
200
+ fireEvent.click(dropdownTrigger);
201
+ expect(getAllByTestId('DesignSystem-Text')[1]).toHaveClass('Text--disabled');
202
+ expect(getAllByTestId('DesignSystem-DropdownOption--WITH_META--Meta')[1]).toHaveClass('Text--disabled');
203
+ });
204
+ });
@@ -16,6 +16,7 @@ const CheckboxOption = (props: OptionTypeProps) => {
16
16
  onChange={onChangeHandler}
17
17
  tabIndex={-1}
18
18
  className="OptionCheckbox"
19
+ data-test={`${dataTest}--Checkbox`}
19
20
  />
20
21
  </div>
21
22
  );
@@ -21,7 +21,9 @@ const IconOption = (props: OptionTypeProps) => {
21
21
  data-test={dataTest}
22
22
  data-disabled={disabled}
23
23
  >
24
- {icon && <Icon className="Option-icon mr-4" name={icon} appearance={appearance} />}
24
+ {icon && (
25
+ <Icon className="Option-icon mr-4" data-test={`${dataTest}--Icon`} name={icon} appearance={appearance} />
26
+ )}
25
27
  <div className={'Option-label'}>
26
28
  <Text className={textClassName} appearance={appearance}>
27
29
  {label}
@@ -30,7 +30,9 @@ const IconWithMetaOption = (props: OptionTypeProps) => {
30
30
  data-test={dataTest}
31
31
  data-disabled={disabled}
32
32
  >
33
- {icon && <Icon className="Option-icon mr-4" name={icon} appearance={appearance} />}
33
+ {icon && (
34
+ <Icon data-test={`${dataTest}--Icon`} className="Option-icon mr-4" name={icon} appearance={appearance} />
35
+ )}
34
36
  <div className={'Option-label'}>
35
37
  <Text className={textClassName} appearance={appearance}>
36
38
  {label}