@nuskin/foundation-ui-components 1.2.0 → 1.4.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 (55) hide show
  1. package/package.json +5 -5
  2. package/src/common/auth-dropdown/NsAuthDropdown.tsx +13 -9
  3. package/src/common/button/NsButton.stories.tsx +3 -2
  4. package/src/common/button/NsButton.tsx +27 -2
  5. package/src/common/button/types.d.ts +21 -17
  6. package/src/common/cart-icon/NsCartIcon.spec.tsx +3 -2
  7. package/src/common/cart-icon/NsCartIcon.stories.tsx +1 -1
  8. package/src/common/cart-icon/NsCartIcon.styled.tsx +14 -0
  9. package/src/common/cart-icon/NsCartIcon.tsx +1 -1
  10. package/src/common/cart-icon/types.d.ts +2 -2
  11. package/src/common/dropdown/NsDropdown.tsx +15 -11
  12. package/src/common/email-simple/NsEmailSimple.tsx +1 -1
  13. package/src/common/flag/NsFlag.spec.tsx +14 -2
  14. package/src/common/flag/NsFlag.styled.tsx +2 -5
  15. package/src/common/hooks/useOnClickOutside.tsx +14 -14
  16. package/src/common/icon/NsIcon.spec.tsx +21 -6
  17. package/src/common/icon/NsIcon.stories.tsx +2 -1
  18. package/src/common/icon/NsIcon.styled.tsx +13 -10
  19. package/src/common/icon/NsIcon.tsx +9 -6
  20. package/src/common/icon/NsIconVariants.ts +2 -0
  21. package/src/common/icon/icons/AlertErrorIcon.tsx +2 -1
  22. package/src/common/icon/icons/ArrowLeft.tsx +2 -2
  23. package/src/common/icon/icons/ArrowRight.tsx +2 -2
  24. package/src/common/icon/icons/CartBadge.tsx +2 -2
  25. package/src/common/icon/icons/Check.tsx +25 -0
  26. package/src/common/icon/icons/CloseIcon.tsx +1 -1
  27. package/src/common/icon/icons/ErrorIcon.tsx +3 -2
  28. package/src/common/icon/icons/SearchIcon.tsx +3 -2
  29. package/src/common/icon/icons/SuccessIcon.tsx +7 -1
  30. package/src/common/icon/icons/TrashIcon.tsx +2 -1
  31. package/src/common/icon/icons/UserIcon.tsx +8 -1
  32. package/src/common/icon/icons/UserOutline.tsx +4 -1
  33. package/src/common/icon/icons/WarningIcon.tsx +3 -2
  34. package/src/common/icon/types.d.ts +3 -2
  35. package/src/common/index.ts +8 -4
  36. package/src/common/progress/NsProgress.spec.tsx +2 -2
  37. package/src/common/progress/NsProgress.stories.tsx +10 -5
  38. package/src/common/progress/NsProgress.styled.tsx +30 -12
  39. package/src/common/progress/NsProgress.tsx +18 -16
  40. package/src/common/progress/types.d.ts +2 -2
  41. package/src/common/radiogroup/NsRadioGroup.spec.tsx +2 -2
  42. package/src/common/radiogroup/NsRadioGroup.stories.tsx +2 -2
  43. package/src/common/radiogroup/NsRadioGroup.tsx +5 -3
  44. package/src/common/radiogroup/types.d.ts +11 -12
  45. package/src/common/select/NsSelect.styled.tsx +38 -71
  46. package/src/common/select/NsSelect.tsx +86 -91
  47. package/src/common/select/NsSelectOption.tsx +10 -14
  48. package/src/common/select/specs/NsSelect.spec.tsx +183 -0
  49. package/src/common/select/specs/NsSelectOption.spec.tsx +32 -0
  50. package/src/common/select/stories/NsSelect.stories.tsx +25 -80
  51. package/src/common/select/stories/countries.ts +53 -0
  52. package/src/common/select/types.d.ts +21 -8
  53. package/src/common/table/NsTable.stories.tsx +1 -0
  54. package/src/common/cart-icon/NsCartIcon.styled.ts +0 -14
  55. package/src/common/select/NsSelect.spec.tsx +0 -274
@@ -1,8 +1,9 @@
1
1
  import React, { useState } from 'react';
2
+
2
3
  import type { Meta, StoryObj } from '@storybook/react';
3
- import NsSelect from '../NsSelect';
4
- import NsSelectOption from '../NsSelectOption';
4
+ import { NsSelectOption, NsSelect, SelectProps } from '../';
5
5
  import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
6
+ import { countries } from './countries';
6
7
 
7
8
  type ComponentType = typeof NsSelect;
8
9
  type Story = StoryObj<ComponentType>;
@@ -32,59 +33,7 @@ export default {
32
33
  hasArrows: { control: 'boolean' },
33
34
  },
34
35
  parameters: {
35
- options: [
36
- { label: 'Alabama', value: 'AL' },
37
- { label: 'Alaska', value: 'AK' },
38
- { label: 'Arizona', value: 'AZ' },
39
- { label: 'Arkansas', value: 'AR' },
40
- { label: 'California', value: 'CA' },
41
- { label: 'Colorado', value: 'CO' },
42
- { label: 'Connecticut', value: 'CT' },
43
- { label: 'Delaware', value: 'DE' },
44
- { label: 'District of Columbia', value: 'DC' },
45
- { label: 'Florida', value: 'FL' },
46
- { label: 'Georgia', value: 'GA' },
47
- { label: 'Hawaii', value: 'HI' },
48
- { label: 'Idaho', value: 'ID' },
49
- { label: 'Illinois', value: 'IL' },
50
- { label: 'Indiana', value: 'IN' },
51
- { label: 'Iowa', value: 'IA' },
52
- { label: 'Kansas', value: 'KA' },
53
- { label: 'Kentucky', value: 'KY' },
54
- { label: 'Louisiana', value: 'LA' },
55
- { label: 'Maine', value: 'ME' },
56
- { label: 'Maryland', value: 'MY' },
57
- { label: 'Massachusetts', value: 'MA' },
58
- { label: 'Michigan', value: 'MC' },
59
- { label: 'Minnesota', value: 'MN' },
60
- { label: 'Mississippi', value: 'MI' },
61
- { label: 'Missouri', value: 'MO' },
62
- { label: 'Montana', value: 'MT' },
63
- { label: 'Nebraska', value: 'NE' },
64
- { label: 'Nevada', value: 'NA' },
65
- { label: 'New Hampshire', value: 'NH' },
66
- { label: 'New Jersey', value: 'NJ' },
67
- { label: 'New Mexico', value: 'NM' },
68
- { label: 'New York', value: 'NY' },
69
- { label: 'North Carolina', value: 'NC' },
70
- { label: 'North Dakota', value: 'CD' },
71
- { label: 'Ohio', value: 'OH' },
72
- { label: 'Oklahoma', value: 'OK' },
73
- { label: 'Oregon', value: 'OR' },
74
- { label: 'Pennsylvania', value: 'PA' },
75
- { label: 'Rhode Island', value: 'RI' },
76
- { label: 'South Carolina', value: 'SC' },
77
- { label: 'South Dakota', value: 'SD' },
78
- { label: 'Tennessee', value: 'TN' },
79
- { label: 'Texas', value: 'TX' },
80
- { label: 'Utah', value: 'UT' },
81
- { label: 'Vermont', value: 'VT' },
82
- { label: 'Virginia', value: 'VA' },
83
- { label: 'Washington', value: 'WA' },
84
- { label: 'West Virginia', value: 'WV' },
85
- { label: 'Wisconsin', value: 'WN' },
86
- { label: 'Wyoming', value: 'WY' },
87
- ],
36
+ options: countries,
88
37
  },
89
38
  args: {
90
39
  type: 'outlined',
@@ -92,15 +41,12 @@ export default {
92
41
  selectBorderColor: 'primary',
93
42
  closeOnMouseLeave: false,
94
43
  showListDivider: true,
95
- selectedValue: '',
96
- selectedLabel: '',
44
+ selected: { label: '', value: '' },
97
45
  label: 'State',
98
46
  placeholder: '',
99
47
  name: '',
100
48
  menuProps: 'auto',
101
49
  reverseArrowControls: false,
102
- itemText: 'Text',
103
- itemValue: 'Value',
104
50
  validateOnBlur: false,
105
51
  autoComplete: '',
106
52
  rules: [],
@@ -108,36 +54,35 @@ export default {
108
54
  },
109
55
  } as MetaStory;
110
56
 
111
- const AppSelect = (props: any) => {
112
- const [selectedLabel, setSelectedLabel] = useState(props.selectedLabel);
113
- const [selectedValue, setSelectedValue] = useState(props.selectedValue);
114
- const handleSelect = (value: string) => {
115
- setSelectedValue(value);
116
- props.options.find((option: any) => {
117
- if (option.value === value) {
118
- setSelectedLabel(option.label);
119
- }
120
- });
121
- console.log('Selected:', value);
122
- };
57
+ const AppSelect = (props: SelectProps) => {
58
+ const { selected } = props;
123
59
 
60
+ const [data, setData] = useState(selected);
61
+ const onSelect = (x: any) => {
62
+ setData(x);
63
+ };
124
64
  return (
125
65
  <NsSelect
126
66
  {...props}
127
- selectedValue={selectedValue}
128
- selectedLabel={selectedLabel}
129
- onSelect={handleSelect}
67
+ selected={data}
68
+ onSelect={onSelect}
130
69
  label={props.label}
131
- >
132
- {props.options.map((option: any) => (
133
- <NsSelectOption key={option.value} value={option.value} label={option.label} />
134
- ))}
135
- </NsSelect>
70
+ options={props.options}
71
+ renderOption={(props) => {
72
+ return <NsSelectOption {...props} key={props?.value} onClick={props.onClick} />;
73
+ }}
74
+ />
136
75
  );
137
76
  };
138
77
  export const Select: Story = {
139
78
  render: (args, context) => {
140
79
  const options = context.parameters.options;
141
- return <AppSelect options={options} {...args} />;
80
+ return <AppSelect {...args} options={options} />;
81
+ },
82
+ };
83
+ export const SelectWithArrows: Story = {
84
+ render: (args, context) => {
85
+ const options = context.parameters.options;
86
+ return <AppSelect {...args} options={options} hasArrows />;
142
87
  },
143
88
  };
@@ -0,0 +1,53 @@
1
+ export const countries = [
2
+ { label: 'Alabama', value: 'AL' },
3
+ { label: 'Alaska', value: 'AK' },
4
+ { label: 'Arizona', value: 'AZ' },
5
+ { label: 'Arkansas', value: 'AR' },
6
+ { label: 'California', value: 'CA' },
7
+ { label: 'Colorado', value: 'CO' },
8
+ { label: 'Connecticut', value: 'CT' },
9
+ { label: 'Delaware', value: 'DE' },
10
+ { label: 'District of Columbia', value: 'DC' },
11
+ { label: 'Florida', value: 'FL' },
12
+ { label: 'Georgia', value: 'GA' },
13
+ { label: 'Hawaii', value: 'HI' },
14
+ { label: 'Idaho', value: 'ID' },
15
+ { label: 'Illinois', value: 'IL' },
16
+ { label: 'Indiana', value: 'IN' },
17
+ { label: 'Iowa', value: 'IA' },
18
+ { label: 'Kansas', value: 'KA' },
19
+ { label: 'Kentucky', value: 'KY' },
20
+ { label: 'Louisiana', value: 'LA' },
21
+ { label: 'Maine', value: 'ME' },
22
+ { label: 'Maryland', value: 'MY' },
23
+ { label: 'Massachusetts', value: 'MA' },
24
+ { label: 'Michigan', value: 'MC' },
25
+ { label: 'Minnesota', value: 'MN' },
26
+ { label: 'Mississippi', value: 'MI' },
27
+ { label: 'Missouri', value: 'MO' },
28
+ { label: 'Montana', value: 'MT' },
29
+ { label: 'Nebraska', value: 'NE' },
30
+ { label: 'Nevada', value: 'NA' },
31
+ { label: 'New Hampshire', value: 'NH' },
32
+ { label: 'New Jersey', value: 'NJ' },
33
+ { label: 'New Mexico', value: 'NM' },
34
+ { label: 'New York', value: 'NY' },
35
+ { label: 'North Carolina', value: 'NC' },
36
+ { label: 'North Dakota', value: 'CD' },
37
+ { label: 'Ohio', value: 'OH' },
38
+ { label: 'Oklahoma', value: 'OK' },
39
+ { label: 'Oregon', value: 'OR' },
40
+ { label: 'Pennsylvania', value: 'PA' },
41
+ { label: 'Rhode Island', value: 'RI' },
42
+ { label: 'South Carolina', value: 'SC' },
43
+ { label: 'South Dakota', value: 'SD' },
44
+ { label: 'Tennessee', value: 'TN' },
45
+ { label: 'Texas', value: 'TX' },
46
+ { label: 'Utah', value: 'UT' },
47
+ { label: 'Vermont', value: 'VT' },
48
+ { label: 'Virginia', value: 'VA' },
49
+ { label: 'Washington', value: 'WA' },
50
+ { label: 'West Virginia', value: 'WV' },
51
+ { label: 'Wisconsin', value: 'WN' },
52
+ { label: 'Wyoming', value: 'WY' },
53
+ ];
@@ -1,10 +1,9 @@
1
- import { ReactNode } from 'react';
2
1
  import { FoundationTheme } from '@nuskin/foundation-theme';
2
+ import { ReactNode } from 'react';
3
3
 
4
4
  export interface SelectProps {
5
- selectedValue: string;
6
- selectedLabel: string;
7
- onSelect: (arg: string) => void; // eslint-disable-line
5
+ selected: LabelValueType;
6
+ onSelect(arg: LabelValueType): void; // eslint-disable-line
8
7
  children?: ReactNode | null;
9
8
  disabled?: boolean;
10
9
  type?: 'outlined' | 'unfilled';
@@ -18,19 +17,33 @@ export interface SelectProps {
18
17
  errorMessage?: string;
19
18
  menuProps?: string | object;
20
19
  reverseArrowControls?: boolean;
21
- itemText?: string;
22
- itemValue?: string;
23
20
  validateOnBlur?: boolean;
24
21
  autoComplete?: string;
25
22
  // eslint-disable-next-line no-undef
26
23
  rules?: Array;
27
24
  hasArrows?: boolean;
25
+ options: LabelValueType[];
26
+ renderOption(x: any): any; // eslint-disable-line
28
27
  }
29
28
 
30
29
  export interface SelectOptionProps {
31
30
  value: string;
32
31
  label: string;
33
- selectedValue?: string;
34
- onSelect?: (arg: string) => void; // eslint-disable-line
32
+ selected?: LabelValueType;
33
+ index: number;
34
+ onClick: () => void;
35
35
  showListDivider?: boolean;
36
36
  }
37
+
38
+ export type LabelValueType = {
39
+ label: string;
40
+ value: string;
41
+ id?: string;
42
+ index?: number;
43
+ };
44
+
45
+ export type RenderSelectOptionArgType = LabelValueType & {
46
+ onClick(): void;
47
+ showListDivider: boolean;
48
+ selected: LabelValueType;
49
+ };
@@ -1,4 +1,5 @@
1
1
  import React from 'react'
2
+
2
3
  import type { Meta, StoryObj } from '@storybook/react';
3
4
  import NsTable from './NsTable';
4
5
  import { withCenterDecorator } from '../../stories/decorators/withCenterDecorator';
@@ -1,14 +0,0 @@
1
- import { Badge, Theme } from '@mui/material';
2
- import { styled, FoundationTheme } from '@nuskin/foundation-theme';
3
-
4
- type ItemCountParams = {
5
- theme?: Theme;
6
- bgcolor: FoundationTheme.PaletteColors;
7
- };
8
-
9
- export const StyledBadge = styled(Badge) <ItemCountParams>`
10
- & .MuiBadge-badge {
11
- background-color: ${({ bgcolor, theme }) => theme?.palette?.[bgcolor]?.main};
12
- color: ${({ bgcolor, theme }) => theme?.palette?.[bgcolor]?.contrastText};
13
- }
14
- `;
@@ -1,274 +0,0 @@
1
- import React from 'react';
2
- import { render, fireEvent, screen, waitFor } from '@/test-utils/index';
3
- import NsSelect from './NsSelect';
4
- import NsSelectOption from './NsSelectOption';
5
-
6
- function createSelectOptions(options: { value: string; label: string }[]) {
7
- return options.map((option) => <NsSelectOption key={option.value} value={option.value} label={option.label} />);
8
- }
9
-
10
- describe('NsSelectOption', () => {
11
- it('1. renders NsSelectOption component without errors', () => {
12
- const value = 'option1';
13
- const label = 'Option 1';
14
- const { getByTestId, getByText } = render(<NsSelectOption value={value} label={label} />);
15
-
16
- // Check if the option container element exists
17
- const optionContainer = getByTestId(`option-${value}`);
18
- expect(optionContainer).toBeInTheDocument();
19
-
20
- // Check if the option label is rendered correctly
21
- const optionLabel = getByText(label);
22
- expect(optionLabel).toBeInTheDocument();
23
- });
24
- it('2. clicking on NsSelectOption selects the option', () => {
25
- const value = 'option1';
26
- const label = 'Option 1';
27
- const onSelect = jest.fn();
28
- const { getByTestId } = render(<NsSelectOption value={value} label={label} onSelect={onSelect} />);
29
- const optionElement = getByTestId(`option-${value}`);
30
- fireEvent.click(optionElement);
31
- expect(onSelect).toHaveBeenCalledWith(value);
32
- });
33
- });
34
-
35
- describe('NsSelect', () => {
36
- const onSelect = jest.fn();
37
- const selectedValue = '';
38
- const selectedLabel = '';
39
-
40
- const options = [
41
- { value: 'Option1', label: 'Option 1' },
42
- { value: 'Option2', label: 'Option 2' },
43
- { value: 'Option3', label: 'Option 3' },
44
- ];
45
-
46
- it('1. renders the placeholder text when no value is selected', () => {
47
- render(
48
- <NsSelect
49
- placeholder="Select an option"
50
- selectedValue={selectedValue}
51
- selectedLabel={selectedLabel}
52
- onSelect={onSelect}
53
- >
54
- {createSelectOptions(options)}
55
- </NsSelect>
56
- );
57
-
58
- expect(screen.getByText('Select an option')).toBeInTheDocument();
59
- });
60
-
61
- it('2. clicking outside the select container closes the dropdown', () => {
62
- const onSelect = jest.fn();
63
- const selectedLabel = 'Option 1';
64
- const { getByTestId, queryByTestId } = render(
65
- <NsSelect selectedValue="Option1" selectedLabel={selectedLabel} onSelect={onSelect} />
66
- );
67
- const selectButton = getByTestId('select-head');
68
- fireEvent.mouseDown(selectButton);
69
- const outsideElement = document.createElement('div');
70
- fireEvent.mouseDown(outsideElement);
71
- // Add assertions to check if the dropdown is closed (isOpen state is false)
72
- expect(queryByTestId('option-Option1')).toBeNull();
73
- });
74
-
75
- it('3. renders the selected value label', () => {
76
- const selectedLabel = 'Option 1';
77
- render(
78
- <NsSelect selectedValue="Option1" selectedLabel={selectedLabel} onSelect={onSelect}>
79
- {createSelectOptions(options)}
80
- </NsSelect>
81
- );
82
-
83
- expect(screen.getByText(selectedLabel)).toBeInTheDocument();
84
- });
85
-
86
- it('4. clicking on select button opens the dropdown', () => {
87
- const { getByTestId, getByText } = render(
88
- <NsSelect selectedValue="Option1" selectedLabel={selectedLabel} onSelect={onSelect}>
89
- {createSelectOptions(options)}
90
- </NsSelect>
91
- );
92
- const selectButton = getByTestId('select-head');
93
- fireEvent.mouseDown(selectButton);
94
-
95
- // Check if the dropdown is opened (isOpen state is true)
96
- const dropdownList = getByTestId('select-list');
97
- expect(dropdownList).toBeInTheDocument();
98
-
99
- // Check if the options are rendered in the dropdown
100
- const option1 = getByText('Option 1');
101
- const option2 = getByText('Option 2');
102
- expect(option1).toBeInTheDocument();
103
- expect(option2).toBeInTheDocument();
104
- });
105
-
106
- it('5. disabling the select component prevents interaction', () => {
107
- const onSelect = jest.fn();
108
- const { getByTestId, queryByTestId } = render(
109
- <NsSelect selectedValue="Option1" selectedLabel={selectedLabel} onSelect={onSelect} disabled>
110
- <NsSelectOption value="option1" label="Option 1" onSelect={onSelect} />
111
- <NsSelectOption value="option2" label="Option 2" onSelect={onSelect} />
112
- </NsSelect>
113
- );
114
- const selectButton = getByTestId('select-head');
115
- fireEvent.mouseDown(selectButton);
116
-
117
- // Check if the dropdown does not open (select list is not present)
118
- const dropdownList = queryByTestId('select-list');
119
- expect(dropdownList).toBeNull();
120
-
121
- // Check if the onSelect callback is not called
122
- expect(onSelect).not.toHaveBeenCalled();
123
- });
124
-
125
- it('6. select closes on mouse leave when closeOnMouseLeave is set to true', async () => {
126
- render(
127
- <NsSelect closeOnMouseLeave selectedValue={selectedValue} selectedLabel={selectedLabel} onSelect={onSelect}>
128
- {createSelectOptions(options)}
129
- </NsSelect>
130
- );
131
-
132
- const selectHead = screen.getByTestId('select-head');
133
- fireEvent.click(selectHead);
134
-
135
- // const selectList = screen.queryByTestId ('select-list');
136
- const option1 = screen.queryByTestId('option-Option1');
137
- const option2 = screen.queryByTestId('option-Option2');
138
- const option3 = screen.queryByTestId('option-Option3');
139
- fireEvent.click(selectHead);
140
-
141
- await waitFor(() => {
142
- expect(option1).not.toBeInTheDocument();
143
- expect(option2).not.toBeInTheDocument();
144
- expect(option3).not.toBeInTheDocument();
145
- });
146
- });
147
- it('7. select does not open when disabled', () => {
148
- render(
149
- <NsSelect selectedValue={selectedValue} selectedLabel={selectedLabel} onSelect={onSelect} disabled>
150
- {createSelectOptions(options)}
151
- </NsSelect>
152
- );
153
-
154
- const selectHead = screen.getByTestId('select-head');
155
- fireEvent.click(selectHead);
156
-
157
- expect(screen.queryByTestId('select-list')).not.toBeInTheDocument();
158
- });
159
-
160
- it('8. opens the select on "ArrowDown" key press', () => {
161
- render(
162
- <NsSelect selectedValue={selectedValue} selectedLabel={selectedLabel} onSelect={onSelect}>
163
- {createSelectOptions(options)}
164
- </NsSelect>
165
- );
166
-
167
- const selectHead = screen.getByTestId('select-head');
168
- fireEvent.keyDown(selectHead, { key: 'arrowDown' });
169
-
170
- expect(selectHead).toBeInTheDocument();
171
- });
172
-
173
- it('9. closes the select when closeSelect is called', () => {
174
- const { getByTestId } = render(
175
- <NsSelect selectedValue={selectedValue} selectedLabel={selectedLabel} onSelect={onSelect} closeOnMouseLeave>
176
- {createSelectOptions(options)}
177
- </NsSelect>
178
- );
179
-
180
- const selectContainer = getByTestId('select-container');
181
- fireEvent.mouseLeave(selectContainer);
182
-
183
- expect(screen.queryByTestId('select-list')).not.toBeInTheDocument();
184
- });
185
-
186
- it('10. does not open the select when disabled', () => {
187
- render(
188
- <NsSelect selectedValue={selectedValue} selectedLabel={selectedLabel} onSelect={onSelect} disabled>
189
- {createSelectOptions(options)}
190
- </NsSelect>
191
- );
192
-
193
- const selectHead = screen.getByTestId('select-head');
194
- fireEvent.mouseDown(selectHead);
195
-
196
- expect(screen.queryByTestId('select-list')).not.toBeInTheDocument();
197
- });
198
-
199
- it('11. selects the next option on arrow right click', () => {
200
- // Render the NsSelect component with options and onSelect function
201
- const onSelect = jest.fn();
202
- const { getByTestId } = render(
203
- <NsSelect selectedValue={selectedValue} selectedLabel={selectedLabel} onSelect={onSelect} hasArrows>
204
- {createSelectOptions(options)}
205
- </NsSelect>
206
- );
207
-
208
- // Simulate the arrow right click on the NsSelect component
209
- const selectHead = getByTestId('select-head');
210
- fireEvent.mouseDown(selectHead);
211
-
212
- const rightArrow = document.getElementsByClassName('RightArrow')[0];
213
- fireEvent.click(rightArrow);
214
-
215
- // Verify that the next option is selected and the onSelect function is called
216
- expect(onSelect).toHaveBeenCalledWith('Option1');
217
- });
218
-
219
- it('12. selects the previous option on arrow left click', () => {
220
- const { getByTestId } = render(
221
- <NsSelect
222
- selectedValue={selectedValue}
223
- selectedLabel={selectedLabel}
224
- onSelect={onSelect}
225
- hasArrows
226
- reverseArrowControls
227
- >
228
- {createSelectOptions(options)}
229
- </NsSelect>
230
- );
231
-
232
- const selectHead = getByTestId('select-head');
233
- fireEvent.mouseDown(selectHead);
234
-
235
- const leftArrow = document.getElementsByClassName('LeftArrow')[0];
236
- fireEvent.click(leftArrow);
237
-
238
- expect(onSelect).toHaveBeenCalledWith('Option1');
239
- });
240
-
241
- it('13. renders an error message with red styles', () => {
242
- const errorMessage = 'Invalid value';
243
- const { getByText } = render(
244
- <NsSelect
245
- selectedValue={selectedValue}
246
- selectedLabel={selectedLabel}
247
- onSelect={onSelect}
248
- errorMessage={errorMessage}
249
- >
250
- {createSelectOptions(options)}
251
- </NsSelect>
252
- );
253
-
254
- // Check if the error message is rendered correctly with red styles
255
- const errorText = getByText(errorMessage);
256
- expect(errorText).toBeInTheDocument();
257
- });
258
- it('14. selecting an option calls the onSelect callback', () => {
259
- const onSelect = jest.fn();
260
- const { getByTestId } = render(
261
- <NsSelect selectedValue={selectedValue} selectedLabel={selectedLabel} onSelect={onSelect}>
262
- {createSelectOptions(options)}
263
- </NsSelect>
264
- );
265
-
266
- const selectHead = getByTestId('select-head');
267
- fireEvent.mouseDown(selectHead);
268
-
269
- const option1 = getByTestId('option-Option1');
270
- fireEvent.click(option1);
271
-
272
- expect(onSelect).toHaveBeenCalledWith('Option1');
273
- });
274
- });