@cnamts/synapse 1.1.0 → 1.1.1
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-DXd4szWO.js → AutocompleteFilter-CGF33skz.js} +1 -1
- package/dist/{DateFilter-BD59Kgwf.js → DateFilter-D7-MsKtx.js} +1 -1
- package/dist/{NumberFilter-BSMZE7uw.js → NumberFilter-bjQPPfsj.js} +1 -1
- package/dist/{PeriodFilter-keUdSSk0.js → PeriodFilter-B3wJpK8-.js} +1 -1
- package/dist/{SelectFilter-Dhvvwazl.js → SelectFilter-BN6DbKAV.js} +1 -1
- package/dist/{TextFilter-CU8FpXz0.js → TextFilter-BffP0J2f.js} +1 -1
- package/dist/{apLightTheme2026-DbS7BPUf.js → apLightTheme2026-C4ygwMHC.js} +11 -11
- package/dist/components/Amelipro/AmeliproAutoCompleteField/AmeliproAutoCompleteField.d.ts +6 -6
- package/dist/components/Amelipro/AmeliproSelect/AmeliproSelect.d.ts +6 -6
- package/dist/components/Amelipro/AmeliproTabs/AmeliproTabs.d.ts +6 -6
- package/dist/components/Captcha/Captcha.d.ts +27 -16
- package/dist/components/Captcha/CaptchaForm.d.ts +29 -3
- package/dist/components/Captcha/types.d.ts +14 -0
- package/dist/components/Captcha/useCaptchaValidation.d.ts +37 -0
- package/dist/components/Customs/Selects/SelectBtnField/SelectBtnField.d.ts +33 -13
- package/dist/components/Customs/Selects/SelectBtnField/composables/useSelectBtnFieldValidation.d.ts +23 -0
- package/dist/components/Customs/Selects/SyAutocomplete/composables/useSyAutocompleteValidation.d.ts +2 -2
- package/dist/components/Customs/Selects/SySelect/composables/useSySelectValidation.d.ts +2 -2
- package/dist/components/Customs/SyCheckBoxGroup/SyCheckBoxGroup.d.ts +17 -48
- package/dist/components/Customs/SyCheckBoxGroup/composables/useSyCheckBoxGroupValidation.d.ts +29 -0
- package/dist/components/Customs/SyCheckBoxGroup/types.d.ts +46 -0
- package/dist/components/Customs/SyCheckbox/SyCheckbox.d.ts +16 -51
- package/dist/components/Customs/SyCheckbox/composables/useSyCheckboxValidation.d.ts +27 -0
- package/dist/components/Customs/SyCheckbox/types.d.ts +49 -0
- package/dist/components/Customs/SyTextField/FieldState.d.ts +5 -0
- package/dist/components/Customs/SyTextField/useSyTextFieldValidation.d.ts +3 -3
- package/dist/components/DialogBox/DialogBox.d.ts +2 -0
- package/dist/components/DialogBox/locales.d.ts +1 -0
- package/dist/components/FilterSideBar/FilterSideBar.d.ts +4 -0
- package/dist/components/LunarCalendar/LunarCalendar.d.ts +43 -14
- package/dist/components/LunarCalendar/types.d.ts +35 -0
- package/dist/components/LunarCalendar/useLunarCalendarValidation.d.ts +11 -12
- package/dist/components/MonthPicker/MonthPicker.d.ts +72 -1747
- package/dist/components/MonthPicker/MonthPickerText/MonthPickerInput.d.ts +21 -1733
- package/dist/components/MonthPicker/MonthPickerText/useTextField.d.ts +5 -0
- package/dist/components/MonthPicker/locales.d.ts +1 -0
- package/dist/components/MonthPicker/types.d.ts +11 -0
- package/dist/components/MonthPicker/useMonthPickerValidation.d.ts +37 -24
- package/dist/components/NirField/NirField.d.ts +6 -4
- package/dist/components/NirField/useNirValidation.d.ts +7 -5
- package/dist/components/PageContainer/PageContainer.d.ts +8 -0
- package/dist/components/PasswordField/PasswordField.d.ts +2 -2
- package/dist/components/PasswordField/usePasswordFieldValidation.d.ts +2 -2
- package/dist/components/PhoneField/PhoneField.d.ts +960 -1938
- package/dist/components/PhoneField/indicatifs.d.ts +715 -8
- package/dist/components/PhoneField/locales.d.ts +7 -0
- package/dist/components/PhoneField/types.d.ts +29 -0
- package/dist/components/PhoneField/usePhoneFieldValidation.d.ts +45 -0
- package/dist/components/PhoneField/usePhoneIndicatifs.d.ts +947 -0
- package/dist/components/SyTextArea/composables/useSyTextAreaValidation.d.ts +2 -2
- package/dist/composables/unifyValidation/documentationValidationProps.d.ts +1 -1
- package/dist/composables/unifyValidation/useValidation.d.ts +4 -5
- package/dist/design-system-v3.js +2 -2
- package/dist/designTokens/tokens/amelipro/apLightTheme.d.ts +10 -10
- package/dist/designTokens/tokens/baseTokens.d.ts +18 -18
- package/dist/designTokens/tokens/cnam/cnamLightTheme.d.ts +10 -10
- package/dist/designTokens/tokens/pa/paLightTheme.d.ts +10 -10
- package/dist/designTokens/tokens/semanticTokens.d.ts +14 -14
- package/dist/{main-D8ryUoS5.js → main-C4wAktOs.js} +13718 -12991
- package/dist/synapse.css +1 -1
- package/dist/vuetifyConfig.js +1 -1
- package/package.json +7 -7
- package/src/assets/compat/_legacy-tokens.scss +91 -0
- package/src/assets/overrides/_utilities.scss +23 -0
- package/src/components/Accordion/Accordion.stories.ts +121 -1
- package/src/components/BackBtn/BackBtn.mdx +1 -1
- package/src/components/BackToTopBtn/BackToTopBtn.mdx +0 -1
- package/src/components/Captcha/Captcha.stories.ts +134 -31
- package/src/components/Captcha/Captcha.vue +95 -28
- package/src/components/Captcha/CaptchaForm.vue +51 -22
- package/src/components/Captcha/tests/Captcha.focus.spec.ts +214 -0
- package/src/components/Captcha/tests/Captcha.spec.ts +233 -24
- package/src/components/Captcha/tests/CaptchaForm.spec.ts +82 -0
- package/src/components/Captcha/tests/__snapshots__/Captcha.spec.ts.snap +16 -42
- package/src/components/Captcha/types.ts +15 -0
- package/src/components/Captcha/useCaptchaValidation.ts +87 -0
- package/src/components/Captcha/validation/validation.stories.ts +1194 -0
- package/src/components/ChipList/ChipList.mdx +0 -1
- package/src/components/CollapsibleList/CollapsibleList.mdx +0 -1
- package/src/components/CookieBanner/CookieBanner.mdx +0 -1
- package/src/components/CopyBtn/CopyBtn.mdx +0 -1
- package/src/components/Customs/Selects/SelectBtnField/SelectBtnField.stories.ts +123 -439
- package/src/components/Customs/Selects/SelectBtnField/SelectBtnField.vue +147 -41
- package/src/components/Customs/Selects/SelectBtnField/Validation/Validation.stories.ts +600 -0
- package/src/components/Customs/Selects/SelectBtnField/composables/useSelectBtnFieldValidation.ts +87 -0
- package/src/components/Customs/Selects/SelectBtnField/tests/SelectBtnField.spec.ts +402 -33
- package/src/components/Customs/Selects/SelectBtnField/tests/__snapshots__/SelectBtnField.spec.ts.snap +52 -38
- package/src/components/Customs/SyCheckBoxGroup/SyCheckBoxGroup.stories.ts +342 -162
- package/src/components/Customs/SyCheckBoxGroup/SyCheckBoxGroup.vue +77 -129
- package/src/components/Customs/SyCheckBoxGroup/Validation/Validation.stories.ts +1008 -0
- package/src/components/Customs/SyCheckBoxGroup/composables/useSyCheckBoxGroupValidation.ts +107 -0
- package/src/components/Customs/SyCheckBoxGroup/tests/SyCheckBoxGroup.spec.ts +180 -7
- package/src/components/Customs/SyCheckBoxGroup/types.ts +49 -0
- package/src/components/Customs/SyCheckbox/SyCheckbox.stories.ts +41 -161
- package/src/components/Customs/SyCheckbox/SyCheckbox.vue +71 -148
- package/src/components/Customs/SyCheckbox/Validation/Validation.stories.ts +654 -0
- package/src/components/Customs/SyCheckbox/composables/useSyCheckboxValidation.ts +105 -0
- package/src/components/Customs/SyCheckbox/tests/SyCheckbox.spec.ts +106 -0
- package/src/components/Customs/SyCheckbox/tests/useSyCheckboxValidation.spec.ts +98 -0
- package/src/components/Customs/SyCheckbox/types.ts +51 -0
- package/src/components/Customs/SyTextField/FieldState.vue +50 -0
- package/src/components/Customs/SyTextField/SyTextField.vue +12 -9
- package/src/components/Customs/SyTextField/useSyTextFieldValidation.ts +2 -11
- package/src/components/DataList/DataList.mdx +0 -1
- package/src/components/DataListGroup/DataListGroup.mdx +0 -1
- package/src/components/DiacriticPicker/DiacriticPicker.mdx +0 -1
- package/src/components/DialogBox/DialogBox.mdx +0 -1
- package/src/components/DialogBox/DialogBox.stories.ts +399 -4
- package/src/components/DialogBox/DialogBox.vue +20 -0
- package/src/components/DialogBox/locales.ts +1 -0
- package/src/components/DialogBox/tests/DialogBox.spec.ts +73 -0
- package/src/components/DialogBox/tests/DialogBox.visual.cy.ts +24 -0
- package/src/components/ErrorPage/ErrorPage.mdx +1 -1
- package/src/components/ExternalLinks/ExternalLinks.mdx +0 -1
- package/src/components/FileList/FileList.mdx +0 -1
- package/src/components/FilterInline/FilterInline.mdx +0 -1
- package/src/components/FilterSideBar/FilterSideBar.mdx +8 -1
- package/src/components/FilterSideBar/FilterSideBar.stories.ts +133 -1
- package/src/components/FilterSideBar/FilterSideBar.vue +19 -2
- package/src/components/FilterSideBar/tests/FilterSideBar.spec.ts +55 -0
- package/src/components/FooterBar/FooterBar.mdx +0 -1
- package/src/components/FranceConnectBtn/FranceConnectBtn.mdx +0 -1
- package/src/components/HeaderBar/HeaderBar.mdx +0 -1
- package/src/components/HeaderLoading/HeaderLoading.mdx +0 -1
- package/src/components/LangBtn/LangBtn.mdx +0 -1
- package/src/components/Logo/Logo.mdx +1 -1
- package/src/components/LunarCalendar/LunarCalendar.mdx +6 -9
- package/src/components/LunarCalendar/LunarCalendar.stories.ts +243 -46
- package/src/components/LunarCalendar/LunarCalendar.vue +61 -26
- package/src/components/LunarCalendar/Validation/Validation.stories.ts +717 -0
- package/src/components/LunarCalendar/tests/LunarCalendar.a11y.spec.ts +1 -1
- package/src/components/LunarCalendar/tests/LunarCalendar.spec.ts +197 -6
- package/src/components/LunarCalendar/tests/useLunarCalendarValidation.spec.ts +287 -0
- package/src/components/LunarCalendar/types.ts +39 -0
- package/src/components/LunarCalendar/useLunarCalendarValidation.ts +115 -39
- package/src/components/MonthPicker/MonthPicker.stories.ts +38 -281
- package/src/components/MonthPicker/MonthPicker.vue +66 -17
- package/src/components/MonthPicker/MonthPickerText/MonthPickerInput.vue +44 -20
- package/src/components/MonthPicker/MonthPickerText/useTextField.ts +5 -0
- package/src/components/MonthPicker/Validation/Validation.stories.ts +1117 -0
- package/src/components/MonthPicker/locales.ts +1 -0
- package/src/components/MonthPicker/tests/MonthPicker.spec.ts +353 -2
- package/src/components/MonthPicker/tests/__snapshots__/MonthPicker.spec.ts.snap +12 -8
- package/src/components/MonthPicker/types.ts +16 -0
- package/src/components/MonthPicker/useMonthPickerValidation.ts +64 -27
- package/src/components/NirField/NirField.mdx +120 -66
- package/src/components/NirField/NirField.stories.ts +216 -0
- package/src/components/NirField/useNirValidation.ts +16 -17
- package/src/components/NotFoundPage/tests/__snapshots__/NotFoundPage.spec.ts.snap +263 -245
- package/src/components/NotificationBar/NotificationBar.mdx +0 -1
- package/src/components/PageContainer/PageContainer.mdx +0 -1
- package/src/components/PageContainer/PageContainer.stories.ts +170 -2
- package/src/components/PageContainer/PageContainer.vue +63 -8
- package/src/components/PageContainer/tests/__snapshots__/PageContainer.spec.ts.snap +19 -11
- package/src/components/PaginatedTable/PaginatedTable.mdx +0 -1
- package/src/components/PeriodField/PeriodField.mdx +0 -1
- package/src/components/PhoneField/PhoneField.mdx +2 -3
- package/src/components/PhoneField/PhoneField.stories.ts +227 -410
- package/src/components/PhoneField/PhoneField.vue +204 -438
- package/src/components/PhoneField/indicatifs.ts +1 -1
- package/src/components/PhoneField/locales.ts +7 -0
- package/src/components/PhoneField/tests/PhoneField.a11y.spec.ts +0 -1
- package/src/components/PhoneField/tests/PhoneField.spec.ts +517 -220
- package/src/components/PhoneField/types.ts +30 -0
- package/src/components/PhoneField/usePhoneFieldValidation.ts +119 -0
- package/src/components/PhoneField/usePhoneIndicatifs.ts +89 -0
- package/src/components/PhoneField/validation/validation.stories.ts +717 -0
- package/src/components/RangeField/RangeField.mdx +0 -1
- package/src/components/RatingPicker/RatingPicker.mdx +0 -1
- package/src/components/SocialMediaLinks/SocialMediaLinks.mdx +0 -1
- package/src/components/StatusPage/StatusPage.vue +1 -0
- package/src/components/StatusPage/tests/__snapshots__/StatusPage.spec.ts.snap +248 -230
- package/src/components/SubHeader/SubHeader.mdx +5 -6
- package/src/components/Tables/common/tests/SyTableFilter.spec.ts +11 -12
- package/src/components/UploadWorkflow/UploadWorkflow.mdx +0 -1
- package/src/components/UserMenuBtn/UserMenuBtn.mdx +0 -1
- package/src/components/UserMenuBtn/UserMenuBtn.stories.ts +177 -0
- package/src/composables/unifyValidation/documentationValidationProps.ts +1 -1
- package/src/composables/unifyValidation/tests/useValidation.spec.ts +13 -1
- package/src/composables/unifyValidation/useValidation.ts +37 -33
- package/src/composantsVuetify/VCard/VCard.mdx +4 -0
- package/src/composantsVuetify/VCard/v-card.stories.ts +93 -1
- package/src/composantsVuetify/VCarousel/VCarousel.mdx +74 -0
- package/src/composantsVuetify/VCarousel/v-carousel.stories.ts +531 -0
- package/src/composantsVuetify/VNavigationDrawer/VNavgationDrawer.mdx +53 -0
- package/src/composantsVuetify/VNavigationDrawer/v-navigation-drawer.stories.ts +310 -0
- package/src/composantsVuetify/VSlideGroup/VSlideGroup.mdx +105 -0
- package/src/composantsVuetify/VSlideGroup/v-slide-group.stories.ts +463 -0
- package/src/designTokens/tokens/baseColors.ts +1 -1
- package/src/designTokens/tokens/baseTokens.ts +18 -18
- package/src/stories/Components/Components.stories.ts +34 -1
- package/src/stories/Demarrer/Releases.stories.ts +16 -2
- package/src/stories/DesignTokens/Arrondis.mdx +1 -1
- package/src/stories/DesignTokens/Correspondances.mdx +219 -0
- package/src/stories/DesignTokens/UtiliserLesTokens.mdx +235 -0
- package/src/stories/DesignTokens/colors.stories.ts +569 -569
- package/src/stories/GuideDuDev/Amelipro.stories.ts +335 -267
- package/dist/components/LunarCalendar/useLunarCalendarRules.d.ts +0 -5
- package/dist/components/PhoneField/tests/types.d.ts +0 -18
- package/src/components/LunarCalendar/tests/useLunarCalendarRules.spec.ts +0 -184
- package/src/components/LunarCalendar/useLunarCalendarRules.ts +0 -96
- package/src/components/PhoneField/tests/types.d.ts +0 -19
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ValidationRule } from '../../composables/validation/useValidation';
|
|
2
|
-
import { ComputedRef, MaybeRefOrGetter } from 'vue';
|
|
3
|
-
export declare function useLunarCalendarRules(successMessage: MaybeRefOrGetter<string | undefined>, required: MaybeRefOrGetter<boolean | undefined>, minYear: MaybeRefOrGetter<number | undefined>, maxYear: MaybeRefOrGetter<number | undefined>): {
|
|
4
|
-
rules: ComputedRef<ValidationRule[]>;
|
|
5
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ComponentPublicInstance } from 'vue';
|
|
2
|
-
declare module '@vue/test-utils' {
|
|
3
|
-
interface VueWrapper {
|
|
4
|
-
vm: ComponentPublicInstance & {
|
|
5
|
-
dialCode: {
|
|
6
|
-
code: string
|
|
7
|
-
country: string
|
|
8
|
-
abbreviation: string
|
|
9
|
-
phoneLength: number
|
|
10
|
-
mask: string
|
|
11
|
-
} | null
|
|
12
|
-
errors: string[]
|
|
13
|
-
hasError: boolean
|
|
14
|
-
phoneMask: string
|
|
15
|
-
validateOnSubmit: () => Promise<boolean>
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import { ref } from 'vue'
|
|
3
|
-
import { useLunarCalendarRules } from '../useLunarCalendarRules'
|
|
4
|
-
|
|
5
|
-
function getRules(opts: {
|
|
6
|
-
successMessage?: string
|
|
7
|
-
required?: boolean
|
|
8
|
-
minYear?: number
|
|
9
|
-
maxYear?: number
|
|
10
|
-
}) {
|
|
11
|
-
const { rules } = useLunarCalendarRules(
|
|
12
|
-
ref(opts.successMessage),
|
|
13
|
-
ref(opts.required),
|
|
14
|
-
ref(opts.minYear),
|
|
15
|
-
ref(opts.maxYear),
|
|
16
|
-
)
|
|
17
|
-
return rules.value
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type CustomRule = { type: 'custom', options: { validate: (v: string) => boolean, message: string } }
|
|
21
|
-
|
|
22
|
-
describe('useLunarCalendarRules', () => {
|
|
23
|
-
describe('règle required', () => {
|
|
24
|
-
it('n\'ajoute pas de règle required si required est false', () => {
|
|
25
|
-
const rules = getRules({ required: false })
|
|
26
|
-
expect(rules.some(r => r.type === 'required')).toBe(false)
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('ajoute une règle required si required est true', () => {
|
|
30
|
-
const rules = getRules({ required: true })
|
|
31
|
-
expect(rules.some(r => r.type === 'required')).toBe(true)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('la règle required contient le bon message', () => {
|
|
35
|
-
const rules = getRules({ required: true })
|
|
36
|
-
const req = rules.find(r => r.type === 'required')
|
|
37
|
-
expect(req?.options.message).toBe('Ce champ est requis.')
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('la règle required contient le successMessage si fourni', () => {
|
|
41
|
-
const rules = getRules({ required: true, successMessage: 'Bravo' })
|
|
42
|
-
const req = rules.find(r => r.type === 'required')
|
|
43
|
-
expect(req?.options.successMessage).toBe('Bravo')
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
describe('règle format DD/MM/YYYY', () => {
|
|
48
|
-
it('valide une date au format DD/MM/YYYY', () => {
|
|
49
|
-
const rules = getRules({})
|
|
50
|
-
const fmt = rules.find(r => r.type === 'custom') as CustomRule
|
|
51
|
-
expect(fmt.options.validate('25/12/2000')).toBe(true)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it('rejette une date sans slashs', () => {
|
|
55
|
-
const rules = getRules({})
|
|
56
|
-
const fmt = rules.find(r => r.type === 'custom') as CustomRule
|
|
57
|
-
expect(fmt.options.validate('25122000')).toBe(false)
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it('rejette une date incomplète', () => {
|
|
61
|
-
const rules = getRules({})
|
|
62
|
-
const fmt = rules.find(r => r.type === 'custom') as CustomRule
|
|
63
|
-
expect(fmt.options.validate('25/12/200')).toBe(false)
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
it('rejette une chaîne vide', () => {
|
|
67
|
-
const rules = getRules({})
|
|
68
|
-
const fmt = rules.find(r => r.type === 'custom') as CustomRule
|
|
69
|
-
expect(fmt.options.validate('')).toBe(false)
|
|
70
|
-
})
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
describe('règle minYear seulement', () => {
|
|
74
|
-
it('retourne true si le format est invalide (year null)', () => {
|
|
75
|
-
const rules = getRules({ minYear: 2000 })
|
|
76
|
-
const minRule = rules.filter(r => r.type === 'custom')[1] as CustomRule
|
|
77
|
-
expect(minRule.options.validate('invalid')).toBe(true)
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
it('retourne true si l\'année >= minYear', () => {
|
|
81
|
-
const rules = getRules({ minYear: 2000 })
|
|
82
|
-
const minRule = rules.filter(r => r.type === 'custom')[1] as CustomRule
|
|
83
|
-
expect(minRule.options.validate('25/12/2000')).toBe(true)
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
it('retourne false si l\'année < minYear', () => {
|
|
87
|
-
const rules = getRules({ minYear: 2000 })
|
|
88
|
-
const minRule = rules.filter(r => r.type === 'custom')[1] as CustomRule
|
|
89
|
-
expect(minRule.options.validate('25/12/1999')).toBe(false)
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
it('contient le bon message', () => {
|
|
93
|
-
const rules = getRules({ minYear: 2000 })
|
|
94
|
-
const minRule = rules.filter(r => r.type === 'custom')[1] as CustomRule
|
|
95
|
-
expect(minRule.options.message).toBe('L\'année doit être supérieure ou égale à 2000.')
|
|
96
|
-
})
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
describe('règle maxYear seulement', () => {
|
|
100
|
-
it('retourne true si le format est invalide (year null)', () => {
|
|
101
|
-
const rules = getRules({ maxYear: 2020 })
|
|
102
|
-
const maxRule = rules.filter(r => r.type === 'custom')[1] as CustomRule
|
|
103
|
-
expect(maxRule.options.validate('invalid')).toBe(true)
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
it('retourne true si l\'année <= maxYear', () => {
|
|
107
|
-
const rules = getRules({ maxYear: 2020 })
|
|
108
|
-
const maxRule = rules.filter(r => r.type === 'custom')[1] as CustomRule
|
|
109
|
-
expect(maxRule.options.validate('25/12/2020')).toBe(true)
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
it('retourne false si l\'année > maxYear', () => {
|
|
113
|
-
const rules = getRules({ maxYear: 2020 })
|
|
114
|
-
const maxRule = rules.filter(r => r.type === 'custom')[1] as CustomRule
|
|
115
|
-
expect(maxRule.options.validate('25/12/2021')).toBe(false)
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
it('contient le bon message', () => {
|
|
119
|
-
const rules = getRules({ maxYear: 2020 })
|
|
120
|
-
const maxRule = rules.filter(r => r.type === 'custom')[1] as CustomRule
|
|
121
|
-
expect(maxRule.options.message).toBe('L\'année doit être inférieure ou égale à 2020.')
|
|
122
|
-
})
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
describe('règle minYear ET maxYear', () => {
|
|
126
|
-
it('retourne true si le format est invalide (year null)', () => {
|
|
127
|
-
const rules = getRules({ minYear: 2000, maxYear: 2020 })
|
|
128
|
-
const rangeRule = rules.filter(r => r.type === 'custom')[1] as CustomRule
|
|
129
|
-
expect(rangeRule.options.validate('invalid')).toBe(true)
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
it('retourne true si l\'année est dans la plage', () => {
|
|
133
|
-
const rules = getRules({ minYear: 2000, maxYear: 2020 })
|
|
134
|
-
const rangeRule = rules.filter(r => r.type === 'custom')[1] as CustomRule
|
|
135
|
-
expect(rangeRule.options.validate('25/12/2010')).toBe(true)
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
it('retourne false si l\'année est avant minYear', () => {
|
|
139
|
-
const rules = getRules({ minYear: 2000, maxYear: 2020 })
|
|
140
|
-
const rangeRule = rules.filter(r => r.type === 'custom')[1] as CustomRule
|
|
141
|
-
expect(rangeRule.options.validate('25/12/1999')).toBe(false)
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
it('retourne false si l\'année est après maxYear', () => {
|
|
145
|
-
const rules = getRules({ minYear: 2000, maxYear: 2020 })
|
|
146
|
-
const rangeRule = rules.filter(r => r.type === 'custom')[1] as CustomRule
|
|
147
|
-
expect(rangeRule.options.validate('25/12/2021')).toBe(false)
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
it('contient le bon message', () => {
|
|
151
|
-
const rules = getRules({ minYear: 2000, maxYear: 2020 })
|
|
152
|
-
const rangeRule = rules.filter(r => r.type === 'custom')[1] as CustomRule
|
|
153
|
-
expect(rangeRule.options.message).toBe('L\'année doit être comprise entre 2000 et 2020.')
|
|
154
|
-
})
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
describe('getYearFromModel (via les règles)', () => {
|
|
158
|
-
it('retourne null si le modèle n\'a pas 3 parties', () => {
|
|
159
|
-
const rules = getRules({ minYear: 2000 })
|
|
160
|
-
const minRule = rules.filter(r => r.type === 'custom')[1] as CustomRule
|
|
161
|
-
expect(minRule.options.validate('25/12')).toBe(true)
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
it('retourne null si l\'année n\'a pas 4 chiffres', () => {
|
|
165
|
-
const rules = getRules({ minYear: 2000 })
|
|
166
|
-
const minRule = rules.filter(r => r.type === 'custom')[1] as CustomRule
|
|
167
|
-
expect(minRule.options.validate('25/12/200')).toBe(true)
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
it('retourne null si l\'année n\'est pas un nombre', () => {
|
|
171
|
-
const rules = getRules({ minYear: 2000 })
|
|
172
|
-
const minRule = rules.filter(r => r.type === 'custom')[1] as CustomRule
|
|
173
|
-
expect(minRule.options.validate('25/12/abcd')).toBe(true)
|
|
174
|
-
})
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
describe('aucune règle year si minYear et maxYear sont undefined', () => {
|
|
178
|
-
it('ne génère que 1 règle custom (format) sans min/max', () => {
|
|
179
|
-
const rules = getRules({})
|
|
180
|
-
const customRules = rules.filter(r => r.type === 'custom')
|
|
181
|
-
expect(customRules.length).toBe(1)
|
|
182
|
-
})
|
|
183
|
-
})
|
|
184
|
-
})
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import type { ValidationRule } from '@/composables/validation/useValidation'
|
|
2
|
-
import { computed, toValue, type ComputedRef, type MaybeRefOrGetter } from 'vue'
|
|
3
|
-
|
|
4
|
-
export function useLunarCalendarRules(
|
|
5
|
-
successMessage: MaybeRefOrGetter<string | undefined>,
|
|
6
|
-
required: MaybeRefOrGetter<boolean | undefined>,
|
|
7
|
-
minYear: MaybeRefOrGetter<number | undefined>,
|
|
8
|
-
maxYear: MaybeRefOrGetter<number | undefined>,
|
|
9
|
-
): { rules: ComputedRef<ValidationRule[]> } {
|
|
10
|
-
const rules = computed(() => {
|
|
11
|
-
const rules: ValidationRule[] = []
|
|
12
|
-
if (toValue(required)) {
|
|
13
|
-
const requiredRule: ValidationRule = {
|
|
14
|
-
type: 'required',
|
|
15
|
-
options: {
|
|
16
|
-
message: 'Ce champ est requis.',
|
|
17
|
-
successMessage: toValue(successMessage),
|
|
18
|
-
},
|
|
19
|
-
}
|
|
20
|
-
rules.push(requiredRule)
|
|
21
|
-
}
|
|
22
|
-
rules.push({
|
|
23
|
-
type: 'custom',
|
|
24
|
-
options: {
|
|
25
|
-
validate: (value: string) => {
|
|
26
|
-
// Validate format DD/MM/YYYY
|
|
27
|
-
const regex = /^\d{2}\/\d{2}\/\d{4}$/
|
|
28
|
-
return regex.test(value)
|
|
29
|
-
},
|
|
30
|
-
message: 'La date est invalide.',
|
|
31
|
-
successMessage: toValue(successMessage),
|
|
32
|
-
},
|
|
33
|
-
})
|
|
34
|
-
if (toValue(minYear) && toValue(maxYear)) {
|
|
35
|
-
const rule: ValidationRule = {
|
|
36
|
-
type: 'custom',
|
|
37
|
-
options: {
|
|
38
|
-
validate: (value: string) => {
|
|
39
|
-
const year = getYearFromModel(value)
|
|
40
|
-
if (year === null) {
|
|
41
|
-
return true
|
|
42
|
-
}
|
|
43
|
-
return year >= toValue(minYear as number) && year <= toValue(maxYear as number)
|
|
44
|
-
},
|
|
45
|
-
message: `L'année doit être comprise entre ${toValue(minYear)} et ${toValue(maxYear)}.`,
|
|
46
|
-
successMessage: toValue(successMessage),
|
|
47
|
-
},
|
|
48
|
-
}
|
|
49
|
-
rules.push(rule)
|
|
50
|
-
}
|
|
51
|
-
else if (toValue(minYear)) {
|
|
52
|
-
const rule: ValidationRule = {
|
|
53
|
-
type: 'custom',
|
|
54
|
-
options: {
|
|
55
|
-
validate: (value: string) => {
|
|
56
|
-
const year = getYearFromModel(value)
|
|
57
|
-
if (year === null) {
|
|
58
|
-
return true
|
|
59
|
-
}
|
|
60
|
-
return year >= toValue(minYear as number)
|
|
61
|
-
},
|
|
62
|
-
message: `L'année doit être supérieure ou égale à ${toValue(minYear)}.`,
|
|
63
|
-
successMessage: toValue(successMessage),
|
|
64
|
-
},
|
|
65
|
-
}
|
|
66
|
-
rules.push(rule)
|
|
67
|
-
}
|
|
68
|
-
else if (toValue(maxYear)) {
|
|
69
|
-
const rule: ValidationRule = {
|
|
70
|
-
type: 'custom',
|
|
71
|
-
options: {
|
|
72
|
-
validate: (value: string) => {
|
|
73
|
-
const year = getYearFromModel(value)
|
|
74
|
-
if (year === null) {
|
|
75
|
-
return true
|
|
76
|
-
}
|
|
77
|
-
return year <= toValue(maxYear as number)
|
|
78
|
-
},
|
|
79
|
-
message: `L'année doit être inférieure ou égale à ${toValue(maxYear)}.`,
|
|
80
|
-
successMessage: toValue(successMessage),
|
|
81
|
-
},
|
|
82
|
-
}
|
|
83
|
-
rules.push(rule)
|
|
84
|
-
}
|
|
85
|
-
return rules
|
|
86
|
-
})
|
|
87
|
-
return { rules: rules }
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function getYearFromModel(model: string): number | null {
|
|
91
|
-
const parts = model.split('/')
|
|
92
|
-
if (parts.length !== 3 || parts[2]?.length !== 4 || isNaN(Number(parts[2]))) {
|
|
93
|
-
return null
|
|
94
|
-
}
|
|
95
|
-
return Number(parts[2])
|
|
96
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ComponentPublicInstance } from 'vue'
|
|
2
|
-
|
|
3
|
-
declare module '@vue/test-utils' {
|
|
4
|
-
interface VueWrapper {
|
|
5
|
-
vm: ComponentPublicInstance & {
|
|
6
|
-
dialCode: {
|
|
7
|
-
code: string
|
|
8
|
-
country: string
|
|
9
|
-
abbreviation: string
|
|
10
|
-
phoneLength: number
|
|
11
|
-
mask: string
|
|
12
|
-
} | null
|
|
13
|
-
errors: string[]
|
|
14
|
-
hasError: boolean
|
|
15
|
-
phoneMask: string
|
|
16
|
-
validateOnSubmit: () => Promise<boolean>
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|