@cnamts/synapse 1.0.26 → 1.0.27
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/{AutocompleteFilter-BPR-a55G.js → AutocompleteFilter-C9eLKyW8.js} +3 -3
- package/dist/{DateFilter-CknrJWs2.js → DateFilter-y-GLkAkn.js} +8 -8
- package/dist/{NumberFilter-DJ-yNlzv.js → NumberFilter-DN6hIBS7.js} +1 -1
- package/dist/{PeriodFilter-CiB5Oa9Z.js → PeriodFilter-MoUUp9qS.js} +1 -1
- package/dist/{SelectFilter-EiafX97M.js → SelectFilter-bCbrdLmu.js} +1 -1
- package/dist/{TextFilter-BzOmpdxj.js → TextFilter-CvjgEaoM.js} +4 -4
- package/dist/apLightTheme2026-ug4Y23ns.js +611 -0
- package/dist/components/Customs/Selects/SyAutocomplete/SyAutocomplete.d.ts +2369 -353
- package/dist/components/Customs/Selects/SyAutocomplete/composables/useSyAutocompleteValidation.d.ts +18 -0
- package/dist/components/Customs/Selects/SyAutocomplete/utils/ariaManager.d.ts +1 -1
- package/dist/components/Customs/Selects/SyAutocomplete/utils/useKeyboardHandler.d.ts +3 -1
- package/dist/components/Customs/Selects/SySelect/SySelect.d.ts +9 -10
- package/dist/components/Customs/Selects/SySelect/composables/useSySelectKeyboard.d.ts +1 -0
- package/dist/components/Customs/Selects/SySelect/composables/useSySelectValidation.d.ts +15 -0
- package/dist/components/Customs/SyCheckBoxGroup/SyCheckBoxGroup.d.ts +3 -3
- package/dist/components/Customs/SyCheckbox/SyCheckbox.d.ts +3 -3
- package/dist/components/Customs/SyIconButton/SyIconButton.d.ts +18 -0
- package/dist/components/Customs/SyRadioGroup/SyRadioGroup.d.ts +20 -38
- package/dist/components/Customs/SyRadioGroup/composables/useSyRadioGroupValidation.d.ts +50 -0
- package/dist/components/Customs/SyTextField/SyTextField.d.ts +6 -6
- package/dist/components/DatePicker/CalendarMode/DatePicker.d.ts +147 -136
- package/dist/components/DatePicker/ComplexDatePicker/ComplexDatePicker.d.ts +62 -54
- package/dist/components/DatePicker/DateTextInput/DateTextInput.d.ts +27 -24
- package/dist/components/DatePicker/composables/index.d.ts +1 -0
- package/dist/components/DatePicker/composables/useDatePickerValidationBridge.d.ts +51 -0
- package/dist/components/MonthPicker/MonthPicker.d.ts +23 -23
- package/dist/components/MonthPicker/MonthPickerText/MonthPickerInput.d.ts +23 -23
- package/dist/components/NirField/NirField.d.ts +56 -56
- package/dist/components/PasswordField/PasswordField.d.ts +3 -3
- package/dist/components/PeriodField/PeriodField.d.ts +236 -212
- package/dist/components/PhoneField/PhoneField.d.ts +23 -23
- package/dist/components/SyTextArea/SyTextArea.d.ts +25 -15
- package/dist/components/SyTextArea/composables/useSyTextAreaValidation.d.ts +20 -0
- package/dist/components/SyTextArea/locales.d.ts +1 -0
- package/dist/components/Tables/SyServerTable/SyServerTable.d.ts +1 -0
- package/dist/components/Tables/SyTable/SyTable.d.ts +1 -0
- package/dist/components/Tables/common/SyTablePagination.d.ts +25 -25
- package/dist/components/Tables/common/types.d.ts +2 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/composables/unifyValidation/documentationValidationProps.d.ts +160 -160
- package/dist/composables/unifyValidation/useValidation.d.ts +16 -14
- package/dist/design-system-v3.js +81 -80
- package/dist/designTokens/tokens/amelipro/apContextual.d.ts +6 -6
- package/dist/designTokens/tokens/amelipro/apDarkTheme.d.ts +3 -1
- package/dist/designTokens/tokens/amelipro/apLightTheme.d.ts +53 -100
- package/dist/designTokens/tokens/baseContextualTokens.d.ts +0 -6
- package/dist/designTokens/tokens/baseTokens.d.ts +232 -0
- package/dist/designTokens/tokens/cnam/cnamContextual.d.ts +6 -6
- package/dist/designTokens/tokens/cnam/cnamDarkTheme.d.ts +1 -1
- package/dist/designTokens/tokens/cnam/cnamLightTheme.d.ts +57 -101
- package/dist/designTokens/tokens/pa/paContextual.d.ts +0 -6
- package/dist/designTokens/tokens/pa/paDarkTheme.d.ts +1 -1
- package/dist/designTokens/tokens/pa/paLightTheme.d.ts +53 -97
- package/dist/designTokens/tokens/pa/paSemantic.d.ts +1 -0
- package/dist/designTokens/tokens/semanticTokens.d.ts +112 -0
- package/dist/main-CI6Q9nmO.js +39234 -0
- package/dist/synapse.css +1 -1
- package/dist/vuetifyConfig.js +208 -72
- package/package.json +4 -2
- package/src/assets/overrides/_icons.scss +5 -4
- package/src/assets/overrides/_otp.scss +4 -4
- package/src/assets/overrides/_typography.scss +2 -1
- package/src/assets/overrides/_utilities.scss +1 -42
- package/src/components/ChipList/ChipList.vue +30 -18
- package/src/components/ChipList/tests/chipList.spec.ts +4 -4
- package/src/components/CopyBtn/CopyBtn.vue +2 -2
- package/src/components/Customs/Selects/SelectBtnField/SelectBtnField.stories.ts +4 -0
- package/src/components/Customs/Selects/SelectBtnField/SelectBtnField.vue +7 -6
- package/src/components/Customs/Selects/SelectBtnField/tests/SelectBtnField.spec.ts +223 -0
- package/src/components/Customs/Selects/SyAutocomplete/SyAutocomplete.stories.ts +283 -351
- package/src/components/Customs/Selects/SyAutocomplete/SyAutocomplete.vue +182 -218
- package/src/components/Customs/Selects/SyAutocomplete/composables/useSyAutocompleteValidation.ts +101 -0
- package/src/components/Customs/Selects/SyAutocomplete/tests/SyAutocomplete.spec.ts +761 -1
- package/src/components/Customs/Selects/SyAutocomplete/utils/ariaManager.ts +3 -1
- package/src/components/Customs/Selects/SyAutocomplete/utils/useKeyboardHandler.ts +79 -5
- package/src/components/Customs/Selects/SyAutocomplete/validation/Validation.stories.ts +1029 -0
- package/src/components/Customs/Selects/SySelect/SySelect.stories.ts +9 -491
- package/src/components/Customs/Selects/SySelect/SySelect.vue +46 -79
- package/src/components/Customs/Selects/SySelect/composables/useSySelectKeyboard.ts +3 -0
- package/src/components/Customs/Selects/SySelect/composables/useSySelectValidation.ts +64 -0
- package/src/components/Customs/Selects/SySelect/tests/SySelect.spec.ts +196 -0
- package/src/components/Customs/Selects/SySelect/validation/Validation.stories.ts +1026 -0
- package/src/components/Customs/SyCheckBoxGroup/SyCheckBoxGroup.stories.ts +18 -7
- package/src/components/Customs/SyCheckBoxGroup/SyCheckBoxGroup.vue +2 -2
- package/src/components/Customs/SyCheckbox/SyCheckbox.stories.ts +8 -8
- package/src/components/Customs/SyCheckbox/SyCheckbox.vue +8 -8
- package/src/components/Customs/SyCheckbox/tests/SyCheckbox.spec.ts +1 -1
- package/src/components/Customs/SyIcon/accessibilite/Accessibility.mdx +0 -6
- package/src/components/Customs/SyIcon/utils/tests/iconUtils.spec.ts +107 -0
- package/src/components/Customs/SyRadioGroup/SyRadioGroup.mdx +2 -2
- package/src/components/Customs/SyRadioGroup/SyRadioGroup.stories.ts +395 -200
- package/src/components/Customs/SyRadioGroup/SyRadioGroup.vue +82 -127
- package/src/components/Customs/SyRadioGroup/composables/useSyRadioGroupValidation.ts +127 -0
- package/src/components/Customs/SyRadioGroup/tests/SyRadioGroup.a11y.spec.ts +93 -1
- package/src/components/Customs/SyRadioGroup/tests/SyRadioGroup.spec.ts +146 -9
- package/src/components/Customs/SyRadioGroup/tests/SyRadioGroup.visual.cy.ts +165 -0
- package/src/components/Customs/SyRadioGroup/validation/Validation.stories.ts +773 -0
- package/src/components/Customs/SyTabs/config.ts +3 -3
- package/src/components/Customs/SyTabs/tests/SyTabs.spec.ts +265 -0
- package/src/components/Customs/SyTabs/tests/useTabTransition.spec.ts +188 -0
- package/src/components/Customs/SyTextField/SyTextField.stories.ts +10 -29
- package/src/components/Customs/SyTextField/SyTextField.vue +23 -15
- package/src/components/DataList/DataList.stories.ts +1 -1
- package/src/components/DataListItem/tests/DataListItem.spec.ts +3 -1
- package/src/components/DatePicker/CalendarMode/DatePicker.vue +37 -142
- package/src/components/DatePicker/CalendarMode/tests/DatePicker.coverage.spec.ts +156 -0
- package/src/components/DatePicker/CalendarMode/tests/DatePicker.spec.ts +495 -4
- package/src/components/DatePicker/ComplexDatePicker/ComplexDatePicker.vue +47 -66
- package/src/components/DatePicker/ComplexDatePicker/tests/ComplexDatePicker.spec.ts +206 -0
- package/src/components/DatePicker/ComplexDatePicker/tests/bridge-integration.regression.spec.ts +210 -0
- package/src/components/DatePicker/ComplexDatePicker/tests/calendar-navigation.regression.spec.ts +214 -0
- package/src/components/DatePicker/ComplexDatePicker/tests/validation-cross.regression.spec.ts +194 -0
- package/src/components/DatePicker/ComplexDatePicker/tests/validation-success-messages.regression.spec.ts +83 -0
- package/src/components/DatePicker/DateTextInput/DateTextInput.vue +129 -54
- package/src/components/DatePicker/DateTextInput/tests/DateTextInput.spec.ts +320 -0
- package/src/components/DatePicker/composables/index.ts +1 -0
- package/src/components/DatePicker/composables/tests/useCalendarKeyboardNavigation.spec.ts +360 -0
- package/src/components/DatePicker/composables/tests/useDatePickerValidationBridge.spec.ts +129 -0
- package/src/components/DatePicker/composables/useDatePickerValidationBridge.ts +205 -0
- package/src/components/DatePicker/docExamples/BidirectionalComplexValidation.vue +1 -1
- package/src/components/DatePicker/docExamples/DatePickerBidirectionalValidation.vue +1 -1
- package/src/components/DatePicker/tests/exposed-methods.coverage.spec.ts +75 -0
- package/src/components/DialogBox/DialogBox.vue +1 -1
- package/src/components/FileList/UploadItem/UploadItem.vue +4 -4
- package/src/components/FileUpload/FileUpload.vue +2 -2
- package/src/components/FileUpload/FileUploadContent.vue +1 -1
- package/src/components/FilterInline/FilterInline.mdx +2 -2
- package/src/components/FilterSideBar/FilterSideBar.stories.ts +1 -1
- package/src/components/FilterSideBar/FilterSideBar.vue +2 -2
- package/src/components/FooterBar/FooterBar.vue +7 -7
- package/src/components/FranceConnectBtn/FranceConnectBtn.vue +1 -1
- package/src/components/HeaderBar/HeaderBurgerMenu/HeaderMenuItem/HeaderMenuItem.vue +2 -2
- package/src/components/HeaderBar/HeaderBurgerMenu/HeaderSubMenu/HeaderSubMenu.vue +7 -7
- package/src/components/HeaderBar/HeaderMenuBtn/HeaderMenuBtn.vue +2 -2
- package/src/components/HeaderLoading/tests/HeaderLoading.spec.ts +87 -8
- package/src/components/HeaderNavigationBar/HorizontalNavbar/HorizontalNavbar.vue +3 -3
- package/src/components/HeaderNavigationBar/HorizontalNavbar/tests/HorizontalNavbar.spec.ts +589 -0
- package/src/components/HeaderToolbar/tests/HeaderToolBar.spec.ts +153 -1
- package/src/components/HeaderToolbar/tests/useMobileRightMenu.spec.ts +258 -0
- package/src/components/LogoBrandSection/tests/LogoBrandSection.spec.ts +2 -2
- package/src/components/LogoBrandSection/tests/__snapshots__/LogoBrandSection.spec.ts.snap +1 -1
- package/src/components/LunarCalendar/tests/useLunarCalendarRules.spec.ts +184 -0
- package/src/components/MonthPicker/MonthPickerVisual/MonthSelector.vue +3 -3
- package/src/components/MonthPicker/MonthPickerVisual/VisualPickerFooter.vue +1 -1
- package/src/components/MonthPicker/MonthPickerVisual/VisualPickerHeader.vue +2 -2
- package/src/components/MonthPicker/MonthPickerVisual/YearSelector.vue +1 -1
- package/src/components/NirField/NirField.vue +3 -3
- package/src/components/NotificationBar/Notification/Notification.vue +12 -12
- package/src/components/NotificationBar/NotificationBar.stories.ts +8 -8
- package/src/components/PaginatedTable/Pagination.vue +2 -2
- package/src/components/PasswordField/PasswordField.vue +8 -8
- package/src/components/PasswordField/tests/PasswordField.spec.ts +3 -3
- package/src/components/RangeField/RangeSlider/RangeSlider.vue +2 -2
- package/src/components/RangeField/RangeSlider/Tooltip/Tooltip.vue +1 -1
- package/src/components/StatusPage/tests/StatusPage.spec.ts +149 -0
- package/src/components/SubHeader/SubHeader.vue +1 -1
- package/src/components/SyAlert/SyAlert.vue +23 -23
- package/src/components/SyTextArea/SyTextArea.stories.ts +177 -131
- package/src/components/SyTextArea/SyTextArea.vue +235 -83
- package/src/components/SyTextArea/composables/useSyTextAreaValidation.ts +81 -0
- package/src/components/SyTextArea/locales.ts +1 -0
- package/src/components/SyTextArea/tests/SyTextArea.spec.ts +449 -1
- package/src/components/SyTextArea/useDefaultValidationRules.ts +2 -7
- package/src/components/SyTextArea/validation/Validation.stories.ts +856 -0
- package/src/components/TableToolbar/TableToolbar.vue +6 -6
- package/src/components/TableToolbar/accessibilite/Accessibility.mdx +81 -7
- package/src/components/Tables/SyServerTable/SyServerTable.stories.ts +163 -0
- package/src/components/Tables/SyServerTable/SyServerTable.vue +2 -1
- package/src/components/Tables/SyServerTable/tests/SyServerTable.spec.ts +67 -0
- package/src/components/Tables/SyTable/SyTable.stories.ts +94 -0
- package/src/components/Tables/SyTable/SyTable.vue +2 -1
- package/src/components/Tables/SyTable/tests/SyTable.spec.ts +64 -0
- package/src/components/Tables/common/TableHeader.vue +2 -2
- package/src/components/Tables/common/filters/logics/tests/NumberFilterLogic.spec.ts +176 -0
- package/src/components/Tables/common/filters/logics/tests/SelectFilterLogic.spec.ts +111 -0
- package/src/components/Tables/common/tableStyles.scss +6 -6
- package/src/components/Tables/common/types.ts +2 -0
- package/src/components/UploadWorkflow/tests/UploadWorkflow.spec.ts +2 -0
- package/src/components/index.ts +1 -0
- package/src/composables/date/tests/useDateFormatDayjs.spec.ts +31 -0
- package/src/composables/date/tests/useHolidayDay.spec.ts +109 -0
- package/src/composables/rules/tests/useFieldValidation.spec.ts +374 -0
- package/src/composables/tests/useError.spec.ts +30 -0
- package/src/composables/tests/useFormFieldErrorHandling.spec.ts +234 -0
- package/src/composables/unifyValidation/documentationValidationProps.ts +5 -5
- package/src/composables/unifyValidation/tests/documentationValidationProps.spec.ts +177 -0
- package/src/composables/unifyValidation/tests/useCustomValidation.spec.ts +30 -0
- package/src/composables/unifyValidation/tests/useValidation.spec.ts +6 -2
- package/src/composables/unifyValidation/useCustomValidation.ts +19 -9
- package/src/composables/unifyValidation/useValidation.ts +18 -21
- package/src/composables/useFilterable/useFilterable.spec.ts +42 -0
- package/src/composables/useFilterable/useFilterable.ts +11 -7
- package/src/composables/useFormFieldErrorHandling.ts +2 -2
- package/src/composantsVuetify/VBtn/VBtn.mdx +9 -39
- package/src/composantsVuetify/VBtn/v-btn.stories.ts +26 -86
- package/src/designTokens/tokens/amelipro/apContextual.ts +6 -0
- package/src/designTokens/tokens/amelipro/apDarkTheme.ts +2 -2
- package/src/designTokens/tokens/amelipro/apLightTheme.ts +72 -103
- package/src/designTokens/tokens/amelipro/apSemantic.ts +1 -1
- package/src/designTokens/tokens/baseContextualTokens.ts +1 -6
- package/src/designTokens/tokens/baseTokens.ts +232 -0
- package/src/designTokens/tokens/cnam/cnamContextual.ts +6 -0
- package/src/designTokens/tokens/cnam/cnamDarkTheme.ts +2 -2
- package/src/designTokens/tokens/cnam/cnamLightTheme.ts +76 -104
- package/src/designTokens/tokens/pa/paDarkTheme.ts +2 -2
- package/src/designTokens/tokens/pa/paLightTheme.ts +73 -99
- package/src/designTokens/tokens/pa/paSemantic.ts +2 -0
- package/src/designTokens/tokens/semanticTokens.ts +114 -0
- package/src/stories/Components/Components.stories.ts +7 -3
- package/src/stories/DesignTokens/ColorIntegrationExample.vue +2 -3
- package/src/stories/DesignTokens/Colors.mdx +6 -8
- package/src/stories/DesignTokens/colors.stories.ts +244 -1081
- package/src/utils/amelipro/toKebabCase/tests/toKebabCase.spec.ts +52 -0
- package/src/utils/formatNir/tests/formatNir.spec.ts +34 -0
- package/src/utils/tests/insertAt.spec.ts +44 -0
- package/dist/apLightTheme-DS0Uy44H.js +0 -954
- package/dist/components/RatingPicker/tests/RatingPicker.a11y.spect.d.ts +0 -1
- package/dist/main-BsJ9ec3i.js +0 -38954
- package/src/components/BackBtn/tests/__snapshots__/back-btn-custom-bg.snap.png +0 -0
- package/src/components/BackBtn/tests/__snapshots__/back-btn-dark-mode.snap.png +0 -0
- package/src/components/BackBtn/tests/__snapshots__/back-btn-default.snap.png +0 -0
- package/src/components/BackBtn/tests/__snapshots__/back-btn-no-icon.snap.png +0 -0
- package/src/components/DatePicker/CalendarMode/tests/DatePicker.events.spec.ts +0 -178
- package/src/components/DialogBox/tests/__snapshots__/dialog-box-custom-texts.snap.png +0 -0
- package/src/components/DialogBox/tests/__snapshots__/dialog-box-default.snap.png +0 -0
- package/src/components/DialogBox/tests/__snapshots__/dialog-box-no-actions.snap.png +0 -0
- package/src/components/HeaderBar/HeaderBurgerMenu/tests/__snapshots__/header-burger-menu-generated-submenu-open.snap.png +0 -0
- package/src/components/HeaderBar/HeaderBurgerMenu/tests/__snapshots__/header-burger-menu-generated.snap.png +0 -0
- package/src/components/HeaderBar/tests/__snapshots__/header-bar-custom-width.snap.png +0 -0
- package/src/components/HeaderBar/tests/__snapshots__/header-bar-default.snap.png +0 -0
- package/src/components/HeaderBar/tests/__snapshots__/header-bar-no-sticky.snap.png +0 -0
- package/src/components/HeaderBar/tests/__snapshots__/header-bar-with-prepend.snap.png +0 -0
- package/src/components/HeaderBar/tests/__snapshots__/header-bar-with-side.snap.png +0 -0
- package/src/components/HeaderBar/tests/__snapshots__/header-bar-with-subtitle.snap.png +0 -0
- package/src/components/Logo/tests/__snapshots__/logo-avatar.snap.png +0 -0
- package/src/components/Logo/tests/__snapshots__/logo-dark.snap.png +0 -0
- package/src/components/Logo/tests/__snapshots__/logo-default.snap.png +0 -0
- package/src/components/Logo/tests/__snapshots__/logo-no-organism.snap.png +0 -0
- package/src/components/Logo/tests/__snapshots__/logo-no-signature.snap.png +0 -0
- package/src/components/Logo/tests/__snapshots__/logo-risque-pro.snap.png +0 -0
- package/src/components/RangeField/tests/__snapshots__/range-field-custom-bg.snap.png +0 -0
- package/src/components/RangeField/tests/__snapshots__/range-field-custom-range.snap.png +0 -0
- package/src/components/RangeField/tests/__snapshots__/range-field-default.snap.png +0 -0
- package/src/components/RangeField/tests/__snapshots__/range-field-step.snap.png +0 -0
- package/src/components/RangeField/tests/__snapshots__/range-field-with-label.snap.png +0 -0
- package/src/components/SyAlert/tests/__snapshots__/sy-alert-closable.snap.png +0 -0
- package/src/components/SyAlert/tests/__snapshots__/sy-alert-error.snap.png +0 -0
- package/src/components/SyAlert/tests/__snapshots__/sy-alert-info.snap.png +0 -0
- package/src/components/SyAlert/tests/__snapshots__/sy-alert-success.snap.png +0 -0
- package/src/components/SyAlert/tests/__snapshots__/sy-alert-variant-outlined.snap.png +0 -0
- package/src/components/SyAlert/tests/__snapshots__/sy-alert-variant-tonal.snap.png +0 -0
- package/src/components/SyAlert/tests/__snapshots__/sy-alert-warning.snap.png +0 -0
- /package/src/components/RatingPicker/tests/{RatingPicker.a11y.spect.ts → RatingPicker.a11y.spec.ts} +0 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
+
import { ref, nextTick, defineComponent } from 'vue'
|
|
3
|
+
import { mount } from '@vue/test-utils'
|
|
4
|
+
import { useFormFieldErrorHandling } from '../useFormFieldErrorHandling'
|
|
5
|
+
|
|
6
|
+
function withSetup<T>(
|
|
7
|
+
composable: () => T,
|
|
8
|
+
): { result: T, unmount: () => void } {
|
|
9
|
+
let result!: T
|
|
10
|
+
const Component = defineComponent({
|
|
11
|
+
setup() {
|
|
12
|
+
result = composable()
|
|
13
|
+
return {}
|
|
14
|
+
},
|
|
15
|
+
template: '<div />',
|
|
16
|
+
})
|
|
17
|
+
const wrapper = mount(Component)
|
|
18
|
+
return { result, unmount: () => wrapper.unmount() }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe('useFormFieldErrorHandling', () => {
|
|
22
|
+
describe('initialisation', () => {
|
|
23
|
+
it('retourne les champs attendus', () => {
|
|
24
|
+
const modelValue = ref<unknown>(null)
|
|
25
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling({}, modelValue))
|
|
26
|
+
|
|
27
|
+
expect(result).toHaveProperty('validateField')
|
|
28
|
+
expect(result).toHaveProperty('validateOnSubmit')
|
|
29
|
+
expect(result).toHaveProperty('checkErrorOnBlur')
|
|
30
|
+
expect(result).toHaveProperty('hasError')
|
|
31
|
+
expect(result).toHaveProperty('hasWarning')
|
|
32
|
+
expect(result).toHaveProperty('hasSuccess')
|
|
33
|
+
expect(result).toHaveProperty('errors')
|
|
34
|
+
expect(result).toHaveProperty('warnings')
|
|
35
|
+
expect(result).toHaveProperty('successes')
|
|
36
|
+
unmount()
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('synchronise errorMessages externes immédiatement', () => {
|
|
40
|
+
const modelValue = ref<unknown>(null)
|
|
41
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling(
|
|
42
|
+
{ errorMessages: ['Erreur externe'] },
|
|
43
|
+
modelValue,
|
|
44
|
+
))
|
|
45
|
+
expect(result.errors.value).toContain('Erreur externe')
|
|
46
|
+
unmount()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('synchronise warningMessages externes immédiatement', () => {
|
|
50
|
+
const modelValue = ref<unknown>(null)
|
|
51
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling(
|
|
52
|
+
{ warningMessages: ['Attention'] },
|
|
53
|
+
modelValue,
|
|
54
|
+
))
|
|
55
|
+
expect(result.warnings.value).toContain('Attention')
|
|
56
|
+
unmount()
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('synchronise successMessages externes immédiatement', () => {
|
|
60
|
+
const modelValue = ref<unknown>(null)
|
|
61
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling(
|
|
62
|
+
{ successMessages: ['OK'] },
|
|
63
|
+
modelValue,
|
|
64
|
+
))
|
|
65
|
+
expect(result.successes.value).toContain('OK')
|
|
66
|
+
unmount()
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
describe('validateField', () => {
|
|
71
|
+
it('retourne true pour une valeur null non requise', async () => {
|
|
72
|
+
const modelValue = ref<unknown>(null)
|
|
73
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling({}, modelValue))
|
|
74
|
+
const res = await result.validateField(null)
|
|
75
|
+
expect(res).toBe(true)
|
|
76
|
+
unmount()
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('retourne true pour un tableau vide non requis', async () => {
|
|
80
|
+
const modelValue = ref<unknown>([])
|
|
81
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling({}, modelValue))
|
|
82
|
+
const res = await result.validateField([])
|
|
83
|
+
expect(res).toBe(true)
|
|
84
|
+
unmount()
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('retourne true et vide la validation si disableErrorHandling', async () => {
|
|
88
|
+
const modelValue = ref<unknown>('test')
|
|
89
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling(
|
|
90
|
+
{ disableErrorHandling: true },
|
|
91
|
+
modelValue,
|
|
92
|
+
))
|
|
93
|
+
const res = await result.validateField('test')
|
|
94
|
+
expect(res).toBe(true)
|
|
95
|
+
expect(result.hasError.value).toBe(false)
|
|
96
|
+
unmount()
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('échoue si required et valeur null', async () => {
|
|
100
|
+
const modelValue = ref<unknown>(null)
|
|
101
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling(
|
|
102
|
+
{ required: true, label: 'Nom' },
|
|
103
|
+
modelValue,
|
|
104
|
+
))
|
|
105
|
+
const res = await result.validateField(null)
|
|
106
|
+
expect(res).toBe(false)
|
|
107
|
+
unmount()
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('réussit si required et valeur non nulle', async () => {
|
|
111
|
+
const modelValue = ref<unknown>('Alice')
|
|
112
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling(
|
|
113
|
+
{ required: true, label: 'Nom' },
|
|
114
|
+
modelValue,
|
|
115
|
+
))
|
|
116
|
+
const res = await result.validateField('Alice')
|
|
117
|
+
expect(res).toBe(true)
|
|
118
|
+
unmount()
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
describe('validateOnSubmit', () => {
|
|
123
|
+
it('valide la valeur courante du modelValue', async () => {
|
|
124
|
+
const modelValue = ref<unknown>('valeur')
|
|
125
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling(
|
|
126
|
+
{ required: true },
|
|
127
|
+
modelValue,
|
|
128
|
+
))
|
|
129
|
+
const res = await result.validateOnSubmit()
|
|
130
|
+
expect(res).toBe(true)
|
|
131
|
+
unmount()
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it('échoue si modelValue est null et required', async () => {
|
|
135
|
+
const modelValue = ref<unknown>(null)
|
|
136
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling(
|
|
137
|
+
{ required: true, label: 'Champ' },
|
|
138
|
+
modelValue,
|
|
139
|
+
))
|
|
140
|
+
const res = await result.validateOnSubmit()
|
|
141
|
+
expect(res).toBe(false)
|
|
142
|
+
unmount()
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
describe('checkErrorOnBlur', () => {
|
|
147
|
+
it('appelle emitUpdate si fourni', async () => {
|
|
148
|
+
const modelValue = ref<unknown>('test')
|
|
149
|
+
const emitUpdate = vi.fn()
|
|
150
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling({}, modelValue, emitUpdate))
|
|
151
|
+
result.checkErrorOnBlur()
|
|
152
|
+
await nextTick()
|
|
153
|
+
expect(emitUpdate).toHaveBeenCalledOnce()
|
|
154
|
+
unmount()
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
it('ne plante pas si emitUpdate n\'est pas fourni', () => {
|
|
158
|
+
const modelValue = ref<unknown>('test')
|
|
159
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling({}, modelValue))
|
|
160
|
+
expect(() => result.checkErrorOnBlur()).not.toThrow()
|
|
161
|
+
unmount()
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
describe('hasError / hasWarning / hasSuccess', () => {
|
|
166
|
+
it('hasError reflète le prop hasError externe', () => {
|
|
167
|
+
const modelValue = ref<unknown>(null)
|
|
168
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling(
|
|
169
|
+
{ hasError: true },
|
|
170
|
+
modelValue,
|
|
171
|
+
))
|
|
172
|
+
expect(result.hasError.value).toBe(true)
|
|
173
|
+
unmount()
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it('hasWarning reflète le prop hasWarning externe', () => {
|
|
177
|
+
const modelValue = ref<unknown>(null)
|
|
178
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling(
|
|
179
|
+
{ hasWarning: true },
|
|
180
|
+
modelValue,
|
|
181
|
+
))
|
|
182
|
+
expect(result.hasWarning.value).toBe(true)
|
|
183
|
+
unmount()
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
it('hasSuccess prop externe est indépendant de hasError externe', async () => {
|
|
187
|
+
const modelValue = ref<unknown>(null)
|
|
188
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling(
|
|
189
|
+
{ hasError: true, hasSuccess: true },
|
|
190
|
+
modelValue,
|
|
191
|
+
))
|
|
192
|
+
expect(result.hasSuccess.value).toBe(true)
|
|
193
|
+
unmount()
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
it('disableErrorHandling vide les erreurs de validation', async () => {
|
|
197
|
+
const modelValue = ref<unknown>(null)
|
|
198
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling(
|
|
199
|
+
{ disableErrorHandling: true },
|
|
200
|
+
modelValue,
|
|
201
|
+
))
|
|
202
|
+
await nextTick()
|
|
203
|
+
expect(result.hasError.value).toBe(false)
|
|
204
|
+
unmount()
|
|
205
|
+
})
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
describe('watcher modelValue', () => {
|
|
209
|
+
it('re-valide automatiquement quand modelValue change (isValidateOnBlur=false)', async () => {
|
|
210
|
+
const modelValue = ref<unknown>(null)
|
|
211
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling(
|
|
212
|
+
{ required: true, label: 'Test', isValidateOnBlur: false },
|
|
213
|
+
modelValue,
|
|
214
|
+
))
|
|
215
|
+
modelValue.value = 'nouvelle valeur'
|
|
216
|
+
await nextTick()
|
|
217
|
+
await nextTick()
|
|
218
|
+
expect(result.errors.value.length).toBe(0)
|
|
219
|
+
unmount()
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
it('ne re-valide pas automatiquement si isValidateOnBlur=true', async () => {
|
|
223
|
+
const modelValue = ref<unknown>(null)
|
|
224
|
+
const { result, unmount } = withSetup(() => useFormFieldErrorHandling(
|
|
225
|
+
{ required: true, isValidateOnBlur: true },
|
|
226
|
+
modelValue,
|
|
227
|
+
))
|
|
228
|
+
modelValue.value = 'test'
|
|
229
|
+
await nextTick()
|
|
230
|
+
expect(result.errors.value.length).toBe(0)
|
|
231
|
+
unmount()
|
|
232
|
+
})
|
|
233
|
+
})
|
|
234
|
+
})
|
|
@@ -137,11 +137,11 @@ export function getValidationDocumentation(type: 'date' | 'number' | 'string' |
|
|
|
137
137
|
type: ${builtInRuleType},
|
|
138
138
|
options: {
|
|
139
139
|
validate: (value: unknown) => boolean | string,
|
|
140
|
-
|
|
140
|
+
warningMessage: string,
|
|
141
141
|
[key: string]: unknown
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
`,
|
|
145
145
|
},
|
|
146
146
|
category: 'props',
|
|
147
147
|
},
|
|
@@ -157,11 +157,11 @@ export function getValidationDocumentation(type: 'date' | 'number' | 'string' |
|
|
|
157
157
|
type: ${builtInRuleType},
|
|
158
158
|
options: {
|
|
159
159
|
validate: (value: unknown) => boolean | string,
|
|
160
|
-
|
|
160
|
+
successMessage: string,
|
|
161
161
|
[key: string]: unknown
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
|
|
164
|
+
`,
|
|
165
165
|
},
|
|
166
166
|
category: 'props',
|
|
167
167
|
},
|
|
@@ -231,5 +231,5 @@ export function getValidationDocumentation(type: 'date' | 'number' | 'string' |
|
|
|
231
231
|
category: 'props',
|
|
232
232
|
},
|
|
233
233
|
},
|
|
234
|
-
}
|
|
234
|
+
} as const
|
|
235
235
|
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { getValidationDocumentation } from '../documentationValidationProps'
|
|
3
|
+
|
|
4
|
+
const EXPECTED_KEYS = [
|
|
5
|
+
'readonly',
|
|
6
|
+
'disabled',
|
|
7
|
+
'required',
|
|
8
|
+
'isValidateOnBlur',
|
|
9
|
+
'showSuccessMessages',
|
|
10
|
+
'disableErrorHandling',
|
|
11
|
+
'useVuetifyValidation',
|
|
12
|
+
'label',
|
|
13
|
+
'rules',
|
|
14
|
+
'customRules',
|
|
15
|
+
'customWarningRules',
|
|
16
|
+
'customSuccessRules',
|
|
17
|
+
'errorMessages',
|
|
18
|
+
'warningMessages',
|
|
19
|
+
'successMessages',
|
|
20
|
+
'hasError',
|
|
21
|
+
'hasWarning',
|
|
22
|
+
'hasSuccess',
|
|
23
|
+
'hideDetails',
|
|
24
|
+
'maxErrors',
|
|
25
|
+
] as const
|
|
26
|
+
|
|
27
|
+
describe('getValidationDocumentation', () => {
|
|
28
|
+
describe('structure retournée', () => {
|
|
29
|
+
it('retourne toutes les clés attendues pour le type "all" (défaut)', () => {
|
|
30
|
+
const doc = getValidationDocumentation()
|
|
31
|
+
for (const key of EXPECTED_KEYS) {
|
|
32
|
+
expect(doc).toHaveProperty(key)
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('chaque entrée possède une description string non vide', () => {
|
|
37
|
+
const doc = getValidationDocumentation()
|
|
38
|
+
for (const key of EXPECTED_KEYS) {
|
|
39
|
+
expect(typeof doc[key].description).toBe('string')
|
|
40
|
+
expect(doc[key].description.length).toBeGreaterThan(0)
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('chaque entrée possède une table avec un type', () => {
|
|
45
|
+
const doc = getValidationDocumentation()
|
|
46
|
+
for (const key of EXPECTED_KEYS) {
|
|
47
|
+
expect(doc[key]).toHaveProperty('table')
|
|
48
|
+
expect(doc[key].table).toHaveProperty('type')
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
describe('type "all" (défaut)', () => {
|
|
54
|
+
it('customRules inclut les types string, number et date', () => {
|
|
55
|
+
const doc = getValidationDocumentation('all')
|
|
56
|
+
const detail = doc.customRules.table.type.detail
|
|
57
|
+
expect(detail).toContain('minLength')
|
|
58
|
+
expect(detail).toContain('min')
|
|
59
|
+
expect(detail).toContain('noWeekend')
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('customWarningRules inclut tous les types', () => {
|
|
63
|
+
const doc = getValidationDocumentation('all')
|
|
64
|
+
const detail = doc.customWarningRules.table.type.detail
|
|
65
|
+
expect(detail).toContain('maxLength')
|
|
66
|
+
expect(detail).toContain('max')
|
|
67
|
+
expect(detail).toContain('notAfterDate')
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('type "string"', () => {
|
|
72
|
+
it('customRules inclut les types string mais pas number ni date', () => {
|
|
73
|
+
const doc = getValidationDocumentation('string')
|
|
74
|
+
const detail = doc.customRules.table.type.detail
|
|
75
|
+
expect(detail).toContain('minLength')
|
|
76
|
+
expect(detail).toContain('email')
|
|
77
|
+
expect(detail).not.toContain('noWeekend')
|
|
78
|
+
expect(detail).not.toContain('notAfterDate')
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
describe('type "number"', () => {
|
|
83
|
+
it('customRules inclut les types number mais pas string ni date', () => {
|
|
84
|
+
const doc = getValidationDocumentation('number')
|
|
85
|
+
const detail = doc.customRules.table.type.detail
|
|
86
|
+
expect(detail).toContain('\'min\'')
|
|
87
|
+
expect(detail).toContain('\'max\'')
|
|
88
|
+
expect(detail).not.toContain('minLength')
|
|
89
|
+
expect(detail).not.toContain('noWeekend')
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
describe('type "date"', () => {
|
|
94
|
+
it('customRules inclut les types date mais pas string ni number', () => {
|
|
95
|
+
const doc = getValidationDocumentation('date')
|
|
96
|
+
const detail = doc.customRules.table.type.detail
|
|
97
|
+
expect(detail).toContain('noWeekend')
|
|
98
|
+
expect(detail).toContain('notAfterDate')
|
|
99
|
+
expect(detail).not.toContain('minLength')
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
describe('valeurs par défaut documentées', () => {
|
|
104
|
+
it('readonly a un defaultValue false', () => {
|
|
105
|
+
const doc = getValidationDocumentation()
|
|
106
|
+
expect(doc.readonly.table.defaultValue).toEqual({ summary: 'false' })
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it('isValidateOnBlur a un defaultValue true', () => {
|
|
110
|
+
const doc = getValidationDocumentation()
|
|
111
|
+
expect(doc.isValidateOnBlur.table.defaultValue).toEqual({ summary: 'true' })
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('showSuccessMessages a un defaultValue true', () => {
|
|
115
|
+
const doc = getValidationDocumentation()
|
|
116
|
+
expect(doc.showSuccessMessages.table.defaultValue).toEqual({ summary: 'true' })
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('disableErrorHandling a un defaultValue false', () => {
|
|
120
|
+
const doc = getValidationDocumentation()
|
|
121
|
+
expect(doc.disableErrorHandling.table.defaultValue).toEqual({ summary: 'false' })
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('useVuetifyValidation a un defaultValue false', () => {
|
|
125
|
+
const doc = getValidationDocumentation()
|
|
126
|
+
expect(doc.useVuetifyValidation.table.defaultValue).toEqual({ summary: 'false' })
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
describe('contrôles Storybook', () => {
|
|
131
|
+
it('les props booléennes ont control="boolean"', () => {
|
|
132
|
+
const doc = getValidationDocumentation()
|
|
133
|
+
const booleanProps = ['readonly', 'disabled', 'required', 'isValidateOnBlur', 'showSuccessMessages', 'disableErrorHandling', 'useVuetifyValidation', 'hasError', 'hasWarning', 'hasSuccess', 'hideDetails'] as const
|
|
134
|
+
for (const key of booleanProps) {
|
|
135
|
+
expect(doc[key].control).toBe('boolean')
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('label a control="text"', () => {
|
|
140
|
+
const doc = getValidationDocumentation()
|
|
141
|
+
expect(doc.label.control).toBe('text')
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
it('customRules a control="object"', () => {
|
|
145
|
+
const doc = getValidationDocumentation()
|
|
146
|
+
expect(doc.customRules.control).toBe('object')
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
it('maxErrors a control="number"', () => {
|
|
150
|
+
const doc = getValidationDocumentation()
|
|
151
|
+
expect(doc.maxErrors.control).toBe('number')
|
|
152
|
+
})
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
describe('catégories table', () => {
|
|
156
|
+
it('toutes les entrées ont category="props"', () => {
|
|
157
|
+
const doc = getValidationDocumentation()
|
|
158
|
+
for (const key of EXPECTED_KEYS) {
|
|
159
|
+
expect(doc[key].table.category).toBe('props')
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
describe('appels successifs', () => {
|
|
165
|
+
it('deux appels avec le même type retournent des objets équivalents', () => {
|
|
166
|
+
const doc1 = getValidationDocumentation('string')
|
|
167
|
+
const doc2 = getValidationDocumentation('string')
|
|
168
|
+
expect(JSON.stringify(doc1)).toBe(JSON.stringify(doc2))
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
it('deux appels avec des types différents retournent des objets différents pour customRules', () => {
|
|
172
|
+
const docString = getValidationDocumentation('string')
|
|
173
|
+
const docDate = getValidationDocumentation('date')
|
|
174
|
+
expect(docString.customRules.table.type.detail).not.toBe(docDate.customRules.table.type.detail)
|
|
175
|
+
})
|
|
176
|
+
})
|
|
177
|
+
})
|
|
@@ -187,6 +187,36 @@ describe('useCustomValidation', () => {
|
|
|
187
187
|
expect(args.errors.value).toEqual([])
|
|
188
188
|
})
|
|
189
189
|
|
|
190
|
+
it('does not trigger validation on blur when isValidateOnBlur is false', async () => {
|
|
191
|
+
const args = defaultArgs()
|
|
192
|
+
args.focused.value = true
|
|
193
|
+
args.modelValue.value = ''
|
|
194
|
+
args.isValidateOnBlur.value = false
|
|
195
|
+
withSetup(() =>
|
|
196
|
+
useCustomValidation(
|
|
197
|
+
args.modelValue,
|
|
198
|
+
args.customRules,
|
|
199
|
+
args.customWarningRules,
|
|
200
|
+
args.customSuccessRules,
|
|
201
|
+
args.errors,
|
|
202
|
+
args.warnings,
|
|
203
|
+
args.successes,
|
|
204
|
+
args.showSuccessMessages,
|
|
205
|
+
args.label,
|
|
206
|
+
args.focused,
|
|
207
|
+
args.isValidateOnBlur,
|
|
208
|
+
args.disableErrorHandling,
|
|
209
|
+
),
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
args.focused.value = false
|
|
213
|
+
await nextTick()
|
|
214
|
+
|
|
215
|
+
expect(args.errors.value).toEqual([])
|
|
216
|
+
expect(args.warnings.value).toEqual([])
|
|
217
|
+
expect(args.successes.value).toEqual([])
|
|
218
|
+
})
|
|
219
|
+
|
|
190
220
|
it('triggers validation on modelValue change when isValidateOnBlur is false', async () => {
|
|
191
221
|
const args = defaultArgs()
|
|
192
222
|
args.isValidateOnBlur.value = false
|
|
@@ -327,12 +327,12 @@ describe('useValidation (unifyValidation)', () => {
|
|
|
327
327
|
expect(result.errors.value).toContain('Requis blur')
|
|
328
328
|
})
|
|
329
329
|
|
|
330
|
-
it('with isValidateOnBlur=false, does not validate
|
|
330
|
+
it('with isValidateOnBlur=false, does not validate on blur (validates on input change instead)', async () => {
|
|
331
331
|
const params = makeParams({
|
|
332
332
|
useVuetifyValidation: false as const,
|
|
333
333
|
isValidateOnBlur: ref(false),
|
|
334
334
|
focused: ref(true),
|
|
335
|
-
modelValue: ref(''),
|
|
335
|
+
modelValue: ref('valeur initiale'),
|
|
336
336
|
customRules: ref([{ type: 'required', options: { message: 'Requis blur input-mode' } }]),
|
|
337
337
|
})
|
|
338
338
|
const { result } = withSetup(() => useValidation(params as Parameters<typeof useValidation>[0]))
|
|
@@ -342,6 +342,10 @@ describe('useValidation (unifyValidation)', () => {
|
|
|
342
342
|
|
|
343
343
|
params.focused.value = false
|
|
344
344
|
await nextTick()
|
|
345
|
+
expect(result.errors.value).toEqual([])
|
|
346
|
+
|
|
347
|
+
params.modelValue.value = ''
|
|
348
|
+
await nextTick()
|
|
345
349
|
expect(result.errors.value).toContain('Requis blur input-mode')
|
|
346
350
|
})
|
|
347
351
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useValidation, type ValidationRule } from '@/composables/validation/useValidation'
|
|
2
2
|
import { useValidatable } from '@/composables/validation/useValidatable'
|
|
3
|
-
import { ref, watch } from 'vue'
|
|
3
|
+
import { reactive, ref, watch } from 'vue'
|
|
4
4
|
import type { Ref } from 'vue'
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -24,21 +24,31 @@ export function useCustomValidation(
|
|
|
24
24
|
) {
|
|
25
25
|
const hasSuccess = ref(false)
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const validatorOptions = reactive({
|
|
28
28
|
showSuccessMessages: showSuccessMessages.value,
|
|
29
29
|
fieldIdentifier: label.value,
|
|
30
30
|
disableErrorHandling: disableErrorHandling.value,
|
|
31
31
|
})
|
|
32
32
|
|
|
33
|
+
const validator = useValidation(validatorOptions)
|
|
34
|
+
|
|
33
35
|
watch(
|
|
34
|
-
() => [showSuccessMessages.value, label.value,
|
|
36
|
+
() => [showSuccessMessages.value, label.value, disableErrorHandling.value],
|
|
35
37
|
() => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
validatorOptions.showSuccessMessages = showSuccessMessages.value
|
|
39
|
+
validatorOptions.fieldIdentifier = label.value
|
|
40
|
+
validatorOptions.disableErrorHandling = disableErrorHandling.value
|
|
41
|
+
|
|
42
|
+
const isDirty = errors.value.length > 0 || warnings.value.length > 0 || successes.value.length > 0 || hasSuccess.value
|
|
43
|
+
if (isDirty) {
|
|
44
|
+
validate()
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
)
|
|
41
48
|
|
|
49
|
+
watch(
|
|
50
|
+
() => [customRules?.value, customWarningRules?.value, customSuccessRules?.value],
|
|
51
|
+
() => {
|
|
42
52
|
const isDirty = errors.value.length > 0 || warnings.value.length > 0 || successes.value.length > 0 || hasSuccess.value
|
|
43
53
|
if (isDirty) {
|
|
44
54
|
validate()
|
|
@@ -85,7 +95,7 @@ export function useCustomValidation(
|
|
|
85
95
|
)
|
|
86
96
|
|
|
87
97
|
watch(focused, (newVal) => {
|
|
88
|
-
if (!newVal && !disableErrorHandling.value) {
|
|
98
|
+
if (isValidateOnBlur.value && !newVal && !disableErrorHandling.value) {
|
|
89
99
|
validate()
|
|
90
100
|
}
|
|
91
101
|
})
|
|
@@ -4,34 +4,31 @@ import type { ValidationRule as VuetifyValidationRule } from 'vuetify'
|
|
|
4
4
|
import { useCustomValidation } from './useCustomValidation'
|
|
5
5
|
import { useVuetifyValidation as useVuetifyValidationComposable } from './useVuetifyValidation'
|
|
6
6
|
|
|
7
|
+
export type { VuetifyValidationRule }
|
|
8
|
+
export type { SyValidationRule as ValidationRule }
|
|
9
|
+
|
|
7
10
|
export interface FieldValidationProps {
|
|
8
|
-
modelValue?: unknown
|
|
9
|
-
readonly?: boolean
|
|
10
|
-
disabled?: boolean
|
|
11
|
-
required?: boolean
|
|
12
|
-
isValidateOnBlur?: boolean
|
|
13
|
-
showSuccessMessages?: boolean
|
|
14
|
-
disableErrorHandling?: boolean
|
|
15
|
-
// Quand cette prop vaut true (mode natif Vuetify), c'est Vuetify qui gère les erreurs, avertissements et succès
|
|
16
|
-
useVuetifyValidation?: boolean
|
|
17
|
-
label?: string
|
|
18
|
-
rules?: VuetifyValidationRule[]
|
|
19
|
-
// Règles de validation personnalisées d'erreur (bloquantes), évaluées à partir de la valeur du champ
|
|
20
11
|
customRules?: SyValidationRule[]
|
|
21
|
-
// Règles de validation personnalisées d'avertissement (non bloquantes), évaluées à partir de la valeur du champ
|
|
22
|
-
customWarningRules?: SyValidationRule[]
|
|
23
|
-
// Règles de validation personnalisées de succès, évaluées à partir de la valeur du champ
|
|
24
12
|
customSuccessRules?: SyValidationRule[]
|
|
25
|
-
|
|
13
|
+
customWarningRules?: SyValidationRule[]
|
|
14
|
+
disableErrorHandling?: boolean
|
|
15
|
+
disabled?: boolean
|
|
26
16
|
errorMessages?: string[] | null
|
|
27
|
-
// Messages d'avertissement injectés par le parent ; ils n'exécutent aucune logique de validation
|
|
28
|
-
warningMessages?: string[] | null
|
|
29
|
-
// Messages de succès injectés par le parent ; ils n'exécutent aucune logique de validation
|
|
30
|
-
successMessages?: string[] | null
|
|
31
17
|
hasError?: boolean
|
|
32
|
-
hasWarning?: boolean
|
|
33
18
|
hasSuccess?: boolean
|
|
19
|
+
hasWarning?: boolean
|
|
20
|
+
isValidateOnBlur?: boolean
|
|
21
|
+
label?: string
|
|
34
22
|
maxErrors?: number
|
|
23
|
+
modelValue?: unknown
|
|
24
|
+
readonly?: boolean
|
|
25
|
+
required?: boolean
|
|
26
|
+
rules?: VuetifyValidationRule[]
|
|
27
|
+
showSuccessMessages?: boolean
|
|
28
|
+
successMessages?: string[] | null
|
|
29
|
+
// When true (Vuetify native mode), the controller should not handle errors/successes
|
|
30
|
+
useVuetifyValidation?: boolean
|
|
31
|
+
warningMessages?: string[] | null
|
|
35
32
|
}
|
|
36
33
|
|
|
37
34
|
/**
|
|
@@ -213,6 +213,48 @@ describe('Filterable', () => {
|
|
|
213
213
|
expect(filterCount).toBe(0)
|
|
214
214
|
})
|
|
215
215
|
|
|
216
|
+
it('returns a chip when only from is set', () => {
|
|
217
|
+
const { getChips, getFilterCount } = useFilterable(
|
|
218
|
+
ref([]),
|
|
219
|
+
() => {},
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
const filter = {
|
|
223
|
+
name: 'Test',
|
|
224
|
+
value: {
|
|
225
|
+
from: '2024-01-01',
|
|
226
|
+
to: null,
|
|
227
|
+
},
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const chips = getChips(filter)
|
|
231
|
+
const filterCount = getFilterCount(filter)
|
|
232
|
+
|
|
233
|
+
expect(chips).toEqual([{ text: '2024-01-01 –', value: { from: '2024-01-01', to: null } }])
|
|
234
|
+
expect(filterCount).toBe(1)
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
it('returns a chip when only to is set', () => {
|
|
238
|
+
const { getChips, getFilterCount } = useFilterable(
|
|
239
|
+
ref([]),
|
|
240
|
+
() => {},
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
const filter = {
|
|
244
|
+
name: 'Test',
|
|
245
|
+
value: {
|
|
246
|
+
from: null,
|
|
247
|
+
to: '2024-12-31',
|
|
248
|
+
},
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const chips = getChips(filter)
|
|
252
|
+
const filterCount = getFilterCount(filter)
|
|
253
|
+
|
|
254
|
+
expect(chips).toEqual([{ text: '– 2024-12-31', value: { from: null, to: '2024-12-31' } }])
|
|
255
|
+
expect(filterCount).toBe(1)
|
|
256
|
+
})
|
|
257
|
+
|
|
216
258
|
it('returns the correct text when the value is an object', () => {
|
|
217
259
|
const { getChips, getFilterCount } = useFilterable(
|
|
218
260
|
ref([]),
|