@registrucentras/rc-ses-react-components 2.7.2 → 3.0.0-rc.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.
- package/dist/assets/icons/phosphorIcons.d.ts +24 -0
- package/dist/components/common/Accordion/hooks/useAccordionController.d.ts +2 -1
- package/dist/components/common/Accordion/index.d.ts +18 -4
- package/dist/components/common/Accordion/types/AccordionControllerState.d.ts +1 -0
- package/dist/components/common/Card/index.d.ts +3 -0
- package/dist/components/common/CheckboxMark/index.d.ts +8 -0
- package/dist/components/common/DataPagination/components/ExpandButton.d.ts +7 -0
- package/dist/components/common/DataPagination/components/PaginationButton.d.ts +2 -1
- package/dist/components/common/DataPagination/index.d.ts +13 -3
- package/dist/components/common/DataPagination/paginationModel.d.ts +4 -0
- package/dist/components/common/Divider/index.d.ts +6 -0
- package/dist/components/common/EmptyState/index.d.ts +21 -0
- package/dist/components/common/IconWithSquareBackground/index.d.ts +2 -2
- package/dist/components/common/ImageCard/index.d.ts +5 -0
- package/dist/components/common/LinkTile/index.d.ts +11 -0
- package/dist/components/common/RadioMark/index.d.ts +8 -0
- package/dist/components/common/StepCard/StepCardFooter/index.d.ts +1 -1
- package/dist/components/common/TitleBlock/types.d.ts +4 -2
- package/dist/components/form/components/FormControlWrapper/index.d.ts +2 -1
- package/dist/components/form/inputs/Datepicker/RangeDatepicker.d.ts +23 -0
- package/dist/components/form/inputs/Datepicker/SingleDatepicker.d.ts +24 -0
- package/dist/components/form/inputs/Datepicker/components/CalendarViewsHeader.d.ts +18 -0
- package/dist/components/form/inputs/Datepicker/index.d.ts +10 -14
- package/dist/components/form/inputs/Datepicker/rangeModel.d.ts +4 -0
- package/dist/components/form/inputs/FileDropzone.d.ts +2 -2
- package/dist/components/form/inputs/RadioButtonGroup.d.ts +1 -0
- package/dist/components/form/inputs/Select/Select.styles.d.ts +84 -0
- package/dist/components/form/inputs/Select/components/OptionCheckbox.d.ts +2 -1
- package/dist/components/form/inputs/TextField.d.ts +27 -12
- package/dist/components/form/inputs/TextField.styles.d.ts +101 -0
- package/dist/components/layout/ServiceWizardStepper/stepperTokens.d.ts +5 -0
- package/dist/components/loaders/Loader/index.d.ts +12 -9
- package/dist/components/overlays/BottomSheet/index.d.ts +3 -2
- package/dist/components/overlays/Dialog/index.d.ts +1 -1
- package/dist/components/storybook/FileUploadTokenPreview.d.ts +4 -0
- package/dist/components/storybook/TabsTokenPreview.d.ts +3 -0
- package/dist/components/storybook/TokenDocs.d.ts +74 -0
- package/dist/library/index.d.ts +30 -1
- package/dist/registrucentras-rc-ses-react-components.cjs +2 -2
- package/dist/registrucentras-rc-ses-react-components.js +11144 -8374
- package/dist/theme/backdropTokens.d.ts +6 -0
- package/dist/theme/borderTokens.d.ts +33 -0
- package/dist/theme/cards.d.ts +42 -73
- package/dist/theme/colorTokens.d.ts +146 -0
- package/dist/theme/effectTokens.d.ts +9 -0
- package/dist/theme/layoutTokens.d.ts +12 -0
- package/dist/theme/light/MuiAccordion.d.ts +2 -2
- package/dist/theme/light/MuiAccordionSummary.d.ts +19 -0
- package/dist/theme/light/MuiButton.d.ts +7 -0
- package/dist/theme/light/MuiInputBase.d.ts +2 -0
- package/dist/theme/light/MuiPickerPopper.d.ts +3 -0
- package/dist/theme/light/MuiTypography.d.ts +0 -14
- package/dist/theme/palette.d.ts +8 -0
- package/dist/theme/sizeTokens.d.ts +20 -0
- package/dist/theme/spacingRoleBasedTokens.d.ts +38 -0
- package/dist/theme/spacingTokens.d.ts +97 -0
- package/dist/theme/tokenTheme.d.ts +13 -0
- package/dist/theme/typographyTokens.d.ts +104 -0
- package/package.json +2 -2
- package/src/assets/icons/phosphorIcons.ts +11 -0
- package/src/components/common/Accordion/hooks/useAccordionController.tsx +39 -7
- package/src/components/common/Accordion/index.test.tsx +132 -0
- package/src/components/common/Accordion/index.tsx +302 -25
- package/src/components/common/Accordion/types/AccordionControllerState.ts +1 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemLeading.tsx +3 -3
- package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemTrailing.tsx +8 -3
- package/src/components/common/AdvancedList/components/AdvancedListItem/index.tsx +3 -2
- package/src/components/common/AdvancedList/components/AdvancedListItemShell/index.test.tsx +3 -3
- package/src/components/common/AdvancedList/components/AdvancedListItemShell/index.tsx +23 -19
- package/src/components/common/AdvancedList/index.test.tsx +4 -2
- package/src/components/common/Alert/index.tsx +10 -6
- package/src/components/common/Badge/index.tsx +50 -37
- package/src/components/common/Button/index.tsx +12 -10
- package/src/components/common/Card/index.tsx +6 -1
- package/src/components/common/CardShell/index.test.tsx +16 -6
- package/src/components/common/CheckboxMark/index.tsx +86 -0
- package/src/components/common/DataPagination/components/DataPaginationSkeleton.tsx +9 -7
- package/src/components/common/DataPagination/components/ExpandButton.tsx +48 -0
- package/src/components/common/DataPagination/components/PaginationButton.tsx +48 -21
- package/src/components/common/DataPagination/index.test.tsx +229 -12
- package/src/components/common/DataPagination/index.tsx +135 -60
- package/src/components/common/DataPagination/paginationModel.ts +35 -0
- package/src/components/common/Divider/index.test.tsx +33 -0
- package/src/components/common/Divider/index.tsx +52 -0
- package/src/components/common/EmptyState/index.test.tsx +56 -0
- package/src/components/common/EmptyState/index.tsx +211 -0
- package/src/components/common/FilterChip/index.tsx +24 -19
- package/src/components/common/IconWithCircularBackground.tsx +24 -6
- package/src/components/common/IconWithSquareBackground/index.test.tsx +14 -2
- package/src/components/common/IconWithSquareBackground/index.tsx +36 -17
- package/src/components/common/ImageCard/index.test.tsx +16 -0
- package/src/components/common/ImageCard/index.tsx +54 -1
- package/src/components/common/LinkTile/index.test.tsx +57 -0
- package/src/components/common/LinkTile/index.tsx +136 -0
- package/src/components/common/ListWithIcons/components/ListWithIconsItem.tsx +39 -23
- package/src/components/common/ListWithIcons/index.test.tsx +20 -9
- package/src/components/common/ListWithIcons/index.tsx +6 -6
- package/src/components/common/Popover/index.tsx +11 -1
- package/src/components/common/RadioMark/index.tsx +76 -0
- package/src/components/common/SegmentedControl/components/SegmentButton/index.tsx +49 -25
- package/src/components/common/SegmentedControl/index.tsx +10 -6
- package/src/components/common/SelectableCardList/components/SelectableCardListItem.tsx +7 -5
- package/src/components/common/SelectableCardList/index.test.tsx +8 -6
- package/src/components/common/SelectionMarks.test.tsx +92 -0
- package/src/components/common/ServiceLinks/ServiceLinkItem/index.tsx +20 -11
- package/src/components/common/ServiceLinks/index.tsx +3 -3
- package/src/components/common/SideNav/SideNavLayout.tsx +6 -1
- package/src/components/common/SideNav/components/SideNavPill.tsx +24 -12
- package/src/components/common/SideNav/components/SideNavPillList.tsx +18 -12
- package/src/components/common/SideNav/components/SideNavRow.tsx +22 -15
- package/src/components/common/SideNav/index.tsx +10 -9
- package/src/components/common/Snackbar/config.ts +27 -8
- package/src/components/common/Snackbar/index.tsx +39 -16
- package/src/components/common/StepCard/StepCardFooter/index.tsx +28 -6
- package/src/components/common/StepCard/index.tsx +18 -6
- package/src/components/common/Switch/index.tsx +10 -4
- package/src/components/common/Tabs/TabPanel.tsx +6 -3
- package/src/components/common/Tabs/TabsWrapper.tsx +15 -7
- package/src/components/common/TitleBlock/index.test.tsx +14 -17
- package/src/components/common/TitleBlock/index.tsx +120 -15
- package/src/components/common/TitleBlock/types.ts +4 -2
- package/src/components/common/Tooltip/index.tsx +32 -3
- package/src/components/form/components/FormControlWrapper/index.tsx +43 -14
- package/src/components/form/inputs/CheckboxFormControl.tsx +25 -13
- package/src/components/form/inputs/Datepicker/RangeDatepicker.tsx +356 -0
- package/src/components/form/inputs/Datepicker/SingleDatepicker.tsx +207 -0
- package/src/components/form/inputs/Datepicker/components/CalendarViewsHeader.tsx +335 -0
- package/src/components/form/inputs/Datepicker/components/RcSesDatepickerCalendarHeader.tsx +22 -10
- package/src/components/form/inputs/Datepicker/index.test.tsx +23 -18
- package/src/components/form/inputs/Datepicker/index.tsx +20 -150
- package/src/components/form/inputs/Datepicker/rangeModel.test.ts +35 -0
- package/src/components/form/inputs/Datepicker/rangeModel.ts +25 -0
- package/src/components/form/inputs/FileDropzone.tsx +73 -46
- package/src/components/form/inputs/FileUpload.tsx +25 -16
- package/src/components/form/inputs/NumberStepper.tsx +36 -14
- package/src/components/form/inputs/PhoneInputFormControl/components/AutocompleteInput.tsx +10 -5
- package/src/components/form/inputs/PhoneInputFormControl/components/ListboxComponent.tsx +7 -1
- package/src/components/form/inputs/PhoneInputFormControl/components/PopperComponent.tsx +5 -2
- package/src/components/form/inputs/PhoneInputFormControl/components/RowComponent.tsx +9 -5
- package/src/components/form/inputs/PhoneInputFormControl/index.tsx +48 -24
- package/src/components/form/inputs/RadioButtonGroup.tsx +14 -6
- package/src/components/form/inputs/Select/Select.styles.ts +76 -0
- package/src/components/form/inputs/Select/components/OptionCheckbox.tsx +6 -33
- package/src/components/form/inputs/Select/index.tsx +124 -86
- package/src/components/form/inputs/SimpleCheckbox.tsx +10 -3
- package/src/components/form/inputs/TextField.presets.test.tsx +284 -0
- package/src/components/form/inputs/TextField.styles.ts +96 -0
- package/src/components/form/inputs/TextField.test.tsx +153 -0
- package/src/components/form/inputs/TextField.tsx +315 -42
- package/src/components/layout/Footer/index.test.tsx +1 -1
- package/src/components/layout/Footer/index.tsx +17 -7
- package/src/components/layout/ServiceFormActions.tsx +5 -1
- package/src/components/layout/ServiceFormContainer/AccordionFormContainer/index.tsx +3 -3
- package/src/components/layout/ServiceHeader.tsx +19 -19
- package/src/components/layout/ServiceWizardStepper/ServiceWizardStepper.css +10 -10
- package/src/components/layout/ServiceWizardStepper/StepConnector.tsx +8 -5
- package/src/components/layout/ServiceWizardStepper/components/CustomStepIcon.tsx +22 -7
- package/src/components/layout/ServiceWizardStepper/components/HorizontalStepperButton.tsx +15 -11
- package/src/components/layout/ServiceWizardStepper/components/StyledStepLabel.tsx +28 -11
- package/src/components/layout/ServiceWizardStepper/stepperTokens.ts +8 -0
- package/src/components/loaders/FullPageLoader/index.test.tsx +18 -7
- package/src/components/loaders/FullPageLoader/index.tsx +14 -9
- package/src/components/loaders/Loader/index.tsx +48 -17
- package/src/components/overlays/BottomSheet/index.test.tsx +36 -3
- package/src/components/overlays/BottomSheet/index.tsx +54 -21
- package/src/components/overlays/Dialog/index.tsx +5 -23
- package/src/components/overlays/Drawer/index.tsx +29 -14
- package/src/components/overlays/Modal/index.tsx +46 -8
- package/src/components/storybook/FileUploadTokenPreview.tsx +68 -0
- package/src/components/storybook/TabsTokenPreview.tsx +58 -0
- package/src/components/storybook/TokenDocs.tsx +347 -0
- package/src/examples/MultipleStepForm/components/TermsAndConditionsForm.tsx +5 -1
- package/src/i18n/namespaces/input/en.json +48 -4
- package/src/i18n/namespaces/input/lt.json +48 -4
- package/src/library/index.ts +50 -0
- package/src/stories/atoms/Badge.stories.tsx +2 -1
- package/src/stories/atoms/Button.stories.tsx +124 -6
- package/src/stories/atoms/CheckboxMark.stories.tsx +79 -0
- package/src/stories/atoms/Divider.stories.tsx +129 -0
- package/src/stories/atoms/FilterChip.stories.tsx +9 -1
- package/src/stories/atoms/IconWithSquareBackground.stories.tsx +7 -7
- package/src/stories/atoms/Icons.stories.tsx +1 -1
- package/src/stories/atoms/NumberStepper.stories.tsx +44 -0
- package/src/stories/atoms/PhoneInput.stories.tsx +42 -0
- package/src/stories/atoms/RadioMark.stories.tsx +132 -0
- package/src/stories/atoms/Select.stories.tsx +139 -2
- package/src/stories/atoms/SimpleCheckbox.stories.tsx +74 -0
- package/src/stories/atoms/Switch.stories.tsx +46 -1
- package/src/stories/atoms/TextField.stories.tsx +508 -0
- package/src/stories/atoms/Tooltip.stories.tsx +5 -0
- package/src/stories/fixtures/foundations/Borders.stories.tsx +84 -0
- package/src/stories/fixtures/foundations/Effects.stories.tsx +204 -0
- package/src/stories/fixtures/foundations/Layout.stories.tsx +76 -0
- package/src/stories/fixtures/foundations/Sizes.stories.tsx +42 -0
- package/src/stories/fixtures/foundations/Spacing.stories.tsx +48 -0
- package/src/stories/fixtures/foundations/Typography.stories.tsx +49 -0
- package/src/stories/foundations/Borders.stories.tsx +179 -0
- package/src/stories/foundations/Colors.stories.tsx +253 -0
- package/src/stories/foundations/Effects.stories.tsx +116 -0
- package/src/stories/foundations/Layout.stories.tsx +177 -0
- package/src/stories/foundations/Sizes.stories.tsx +123 -0
- package/src/stories/foundations/Spacing.stories.tsx +159 -0
- package/src/stories/foundations/ThemeAdapter.stories.tsx +389 -0
- package/src/stories/foundations/Typography.stories.tsx +148 -0
- package/src/stories/molecules/Alert.stories.tsx +18 -0
- package/src/stories/molecules/Breadcrumbs.stories.tsx +51 -0
- package/src/stories/molecules/Card.stories.tsx +1 -1
- package/src/stories/molecules/CardShell.stories.tsx +1 -0
- package/src/stories/molecules/DatePicker.stories.tsx +133 -3
- package/src/stories/molecules/EmptyState.stories.tsx +106 -0
- package/src/stories/molecules/FormControlWrapper.stories.tsx +59 -0
- package/src/stories/molecules/LinkTile.stories.tsx +151 -0
- package/src/stories/molecules/ListWithIcons.stories.tsx +27 -2
- package/src/stories/molecules/RadioButtonGroup.stories.tsx +23 -0
- package/src/stories/molecules/SegmentedControl.stories.tsx +62 -1
- package/src/stories/molecules/Tabs.stories.tsx +4 -0
- package/src/stories/molecules/TitleBlock.stories.tsx +16 -16
- package/src/stories/organisms/Accordion.stories.tsx +132 -0
- package/src/stories/organisms/AdvancedListItemShell.stories.tsx +63 -23
- package/src/stories/organisms/BottomSheet.stories.tsx +48 -1
- package/src/stories/organisms/DataPagination.stories.tsx +127 -3
- package/src/stories/organisms/Dialog.stories.tsx +13 -0
- package/src/stories/organisms/FileDropzone.stories.tsx +6 -0
- package/src/stories/organisms/FileUpload.stories.tsx +4 -0
- package/src/stories/organisms/Footer.stories.tsx +20 -0
- package/src/stories/organisms/Modal.stories.tsx +53 -0
- package/src/stories/organisms/ServiceHeader.stories.tsx +25 -3
- package/src/stories/organisms/ServiceLinks.stories.tsx +1 -1
- package/src/stories/organisms/ServiceWizardStepper.stories.tsx +37 -1
- package/src/stories/organisms/SideNav.stories.tsx +8 -1
- package/src/theme/backdropTokens.test.ts +11 -0
- package/src/theme/backdropTokens.ts +11 -0
- package/src/theme/borderTokens.test.ts +59 -0
- package/src/theme/borderTokens.ts +36 -0
- package/src/theme/cards.ts +28 -28
- package/src/theme/colorTokens.test.ts +66 -0
- package/src/theme/colorTokens.ts +87 -0
- package/src/theme/effectTokens.test.ts +29 -0
- package/src/theme/effectTokens.ts +11 -0
- package/src/theme/layoutTokens.test.ts +42 -0
- package/src/theme/layoutTokens.ts +14 -0
- package/src/theme/light/MuiAccordion.tsx +30 -26
- package/src/theme/light/MuiAccordionDetails.ts +10 -5
- package/src/theme/light/MuiAccordionSummary.tsx +31 -17
- package/src/theme/light/MuiAlert.tsx +42 -65
- package/src/theme/light/MuiAutocomplete.ts +14 -7
- package/src/theme/light/MuiBreadcrumbs.tsx +17 -9
- package/src/theme/light/MuiButton.tsx +213 -204
- package/src/theme/light/MuiCard.tsx +5 -4
- package/src/theme/light/MuiCheckbox.ts +45 -14
- package/src/theme/light/MuiChip.tsx +3 -1
- package/src/theme/light/MuiDialog.ts +45 -6
- package/src/theme/light/MuiFormControl.ts +19 -9
- package/src/theme/light/MuiFormControlLabel.ts +16 -25
- package/src/theme/light/MuiFormGroup.ts +29 -26
- package/src/theme/light/MuiFormHelperText.ts +15 -4
- package/src/theme/light/MuiFormLabel.ts +20 -20
- package/src/theme/light/MuiInputBase.ts +49 -84
- package/src/theme/light/MuiOutlinedInput.ts +50 -6
- package/src/theme/light/MuiPagination.ts +21 -21
- package/src/theme/light/MuiPickerPopper.ts +17 -0
- package/src/theme/light/MuiPickersLayout.ts +63 -34
- package/src/theme/light/MuiPickersOutlinedInput.ts +38 -38
- package/src/theme/light/MuiPopover.ts +3 -1
- package/src/theme/light/MuiRadio.tsx +35 -52
- package/src/theme/light/MuiStepper.ts +21 -17
- package/src/theme/light/MuiSwitch.tsx +27 -23
- package/src/theme/light/MuiTab.tsx +27 -18
- package/src/theme/light/MuiTableCell.ts +4 -2
- package/src/theme/light/MuiTabs.tsx +11 -9
- package/src/theme/light/MuiTooltip.ts +2 -1
- package/src/theme/light/MuiTypography.tsx +0 -17
- package/src/theme/light/index.tsx +2 -0
- package/src/theme/light/themePalette.tsx +1 -0
- package/src/theme/palette.tsx +9 -0
- package/src/theme/sizeTokens.test.ts +37 -0
- package/src/theme/sizeTokens.ts +21 -0
- package/src/theme/spacingRoleBasedTokens.ts +41 -0
- package/src/theme/spacingTokens.test.ts +58 -0
- package/src/theme/spacingTokens.ts +114 -0
- package/src/theme/tokenTheme.test.tsx +402 -0
- package/src/theme/tokenTheme.ts +429 -0
- package/src/theme/tokens.css +476 -0
- package/src/theme/tokens.test.ts +174 -0
- package/src/theme/typographyTokens.test.ts +120 -0
- package/src/theme/typographyTokens.ts +119 -0
- package/dist/theme/spacing.d.ts +0 -4
- package/src/stories/foundations/Colors.mdx +0 -127
- package/src/theme/spacing.ts +0 -5
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { InputAdornment, ThemeProvider } from '@mui/material'
|
|
2
|
+
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
3
|
+
import { createRef, useState } from 'react'
|
|
4
|
+
import { useForm } from 'react-hook-form'
|
|
5
|
+
import { vi } from 'vitest'
|
|
6
|
+
|
|
7
|
+
import theme from '@/theme/light'
|
|
8
|
+
|
|
9
|
+
import RcSesTextField from './TextField'
|
|
10
|
+
|
|
11
|
+
test('Text retains the shared required marker, connected label and no implicit icon', () => {
|
|
12
|
+
render(<RcSesTextField label='Name' required />)
|
|
13
|
+
const input = screen.getByRole('textbox', { name: 'Name' })
|
|
14
|
+
expect(input).toBeRequired()
|
|
15
|
+
expect(document.querySelector('.MuiFormLabel-asterisk')).toHaveAttribute('aria-hidden')
|
|
16
|
+
expect(document.querySelector('.MuiInputAdornment-root')).not.toBeInTheDocument()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('shared wrapper retains helper with error and preserves description IDs', () => {
|
|
20
|
+
const { rerender } = render(
|
|
21
|
+
<RcSesTextField
|
|
22
|
+
id='name'
|
|
23
|
+
label='Name'
|
|
24
|
+
helperText='Help'
|
|
25
|
+
aria-describedby='external'
|
|
26
|
+
/>,
|
|
27
|
+
)
|
|
28
|
+
expect(screen.getByRole('textbox')).toHaveAttribute(
|
|
29
|
+
'aria-describedby',
|
|
30
|
+
'external name-description',
|
|
31
|
+
)
|
|
32
|
+
rerender(
|
|
33
|
+
<RcSesTextField
|
|
34
|
+
id='name'
|
|
35
|
+
label='Name'
|
|
36
|
+
helperText='Help'
|
|
37
|
+
errorText='Required'
|
|
38
|
+
aria-describedby='external'
|
|
39
|
+
/>,
|
|
40
|
+
)
|
|
41
|
+
const input = screen.getByRole('textbox')
|
|
42
|
+
expect(input).toHaveAttribute('aria-invalid', 'true')
|
|
43
|
+
expect(screen.getByText('Help')).toBeVisible()
|
|
44
|
+
expect(screen.getByText('Required')).toHaveAttribute('id', 'name-errors')
|
|
45
|
+
expect(input).toHaveAttribute(
|
|
46
|
+
'aria-describedby',
|
|
47
|
+
'external name-description name-errors',
|
|
48
|
+
)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('fields do not infer optional status from the absence of native required', () => {
|
|
52
|
+
function Form() {
|
|
53
|
+
const { register } = useForm()
|
|
54
|
+
return <RcSesTextField label='Name' {...register('name', { required: true })} />
|
|
55
|
+
}
|
|
56
|
+
render(<Form />)
|
|
57
|
+
expect(screen.queryByText(/neprivaloma|optional/)).not.toBeInTheDocument()
|
|
58
|
+
expect(screen.getByRole('textbox')).not.toBeRequired()
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('ReactNode errors render in the shared wrapper with helper associations', () => {
|
|
62
|
+
render(
|
|
63
|
+
<RcSesTextField
|
|
64
|
+
id='rich-error'
|
|
65
|
+
label='Name'
|
|
66
|
+
helperText='Help'
|
|
67
|
+
errorText={<strong>Required</strong>}
|
|
68
|
+
/>,
|
|
69
|
+
)
|
|
70
|
+
expect(screen.getByRole('textbox')).toHaveAttribute(
|
|
71
|
+
'aria-describedby',
|
|
72
|
+
'rich-error-description rich-error-errors',
|
|
73
|
+
)
|
|
74
|
+
expect(screen.getByText('Required')).toBeVisible()
|
|
75
|
+
expect(screen.getByRole('textbox')).toHaveAttribute('aria-invalid', 'true')
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test('a hidden wrapper label still supplies the accessible name', () => {
|
|
79
|
+
render(<RcSesTextField label='Name' slotProps={{ wrapper: { hideLabel: true } }} />)
|
|
80
|
+
expect(screen.getByRole('textbox', { name: 'Name' })).toBeVisible()
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('Search clears a native uncontrolled field and delivers the normal change event', () => {
|
|
84
|
+
const onChange = vi.fn()
|
|
85
|
+
render(
|
|
86
|
+
<RcSesTextField
|
|
87
|
+
preset='search'
|
|
88
|
+
label='Search'
|
|
89
|
+
required
|
|
90
|
+
defaultValue='Query'
|
|
91
|
+
onChange={onChange}
|
|
92
|
+
/>,
|
|
93
|
+
)
|
|
94
|
+
const input = screen.getByRole('searchbox')
|
|
95
|
+
fireEvent.click(screen.getByRole('button', { name: /Išvalyti|Clear/ }))
|
|
96
|
+
expect(input).toHaveValue('')
|
|
97
|
+
expect(onChange).toHaveBeenCalledOnce()
|
|
98
|
+
expect(onChange.mock.calls[0][0].target).toBe(input)
|
|
99
|
+
expect(input).toHaveFocus()
|
|
100
|
+
expect(screen.queryByRole('button', { name: /Išvalyti|Clear/ })).not.toBeInTheDocument()
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test('Search clearing works with controlled parent values', () => {
|
|
104
|
+
function Controlled() {
|
|
105
|
+
const [value, setValue] = useState('Query')
|
|
106
|
+
return (
|
|
107
|
+
<RcSesTextField
|
|
108
|
+
preset='search'
|
|
109
|
+
label='Search'
|
|
110
|
+
required
|
|
111
|
+
value={value}
|
|
112
|
+
onChange={(event) => setValue(event.target.value)}
|
|
113
|
+
/>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
render(<Controlled />)
|
|
117
|
+
fireEvent.click(screen.getByRole('button', { name: /Išvalyti|Clear/ }))
|
|
118
|
+
expect(screen.getByRole('searchbox')).toHaveValue('')
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test('Search clearing updates react-hook-form and no nested form is rendered', () => {
|
|
122
|
+
function Form() {
|
|
123
|
+
const { register, watch, reset } = useForm({ defaultValues: { query: 'Query' } })
|
|
124
|
+
return (
|
|
125
|
+
<form>
|
|
126
|
+
<RcSesTextField {...register('query')} preset='search' label='Search' />
|
|
127
|
+
<output>{watch('query') || 'Empty'}</output>
|
|
128
|
+
<button type='button' onClick={() => reset({ query: 'Reset query' })}>
|
|
129
|
+
Reset
|
|
130
|
+
</button>
|
|
131
|
+
</form>
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
render(<Form />)
|
|
135
|
+
expect(document.querySelectorAll('form')).toHaveLength(1)
|
|
136
|
+
fireEvent.click(screen.getByRole('button', { name: /Išvalyti|Clear/ }))
|
|
137
|
+
expect(screen.getByText('Empty')).toBeVisible()
|
|
138
|
+
fireEvent.click(screen.getByRole('button', { name: 'Reset' }))
|
|
139
|
+
expect(screen.getByRole('searchbox')).toHaveValue('Reset query')
|
|
140
|
+
expect(screen.getByRole('button', { name: /Išvalyti|Clear/ })).toBeVisible()
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
test('uncontrolled native reset also resets Clear visibility', async () => {
|
|
144
|
+
render(
|
|
145
|
+
<form data-testid='form'>
|
|
146
|
+
<RcSesTextField preset='search' label='Search' defaultValue='' />
|
|
147
|
+
</form>,
|
|
148
|
+
)
|
|
149
|
+
fireEvent.change(screen.getByRole('searchbox'), { target: { value: 'Typed' } })
|
|
150
|
+
expect(screen.getByRole('button', { name: /Išvalyti|Clear/ })).toBeVisible()
|
|
151
|
+
act(() => screen.getByTestId<HTMLFormElement>('form').reset())
|
|
152
|
+
await waitFor(() =>
|
|
153
|
+
expect(
|
|
154
|
+
screen.queryByRole('button', { name: /Išvalyti|Clear/ }),
|
|
155
|
+
).not.toBeInTheDocument(),
|
|
156
|
+
)
|
|
157
|
+
expect(screen.getByRole('searchbox')).toHaveValue('')
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
test.each(['readOnly', 'disabled'] as const)('%s prevents Search clearing', (state) => {
|
|
161
|
+
render(
|
|
162
|
+
<RcSesTextField
|
|
163
|
+
preset='search'
|
|
164
|
+
label='Search'
|
|
165
|
+
defaultValue='Query'
|
|
166
|
+
{...{ [state]: true }}
|
|
167
|
+
/>,
|
|
168
|
+
)
|
|
169
|
+
const input = screen.getByRole('searchbox')
|
|
170
|
+
expect(screen.getByRole('button', { name: /Išvalyti|Clear/ })).toBeDisabled()
|
|
171
|
+
expect(input).toHaveValue('Query')
|
|
172
|
+
if (state === 'readOnly') {
|
|
173
|
+
expect(input).toHaveAttribute('readonly')
|
|
174
|
+
expect(input).not.toBeDisabled()
|
|
175
|
+
act(() => input.focus())
|
|
176
|
+
expect(input).toHaveFocus()
|
|
177
|
+
} else expect(input).toBeDisabled()
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
test('Password toggles presentation without changing value or submitting', () => {
|
|
181
|
+
const submit = vi.fn((event) => event.preventDefault())
|
|
182
|
+
render(
|
|
183
|
+
<form onSubmit={submit}>
|
|
184
|
+
<RcSesTextField preset='password' label='Password' required defaultValue='Secret' />
|
|
185
|
+
</form>,
|
|
186
|
+
)
|
|
187
|
+
const input = screen.getByLabelText(/^Password/)
|
|
188
|
+
const toggle = screen.getByRole('button', { name: /slaptažodį|password/ })
|
|
189
|
+
expect(input).toHaveAttribute('type', 'password')
|
|
190
|
+
fireEvent.click(toggle)
|
|
191
|
+
expect(input).toHaveAttribute('type', 'text')
|
|
192
|
+
expect(toggle).toHaveAttribute('aria-pressed', 'true')
|
|
193
|
+
expect(input).toHaveValue('Secret')
|
|
194
|
+
expect(submit).not.toHaveBeenCalled()
|
|
195
|
+
fireEvent.click(toggle)
|
|
196
|
+
expect(input).toHaveAttribute('type', 'password')
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
test('Phone and Number preserve native data, prefixes and non-interactive units', () => {
|
|
200
|
+
render(
|
|
201
|
+
<>
|
|
202
|
+
<RcSesTextField preset='phone' label='Phone' defaultValue='600 00000' />
|
|
203
|
+
<RcSesTextField preset='number' label='Amount' suffix='€' defaultValue='12,00' />
|
|
204
|
+
</>,
|
|
205
|
+
)
|
|
206
|
+
expect(screen.getByRole('textbox', { name: /Phone/ })).toHaveAttribute('type', 'tel')
|
|
207
|
+
const amount = screen.getByRole('textbox', { name: /Amount/ })
|
|
208
|
+
expect(amount).toHaveAttribute('inputmode', 'decimal')
|
|
209
|
+
expect(amount).toHaveValue('12,00')
|
|
210
|
+
expect(screen.getByText('+370')).toBeVisible()
|
|
211
|
+
expect(screen.getByText('€').closest('button')).toBeNull()
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
test('MUI slot callbacks, additional descriptions and native refs are preserved', () => {
|
|
215
|
+
const ref = createRef<HTMLInputElement>()
|
|
216
|
+
render(
|
|
217
|
+
<ThemeProvider theme={theme}>
|
|
218
|
+
<RcSesTextField
|
|
219
|
+
label='Custom'
|
|
220
|
+
ref={ref}
|
|
221
|
+
helperText='Help'
|
|
222
|
+
id='custom'
|
|
223
|
+
slotProps={{
|
|
224
|
+
input: () => ({
|
|
225
|
+
startAdornment: (
|
|
226
|
+
<InputAdornment position='start'>Custom prefix</InputAdornment>
|
|
227
|
+
),
|
|
228
|
+
}),
|
|
229
|
+
htmlInput: () => ({ 'aria-describedby': 'additional', maxLength: 10 }),
|
|
230
|
+
}}
|
|
231
|
+
/>
|
|
232
|
+
</ThemeProvider>,
|
|
233
|
+
)
|
|
234
|
+
const input = screen.getByRole('textbox')
|
|
235
|
+
expect(ref.current).toBe(input)
|
|
236
|
+
expect(input).toHaveAttribute('maxlength', '10')
|
|
237
|
+
expect(input).toHaveAttribute('aria-describedby', 'additional custom-description')
|
|
238
|
+
expect(screen.getByText('Custom prefix')).toBeVisible()
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
test('existing nested field and wrapper APIs retain values, classes and sx targets', () => {
|
|
242
|
+
render(
|
|
243
|
+
<RcSesTextField
|
|
244
|
+
label='Existing'
|
|
245
|
+
slotProps={{
|
|
246
|
+
field: { defaultValue: '123', className: 'field-custom', sx: { width: '300px' } },
|
|
247
|
+
wrapper: {
|
|
248
|
+
className: 'wrapper-custom',
|
|
249
|
+
labelOnTop: false,
|
|
250
|
+
description: 'Existing help',
|
|
251
|
+
},
|
|
252
|
+
}}
|
|
253
|
+
/>,
|
|
254
|
+
)
|
|
255
|
+
const input = screen.getByRole('textbox')
|
|
256
|
+
expect(input).toHaveValue('123')
|
|
257
|
+
const field = input.closest('.field-custom')
|
|
258
|
+
expect(field).toHaveClass('MuiTextField-root')
|
|
259
|
+
expect(field).toHaveStyle({ width: '300px' })
|
|
260
|
+
expect(input.closest('.wrapper-custom')).toContainElement(
|
|
261
|
+
screen.getByText('Existing help'),
|
|
262
|
+
)
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
test('custom slots override presets, null can remove a preset adornment', () => {
|
|
266
|
+
render(
|
|
267
|
+
<RcSesTextField
|
|
268
|
+
preset='search'
|
|
269
|
+
label='Search'
|
|
270
|
+
defaultValue='Query'
|
|
271
|
+
leading={null}
|
|
272
|
+
trailing={<span>Custom trailing</span>}
|
|
273
|
+
/>,
|
|
274
|
+
)
|
|
275
|
+
expect(screen.queryByRole('button')).not.toBeInTheDocument()
|
|
276
|
+
expect(screen.getByText('Custom trailing')).toBeVisible()
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
test('Loading is announced and does not falsely mark the field disabled', () => {
|
|
280
|
+
render(<RcSesTextField label='Loading field' loading />)
|
|
281
|
+
expect(screen.getByRole('textbox')).toHaveAttribute('aria-busy', 'true')
|
|
282
|
+
expect(screen.getByRole('textbox')).not.toBeDisabled()
|
|
283
|
+
expect(screen.getByRole('status')).toHaveAccessibleName(/Kraunama|Loading/)
|
|
284
|
+
})
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { borderTokens } from '@/theme/borderTokens'
|
|
2
|
+
import { colorTokens } from '@/theme/colorTokens'
|
|
3
|
+
import { effectTokens } from '@/theme/effectTokens'
|
|
4
|
+
import { spacingRoleBasedTokens } from '@/theme/spacingRoleBasedTokens'
|
|
5
|
+
import { spacingTokens } from '@/theme/spacingTokens'
|
|
6
|
+
import { typographyTokens } from '@/theme/typographyTokens'
|
|
7
|
+
|
|
8
|
+
// Scoped to TextField: the shared InputBase theme remains unchanged.
|
|
9
|
+
const fieldHeight = `calc(${typographyTokens['line-height-body-regular']} + 2 * ${spacingTokens['spacing-aliases-input-padding-y']} + 2 * ${borderTokens['stroke-1']})`
|
|
10
|
+
|
|
11
|
+
export const textFieldStyles = {
|
|
12
|
+
minWidth: 0,
|
|
13
|
+
width: '100%',
|
|
14
|
+
'&&[data-multiline="true"] .MuiOutlinedInput-root': {
|
|
15
|
+
height: 'auto',
|
|
16
|
+
minHeight: fieldHeight,
|
|
17
|
+
paddingBlock: spacingTokens['spacing-aliases-input-padding-y'],
|
|
18
|
+
},
|
|
19
|
+
'&&[data-leading-hidden="true"] .MuiOutlinedInput-root .MuiOutlinedInput-input': {
|
|
20
|
+
paddingLeft: 0,
|
|
21
|
+
},
|
|
22
|
+
'&&[data-trailing-hidden="true"] .MuiOutlinedInput-root .MuiOutlinedInput-input': {
|
|
23
|
+
paddingRight: 0,
|
|
24
|
+
},
|
|
25
|
+
'&& .MuiOutlinedInput-root': {
|
|
26
|
+
height: fieldHeight,
|
|
27
|
+
boxSizing: 'border-box',
|
|
28
|
+
borderRadius: borderTokens['radius-input'],
|
|
29
|
+
backgroundColor: colorTokens['surface-base'],
|
|
30
|
+
padding: `0 ${spacingRoleBasedTokens['space-12']}`,
|
|
31
|
+
gap: spacingRoleBasedTokens['space-8'],
|
|
32
|
+
'& .MuiOutlinedInput-input': {
|
|
33
|
+
padding: 0,
|
|
34
|
+
paddingLeft: spacingRoleBasedTokens['space-8'],
|
|
35
|
+
paddingRight: spacingRoleBasedTokens['space-8'],
|
|
36
|
+
minWidth: 0,
|
|
37
|
+
height: 'auto',
|
|
38
|
+
fontSize: typographyTokens['font-size-body-regular'],
|
|
39
|
+
lineHeight: typographyTokens['line-height-body-regular'],
|
|
40
|
+
color: colorTokens['text-default'],
|
|
41
|
+
'&::placeholder': { color: colorTokens['text-muted'], opacity: 1 },
|
|
42
|
+
'&::-webkit-search-cancel-button': { WebkitAppearance: 'none' },
|
|
43
|
+
'&.Mui-disabled': {
|
|
44
|
+
color: colorTokens['text-muted'],
|
|
45
|
+
WebkitTextFillColor: colorTokens['text-muted'],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
'&.MuiInputBase-adornedStart .MuiOutlinedInput-input': { paddingLeft: 0 },
|
|
49
|
+
'&.MuiInputBase-adornedEnd .MuiOutlinedInput-input': { paddingRight: 0 },
|
|
50
|
+
'& .MuiInputAdornment-root': {
|
|
51
|
+
margin: 0,
|
|
52
|
+
color: colorTokens['text-secondary'],
|
|
53
|
+
fontSize: typographyTokens['font-size-body-regular'],
|
|
54
|
+
lineHeight: typographyTokens['line-height-body-regular'],
|
|
55
|
+
},
|
|
56
|
+
'& .MuiOutlinedInput-notchedOutline': {
|
|
57
|
+
borderColor: colorTokens['border-strong'],
|
|
58
|
+
borderWidth: borderTokens['stroke-1'],
|
|
59
|
+
boxShadow: 'none',
|
|
60
|
+
},
|
|
61
|
+
'&:hover:not(.Mui-disabled):not(.Mui-readOnly):not(.Mui-focused) .MuiOutlinedInput-notchedOutline':
|
|
62
|
+
{ borderColor: colorTokens['control-border'] },
|
|
63
|
+
'&.Mui-error .MuiOutlinedInput-notchedOutline': {
|
|
64
|
+
borderColor: colorTokens['status-error-border'],
|
|
65
|
+
},
|
|
66
|
+
'&.Mui-error:hover:not(.Mui-disabled):not(.Mui-readOnly):not(.Mui-focused)': {
|
|
67
|
+
backgroundColor: colorTokens['status-error-bg'],
|
|
68
|
+
'& .MuiOutlinedInput-notchedOutline': {
|
|
69
|
+
borderColor: colorTokens['status-error-border'],
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
'&.Mui-focused, &.Mui-focused.Mui-error': {
|
|
73
|
+
backgroundColor: colorTokens['surface-base'],
|
|
74
|
+
'& .MuiOutlinedInput-notchedOutline': {
|
|
75
|
+
borderColor: colorTokens['border-focus'],
|
|
76
|
+
borderWidth: borderTokens['border-focus'],
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
'&.Mui-disabled': {
|
|
80
|
+
opacity: 0.6,
|
|
81
|
+
backgroundColor: colorTokens['surface-muted'],
|
|
82
|
+
'& .MuiOutlinedInput-notchedOutline': {
|
|
83
|
+
borderColor: colorTokens['border-subtle'],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
} as const
|
|
88
|
+
|
|
89
|
+
export const inputActionStyles = {
|
|
90
|
+
width: '20px',
|
|
91
|
+
height: '20px',
|
|
92
|
+
padding: 0,
|
|
93
|
+
color: colorTokens['text-secondary'],
|
|
94
|
+
'&::after': { content: '""', position: 'absolute', inset: '-2px' },
|
|
95
|
+
'&.Mui-focusVisible': { boxShadow: effectTokens['focus-ring-default'] },
|
|
96
|
+
} as const
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { InputAdornment, ThemeProvider } from '@mui/material'
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react'
|
|
3
|
+
import { createRef } from 'react'
|
|
4
|
+
import { vi } from 'vitest'
|
|
5
|
+
|
|
6
|
+
import RcSesLoadingSpinner from '@/components/loaders/LoadingSpinner'
|
|
7
|
+
import theme from '@/theme/light'
|
|
8
|
+
|
|
9
|
+
import RcSesTextField from './TextField'
|
|
10
|
+
|
|
11
|
+
describe('RcSesTextField token migration', () => {
|
|
12
|
+
test('input sx overrides token defaults for padding', () => {
|
|
13
|
+
render(
|
|
14
|
+
<ThemeProvider theme={theme}>
|
|
15
|
+
<RcSesTextField
|
|
16
|
+
label='Custom input'
|
|
17
|
+
slotProps={{
|
|
18
|
+
field: {
|
|
19
|
+
slotProps: {
|
|
20
|
+
input: {
|
|
21
|
+
sx: {
|
|
22
|
+
'& .MuiInputBase-input': { fontSize: '20px', padding: '4px 8px' },
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
}}
|
|
28
|
+
/>
|
|
29
|
+
</ThemeProvider>,
|
|
30
|
+
)
|
|
31
|
+
expect(screen.getByRole('textbox')).toHaveStyle({ padding: '4px 8px' })
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('input slot callbacks and sx arrays retain their overrides and props', () => {
|
|
35
|
+
render(
|
|
36
|
+
<ThemeProvider theme={theme}>
|
|
37
|
+
<RcSesTextField
|
|
38
|
+
label='Callback input'
|
|
39
|
+
slotProps={{
|
|
40
|
+
field: {
|
|
41
|
+
slotProps: {
|
|
42
|
+
input: (ownerState) => ({
|
|
43
|
+
readOnly: true,
|
|
44
|
+
sx: [
|
|
45
|
+
{ '& .MuiInputBase-input': { fontSize: '18px' } },
|
|
46
|
+
(activeTheme) => ({
|
|
47
|
+
'& .MuiInputBase-input': {
|
|
48
|
+
fontSize: ownerState.disabled ? '16px' : '24px',
|
|
49
|
+
padding: activeTheme.spacing(1),
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
],
|
|
53
|
+
}),
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
58
|
+
</ThemeProvider>,
|
|
59
|
+
)
|
|
60
|
+
expect(screen.getByRole('textbox')).toHaveAttribute('readonly')
|
|
61
|
+
expect(screen.getByRole('textbox')).toHaveStyle({ padding: '8px' })
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test.each(['small', 'large'] as const)(
|
|
65
|
+
'adornments preserve the %s spinner geometry',
|
|
66
|
+
(size) => {
|
|
67
|
+
render(
|
|
68
|
+
<ThemeProvider theme={theme}>
|
|
69
|
+
<RcSesLoadingSpinner size={size} />
|
|
70
|
+
<RcSesTextField
|
|
71
|
+
label='Loading input'
|
|
72
|
+
slotProps={{
|
|
73
|
+
field: {
|
|
74
|
+
slotProps: {
|
|
75
|
+
input: {
|
|
76
|
+
endAdornment: (
|
|
77
|
+
<InputAdornment position='end'>
|
|
78
|
+
<RcSesLoadingSpinner size={size} />
|
|
79
|
+
</InputAdornment>
|
|
80
|
+
),
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
}}
|
|
85
|
+
/>
|
|
86
|
+
</ThemeProvider>,
|
|
87
|
+
)
|
|
88
|
+
const [standalone, adorned] = screen.getAllByRole('progressbar')
|
|
89
|
+
expect(adorned.style.width).toBe(standalone.style.width)
|
|
90
|
+
const standaloneSvg = standalone.querySelector('svg')!
|
|
91
|
+
const adornedSvg = adorned.querySelector('svg')!
|
|
92
|
+
expect(getComputedStyle(adornedSvg).width).toBe(
|
|
93
|
+
getComputedStyle(standaloneSvg).width,
|
|
94
|
+
)
|
|
95
|
+
expect(getComputedStyle(adornedSvg).height).toBe(
|
|
96
|
+
getComputedStyle(standaloneSvg).height,
|
|
97
|
+
)
|
|
98
|
+
},
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
test('retains native change events and input ref', () => {
|
|
102
|
+
const ref = createRef<HTMLInputElement>()
|
|
103
|
+
const onChange = vi.fn()
|
|
104
|
+
render(
|
|
105
|
+
<ThemeProvider theme={theme}>
|
|
106
|
+
<RcSesTextField label='Vardas' ref={ref} onChange={onChange} />
|
|
107
|
+
</ThemeProvider>,
|
|
108
|
+
)
|
|
109
|
+
const input = screen.getByRole('textbox', { name: /^Vardas/ })
|
|
110
|
+
fireEvent.change(input, { target: { value: 'Jonas' } })
|
|
111
|
+
expect(onChange.mock.calls[0][0].target.value).toBe('Jonas')
|
|
112
|
+
expect(ref.current).toBe(input)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
test('retains native defaultValue and form reset', () => {
|
|
116
|
+
render(
|
|
117
|
+
<form data-testid='form'>
|
|
118
|
+
<RcSesTextField label='Vardas' slotProps={{ field: { defaultValue: 'Jonas' } }} />
|
|
119
|
+
</form>,
|
|
120
|
+
)
|
|
121
|
+
const input = screen.getByRole('textbox')
|
|
122
|
+
const form = screen.getByTestId<HTMLFormElement>('form')
|
|
123
|
+
fireEvent.change(input, { target: { value: 'Petras' } })
|
|
124
|
+
form.reset()
|
|
125
|
+
expect(input).toHaveValue('Jonas')
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
test('retains required and disabled attributes', () => {
|
|
129
|
+
render(<RcSesTextField label='Vardas' required disabled />)
|
|
130
|
+
expect(screen.getByRole('textbox')).toBeDisabled()
|
|
131
|
+
expect(screen.getByRole('textbox')).toBeRequired()
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
test('retains multiline and wrapper error API', () => {
|
|
135
|
+
render(
|
|
136
|
+
<RcSesTextField
|
|
137
|
+
label='Aprašymas'
|
|
138
|
+
multiline
|
|
139
|
+
errors={{ type: 'required', message: 'Įveskite aprašymą' }}
|
|
140
|
+
slotProps={{
|
|
141
|
+
field: { rows: 4 },
|
|
142
|
+
wrapper: { labelOnTop: true, description: 'Pagalba' },
|
|
143
|
+
}}
|
|
144
|
+
/>,
|
|
145
|
+
)
|
|
146
|
+
const input = screen.getByRole('textbox', { name: /^Aprašymas/ })
|
|
147
|
+
expect(input.tagName).toBe('TEXTAREA')
|
|
148
|
+
expect(input).toHaveAttribute('rows', '4')
|
|
149
|
+
expect(input).toHaveAttribute('aria-invalid', 'true')
|
|
150
|
+
expect(screen.getByText('Įveskite aprašymą')).toBeVisible()
|
|
151
|
+
expect(screen.getByText('Pagalba')).toBeVisible()
|
|
152
|
+
})
|
|
153
|
+
})
|