@cnamts/synapse 1.0.23 → 1.0.24
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-BWLR3U7W.js +114 -0
- package/dist/AutocompleteFilter-D9jzRzAL.cjs +1 -0
- package/dist/{DateFilter-Dc-gSGwk.js → DateFilter-BpwFexzi.js} +1 -1
- package/dist/DateFilter-DTUl8hb1.cjs +1 -0
- package/dist/{NumberFilter-vP38Wp6j.js → NumberFilter-Bz_NTdX9.js} +3 -3
- package/dist/NumberFilter-MAEojdk0.cjs +1 -0
- package/dist/PeriodFilter-CC4WgIhl.cjs +1 -0
- package/dist/{PeriodFilter-Ba1uYUnT.js → PeriodFilter-DX_wy9g-.js} +1 -1
- package/dist/SelectFilter-BR3fvl-a.cjs +1 -0
- package/dist/SelectFilter-xqiPtPgX.js +135 -0
- package/dist/{TextFilter-B84dpnoq.js → TextFilter-BBl3JFqK.js} +7 -7
- package/dist/TextFilter-CCfYFl5F.cjs +1 -0
- package/dist/apLightTheme-CFSRrjv2.cjs +1 -0
- package/dist/apLightTheme-D1P4jcD0.js +1231 -0
- package/dist/components/Amelipro/AmeliproAutoCompleteField/AmeliproAutoCompleteField.d.ts +7022 -9616
- package/dist/components/Amelipro/AmeliproCarousel/AmeliproCarousel.d.ts +2 -2
- package/dist/components/Amelipro/AmeliproIconBtn/AmeliproIconBtn.d.ts +2 -2
- package/dist/components/Amelipro/AmeliproPostalAddressField/AmeliproPostalAddressCityRow/AmeliproPostalAddressCityRow.d.ts +40 -40
- package/dist/components/Amelipro/AmeliproPostalAddressField/AmeliproPostalAddressField.d.ts +60 -60
- package/dist/components/Amelipro/AmeliproSelect/AmeliproSelect.d.ts +7168 -9762
- package/dist/components/Amelipro/AmeliproStepper/AmeliproStepper.d.ts +2 -2
- package/dist/components/Amelipro/AmeliproTabs/AmeliproTabs.d.ts +7501 -10095
- package/dist/components/Amelipro/AmeliproTextArea/AmeliproTextArea.d.ts +21 -21
- package/dist/components/Amelipro/AmeliproTextField/AmeliproTextField.d.ts +41 -41
- package/dist/components/Amelipro/StructureMenu/StructureTabs/StructureTabs.d.ts +2 -2
- package/dist/components/CookiesSelection/CookiesInformation/CookiesInformation.d.ts +20 -498
- package/dist/components/Customs/Selects/SyAutocomplete/SyAutocomplete.d.ts +108 -146
- package/dist/components/Customs/Selects/SyInputSelect/SyInputSelect.d.ts +5 -5
- package/dist/components/Customs/Selects/SySelect/SySelect.d.ts +12 -16
- package/dist/components/Customs/SyCheckBoxGroup/SyCheckBoxGroup.d.ts +8 -8
- package/dist/components/Customs/SyCheckbox/SyCheckbox.d.ts +28 -506
- package/dist/components/Customs/SyRadioGroup/SyRadioGroup.d.ts +28 -506
- package/dist/components/Customs/SyTextField/SyTextField.d.ts +65 -85
- package/dist/components/DatePicker/CalendarMode/DatePicker.d.ts +627 -771
- package/dist/components/DatePicker/ComplexDatePicker/ComplexDatePicker.d.ts +315 -402
- package/dist/components/DatePicker/DateTextInput/DateTextInput.d.ts +112 -155
- package/dist/components/DatePicker/composables/index.d.ts +1 -0
- package/dist/components/DatePicker/composables/useDatePickerFocusTrap.d.ts +11 -0
- package/dist/components/DatePicker/composables/useDateTextField.d.ts +4 -4
- package/dist/components/DatePicker/composables/useDateValidation.d.ts +3 -3
- package/dist/components/DatePicker/composables/useInputBlurHandler.d.ts +2 -2
- package/dist/components/DatePicker/composables/useManualDateValidation.d.ts +2 -2
- package/dist/components/HeaderNavigationBar/HeaderNavigationBar.d.ts +4 -4
- package/dist/components/HeaderToolbar/HeaderToolbar.d.ts +20 -28
- package/dist/components/LunarCalendar/useLunarCalendarValidation.d.ts +3 -3
- package/dist/components/MonthPicker/MonthPicker.d.ts +86 -122
- package/dist/components/MonthPicker/MonthPickerText/MonthPickerInput.d.ts +85 -121
- package/dist/components/NirField/NirField.d.ts +206 -270
- package/dist/components/NirField/locales.d.ts +10 -10
- package/dist/components/NirField/useNirValidation.d.ts +64 -0
- package/dist/components/PasswordField/PasswordField.d.ts +8 -9
- package/dist/components/PeriodField/PeriodField.d.ts +1352 -1640
- package/dist/components/PhoneField/PhoneField.d.ts +88 -124
- package/dist/components/RangeField/RangeSlider/RangeSlider.d.ts +12 -12
- package/dist/components/SyTextArea/SyTextArea.d.ts +34 -14
- package/dist/components/SyTextArea/useDefaultValidationRules.d.ts +11 -0
- package/dist/components/Tables/SyServerTable/SyServerTable.d.ts +9 -6
- package/dist/components/Tables/SyTable/SyTable.d.ts +9 -6
- package/dist/components/Tables/common/SyTableFilter.d.ts +2 -3
- package/dist/components/Tables/common/SyTablePagination.d.ts +17 -19
- package/dist/components/Tables/common/filters/AutocompleteFilter.d.ts +120 -0
- package/dist/components/Tables/common/filters/locales.d.ts +0 -1
- package/dist/components/Tables/common/types.d.ts +19 -3
- package/dist/components/Tables/common/useClickableTableRow.d.ts +17 -0
- package/dist/components/Tables/common/usePagination.d.ts +3 -1
- package/dist/components/Tables/common/usePinnedColumns.d.ts +31 -0
- package/dist/components/Tables/common/useTableHeaders.d.ts +2 -0
- package/dist/components/Tables/common/useTableRowCheckboxAccessibility.d.ts +5 -0
- package/dist/components/UploadWorkflow/UploadWorkflow.d.ts +6 -6
- package/dist/composables/date/useDatePickerAccessibility.d.ts +1 -1
- package/dist/composables/rules/useFieldValidation.d.ts +4 -4
- package/dist/composables/unifyValidation/useCustomValidation.d.ts +8 -0
- package/dist/composables/unifyValidation/useValidation.d.ts +102 -0
- package/dist/composables/unifyValidation/useVuetifyValidation.d.ts +18 -0
- package/dist/composables/useFormFieldErrorHandling.d.ts +2 -2
- package/dist/composables/validation/useFormValidation.d.ts +11 -2
- package/dist/composables/validation/useValidation.d.ts +15 -9
- package/dist/design-system-v3.d.ts +2 -0
- package/dist/design-system-v3.js +186 -187
- package/dist/design-system-v3.umd.cjs +1 -1066
- package/dist/{main-aLKwdMi1.js → main-BtTqyn4z.js} +16434 -15672
- package/dist/main-C1e3eoxd.cjs +1067 -0
- package/dist/main.d.ts +0 -1
- package/dist/synapse.css +1 -0
- package/dist/tooth-11-D3sLWv2n.cjs +1 -0
- package/dist/tooth-12-CXrLuH03.cjs +1 -0
- package/dist/tooth-13-BSfo5fpT.cjs +1 -0
- package/dist/tooth-14-DMzulx0h.cjs +1 -0
- package/dist/tooth-15-BKRFVi-9.cjs +1 -0
- package/dist/tooth-16-CpuxAbuM.cjs +1 -0
- package/dist/tooth-17-BPoahUdg.cjs +1 -0
- package/dist/tooth-18-DhHJz8sy.cjs +1 -0
- package/dist/tooth-21-Dgd5hn_X.cjs +1 -0
- package/dist/tooth-22-C2Tn19sB.cjs +1 -0
- package/dist/tooth-23-C9uaaSGb.cjs +1 -0
- package/dist/tooth-24-BrK9UGpf.cjs +1 -0
- package/dist/tooth-25-CE_EfGNp.cjs +1 -0
- package/dist/tooth-26-Ctv4i9Fy.cjs +1 -0
- package/dist/tooth-27-C5J7JkWM.cjs +1 -0
- package/dist/tooth-28-Z9oWqjo0.cjs +1 -0
- package/dist/tooth-31-BrYqmkTi.cjs +1 -0
- package/dist/tooth-32-BNNR0oCZ.cjs +1 -0
- package/dist/tooth-33-DuxvqO2J.cjs +1 -0
- package/dist/tooth-34-BCSCXMB6.cjs +1 -0
- package/dist/tooth-35-BLUXkX88.cjs +1 -0
- package/dist/tooth-36-IrKHYqlA.cjs +1 -0
- package/dist/tooth-37-BYqpdMwo.cjs +1 -0
- package/dist/tooth-38-B_eNXXdu.cjs +1 -0
- package/dist/tooth-41-Ddva4Ot8.cjs +1 -0
- package/dist/tooth-42-szcDqlM0.cjs +1 -0
- package/dist/tooth-43-B3ka6rQm.cjs +1 -0
- package/dist/tooth-44-CazyQucj.cjs +1 -0
- package/dist/tooth-45-B4HQtc8n.cjs +1 -0
- package/dist/tooth-46-BPM40gbG.cjs +1 -0
- package/dist/tooth-47-Dvr20dlh.cjs +1 -0
- package/dist/tooth-48-Bd8ljGsF.cjs +1 -0
- package/dist/tooth-51-OBpwCOF3.cjs +1 -0
- package/dist/tooth-52-aKxyHcmq.cjs +1 -0
- package/dist/tooth-53-vCwJjTOc.cjs +1 -0
- package/dist/tooth-54-DsWu2iFy.cjs +1 -0
- package/dist/tooth-55-BxC1X2Dn.cjs +1 -0
- package/dist/tooth-61-BbLvxMQi.cjs +1 -0
- package/dist/tooth-62-CmTkWczP.cjs +1 -0
- package/dist/tooth-63-DI7l_2qI.cjs +1 -0
- package/dist/tooth-64-B21sOsJh.cjs +1 -0
- package/dist/tooth-65-D2ZC2VEr.cjs +1 -0
- package/dist/tooth-71-D473PPO5.cjs +1 -0
- package/dist/tooth-72-Drh1wnNu.cjs +1 -0
- package/dist/tooth-73-DzlwYI23.cjs +1 -0
- package/dist/tooth-74-8aGvcZPg.cjs +1 -0
- package/dist/tooth-75-BFK7At_r.cjs +1 -0
- package/dist/tooth-81-BZmR-I0M.cjs +1 -0
- package/dist/tooth-82-euVfUUZV.cjs +1 -0
- package/dist/tooth-83-KV010j64.cjs +1 -0
- package/dist/tooth-84-BBg1RjhZ.cjs +1 -0
- package/dist/tooth-85-Cr-kc1wM.cjs +1 -0
- package/dist/vuetifyConfig.js +561 -0
- package/dist/vuetifyConfig.umd.cjs +1 -0
- package/package.json +10 -4
- package/src/assets/overrides/_btns.scss +0 -6
- package/src/assets/overrides/_icons.scss +9 -1
- package/src/assets/overrides/_typography.scss +0 -10
- package/src/components/Amelipro/AmeliproAutoCompleteField/__tests__/__snapshots__/AmeliproAutoCompleteField.spec.ts.snap +2 -2
- package/src/components/Amelipro/AmeliproHeader/AmeliproHeaderBar/AmeliproHeaderBrandSection/__tests__/__snapshots__/AmeliproHeaderBrandSection.spec.ts.snap +1 -1
- package/src/components/Amelipro/AmeliproTextArea/__tests__/__snapshots__/AmeliproTextArea.spec.ts.snap +2 -2
- package/src/components/Captcha/accessibilite/Accessibility.mdx +86 -8
- package/src/components/Captcha/tests/__snapshots__/Captcha.spec.ts.snap +12 -12
- package/src/components/ChipList/ChipList.stories.ts +0 -15
- package/src/components/ChipList/ChipList.vue +5 -1
- package/src/components/ChipList/accessibilite/Accessibility.mdx +83 -10
- package/src/components/ChipList/tests/ChipList.a11y.spec.ts +41 -0
- package/src/components/Customs/Selects/SelectBtnField/accessibilite/Accessibility.mdx +0 -9
- package/src/components/Customs/Selects/SyAutocomplete/SyAutocomplete.vue +22 -5
- package/src/components/Customs/Selects/SyAutocomplete/tests/SyAutocomplete.spec.ts +143 -0
- package/src/components/Customs/Selects/SyAutocomplete/utils/ariaManager.ts +14 -10
- package/src/components/Customs/Selects/SyInputSelect/SyInputSelect.stories.ts +4 -4
- package/src/components/Customs/Selects/SyInputSelect/SyInputSelect.vue +8 -9
- package/src/components/Customs/Selects/SyInputSelect/tests/SyInputSelect.spec.ts +10 -10
- package/src/components/Customs/Selects/SySelect/SySelect.vue +14 -11
- package/src/components/Customs/Selects/SySelect/tests/SySelect.spec.ts +54 -0
- package/src/components/Customs/SyCheckBoxGroup/SyCheckBoxGroup.vue +6 -9
- package/src/components/Customs/SyCheckbox/SyCheckbox.stories.ts +10 -16
- package/src/components/Customs/SyCheckbox/SyCheckbox.vue +16 -11
- package/src/components/Customs/SyCheckbox/accessibilite/Accessibility.mdx +35 -0
- package/src/components/Customs/SyCheckbox/tests/SyCheckbox.a11y.spec.ts +134 -2
- package/src/components/Customs/SyForm/SyForm.stories.ts +31 -5
- package/src/components/Customs/SyRadioGroup/SyRadioGroup.vue +4 -7
- package/src/components/Customs/SyTextField/SyTextField.mdx +1 -1
- package/src/components/Customs/SyTextField/SyTextField.stories.ts +29 -27
- package/src/components/Customs/SyTextField/SyTextField.vue +154 -157
- package/src/components/Customs/SyTextField/tests/SyTextField.a11y.spec.ts +32 -0
- package/src/components/Customs/SyTextField/tests/SyTextField.spec.ts +120 -11
- package/src/components/DatePicker/CalendarMode/DatePicker.stories.ts +62 -58
- package/src/components/DatePicker/CalendarMode/DatePicker.vue +330 -223
- package/src/components/DatePicker/CalendarMode/accessibilite/Accessibility.mdx +82 -0
- package/src/components/DatePicker/CalendarMode/tests/DatePicker.a11y.spec.ts +141 -0
- package/src/components/DatePicker/ComplexDatePicker/ComplexDatePicker.stories.ts +2 -56
- package/src/components/DatePicker/ComplexDatePicker/ComplexDatePicker.vue +195 -159
- package/src/components/DatePicker/ComplexDatePicker/accessibilite/Accessibility.mdx +76 -0
- package/src/components/DatePicker/ComplexDatePicker/tests/ComplexDatePicker.spec.ts +10 -10
- package/src/components/DatePicker/DatePickerValidationExample/CalendarMode.stories.ts +8 -8
- package/src/components/DatePicker/DatePickerValidationExample/ComplexDatePicker.stories.ts +106 -8
- package/src/components/DatePicker/DatePickerValidationExample/DateTextInput.stories.ts +12 -11
- package/src/components/DatePicker/DatePickerValidationExample/MultiMode.stories.ts +12 -12
- package/src/components/DatePicker/DateTextInput/DateRange.stories.ts +0 -12
- package/src/components/DatePicker/DateTextInput/DateTextInput.vue +63 -57
- package/src/components/DatePicker/DateTextInput/NoCalendar.stories.ts +3 -0
- package/src/components/DatePicker/DateTextInput/accessibilite/Accessibility.mdx +66 -0
- package/src/components/DatePicker/DateTextInput/tests/DateTextInput.spec.ts +52 -1
- package/src/components/DatePicker/composables/index.ts +1 -0
- package/src/components/DatePicker/composables/tests/useCalendarKeyboardNavigation.spec.ts +109 -65
- package/src/components/DatePicker/composables/tests/useDatePickerFocusTrap.spec.ts +138 -0
- package/src/components/DatePicker/composables/tests/useDateValidation.spec.ts +74 -18
- package/src/components/DatePicker/composables/tests/useInputBlurHandler.spec.ts +39 -0
- package/src/components/DatePicker/composables/tests/useManualDateValidation.spec.ts +91 -0
- package/src/components/DatePicker/composables/useCalendarKeyboardNavigation.ts +442 -36
- package/src/components/DatePicker/composables/useDatePickerFocusTrap.ts +92 -0
- package/src/components/DatePicker/composables/useDateTextField.ts +7 -6
- package/src/components/DatePicker/composables/useDateValidation.ts +36 -35
- package/src/components/DatePicker/composables/useInputBlurHandler.ts +3 -3
- package/src/components/DatePicker/composables/useManualDateValidation.ts +6 -2
- package/src/components/DiacriticPicker/accessibilite/Accessibility.mdx +76 -8
- package/src/components/HeaderBar/HeaderBar.stories.ts +14 -2
- package/src/components/Logo/accessibilite/Accessibility.mdx +73 -11
- package/src/components/LogoBrandSection/accessibilite/Accessibility.mdx +85 -9
- package/src/components/LunarCalendar/tests/LunarCalendar.spec.ts +3 -1
- package/src/components/LunarCalendar/useLunarCalendarValidation.ts +4 -5
- package/src/components/MonthPicker/tests/MonthPicker.spec.ts +2 -1
- package/src/components/MonthPicker/tests/__snapshots__/MonthPicker.spec.ts.snap +7 -7
- package/src/components/NirField/NirField.stories.ts +4 -0
- package/src/components/NirField/NirField.vue +64 -260
- package/src/components/NirField/accessibilite/Accessibility.mdx +2 -2
- package/src/components/NirField/locales.ts +1 -1
- package/src/components/NirField/tests/NirField.spec.ts +6 -0
- package/src/components/NirField/useNirValidation.ts +271 -0
- package/src/components/PasswordField/PasswordField.stories.ts +4 -4
- package/src/components/PasswordField/PasswordField.vue +18 -24
- package/src/components/PasswordField/tests/PasswordField.spec.ts +6 -3
- package/src/components/PeriodField/PeriodField.stories.ts +4 -4
- package/src/components/PeriodField/PeriodField.vue +57 -57
- package/src/components/PeriodField/__tests__/PeriodField.async.spec.ts +32 -0
- package/src/components/PeriodField/accessibilite/Accessibility.mdx +68 -8
- package/src/components/PeriodField/tests/PeriodField.spec.ts +28 -2
- package/src/components/PhoneField/PhoneField.vue +5 -6
- package/src/components/PhoneField/tests/PhoneField.spec.ts +1 -0
- package/src/components/RangeField/RangeField.vue +6 -0
- package/src/components/SyTextArea/SyTextArea.stories.ts +138 -2
- package/src/components/SyTextArea/SyTextArea.vue +53 -23
- package/src/components/SyTextArea/tests/SyTextArea.spec.ts +126 -3
- package/src/components/SyTextArea/useDefaultValidationRules.ts +74 -0
- package/src/components/Tables/SyServerTable/SyServerTable.mdx +25 -0
- package/src/components/Tables/SyServerTable/SyServerTable.stories.ts +673 -1
- package/src/components/Tables/SyServerTable/SyServerTable.vue +148 -91
- package/src/components/Tables/SyServerTable/tests/SyServerTable.a11y.spec.ts +58 -0
- package/src/components/Tables/SyServerTable/tests/SyServerTable.spec.ts +122 -0
- package/src/components/Tables/SyTable/SyTable.mdx +25 -0
- package/src/components/Tables/SyTable/SyTable.stories.ts +452 -1
- package/src/components/Tables/SyTable/SyTable.vue +130 -56
- package/src/components/Tables/SyTable/tests/SyTable.a11y.spec.ts +57 -0
- package/src/components/Tables/SyTable/tests/SyTable.spec.ts +108 -0
- package/src/components/Tables/common/SyTableFilter.vue +22 -2
- package/src/components/Tables/common/TableHeader.vue +5 -1
- package/src/components/Tables/common/filters/AutocompleteFilter.vue +160 -0
- package/src/components/Tables/common/filters/NumberFilter.vue +1 -1
- package/src/components/Tables/common/filters/SelectFilter.vue +10 -11
- package/src/components/Tables/common/filters/TextFilter.vue +1 -1
- package/src/components/Tables/common/filters/getFilterComponent.ts +8 -1
- package/src/components/Tables/common/filters/locales.ts +0 -1
- package/src/components/Tables/common/filters/tests/AutocompleteFilter.a11y.spec.ts +110 -0
- package/src/components/Tables/common/filters/tests/AutocompleteFilter.spec.ts +203 -0
- package/src/components/Tables/common/filters/tests/SelectFilter.a11y.spec.ts +104 -0
- package/src/components/Tables/common/filters/tests/SelectFilter.spec.ts +152 -16
- package/src/components/Tables/common/tableFilterUtils.ts +3 -0
- package/src/components/Tables/common/tableStyles.scss +48 -4
- package/src/components/Tables/common/tests/filterByRange.spec.ts +2 -1
- package/src/components/Tables/common/types.ts +13 -4
- package/src/components/Tables/common/useClickableTableRow.ts +103 -0
- package/src/components/Tables/common/usePagination.ts +13 -0
- package/src/components/Tables/common/usePinnedColumns.ts +237 -0
- package/src/components/Tables/common/useTableHeaders.ts +3 -3
- package/src/components/Tables/common/useTableRowCheckboxAccessibility.ts +41 -0
- package/src/composables/date/tests/useDatePickerAccessibility.spec.ts +2 -6
- package/src/composables/date/useDatePickerAccessibility.ts +42 -207
- package/src/composables/rules/tests/useFieldValidation.spec.ts +120 -120
- package/src/composables/rules/useFieldValidation.ts +34 -17
- package/src/composables/unifyValidation/tests/useCustomValidation.spec.ts +601 -0
- package/src/composables/unifyValidation/tests/useValidation.spec.ts +2048 -0
- package/src/composables/unifyValidation/tests/useVuetifyValidation.spec.ts +184 -0
- package/src/composables/unifyValidation/useCustomValidation.ts +95 -0
- package/src/composables/unifyValidation/useValidation.ts +190 -0
- package/src/composables/unifyValidation/useVuetifyValidation.ts +54 -0
- package/src/composables/useFormFieldErrorHandling.ts +4 -7
- package/src/composables/validation/tests/useFormValidation.spec.ts +14 -0
- package/src/composables/validation/tests/useValidation.spec.ts +116 -21
- package/src/composables/validation/useFormValidation.ts +20 -13
- package/src/composables/validation/useValidatable.ts +8 -1
- package/src/composables/validation/useValidation.ts +135 -99
- package/src/composantsVuetify/Introduction.mdx +48 -0
- package/src/composantsVuetify/VBtn/VBtn.mdx +72 -0
- package/src/composantsVuetify/VBtn/v-btn.stories.ts +121 -0
- package/src/composantsVuetify/VTooltip/VTooltip.mdx +32 -0
- package/src/composantsVuetify/VTooltip/v-tooltip.stories.ts +95 -0
- package/src/designTokens/tokens/cnam/cnamSemantic.ts +2 -2
- package/src/main.ts +0 -2
- package/src/stories/Components/Components.stories.ts +74 -9
- package/src/stories/Demarrer/Accueil.stories.ts +3 -3
- package/src/stories/GuideDuDev/Amelipro.mdx +15 -0
- package/src/stories/GuideDuDev/Amelipro.stories.ts +209 -0
- package/src/stories/GuideDuDev/vuetifyOptions.mdx +3 -3
- package/dist/SelectFilter-BioGT6Nn.js +0 -136
- package/dist/style.css +0 -1
- package/src/components/DatePicker/Accessibilite.mdx +0 -14
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { defineComponent, nextTick, ref } from 'vue'
|
|
3
|
+
import { mount } from '@vue/test-utils'
|
|
4
|
+
import { useCustomValidation } from '../useCustomValidation'
|
|
5
|
+
import type { ValidationRule } from '@/composables/validation/useValidation'
|
|
6
|
+
|
|
7
|
+
// Helper to run a composable inside a Vue component context
|
|
8
|
+
function withSetup<T>(setup: () => T): { result: T, wrapper: ReturnType<typeof mount> } {
|
|
9
|
+
let result: T
|
|
10
|
+
const TestComponent = defineComponent({
|
|
11
|
+
setup() {
|
|
12
|
+
result = setup()
|
|
13
|
+
return {}
|
|
14
|
+
},
|
|
15
|
+
render: () => null,
|
|
16
|
+
})
|
|
17
|
+
const wrapper = mount(TestComponent)
|
|
18
|
+
return { result: result!, wrapper }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe('useCustomValidation', () => {
|
|
22
|
+
const defaultArgs = () => ({
|
|
23
|
+
modelValue: ref<unknown>(''),
|
|
24
|
+
customRules: ref<ValidationRule[]>([{ type: 'required', options: { message: 'Requis' } }]),
|
|
25
|
+
customWarningRules: ref<ValidationRule[]>([]),
|
|
26
|
+
customSuccessRules: ref<ValidationRule[]>([]),
|
|
27
|
+
errors: ref<string[]>([]),
|
|
28
|
+
warnings: ref<string[]>([]),
|
|
29
|
+
successes: ref<string[]>([]),
|
|
30
|
+
showSuccessMessages: ref(true),
|
|
31
|
+
label: ref('Mon champ'),
|
|
32
|
+
focused: ref(false),
|
|
33
|
+
isValidateOnBlur: ref(true),
|
|
34
|
+
disableErrorHandling: ref(false),
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('returns a validate function', () => {
|
|
38
|
+
const args = defaultArgs()
|
|
39
|
+
const { result } = withSetup(() =>
|
|
40
|
+
useCustomValidation(
|
|
41
|
+
args.modelValue,
|
|
42
|
+
args.customRules,
|
|
43
|
+
args.customWarningRules,
|
|
44
|
+
args.customSuccessRules,
|
|
45
|
+
args.errors,
|
|
46
|
+
args.warnings,
|
|
47
|
+
args.successes,
|
|
48
|
+
args.showSuccessMessages,
|
|
49
|
+
args.label,
|
|
50
|
+
args.focused,
|
|
51
|
+
args.isValidateOnBlur,
|
|
52
|
+
args.disableErrorHandling,
|
|
53
|
+
),
|
|
54
|
+
)
|
|
55
|
+
expect(typeof result.validate).toBe('function')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('validate() sets errors when required rule fails on empty value', async () => {
|
|
59
|
+
const args = defaultArgs()
|
|
60
|
+
args.modelValue.value = ''
|
|
61
|
+
const { result } = withSetup(() =>
|
|
62
|
+
useCustomValidation(
|
|
63
|
+
args.modelValue,
|
|
64
|
+
args.customRules,
|
|
65
|
+
args.customWarningRules,
|
|
66
|
+
args.customSuccessRules,
|
|
67
|
+
args.errors,
|
|
68
|
+
args.warnings,
|
|
69
|
+
args.successes,
|
|
70
|
+
args.showSuccessMessages,
|
|
71
|
+
args.label,
|
|
72
|
+
args.focused,
|
|
73
|
+
args.isValidateOnBlur,
|
|
74
|
+
args.disableErrorHandling,
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
await result.validate()
|
|
78
|
+
expect(args.errors.value).toContain('Requis')
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('validate() clears errors when value is valid', async () => {
|
|
82
|
+
const args = defaultArgs()
|
|
83
|
+
args.modelValue.value = 'some value'
|
|
84
|
+
const { result } = withSetup(() =>
|
|
85
|
+
useCustomValidation(
|
|
86
|
+
args.modelValue,
|
|
87
|
+
args.customRules,
|
|
88
|
+
args.customWarningRules,
|
|
89
|
+
args.customSuccessRules,
|
|
90
|
+
args.errors,
|
|
91
|
+
args.warnings,
|
|
92
|
+
args.successes,
|
|
93
|
+
args.showSuccessMessages,
|
|
94
|
+
args.label,
|
|
95
|
+
args.focused,
|
|
96
|
+
args.isValidateOnBlur,
|
|
97
|
+
args.disableErrorHandling,
|
|
98
|
+
),
|
|
99
|
+
)
|
|
100
|
+
await result.validate()
|
|
101
|
+
expect(args.errors.value).toEqual([])
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('validate() updates warnings from warning rules', async () => {
|
|
105
|
+
const args = defaultArgs()
|
|
106
|
+
args.customRules.value = []
|
|
107
|
+
args.customWarningRules.value = [{
|
|
108
|
+
type: 'minLength',
|
|
109
|
+
options: {
|
|
110
|
+
length: 10,
|
|
111
|
+
warningMessage: 'Trop court',
|
|
112
|
+
isWarning: true,
|
|
113
|
+
},
|
|
114
|
+
}]
|
|
115
|
+
args.modelValue.value = 'abc'
|
|
116
|
+
const { result } = withSetup(() =>
|
|
117
|
+
useCustomValidation(
|
|
118
|
+
args.modelValue,
|
|
119
|
+
args.customRules,
|
|
120
|
+
args.customWarningRules,
|
|
121
|
+
args.customSuccessRules,
|
|
122
|
+
args.errors,
|
|
123
|
+
args.warnings,
|
|
124
|
+
args.successes,
|
|
125
|
+
args.showSuccessMessages,
|
|
126
|
+
args.label,
|
|
127
|
+
args.focused,
|
|
128
|
+
args.isValidateOnBlur,
|
|
129
|
+
args.disableErrorHandling,
|
|
130
|
+
),
|
|
131
|
+
)
|
|
132
|
+
await result.validate()
|
|
133
|
+
expect(args.warnings.value.length).toBeGreaterThan(0)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it('triggers validation when focused changes from true to false', async () => {
|
|
137
|
+
const args = defaultArgs()
|
|
138
|
+
args.focused.value = true
|
|
139
|
+
args.modelValue.value = ''
|
|
140
|
+
const { result } = withSetup(() =>
|
|
141
|
+
useCustomValidation(
|
|
142
|
+
args.modelValue,
|
|
143
|
+
args.customRules,
|
|
144
|
+
args.customWarningRules,
|
|
145
|
+
args.customSuccessRules,
|
|
146
|
+
args.errors,
|
|
147
|
+
args.warnings,
|
|
148
|
+
args.successes,
|
|
149
|
+
args.showSuccessMessages,
|
|
150
|
+
args.label,
|
|
151
|
+
args.focused,
|
|
152
|
+
args.isValidateOnBlur,
|
|
153
|
+
args.disableErrorHandling,
|
|
154
|
+
),
|
|
155
|
+
)
|
|
156
|
+
expect(result).toBeDefined()
|
|
157
|
+
|
|
158
|
+
args.focused.value = false
|
|
159
|
+
await nextTick()
|
|
160
|
+
|
|
161
|
+
expect(args.errors.value).toContain('Requis')
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
it('does not trigger validation on blur when disableErrorHandling is true', async () => {
|
|
165
|
+
const args = defaultArgs()
|
|
166
|
+
args.focused.value = true
|
|
167
|
+
args.modelValue.value = ''
|
|
168
|
+
args.disableErrorHandling.value = true
|
|
169
|
+
withSetup(() =>
|
|
170
|
+
useCustomValidation(
|
|
171
|
+
args.modelValue,
|
|
172
|
+
args.customRules,
|
|
173
|
+
args.customWarningRules,
|
|
174
|
+
args.customSuccessRules,
|
|
175
|
+
args.errors,
|
|
176
|
+
args.warnings,
|
|
177
|
+
args.successes,
|
|
178
|
+
args.showSuccessMessages,
|
|
179
|
+
args.label,
|
|
180
|
+
args.focused,
|
|
181
|
+
args.isValidateOnBlur,
|
|
182
|
+
args.disableErrorHandling,
|
|
183
|
+
),
|
|
184
|
+
)
|
|
185
|
+
args.focused.value = false
|
|
186
|
+
await nextTick()
|
|
187
|
+
expect(args.errors.value).toEqual([])
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
it('triggers validation on modelValue change when isValidateOnBlur is false', async () => {
|
|
191
|
+
const args = defaultArgs()
|
|
192
|
+
args.isValidateOnBlur.value = false
|
|
193
|
+
args.modelValue.value = 'initial'
|
|
194
|
+
withSetup(() =>
|
|
195
|
+
useCustomValidation(
|
|
196
|
+
args.modelValue,
|
|
197
|
+
args.customRules,
|
|
198
|
+
args.customWarningRules,
|
|
199
|
+
args.customSuccessRules,
|
|
200
|
+
args.errors,
|
|
201
|
+
args.warnings,
|
|
202
|
+
args.successes,
|
|
203
|
+
args.showSuccessMessages,
|
|
204
|
+
args.label,
|
|
205
|
+
args.focused,
|
|
206
|
+
args.isValidateOnBlur,
|
|
207
|
+
args.disableErrorHandling,
|
|
208
|
+
),
|
|
209
|
+
)
|
|
210
|
+
// Change to empty value — should trigger error
|
|
211
|
+
args.modelValue.value = ''
|
|
212
|
+
await nextTick()
|
|
213
|
+
expect(args.errors.value).toContain('Requis')
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
it('does not trigger validation on modelValue change when isValidateOnBlur is true', async () => {
|
|
217
|
+
const args = defaultArgs()
|
|
218
|
+
args.isValidateOnBlur.value = true
|
|
219
|
+
args.modelValue.value = 'initial'
|
|
220
|
+
withSetup(() =>
|
|
221
|
+
useCustomValidation(
|
|
222
|
+
args.modelValue,
|
|
223
|
+
args.customRules,
|
|
224
|
+
args.customWarningRules,
|
|
225
|
+
args.customSuccessRules,
|
|
226
|
+
args.errors,
|
|
227
|
+
args.warnings,
|
|
228
|
+
args.successes,
|
|
229
|
+
args.showSuccessMessages,
|
|
230
|
+
args.label,
|
|
231
|
+
args.focused,
|
|
232
|
+
args.isValidateOnBlur,
|
|
233
|
+
args.disableErrorHandling,
|
|
234
|
+
),
|
|
235
|
+
)
|
|
236
|
+
args.modelValue.value = ''
|
|
237
|
+
await nextTick()
|
|
238
|
+
// Errors should NOT be populated since we validate on blur
|
|
239
|
+
expect(args.errors.value).toEqual([])
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
it('does not trigger validation on modelValue change when disableErrorHandling is true', async () => {
|
|
243
|
+
const args = defaultArgs()
|
|
244
|
+
args.isValidateOnBlur.value = false
|
|
245
|
+
args.disableErrorHandling.value = true
|
|
246
|
+
args.modelValue.value = 'initial'
|
|
247
|
+
withSetup(() =>
|
|
248
|
+
useCustomValidation(
|
|
249
|
+
args.modelValue,
|
|
250
|
+
args.customRules,
|
|
251
|
+
args.customWarningRules,
|
|
252
|
+
args.customSuccessRules,
|
|
253
|
+
args.errors,
|
|
254
|
+
args.warnings,
|
|
255
|
+
args.successes,
|
|
256
|
+
args.showSuccessMessages,
|
|
257
|
+
args.label,
|
|
258
|
+
args.focused,
|
|
259
|
+
args.isValidateOnBlur,
|
|
260
|
+
args.disableErrorHandling,
|
|
261
|
+
),
|
|
262
|
+
)
|
|
263
|
+
args.modelValue.value = ''
|
|
264
|
+
await nextTick()
|
|
265
|
+
expect(args.errors.value).toEqual([])
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
it('re-creates the validator when customRules change and auto-validates when dirty', async () => {
|
|
269
|
+
const args = defaultArgs()
|
|
270
|
+
args.modelValue.value = 'hello'
|
|
271
|
+
const { result } = withSetup(() =>
|
|
272
|
+
useCustomValidation(
|
|
273
|
+
args.modelValue,
|
|
274
|
+
args.customRules,
|
|
275
|
+
args.customWarningRules,
|
|
276
|
+
args.customSuccessRules,
|
|
277
|
+
args.errors,
|
|
278
|
+
args.warnings,
|
|
279
|
+
args.successes,
|
|
280
|
+
args.showSuccessMessages,
|
|
281
|
+
args.label,
|
|
282
|
+
args.focused,
|
|
283
|
+
args.isValidateOnBlur,
|
|
284
|
+
args.disableErrorHandling,
|
|
285
|
+
),
|
|
286
|
+
)
|
|
287
|
+
// Make the field dirty by validating first
|
|
288
|
+
await result.validate()
|
|
289
|
+
expect(args.errors.value).toEqual([])
|
|
290
|
+
|
|
291
|
+
// Change rules to minLength that the value doesn't satisfy
|
|
292
|
+
args.customRules.value = [{
|
|
293
|
+
type: 'minLength',
|
|
294
|
+
options: { length: 20, message: 'Trop court' },
|
|
295
|
+
}]
|
|
296
|
+
await nextTick()
|
|
297
|
+
|
|
298
|
+
// Should auto-validate since the field was already dirty (had successes)
|
|
299
|
+
expect(args.errors.value.length).toBeGreaterThan(0)
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
it('re-creates the validator when label changes and auto-validates when dirty', async () => {
|
|
303
|
+
const args = defaultArgs()
|
|
304
|
+
args.modelValue.value = 'valid'
|
|
305
|
+
args.customRules.value = []
|
|
306
|
+
const { result } = withSetup(() =>
|
|
307
|
+
useCustomValidation(
|
|
308
|
+
args.modelValue,
|
|
309
|
+
args.customRules,
|
|
310
|
+
args.customWarningRules,
|
|
311
|
+
args.customSuccessRules,
|
|
312
|
+
args.errors,
|
|
313
|
+
args.warnings,
|
|
314
|
+
args.successes,
|
|
315
|
+
args.showSuccessMessages,
|
|
316
|
+
args.label,
|
|
317
|
+
args.focused,
|
|
318
|
+
args.isValidateOnBlur,
|
|
319
|
+
args.disableErrorHandling,
|
|
320
|
+
),
|
|
321
|
+
)
|
|
322
|
+
await result.validate()
|
|
323
|
+
const successBefore = [...args.successes.value]
|
|
324
|
+
expect(successBefore.some(s => s.includes('Nouveau champ'))).toBe(false)
|
|
325
|
+
|
|
326
|
+
// Change label — validator should be re-created and auto-validate since dirty
|
|
327
|
+
args.label.value = 'Nouveau champ'
|
|
328
|
+
await nextTick()
|
|
329
|
+
|
|
330
|
+
// Should have auto-validated with the new label
|
|
331
|
+
expect(args.successes.value.some(s => s.includes('Nouveau champ'))).toBe(true)
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
it('re-creates the validator when disableErrorHandling changes and auto-validates when dirty', async () => {
|
|
335
|
+
const args = defaultArgs()
|
|
336
|
+
args.modelValue.value = ''
|
|
337
|
+
const { result } = withSetup(() =>
|
|
338
|
+
useCustomValidation(
|
|
339
|
+
args.modelValue,
|
|
340
|
+
args.customRules,
|
|
341
|
+
args.customWarningRules,
|
|
342
|
+
args.customSuccessRules,
|
|
343
|
+
args.errors,
|
|
344
|
+
args.warnings,
|
|
345
|
+
args.successes,
|
|
346
|
+
args.showSuccessMessages,
|
|
347
|
+
args.label,
|
|
348
|
+
args.focused,
|
|
349
|
+
args.isValidateOnBlur,
|
|
350
|
+
args.disableErrorHandling,
|
|
351
|
+
),
|
|
352
|
+
)
|
|
353
|
+
// Validation should report errors
|
|
354
|
+
await result.validate()
|
|
355
|
+
expect(args.errors.value).toContain('Requis')
|
|
356
|
+
|
|
357
|
+
// Toggle disableErrorHandling — validator re-created + auto-validates since dirty
|
|
358
|
+
args.disableErrorHandling.value = true
|
|
359
|
+
await nextTick()
|
|
360
|
+
|
|
361
|
+
// Should auto-clear errors since disableErrorHandling is now true
|
|
362
|
+
expect(args.errors.value).toEqual([])
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
it('re-creates the validator when showSuccessMessages changes and auto-validates when dirty', async () => {
|
|
366
|
+
const args = defaultArgs()
|
|
367
|
+
args.customRules.value = []
|
|
368
|
+
args.modelValue.value = 'valid'
|
|
369
|
+
const { result } = withSetup(() =>
|
|
370
|
+
useCustomValidation(
|
|
371
|
+
args.modelValue,
|
|
372
|
+
args.customRules,
|
|
373
|
+
args.customWarningRules,
|
|
374
|
+
args.customSuccessRules,
|
|
375
|
+
args.errors,
|
|
376
|
+
args.warnings,
|
|
377
|
+
args.successes,
|
|
378
|
+
args.showSuccessMessages,
|
|
379
|
+
args.label,
|
|
380
|
+
args.focused,
|
|
381
|
+
args.isValidateOnBlur,
|
|
382
|
+
args.disableErrorHandling,
|
|
383
|
+
),
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
await result.validate()
|
|
387
|
+
expect(args.successes.value.length).toBeGreaterThan(0)
|
|
388
|
+
|
|
389
|
+
// Disable success messages — validator re-created + auto-validates since dirty
|
|
390
|
+
args.showSuccessMessages.value = false
|
|
391
|
+
await nextTick()
|
|
392
|
+
|
|
393
|
+
// Should auto-clear successes since showSuccessMessages is now false
|
|
394
|
+
expect(args.successes.value).toEqual([])
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
it('validate() returns a result with the correct structure', async () => {
|
|
398
|
+
const args = defaultArgs()
|
|
399
|
+
args.modelValue.value = ''
|
|
400
|
+
const { result } = withSetup(() =>
|
|
401
|
+
useCustomValidation(
|
|
402
|
+
args.modelValue,
|
|
403
|
+
args.customRules,
|
|
404
|
+
args.customWarningRules,
|
|
405
|
+
args.customSuccessRules,
|
|
406
|
+
args.errors,
|
|
407
|
+
args.warnings,
|
|
408
|
+
args.successes,
|
|
409
|
+
args.showSuccessMessages,
|
|
410
|
+
args.label,
|
|
411
|
+
args.focused,
|
|
412
|
+
args.isValidateOnBlur,
|
|
413
|
+
args.disableErrorHandling,
|
|
414
|
+
),
|
|
415
|
+
)
|
|
416
|
+
const validationResult = await result.validate()
|
|
417
|
+
|
|
418
|
+
expect(validationResult).toHaveProperty('hasError')
|
|
419
|
+
expect(validationResult).toHaveProperty('hasWarning')
|
|
420
|
+
expect(validationResult).toHaveProperty('hasSuccess')
|
|
421
|
+
expect(validationResult).toHaveProperty('state')
|
|
422
|
+
expect(validationResult.state).toHaveProperty('errors')
|
|
423
|
+
expect(validationResult.state).toHaveProperty('warnings')
|
|
424
|
+
expect(validationResult.state).toHaveProperty('successes')
|
|
425
|
+
})
|
|
426
|
+
|
|
427
|
+
it('validate() populates successes when value is valid and showSuccessMessages is true', async () => {
|
|
428
|
+
const args = defaultArgs()
|
|
429
|
+
args.modelValue.value = 'valid value'
|
|
430
|
+
const { result } = withSetup(() =>
|
|
431
|
+
useCustomValidation(
|
|
432
|
+
args.modelValue,
|
|
433
|
+
args.customRules,
|
|
434
|
+
args.customWarningRules,
|
|
435
|
+
args.customSuccessRules,
|
|
436
|
+
args.errors,
|
|
437
|
+
args.warnings,
|
|
438
|
+
args.successes,
|
|
439
|
+
args.showSuccessMessages,
|
|
440
|
+
args.label,
|
|
441
|
+
args.focused,
|
|
442
|
+
args.isValidateOnBlur,
|
|
443
|
+
args.disableErrorHandling,
|
|
444
|
+
),
|
|
445
|
+
)
|
|
446
|
+
await result.validate()
|
|
447
|
+
expect(args.successes.value.length).toBeGreaterThan(0)
|
|
448
|
+
expect(args.errors.value).toEqual([])
|
|
449
|
+
})
|
|
450
|
+
|
|
451
|
+
it('validate() does not populate successes when showSuccessMessages is false', async () => {
|
|
452
|
+
const args = defaultArgs()
|
|
453
|
+
args.modelValue.value = 'valid value'
|
|
454
|
+
args.showSuccessMessages.value = false
|
|
455
|
+
const { result } = withSetup(() =>
|
|
456
|
+
useCustomValidation(
|
|
457
|
+
args.modelValue,
|
|
458
|
+
args.customRules,
|
|
459
|
+
args.customWarningRules,
|
|
460
|
+
args.customSuccessRules,
|
|
461
|
+
args.errors,
|
|
462
|
+
args.warnings,
|
|
463
|
+
args.successes,
|
|
464
|
+
args.showSuccessMessages,
|
|
465
|
+
args.label,
|
|
466
|
+
args.focused,
|
|
467
|
+
args.isValidateOnBlur,
|
|
468
|
+
args.disableErrorHandling,
|
|
469
|
+
),
|
|
470
|
+
)
|
|
471
|
+
await result.validate()
|
|
472
|
+
expect(args.successes.value).toEqual([])
|
|
473
|
+
})
|
|
474
|
+
|
|
475
|
+
it('works with undefined customRules', async () => {
|
|
476
|
+
const args = defaultArgs()
|
|
477
|
+
args.modelValue.value = 'test'
|
|
478
|
+
const { result } = withSetup(() =>
|
|
479
|
+
useCustomValidation(
|
|
480
|
+
args.modelValue,
|
|
481
|
+
undefined,
|
|
482
|
+
args.customWarningRules,
|
|
483
|
+
args.customSuccessRules,
|
|
484
|
+
args.errors,
|
|
485
|
+
args.warnings,
|
|
486
|
+
args.successes,
|
|
487
|
+
args.showSuccessMessages,
|
|
488
|
+
args.label,
|
|
489
|
+
args.focused,
|
|
490
|
+
args.isValidateOnBlur,
|
|
491
|
+
args.disableErrorHandling,
|
|
492
|
+
),
|
|
493
|
+
)
|
|
494
|
+
await result.validate()
|
|
495
|
+
expect(args.errors.value).toEqual([])
|
|
496
|
+
})
|
|
497
|
+
|
|
498
|
+
it('does not trigger validation on blur when focused changes to true', async () => {
|
|
499
|
+
const args = defaultArgs()
|
|
500
|
+
args.focused.value = false
|
|
501
|
+
args.modelValue.value = ''
|
|
502
|
+
withSetup(() =>
|
|
503
|
+
useCustomValidation(
|
|
504
|
+
args.modelValue,
|
|
505
|
+
args.customRules,
|
|
506
|
+
args.customWarningRules,
|
|
507
|
+
args.customSuccessRules,
|
|
508
|
+
args.errors,
|
|
509
|
+
args.warnings,
|
|
510
|
+
args.successes,
|
|
511
|
+
args.showSuccessMessages,
|
|
512
|
+
args.label,
|
|
513
|
+
args.focused,
|
|
514
|
+
args.isValidateOnBlur,
|
|
515
|
+
args.disableErrorHandling,
|
|
516
|
+
),
|
|
517
|
+
)
|
|
518
|
+
args.focused.value = true
|
|
519
|
+
await nextTick()
|
|
520
|
+
// Should not trigger validation when gaining focus
|
|
521
|
+
expect(args.errors.value).toEqual([])
|
|
522
|
+
})
|
|
523
|
+
|
|
524
|
+
it('does not auto-validate on rule change when field is not dirty', async () => {
|
|
525
|
+
const args = defaultArgs()
|
|
526
|
+
args.modelValue.value = ''
|
|
527
|
+
withSetup(() =>
|
|
528
|
+
useCustomValidation(
|
|
529
|
+
args.modelValue,
|
|
530
|
+
args.customRules,
|
|
531
|
+
args.customWarningRules,
|
|
532
|
+
args.customSuccessRules,
|
|
533
|
+
args.errors,
|
|
534
|
+
args.warnings,
|
|
535
|
+
args.successes,
|
|
536
|
+
args.showSuccessMessages,
|
|
537
|
+
args.label,
|
|
538
|
+
args.focused,
|
|
539
|
+
args.isValidateOnBlur,
|
|
540
|
+
args.disableErrorHandling,
|
|
541
|
+
),
|
|
542
|
+
)
|
|
543
|
+
// Don't validate first — field is pristine
|
|
544
|
+
expect(args.errors.value).toEqual([])
|
|
545
|
+
|
|
546
|
+
// Change rules — should NOT trigger validation since field was never validated
|
|
547
|
+
args.customRules.value = [{
|
|
548
|
+
type: 'minLength',
|
|
549
|
+
options: { length: 20, message: 'Trop court' },
|
|
550
|
+
}]
|
|
551
|
+
await nextTick()
|
|
552
|
+
|
|
553
|
+
expect(args.errors.value).toEqual([])
|
|
554
|
+
})
|
|
555
|
+
|
|
556
|
+
it('validate() returns hasError true when there are errors', async () => {
|
|
557
|
+
const args = defaultArgs()
|
|
558
|
+
args.modelValue.value = ''
|
|
559
|
+
const { result } = withSetup(() =>
|
|
560
|
+
useCustomValidation(
|
|
561
|
+
args.modelValue,
|
|
562
|
+
args.customRules,
|
|
563
|
+
args.customWarningRules,
|
|
564
|
+
args.customSuccessRules,
|
|
565
|
+
args.errors,
|
|
566
|
+
args.warnings,
|
|
567
|
+
args.successes,
|
|
568
|
+
args.showSuccessMessages,
|
|
569
|
+
args.label,
|
|
570
|
+
args.focused,
|
|
571
|
+
args.isValidateOnBlur,
|
|
572
|
+
args.disableErrorHandling,
|
|
573
|
+
),
|
|
574
|
+
)
|
|
575
|
+
const validationResult = await result.validate()
|
|
576
|
+
expect(validationResult.hasError).toBe(true)
|
|
577
|
+
})
|
|
578
|
+
|
|
579
|
+
it('validate() returns hasError false when there are no errors', async () => {
|
|
580
|
+
const args = defaultArgs()
|
|
581
|
+
args.modelValue.value = 'valid'
|
|
582
|
+
const { result } = withSetup(() =>
|
|
583
|
+
useCustomValidation(
|
|
584
|
+
args.modelValue,
|
|
585
|
+
args.customRules,
|
|
586
|
+
args.customWarningRules,
|
|
587
|
+
args.customSuccessRules,
|
|
588
|
+
args.errors,
|
|
589
|
+
args.warnings,
|
|
590
|
+
args.successes,
|
|
591
|
+
args.showSuccessMessages,
|
|
592
|
+
args.label,
|
|
593
|
+
args.focused,
|
|
594
|
+
args.isValidateOnBlur,
|
|
595
|
+
args.disableErrorHandling,
|
|
596
|
+
),
|
|
597
|
+
)
|
|
598
|
+
const validationResult = await result.validate()
|
|
599
|
+
expect(validationResult.hasError).toBe(false)
|
|
600
|
+
})
|
|
601
|
+
})
|