@registrucentras/rc-ses-react-components 1.6.4 → 1.6.6
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.
- package/dist/assets/IconProps.d.ts +2 -0
- package/dist/assets/icons/ArrowsClockwiseIcon.d.ts +3 -0
- package/dist/assets/icons/CheckIcon.d.ts +3 -0
- package/dist/assets/icons/PencilSimpleLineIcon.d.ts +3 -0
- package/dist/components/common/Card/index.d.ts +4 -1
- package/dist/components/form/inputs/SearchInput/index.d.ts +27 -0
- package/dist/components/form/inputs/Select/Select.types.d.ts +5 -0
- package/dist/components/form/inputs/Select/hooks/useFilteredOptions.d.ts +3 -0
- package/dist/components/form/inputs/Select/hooks/useSelectAllLogic.d.ts +7 -0
- package/dist/components/form/inputs/{Select.d.ts → Select/index.d.ts} +12 -12
- package/dist/library/icons.d.ts +3 -1
- package/dist/library/index.d.ts +2 -0
- package/dist/registrucentras-rc-ses-react-components.cjs +11 -11
- package/dist/registrucentras-rc-ses-react-components.js +3346 -2752
- package/dist/stories/components/display/Card.stories.d.ts +6 -47
- package/dist/stories/components/display/ImageCard.stories.d.ts +6 -6
- package/dist/stories/components/feedback/Alert.stories.d.ts +7 -16
- package/dist/stories/components/form/CardFormContainer.stories.d.ts +5 -5
- package/dist/stories/components/form/CheckboxFormControl.stories.d.ts +3 -23
- package/dist/stories/components/form/ServiceFormActions.stories.d.ts +3 -9
- package/dist/stories/components/icons/Icons.stories.d.ts +3 -2
- package/dist/stories/components/inputs/FileDropzone.stories.d.ts +3 -29
- package/dist/stories/components/inputs/NumberStepper.stories.d.ts +3 -31
- package/dist/stories/components/inputs/RadioButtonGroup.stories.d.ts +4 -32
- package/dist/stories/components/inputs/SearchInput.stories.d.ts +11 -0
- package/dist/stories/components/inputs/SearchableField.stories.d.ts +3 -332
- package/dist/stories/components/inputs/Select.stories.d.ts +4 -871
- package/dist/stories/components/inputs/TextField.stories.d.ts +3 -610
- package/dist/stories/components/layout/Footer.stories.d.ts +3 -5
- package/dist/stories/components/navigation/Breadcrumbs.stories.d.ts +4 -6
- package/dist/stories/components/navigation/ServiceWizardStepper.stories.d.ts +5 -5
- package/dist/theme/light/MuiOutlinedInput.d.ts +3 -0
- package/package.json +1 -1
- package/src/assets/IconProps.ts +2 -0
- package/src/assets/icons/ArrowsClockwiseIcon.tsx +16 -0
- package/src/assets/icons/CheckIcon.tsx +23 -0
- package/src/assets/icons/PencilSimpleLineIcon.tsx +17 -0
- package/src/components/common/Card/index.test.tsx +8 -0
- package/src/components/common/Card/index.tsx +64 -25
- package/src/components/common/SelectableCardList/index.tsx +2 -1
- package/src/components/form/components/FormControlWrapper/index.tsx +6 -1
- package/src/components/form/inputs/PhoneInputFormControl/index.tsx +11 -3
- package/src/components/form/inputs/SearchInput/index.test.tsx +203 -0
- package/src/components/form/inputs/SearchInput/index.tsx +282 -0
- package/src/components/form/inputs/Select/Select.types.ts +5 -0
- package/src/components/form/inputs/Select/hooks/useFilteredOptions.ts +18 -0
- package/src/components/form/inputs/Select/hooks/useSelectAllLogic.ts +22 -0
- package/src/components/form/inputs/Select/index.tsx +494 -0
- package/src/i18n/namespaces/input/en.json +5 -0
- package/src/i18n/namespaces/input/lt.json +5 -0
- package/src/library/icons.ts +4 -0
- package/src/library/index.ts +2 -0
- package/src/stories/components/display/Card.stories.tsx +64 -47
- package/src/stories/components/display/ImageCard.stories.tsx +29 -27
- package/src/stories/components/feedback/Alert.stories.tsx +59 -50
- package/src/stories/components/form/CardFormContainer.stories.tsx +77 -63
- package/src/stories/components/form/CheckboxFormControl.stories.tsx +29 -71
- package/src/stories/components/form/ServiceFormActions.stories.tsx +18 -21
- package/src/stories/components/form/ServiceFormContainer.stories.tsx +1 -1
- package/src/stories/components/icons/Icons.stories.tsx +6 -2
- package/src/stories/components/inputs/FileDropzone.stories.tsx +17 -34
- package/src/stories/components/inputs/NumberStepper.stories.tsx +32 -60
- package/src/stories/components/inputs/RadioButtonGroup.stories.tsx +22 -20
- package/src/stories/components/inputs/SearchInput.stories.tsx +134 -0
- package/src/stories/components/inputs/SearchableField.stories.tsx +16 -14
- package/src/stories/components/inputs/Select.stories.tsx +245 -13
- package/src/stories/components/inputs/TextField.stories.tsx +47 -47
- package/src/stories/components/layout/Footer.stories.tsx +6 -6
- package/src/stories/components/navigation/Breadcrumbs.stories.tsx +6 -8
- package/src/stories/components/navigation/ServiceWizardStepper.stories.tsx +29 -22
- package/src/theme/light/MuiAutocomplete.ts +52 -3
- package/src/theme/light/MuiOutlinedInput.ts +15 -0
- package/src/theme/light/index.tsx +2 -0
- package/src/components/form/inputs/Select.tsx +0 -152
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { Meta,
|
|
2
|
-
import { default as RcSesBreadcrumbs
|
|
3
|
-
import { AnnotatedStoryFn } from '@storybook/core/csf';
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as RcSesBreadcrumbs } from '../../../components/common/Breadcrumbs';
|
|
4
3
|
declare const meta: Meta<typeof RcSesBreadcrumbs>;
|
|
5
4
|
export default meta;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}>;
|
|
5
|
+
type Story = StoryObj<typeof RcSesBreadcrumbs>;
|
|
6
|
+
export declare const Main: Story;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Meta,
|
|
2
|
-
import { default as ServiceWizardStepper
|
|
3
|
-
import { StoryAnnotations } from '@storybook/core/csf';
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { default as ServiceWizardStepper } from '../../../components/layout/ServiceWizardStepper';
|
|
4
3
|
declare const meta: Meta<typeof ServiceWizardStepper>;
|
|
5
4
|
export default meta;
|
|
6
|
-
|
|
7
|
-
export declare const
|
|
5
|
+
type Story = StoryObj<typeof ServiceWizardStepper>;
|
|
6
|
+
export declare const Horizontal: Story;
|
|
7
|
+
export declare const Vertical: Story;
|
package/package.json
CHANGED
package/src/assets/IconProps.ts
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ArrowsClockwiseIcon as PhosphorArrowClockwiseIcon } from '@phosphor-icons/react'
|
|
2
|
+
|
|
3
|
+
import IconProps from '../IconProps'
|
|
4
|
+
|
|
5
|
+
function ArrowsClockwiseIcon({ className, size = 24, fillColor, ...rest }: IconProps) {
|
|
6
|
+
return (
|
|
7
|
+
<PhosphorArrowClockwiseIcon
|
|
8
|
+
{...rest}
|
|
9
|
+
className={className}
|
|
10
|
+
size={size}
|
|
11
|
+
color={fillColor}
|
|
12
|
+
/>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default ArrowsClockwiseIcon
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CheckIcon as CheckFillIcon } from '@phosphor-icons/react'
|
|
2
|
+
|
|
3
|
+
import IconProps from '../IconProps'
|
|
4
|
+
|
|
5
|
+
function CheckIcon({
|
|
6
|
+
className,
|
|
7
|
+
fillColor,
|
|
8
|
+
size = 24,
|
|
9
|
+
weight = 'fill',
|
|
10
|
+
...rest
|
|
11
|
+
}: IconProps) {
|
|
12
|
+
return (
|
|
13
|
+
<CheckFillIcon
|
|
14
|
+
{...rest}
|
|
15
|
+
className={className}
|
|
16
|
+
size={size}
|
|
17
|
+
weight={weight}
|
|
18
|
+
color={fillColor}
|
|
19
|
+
/>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default CheckIcon
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PencilSimpleLineIcon as PencilSimpleLine } from '@phosphor-icons/react'
|
|
2
|
+
|
|
3
|
+
import IconProps from '../IconProps'
|
|
4
|
+
|
|
5
|
+
function PencilSimpleLineIcon({ className, fillColor, size = 24, ...rest }: IconProps) {
|
|
6
|
+
return (
|
|
7
|
+
<PencilSimpleLine
|
|
8
|
+
{...rest}
|
|
9
|
+
className={className}
|
|
10
|
+
size={size}
|
|
11
|
+
weight='fill'
|
|
12
|
+
color={fillColor}
|
|
13
|
+
/>
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default PencilSimpleLineIcon
|
|
@@ -16,6 +16,7 @@ describe('RcSesCard', () => {
|
|
|
16
16
|
<RcSesCard
|
|
17
17
|
title='Card title'
|
|
18
18
|
description='Card description'
|
|
19
|
+
headerAction={<button type='button'>Edit</button>}
|
|
19
20
|
leadingActions={<button type='button'>Back</button>}
|
|
20
21
|
trailingActions={<button type='button'>Continue</button>}
|
|
21
22
|
>
|
|
@@ -26,6 +27,7 @@ describe('RcSesCard', () => {
|
|
|
26
27
|
expect(screen.getByText('Card title')).toBeInTheDocument()
|
|
27
28
|
expect(screen.getByText('Card description')).toBeInTheDocument()
|
|
28
29
|
expect(screen.getByText('Card content')).toBeInTheDocument()
|
|
30
|
+
expect(screen.getByRole('button', { name: 'Edit' })).toBeInTheDocument()
|
|
29
31
|
expect(screen.getByRole('button', { name: 'Back' })).toBeInTheDocument()
|
|
30
32
|
expect(screen.getByRole('button', { name: 'Continue' })).toBeInTheDocument()
|
|
31
33
|
})
|
|
@@ -47,6 +49,7 @@ describe('RcSesCard', () => {
|
|
|
47
49
|
<RcSesCard
|
|
48
50
|
title='Slotted title'
|
|
49
51
|
description='Slotted description'
|
|
52
|
+
headerAction={<button type='button'>Edit</button>}
|
|
50
53
|
leadingActions={<button type='button'>Leading</button>}
|
|
51
54
|
trailingActions={<button type='button'>Trailing</button>}
|
|
52
55
|
slotProps={{
|
|
@@ -54,6 +57,7 @@ describe('RcSesCard', () => {
|
|
|
54
57
|
content: { className: 'content-slot' },
|
|
55
58
|
description: { className: 'description-slot' },
|
|
56
59
|
header: { className: 'header-slot' },
|
|
60
|
+
headerAction: { className: 'header-action-slot' },
|
|
57
61
|
leadingActions: { className: 'leading-actions-slot' },
|
|
58
62
|
title: { className: 'title-slot' },
|
|
59
63
|
trailingActions: { className: 'trailing-actions-slot' },
|
|
@@ -64,6 +68,7 @@ describe('RcSesCard', () => {
|
|
|
64
68
|
)
|
|
65
69
|
|
|
66
70
|
expect(container.querySelector('.header-slot')).toBeInTheDocument()
|
|
71
|
+
expect(container.querySelector('.header-action-slot')).toBeInTheDocument()
|
|
67
72
|
expect(container.querySelector('.title-slot')).toBeInTheDocument()
|
|
68
73
|
expect(container.querySelector('.description-slot')).toBeInTheDocument()
|
|
69
74
|
expect(container.querySelector('.content-slot')).toBeInTheDocument()
|
|
@@ -77,11 +82,13 @@ describe('RcSesCard', () => {
|
|
|
77
82
|
<RcSesCard
|
|
78
83
|
title='Test id title'
|
|
79
84
|
description='Test id description'
|
|
85
|
+
headerAction={<button type='button'>Edit</button>}
|
|
80
86
|
leadingActions={<button type='button'>Leading</button>}
|
|
81
87
|
trailingActions={<button type='button'>Trailing</button>}
|
|
82
88
|
testIds={{
|
|
83
89
|
root: 'card-root',
|
|
84
90
|
header: 'card-header',
|
|
91
|
+
headerAction: 'card-header-action',
|
|
85
92
|
title: 'card-title',
|
|
86
93
|
description: 'card-description',
|
|
87
94
|
content: 'card-content',
|
|
@@ -96,6 +103,7 @@ describe('RcSesCard', () => {
|
|
|
96
103
|
|
|
97
104
|
expect(screen.getByTestId('card-root')).toBeInTheDocument()
|
|
98
105
|
expect(screen.getByTestId('card-header')).toBeInTheDocument()
|
|
106
|
+
expect(screen.getByTestId('card-header-action')).toBeInTheDocument()
|
|
99
107
|
expect(screen.getByTestId('card-title')).toBeInTheDocument()
|
|
100
108
|
expect(screen.getByTestId('card-description')).toBeInTheDocument()
|
|
101
109
|
expect(screen.getByTestId('card-content')).toBeInTheDocument()
|
|
@@ -18,6 +18,7 @@ export type RcSesCardTestIds = {
|
|
|
18
18
|
root?: string
|
|
19
19
|
image?: string
|
|
20
20
|
header?: string
|
|
21
|
+
headerAction?: string
|
|
21
22
|
title?: string
|
|
22
23
|
description?: string
|
|
23
24
|
content?: string
|
|
@@ -30,6 +31,7 @@ export type RcSesCardProps = Omit<CardProps, 'children' | 'title'> & {
|
|
|
30
31
|
title: ReactNode
|
|
31
32
|
description?: ReactNode
|
|
32
33
|
image?: ReactNode
|
|
34
|
+
headerAction?: ReactNode
|
|
33
35
|
centered?: boolean
|
|
34
36
|
contentBackground?: boolean
|
|
35
37
|
children?: ReactNode
|
|
@@ -41,6 +43,7 @@ export type RcSesCardProps = Omit<CardProps, 'children' | 'title'> & {
|
|
|
41
43
|
content?: BoxProps
|
|
42
44
|
description?: TypographyProps
|
|
43
45
|
header?: StackProps
|
|
46
|
+
headerAction?: BoxProps
|
|
44
47
|
image?: BoxProps
|
|
45
48
|
leadingActions?: StackProps
|
|
46
49
|
title?: TypographyProps
|
|
@@ -73,6 +76,7 @@ function RcSesCard({
|
|
|
73
76
|
title,
|
|
74
77
|
description,
|
|
75
78
|
image,
|
|
79
|
+
headerAction,
|
|
76
80
|
centered = false,
|
|
77
81
|
contentBackground = true,
|
|
78
82
|
children,
|
|
@@ -87,6 +91,7 @@ function RcSesCard({
|
|
|
87
91
|
const contentProps = slotProps?.content
|
|
88
92
|
const descriptionProps = slotProps?.description
|
|
89
93
|
const headerProps = slotProps?.header
|
|
94
|
+
const headerActionProps = slotProps?.headerAction
|
|
90
95
|
const imageProps = slotProps?.image
|
|
91
96
|
const leadingActionsProps = slotProps?.leadingActions
|
|
92
97
|
const titleProps = slotProps?.title
|
|
@@ -95,6 +100,7 @@ function RcSesCard({
|
|
|
95
100
|
const normalizedSx = normalizeSx(sx)
|
|
96
101
|
const normalizedTitleSx = normalizeSx(titleProps?.sx)
|
|
97
102
|
const normalizedDescriptionSx = normalizeSx(descriptionProps?.sx)
|
|
103
|
+
const normalizedHeaderActionSx = normalizeSx(headerActionProps?.sx)
|
|
98
104
|
const normalizedContentSx = normalizeSx(contentProps?.sx)
|
|
99
105
|
const normalizedActionsSx = normalizeSx(actionsProps?.sx)
|
|
100
106
|
const normalizedImageSx = normalizeSx(imageProps?.sx)
|
|
@@ -135,45 +141,78 @@ function RcSesCard({
|
|
|
135
141
|
) : null}
|
|
136
142
|
|
|
137
143
|
<Stack
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
direction='row'
|
|
145
|
+
sx={{
|
|
146
|
+
alignItems: 'flex-start',
|
|
147
|
+
justifyContent: 'space-between',
|
|
148
|
+
width: '100%',
|
|
149
|
+
}}
|
|
142
150
|
>
|
|
143
|
-
<
|
|
144
|
-
|
|
145
|
-
data-testid={testIds?.
|
|
146
|
-
|
|
147
|
-
{...titleProps}
|
|
151
|
+
<Stack
|
|
152
|
+
{...headerProps}
|
|
153
|
+
data-testid={testIds?.header}
|
|
154
|
+
spacing={0.5}
|
|
148
155
|
sx={[
|
|
149
156
|
{
|
|
150
|
-
|
|
151
|
-
|
|
157
|
+
flex: 1,
|
|
158
|
+
minWidth: 0,
|
|
152
159
|
},
|
|
153
|
-
|
|
160
|
+
centered ? { alignItems: 'center' } : {},
|
|
161
|
+
...normalizeSx(headerProps?.sx),
|
|
154
162
|
]}
|
|
155
163
|
>
|
|
156
|
-
{title}
|
|
157
|
-
</Typography>
|
|
158
|
-
|
|
159
|
-
{!!description && (
|
|
160
164
|
<Typography
|
|
161
|
-
color={palette.grey[
|
|
162
|
-
data-testid={testIds?.
|
|
163
|
-
variant='
|
|
164
|
-
{...
|
|
165
|
+
color={palette.grey[900]}
|
|
166
|
+
data-testid={testIds?.title}
|
|
167
|
+
variant='h5'
|
|
168
|
+
{...titleProps}
|
|
165
169
|
sx={[
|
|
166
170
|
{
|
|
167
|
-
|
|
168
|
-
lineHeight: '1.25rem',
|
|
171
|
+
lineHeight: '1.75rem',
|
|
169
172
|
...(centered ? { textAlign: 'center' } : {}),
|
|
170
173
|
},
|
|
171
|
-
...
|
|
174
|
+
...normalizedTitleSx,
|
|
172
175
|
]}
|
|
173
176
|
>
|
|
174
|
-
{
|
|
177
|
+
{title}
|
|
175
178
|
</Typography>
|
|
176
|
-
|
|
179
|
+
|
|
180
|
+
{!!description && (
|
|
181
|
+
<Typography
|
|
182
|
+
color={palette.grey[800]}
|
|
183
|
+
data-testid={testIds?.description}
|
|
184
|
+
variant='body2'
|
|
185
|
+
{...descriptionProps}
|
|
186
|
+
sx={[
|
|
187
|
+
{
|
|
188
|
+
fontWeight: 300,
|
|
189
|
+
lineHeight: '1.25rem',
|
|
190
|
+
...(centered ? { textAlign: 'center' } : {}),
|
|
191
|
+
},
|
|
192
|
+
...normalizedDescriptionSx,
|
|
193
|
+
]}
|
|
194
|
+
>
|
|
195
|
+
{description}
|
|
196
|
+
</Typography>
|
|
197
|
+
)}
|
|
198
|
+
</Stack>
|
|
199
|
+
|
|
200
|
+
{headerAction ? (
|
|
201
|
+
<Box
|
|
202
|
+
{...headerActionProps}
|
|
203
|
+
data-testid={testIds?.headerAction}
|
|
204
|
+
sx={[
|
|
205
|
+
{
|
|
206
|
+
alignItems: 'flex-start',
|
|
207
|
+
display: 'flex',
|
|
208
|
+
flexShrink: 0,
|
|
209
|
+
},
|
|
210
|
+
...normalizedHeaderActionSx,
|
|
211
|
+
]}
|
|
212
|
+
>
|
|
213
|
+
{headerAction}
|
|
214
|
+
</Box>
|
|
215
|
+
) : null}
|
|
177
216
|
</Stack>
|
|
178
217
|
|
|
179
218
|
{children ? (
|
|
@@ -59,7 +59,12 @@ function RcSesFormControlWrapper({
|
|
|
59
59
|
xs: '0 0 0%',
|
|
60
60
|
sm: labelOnTop ? '0 0 0%' : `0 0 ${formControlDesktopLabelWidth}`,
|
|
61
61
|
},
|
|
62
|
-
...(labelOnTop && {
|
|
62
|
+
...(labelOnTop && {
|
|
63
|
+
'&': {
|
|
64
|
+
fontSize: '.8125rem',
|
|
65
|
+
fontWeight: 400,
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
63
68
|
marginBottom: { xs: '.25rem', sm: labelOnTop ? '.25rem' : '0' },
|
|
64
69
|
pr: 3,
|
|
65
70
|
textAlign: { xs: 'left', sm: labelOnTop ? 'left' : 'right' },
|
|
@@ -83,13 +83,21 @@ function RcSesPhoneInputFormControl(props: Props) {
|
|
|
83
83
|
rules: {
|
|
84
84
|
...rules,
|
|
85
85
|
validate: {
|
|
86
|
-
phoneNoFormat: (value) =>
|
|
87
|
-
|
|
86
|
+
phoneNoFormat: (value) => {
|
|
87
|
+
if (typeof value !== 'string') {
|
|
88
|
+
return t('invalid')
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return mask.completed(value.replace(country.code ?? '', '')) || t('invalid')
|
|
92
|
+
},
|
|
88
93
|
...rules?.validate,
|
|
89
94
|
},
|
|
90
95
|
},
|
|
91
96
|
})
|
|
92
97
|
|
|
98
|
+
const phoneValue =
|
|
99
|
+
typeof controllerProps.value === 'string' ? controllerProps.value : ''
|
|
100
|
+
|
|
93
101
|
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null)
|
|
94
102
|
|
|
95
103
|
const handleClick = (e: React.MouseEvent<HTMLElement>) => setAnchorEl(e.currentTarget)
|
|
@@ -172,7 +180,7 @@ function RcSesPhoneInputFormControl(props: Props) {
|
|
|
172
180
|
pattern: '^[0-9\\(\\)\\- ]*$/',
|
|
173
181
|
}}
|
|
174
182
|
placeholder={mask.opts.mask?.toString()}
|
|
175
|
-
value={mask.masked(
|
|
183
|
+
value={mask.masked(phoneValue.replace(country.code ?? '', ''))}
|
|
176
184
|
onChange={(e) =>
|
|
177
185
|
controllerProps.onChange({
|
|
178
186
|
...e,
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { ThemeProvider } from '@mui/material/styles'
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react'
|
|
3
|
+
import { useForm } from 'react-hook-form'
|
|
4
|
+
import { vi } from 'vitest'
|
|
5
|
+
|
|
6
|
+
import theme from '@/theme/light'
|
|
7
|
+
|
|
8
|
+
import RcSesSearchInput from './index'
|
|
9
|
+
|
|
10
|
+
vi.mock('react-i18next', () => ({
|
|
11
|
+
useTranslation: () => ({
|
|
12
|
+
t: (key: string) => key,
|
|
13
|
+
}),
|
|
14
|
+
initReactI18next: {
|
|
15
|
+
type: '3rdParty',
|
|
16
|
+
init: () => {},
|
|
17
|
+
},
|
|
18
|
+
}))
|
|
19
|
+
|
|
20
|
+
// Fake md breakpoint so the search button is always rendered
|
|
21
|
+
vi.mock('@mui/material', async (importOriginal) => {
|
|
22
|
+
const actual = await importOriginal<typeof import('@mui/material')>()
|
|
23
|
+
return {
|
|
24
|
+
...actual,
|
|
25
|
+
useMediaQuery: () => true,
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
type WrapperProps = Partial<React.ComponentProps<typeof RcSesSearchInput>> & {
|
|
30
|
+
onSearch?: (value: string) => void
|
|
31
|
+
defaultValue?: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const TestWrapper = ({
|
|
35
|
+
defaultValue = '',
|
|
36
|
+
onSearch = vi.fn(),
|
|
37
|
+
...props
|
|
38
|
+
}: WrapperProps) => {
|
|
39
|
+
const { control } = useForm({ defaultValues: { search: defaultValue } })
|
|
40
|
+
return (
|
|
41
|
+
<ThemeProvider theme={theme}>
|
|
42
|
+
<RcSesSearchInput
|
|
43
|
+
id='search'
|
|
44
|
+
name='search'
|
|
45
|
+
control={control}
|
|
46
|
+
label='Search'
|
|
47
|
+
errors={undefined}
|
|
48
|
+
onSearch={onSearch}
|
|
49
|
+
{...props}
|
|
50
|
+
/>
|
|
51
|
+
</ThemeProvider>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
describe('RcSesSearchInput', () => {
|
|
56
|
+
test('renders the text input', () => {
|
|
57
|
+
render(<TestWrapper />)
|
|
58
|
+
expect(screen.getByRole('textbox')).toBeInTheDocument()
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('renders label', () => {
|
|
62
|
+
render(<TestWrapper label='My label' />)
|
|
63
|
+
expect(screen.getByText('My label')).toBeInTheDocument()
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('does not show clear button when value is empty', () => {
|
|
67
|
+
render(<TestWrapper />)
|
|
68
|
+
expect(
|
|
69
|
+
screen.queryByRole('button', { name: /clearValueAriaLabel/i }),
|
|
70
|
+
).not.toBeInTheDocument()
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('search button is disabled when input is empty', () => {
|
|
74
|
+
render(<TestWrapper />)
|
|
75
|
+
const btn = screen.getByRole('button', { name: /search/i })
|
|
76
|
+
expect(btn).toBeDisabled()
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('search button is not rendered when showSearchButton=false', () => {
|
|
80
|
+
render(<TestWrapper showSearchButton={false} />)
|
|
81
|
+
expect(screen.queryByRole('button', { name: /search/i })).not.toBeInTheDocument()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
describe('handleSearchClick', () => {
|
|
85
|
+
test('calls onSearch with current value when button is clicked', () => {
|
|
86
|
+
const onSearch = vi.fn()
|
|
87
|
+
render(<TestWrapper onSearch={onSearch} defaultValue='hello' />)
|
|
88
|
+
|
|
89
|
+
fireEvent.click(screen.getByRole('button', { name: /search/i }))
|
|
90
|
+
|
|
91
|
+
expect(onSearch).toHaveBeenCalledWith('hello')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('does not call onSearch when slotProps.searchButton.onClick calls preventDefault', () => {
|
|
95
|
+
const onSearch = vi.fn()
|
|
96
|
+
|
|
97
|
+
render(
|
|
98
|
+
<TestWrapper
|
|
99
|
+
onSearch={onSearch}
|
|
100
|
+
defaultValue='test'
|
|
101
|
+
slotProps={{
|
|
102
|
+
searchButton: {
|
|
103
|
+
onClick: (e) => e.preventDefault(),
|
|
104
|
+
},
|
|
105
|
+
}}
|
|
106
|
+
/>,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
fireEvent.click(screen.getByRole('button', { name: /search/i }))
|
|
110
|
+
|
|
111
|
+
expect(onSearch).not.toHaveBeenCalled()
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
describe('handleFieldKeyDown', () => {
|
|
116
|
+
test('calls onSearch on Enter when search button is hidden', () => {
|
|
117
|
+
const onSearch = vi.fn()
|
|
118
|
+
render(<TestWrapper onSearch={onSearch} showSearchButton={false} />)
|
|
119
|
+
|
|
120
|
+
const input = screen.getByRole('textbox')
|
|
121
|
+
fireEvent.change(input, { target: { value: 'query' } })
|
|
122
|
+
fireEvent.keyDown(input, { key: 'Enter', code: 'Enter', charCode: 13 })
|
|
123
|
+
|
|
124
|
+
expect(onSearch).toHaveBeenCalledWith('query')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('does not call onSearch on Enter when value is empty', () => {
|
|
128
|
+
const onSearch = vi.fn()
|
|
129
|
+
render(<TestWrapper onSearch={onSearch} showSearchButton={false} />)
|
|
130
|
+
|
|
131
|
+
const input = screen.getByRole('textbox')
|
|
132
|
+
fireEvent.click(input)
|
|
133
|
+
fireEvent.keyDown(input, { key: 'Enter', code: 'Enter', charCode: 13 })
|
|
134
|
+
|
|
135
|
+
expect(onSearch).not.toHaveBeenCalled()
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
test('does not call onSearch on Enter when search button is enabled (shouldSearchOnEnter=false)', () => {
|
|
139
|
+
const onSearch = vi.fn()
|
|
140
|
+
render(<TestWrapper onSearch={onSearch} defaultValue='hello' />)
|
|
141
|
+
|
|
142
|
+
const input = screen.getByRole('textbox')
|
|
143
|
+
fireEvent.click(input)
|
|
144
|
+
fireEvent.keyDown(input, { key: 'Enter', code: 'Enter', charCode: 13 })
|
|
145
|
+
|
|
146
|
+
expect(onSearch).not.toHaveBeenCalled()
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
test('does not call onSearch when slotProps.field.onKeyDown calls preventDefault', () => {
|
|
150
|
+
const onSearch = vi.fn()
|
|
151
|
+
|
|
152
|
+
render(
|
|
153
|
+
<TestWrapper
|
|
154
|
+
onSearch={onSearch}
|
|
155
|
+
showSearchButton={false}
|
|
156
|
+
slotProps={{
|
|
157
|
+
field: {
|
|
158
|
+
onKeyDown: (e) => {
|
|
159
|
+
if (e.key === 'Enter') e.preventDefault()
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
}}
|
|
163
|
+
/>,
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
const input = screen.getByRole('textbox')
|
|
167
|
+
fireEvent.change(input, { target: { value: 'hi' } })
|
|
168
|
+
fireEvent.keyDown(input, { key: 'Enter', code: 'Enter', charCode: 13 })
|
|
169
|
+
|
|
170
|
+
expect(onSearch).not.toHaveBeenCalled()
|
|
171
|
+
})
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
describe('handleFieldChange', () => {
|
|
175
|
+
test('updates field value as user types', () => {
|
|
176
|
+
render(<TestWrapper />)
|
|
177
|
+
|
|
178
|
+
const input = screen.getByRole('textbox')
|
|
179
|
+
fireEvent.change(input, { target: { value: 'hello' } })
|
|
180
|
+
|
|
181
|
+
expect(input).toHaveValue('hello')
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
test('strips non-numeric characters when onlyNumbers=true', () => {
|
|
185
|
+
render(<TestWrapper onlyNumbers />)
|
|
186
|
+
|
|
187
|
+
const input = screen.getByRole('textbox')
|
|
188
|
+
fireEvent.change(input, { target: { value: 'ab12cd3' } })
|
|
189
|
+
|
|
190
|
+
expect(input).toHaveValue('123')
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
test('calls slotProps.field.onChange before updating value', () => {
|
|
194
|
+
const fieldOnChange = vi.fn()
|
|
195
|
+
|
|
196
|
+
render(<TestWrapper slotProps={{ field: { onChange: fieldOnChange } }} />)
|
|
197
|
+
|
|
198
|
+
fireEvent.change(screen.getByRole('textbox'), { target: { value: 'x' } })
|
|
199
|
+
|
|
200
|
+
expect(fieldOnChange).toHaveBeenCalled()
|
|
201
|
+
})
|
|
202
|
+
})
|
|
203
|
+
})
|