diff --git a/packages/synapse-bridge/src/patterns/DatePicker/DatePicker.vue b/packages/synapse-bridge/src/patterns/DatePicker/DatePicker.vue
index ac7a717000..88b5cfa415 100644
--- a/packages/synapse-bridge/src/patterns/DatePicker/DatePicker.vue
+++ b/packages/synapse-bridge/src/patterns/DatePicker/DatePicker.vue
@@ -1,124 +1,39 @@
+
-
-
-
- {{ date.getDate() }}
-
-
-
+
{
+ handleFocusChange(e)
+ e ? onFocus() : onBlur()
+ }
"
- :variant="getVariant"
- @blur="emitUpdateEvent"
- @paste="handlePaste"
- @cut="handleCut"
+ @click:clear="onClear"
>
-
+
{{ calendarIcon }}
-
-
-
+
+
- {{ calendarIcon }}
-
-
-
-
-
+
+ {{ error }}
+
+
+
+
+
+ {{ hint }}
+
+
+
+ {{ date.getDate() }}
+
+
+
+
diff --git a/packages/synapse-bridge/src/patterns/DatePickerField/WarningMixin.ts b/packages/synapse-bridge/src/patterns/DatePicker/WarningMixin.ts
similarity index 100%
rename from packages/synapse-bridge/src/patterns/DatePickerField/WarningMixin.ts
rename to packages/synapse-bridge/src/patterns/DatePicker/WarningMixin.ts
diff --git a/packages/synapse-bridge/src/patterns/DatePicker/config.ts b/packages/synapse-bridge/src/patterns/DatePicker/config.ts
index ea4a7759d9..4698dee8fb 100644
--- a/packages/synapse-bridge/src/patterns/DatePicker/config.ts
+++ b/packages/synapse-bridge/src/patterns/DatePicker/config.ts
@@ -1,22 +1,15 @@
export const config = {
textField: {
- hint: 'Format JJ/MM/AAAA',
- label: 'Date',
+ hideDetails: 'auto',
persistentHint: true,
- validateOnBlur: true,
- },
- menu: {
- minWidth: '290px',
- closeOnContentClick: false,
- contentClass: 'vd-date-picker-menu',
- },
- btn: {
- icon: true,
- variant: 'text',
+ validateOn: 'blur',
+ color: '#0C419A',
+ maxErrors: 5,
},
datePicker: {
- hideHeader: true,
- location: 'bottom end',
+ hideOffsetDates: true,
+ dayNames: ['L', 'M', 'M', 'J', 'V', 'S', 'D'],
+ locale: 'fr',
},
icon: {
color: '#808080',
diff --git a/packages/synapse-bridge/src/patterns/DatePicker/locales.ts b/packages/synapse-bridge/src/patterns/DatePicker/locales.ts
deleted file mode 100644
index c874660205..0000000000
--- a/packages/synapse-bridge/src/patterns/DatePicker/locales.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export const locales = {
- openCalendar: 'Ouvrir le calendrier',
-}
diff --git a/packages/synapse-bridge/src/patterns/DatePicker/mixins/birthdate.ts b/packages/synapse-bridge/src/patterns/DatePicker/mixins/birthdate.ts
deleted file mode 100644
index 9b2b6e6147..0000000000
--- a/packages/synapse-bridge/src/patterns/DatePicker/mixins/birthdate.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-import dayjs from 'dayjs'
-import { defineComponent } from 'vue'
-
-import { INTERNAL_FORMAT } from './dateLogic'
-
-export const Birthdate = defineComponent({
- props: {
- birthdate: {
- type: Boolean,
- default: false,
- },
- },
- data() {
- return {
- activePicker: null as string | null,
- max: this.birthdate ? dayjs().format(INTERNAL_FORMAT) : null,
- min: this.birthdate ? '1900-01-01' : null,
- }
- },
- watch: {
- menuOpen(value: boolean): void {
- if (this.birthdate && value) {
- this.setActivePicker()
- }
- },
- },
- methods: {
- setActivePicker(): void {
- this.activePicker = 'year'
- },
- changePicker(): void {
- if (this.birthdate) this.activePicker = 'months'
- },
- },
-})
diff --git a/packages/synapse-bridge/src/patterns/DatePicker/mixins/dateLogic.ts b/packages/synapse-bridge/src/patterns/DatePicker/mixins/dateLogic.ts
deleted file mode 100644
index 63b265d942..0000000000
--- a/packages/synapse-bridge/src/patterns/DatePicker/mixins/dateLogic.ts
+++ /dev/null
@@ -1,239 +0,0 @@
-import { defineComponent } from 'vue'
-
-import { parseDate } from '@/helpers/parseDate'
-
-import type { Refs } from '@/types'
-import { VMenu, VTextField } from 'vuetify/components'
-import { WarningRules } from '@/mixins/warningRules'
-import dayjs from 'dayjs'
-
-export const INTERNAL_FORMAT = 'YYYY-MM-DD'
-export const INTERNAL_FORMAT_REGEX =
- /\d{4}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])/
-
-const locales = {
- invalidDate: 'La date saisie n’est pas valide.',
-}
-
-export const DateLogic = defineComponent({
- mixins: [WarningRules],
- props: {
- dateFormat: {
- type: String,
- default: 'DD/MM/YYYY',
- },
- dateFormatReturn: {
- type: String,
- default: 'YYYY-MM-DD',
- },
- modelValue: {
- type: String,
- default: '',
- },
- },
- data() {
- return {
- $refs: {} as Refs<{
- menu: VMenu
- input: VTextField
- }>,
-
- /* Js date object */
- dateObject: new Date(this.modelValue),
-
- /** YYYY-MM-DD format */
- date: '',
-
- /** DD/MM/YYYY format */
- textFieldDate: '',
-
- errorMessages: null as string[] | null,
- }
- },
- watch: {
- modelValue: {
- // YYYY-MM-DD format
- handler(newDate: string): void {
- if (!newDate) {
- this.clearInternalModel()
-
- return
- }
-
- const parsed = this.parseDatetoInternalFormat(newDate)
-
- if (!parsed) {
- return
- }
-
- this.date = parsed
- this.dateObject = new Date(parsed)
- this.setTextFieldModel()
-
- this.validate(this.textFieldDate)
- this.validateVuetify()
- },
- immediate: true,
- },
- /**
- * This method is fired every time textFieldDate changes,
- * that means on every key strokes, so don't validate
- * on input if validateOnBlur is true
- */
- textFieldDate(value: string): void {
- this.errorMessages = null
- if (!this.validateOnBlurEnabled) {
- this.validate(value)
- }
- },
- date(): void {
- this.errorMessages = null
- },
- },
- mounted() {
- // Watch VTextField 'hasError' computed value since 'update:error' event isn't reliable
- // (it's not fired at initial state and 'validateOnBlur' can cause issues as well)
-
- this.$watch(
- () => this.$refs.input.hasError,
- (error: boolean) => {
- this.$emit('error', error)
- },
- {
- deep: true, // Required since watching $refs object
- }
- )
- },
- computed: {
- validateOnBlurEnabled(): boolean {
- return true //Boolean(this.options?.textField?.validateOnBlur);
- },
- },
- methods: {
- /** Parse a date with dateFormatReturn format to internal format */
- parseDatetoInternalFormat(date: string): string | null {
- const parsed = parseDate(date, this.dateFormatReturn)
-
- if (!parsed.isValid()) {
- return null
- }
-
- return parsed.format(INTERNAL_FORMAT)
- },
-
- // Take a date in DD/MM/YYYY format and return it in YYYY-MM-DD format
- parseTextFieldDate(date: string): string | null {
- const parsed = parseDate(date, this.dateFormat)
- const formatted = parsed.format(INTERNAL_FORMAT)
-
- if (!parsed.isValid() || !formatted.match(INTERNAL_FORMAT_REGEX)) {
- this.errorMessages = [locales.invalidDate]
-
- return null
- }
-
- return formatted
- },
-
- setTextFieldModel(): void {
- this.textFieldDate = parseDate(this.date, INTERNAL_FORMAT).format(
- this.dateFormat
- )
- },
-
- saveFromCalendar(): void {
- this.date = dayjs(this.dateObject).format(INTERNAL_FORMAT)
- this.setTextFieldModel()
-
- // Trigger validation when the calendar is clicked since
- // the input loose focus and fires textFieldBlur
- this.validate(this.textFieldDate)
-
- if (this.validateOnBlurEnabled) {
- // Validate the VTextField since no blur event is emitted
- this.validateVuetify()
- }
-
- this.emitChangeEvent()
- },
-
- saveFromTextField(): void {
- if (!this.textFieldDate) {
- this.$emit('update:modelValue', '')
- this.clearInternalModel()
-
- return
- }
-
- const formatted = this.parseTextFieldDate(this.textFieldDate)
-
- if (!formatted) {
- return
- }
-
- this.date = formatted
- this.emitChangeEvent()
- },
-
- saveFromPasted(event: ClipboardEvent): void {
- const value = event.clipboardData?.getData('text/plain')
-
- if (!value) {
- return
- }
-
- const parsedWithDisplayFormat = parseDate(value, this.dateFormat)
-
- if (parsedWithDisplayFormat.isValid()) {
- this.date = parsedWithDisplayFormat.format(INTERNAL_FORMAT)
- }
-
- const parsedWithReturnFormat = parseDate(
- value,
- this.dateFormatReturn
- )
-
- if (parsedWithReturnFormat.isValid()) {
- this.date = parsedWithReturnFormat.format(INTERNAL_FORMAT)
- }
-
- this.emitChangeEvent()
- },
-
- clearInternalModel(): void {
- this.date = ''
- this.textFieldDate = ''
- this.dateObject = new Date()
- },
-
- emitChangeEvent(): void {
- this.$emit(
- 'update:modelValue',
- parseDate(this.date, INTERNAL_FORMAT).format(
- this.dateFormatReturn
- )
- )
- },
-
- validateVuetify(): void {
- this.$nextTick(() => {
- // Set hasFocused to true on VTextField
- // to fix https://github.com/vuetifyjs/vuetify/issues/7876
- // (error messages aren't shown if the input hasn't been focused)
- if (this.$refs.input.hasFocused !== undefined) {
- this.$refs.input.hasFocused = true
- }
-
- this.$refs.input.validate()
- })
- },
-
- textFieldBlur(): void {
- this.saveFromTextField()
-
- if (this.validateOnBlurEnabled) {
- this.validate(this.textFieldDate)
- }
- },
- },
-})
diff --git a/packages/synapse-bridge/src/patterns/DatePicker/mixins/errorProp.ts b/packages/synapse-bridge/src/patterns/DatePicker/mixins/errorProp.ts
deleted file mode 100644
index f1f8bf0f09..0000000000
--- a/packages/synapse-bridge/src/patterns/DatePicker/mixins/errorProp.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { defineComponent } from 'vue'
-
-export const ErrorProp = defineComponent({
- props: {
- error: {
- type: Boolean,
- default: false,
- },
- },
- computed: {
- internalErrorProp: {
- get() {
- return this.error
- },
- set(value: unknown) {
- this.$emit('update:error', value)
- },
- },
- },
- template: `
`,
-})
diff --git a/packages/synapse-bridge/src/patterns/DatePicker/mixins/maskValue.ts b/packages/synapse-bridge/src/patterns/DatePicker/mixins/maskValue.ts
deleted file mode 100644
index 5c74b2d9f5..0000000000
--- a/packages/synapse-bridge/src/patterns/DatePicker/mixins/maskValue.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import { defineComponent } from 'vue'
-import { DateLogic } from './dateLogic'
-
-export const MaskValue = defineComponent({
- mixins: [DateLogic],
- props: {
- mask: {
- type: [String, Boolean],
- default: undefined,
- },
- },
- computed: {
- maskValue(): { mask: string } | undefined {
- if (this.mask === false) {
- return
- }
-
- if (typeof this.mask === 'string') {
- return { mask: this.mask }
- }
-
- return {
- mask: this.dateFormat.replace(/[a-z]/gim, '#'),
- }
- },
- },
-})
diff --git a/packages/synapse-bridge/src/patterns/DatePicker/mixins/tests/errorProp.spec.ts b/packages/synapse-bridge/src/patterns/DatePicker/mixins/tests/errorProp.spec.ts
deleted file mode 100644
index c8d6c07fd5..0000000000
--- a/packages/synapse-bridge/src/patterns/DatePicker/mixins/tests/errorProp.spec.ts
+++ /dev/null
@@ -1,43 +0,0 @@
-import { shallowMount } from '@vue/test-utils'
-import { ErrorProp } from '../errorProp.ts'
-import { describe, it, expect } from 'vitest'
-
-describe('ErrorProp', () => {
- it('defaults error prop to false', () => {
- const wrapper = shallowMount(ErrorProp)
- expect(wrapper.vm.error).toBe(false)
- })
-
- it('accepts error prop', () => {
- const wrapper = shallowMount(ErrorProp, {
- propsData: {
- error: true,
- },
- })
- expect(wrapper.vm.error).toBe(true)
- })
-
- it('emits update:error event when internalErrorProp is set', async () => {
- const wrapper = shallowMount(ErrorProp, {
- propsData: {
- error: false,
- },
- })
- wrapper.vm.internalErrorProp = true
- await wrapper.vm.$nextTick()
- expect(wrapper.emitted('update:error')).toBeTruthy()
- const emittedErrorEvent = wrapper.emitted('update:error')
- if (emittedErrorEvent) {
- expect(emittedErrorEvent[0]).toEqual([true])
- }
- })
-
- it('returns the value of error prop when internalErrorProp is accessed', () => {
- const wrapper = shallowMount(ErrorProp, {
- propsData: {
- error: true,
- },
- })
- expect((wrapper.vm as any).internalErrorProp).toBe(true)
- })
-})
diff --git a/packages/synapse-bridge/src/patterns/DatePicker/tests/DatePicker.spec.ts b/packages/synapse-bridge/src/patterns/DatePicker/tests/DatePicker.spec.ts
deleted file mode 100644
index 64afba6ceb..0000000000
--- a/packages/synapse-bridge/src/patterns/DatePicker/tests/DatePicker.spec.ts
+++ /dev/null
@@ -1,794 +0,0 @@
-import { shallowMount } from '@vue/test-utils'
-import DatePicker from '../'
-import { describe, expect, it, vi } from 'vitest'
-import { notAfterToday } from '@/rules/notAfterToday/index.ts'
-import dayjs from 'dayjs'
-
-describe('DatePicker', () => {
- it('returns correct textFieldClasses', () => {
- const wrapper = shallowMount(DatePicker)
- const expectedTextFieldClasses = wrapper.vm.buildTextFieldClasses()
- expect(wrapper.vm.textFieldClasses).toEqual(expectedTextFieldClasses)
- })
-
- it('returns correct textFieldClasses with error with error-style class', () => {
- const wrapper = shallowMount(DatePicker, {
- data() {
- return {
- errorMessages: ["La date saisie n'est pas valide"],
- }
- },
- })
-
- wrapper.vm.buildTextFieldClasses()
- expect(wrapper.vm.textFieldClasses).toContain('error-style')
- })
-
- it('returns correct buildTextFieldClasses if warningRules is not empty', () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- warningRules: [notAfterToday],
- },
- })
-
- const expectedTextFieldClasses = wrapper.vm.buildTextFieldClasses()
- expect(wrapper.vm.textFieldClasses).toEqual(expectedTextFieldClasses)
- })
-
- it('returns correct variant', () => {
- const wrapper = shallowMount(DatePicker)
- const expectedVariant = wrapper.vm.determineVariant()
- expect(wrapper.vm.getVariant).toEqual(expectedVariant)
- })
-
- it('returns correct prependIconValue when appendIcon and noPrependIcon are false', () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- appendIcon: false,
- noPrependIcon: false,
- },
- })
-
- const expectedPrependIconValue = wrapper.vm.calendarIcon
- expect(wrapper.vm.prependIconValue).toEqual(expectedPrependIconValue)
- })
-
- it('returns undefined when appendIcon or noPrependIcon is true', () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- appendIcon: true,
- noPrependIcon: false,
- },
- })
-
- expect(wrapper.vm.prependIconValue).toBeUndefined()
- wrapper.setProps({ appendIcon: false, noPrependIcon: true })
- expect(wrapper.vm.prependIconValue).toBeUndefined()
- })
-
- it('returns undefined when appendIcon or noIcon is false', () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- noPrependIcon: true,
- noIcon: false,
- },
- })
-
- expect(wrapper.vm.prependIconValue).toBeUndefined()
- wrapper.setProps({ noPrependIcon: false, noIcon: true })
- expect(wrapper.vm.prependIconValue).toBeUndefined()
- })
-
- it('returns undefined when appendIcon or noIcon is true', () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- noPrependIcon: false,
- noIcon: true,
- },
- })
-
- expect(wrapper.vm.prependIconValue).toBeUndefined()
- wrapper.setProps({ noPrependIcon: true, noIcon: true })
- expect(wrapper.vm.prependIconValue).toBeUndefined()
- })
-
- it('returns correct date when day slot is called', () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- showWeekends: true,
- },
- })
- wrapper.vm.isWeekend = vi.fn(() => true)
- const date = new Date(2023, 3, 15) // April 15, 2023
- const expectedDate = date.getDate()
- expect(expectedDate).toBe(15)
- })
-
- it('returns correct dateFormat', () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- dateFormat: 'DD/MM/YY',
- },
- })
- const expectedDateFormat = wrapper.vm.dateFormat
- expect(expectedDateFormat).toBe('DD/MM/YY')
- })
-
- it('returns correct dateFormatReturn', () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- dateFormatReturn: 'DD/MM/YY',
- },
- })
- const expectedDateFormatReturn = wrapper.vm.dateFormatReturn
- expect(expectedDateFormatReturn).toBe('DD/MM/YY')
- })
-})
-
-describe('Computed', () => {
- it('adds "error-style" to textFieldClasses when hasError is true', () => {
- const wrapper = shallowMount(DatePicker, {
- data() {
- return {
- errorMessages: ["La date saisie n'est pas valide"],
- }
- },
- })
- expect(wrapper.vm.textFieldClasses).toContain('error-style')
- })
-
- it('does not add "error-style" to textFieldClasses when hasError is false', () => {
- const wrapper = shallowMount(DatePicker, {
- data() {
- return {
- errorMessages: [],
- }
- },
- })
-
- expect(wrapper.vm.textFieldClasses).not.toContain('error-style')
- })
-
- it('returns correct indexedThis', () => {
- const wrapper = shallowMount(DatePicker)
- const expectedIndexedThis = wrapper.vm.indexedThis
- expect(wrapper.vm.indexedThis).toEqual(expectedIndexedThis)
- })
- it('returns correct textFieldOptions', () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- label: 'Test Label',
- disabled: false,
- outlined: false,
- appendIcon: false,
- rules: [],
- },
- data() {
- return {
- lastTypeAddedDate: 'date',
- date: new Date(2023, 3, 15), // April 15, 2023
- inputValue: '',
- calendarIcon: 'calendarIcon',
- errorMessages: [],
- }
- },
- })
-
- const expectedTextFieldOptions = {
- value: wrapper.vm.formatDate(wrapper.vm.date),
- type: 'text',
- hideDetails: 'auto',
- label: 'Test Label',
- 'aria-describedby': 'Test Label',
- variant: wrapper.vm.getVariant,
- disabled: false,
- hint: wrapper.vm.hint,
- persistentHint: true,
- rules: [wrapper.vm.validateDateFormat, ...wrapper.vm.rules],
- errorMessages: [],
- }
-
- expect(wrapper.vm.textFieldOptions).toEqual(expectedTextFieldOptions)
- })
-
- it('returns false when errorMessages is empty', () => {
- const wrapper = shallowMount(DatePicker, {
- data() {
- return {
- errorMessages: [],
- }
- },
- })
- expect(wrapper.vm.hasError).toBe(false)
- })
-
- it('returns false when errorMessages is empty', () => {
- const wrapper = shallowMount(DatePicker, {
- data() {
- return {
- errorMessages: ["La date saisie n'est pas valide"],
- }
- },
- })
- expect(wrapper.vm.hasError).toBe(true)
- })
-
- it('returns correct textFieldClasses', () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- disabled: false,
- outlined: false,
- },
- })
- const expectedTextFieldClasses = wrapper.vm.buildTextFieldClasses()
- expect(wrapper.vm.textFieldClasses).toEqual(expectedTextFieldClasses)
- })
-
- it('returns outlined when outlined is true', () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- outlined: true,
- },
- })
- expect(wrapper.vm.getVariant).toBe('outlined')
- })
-
- it('returns true when errorMessages contains "La date saisie n\'est pas valide"', () => {
- const wrapper = shallowMount(DatePicker, {
- data() {
- return {
- errorMessages: ["La date saisie n'est pas valide"],
- }
- },
- })
- expect(wrapper.vm.hasError).toBe(true)
- })
-})
-
-describe('Methods', () => {
- it('emits update:model-value event when date is not an array', () => {
- const wrapper = shallowMount(DatePicker, {
- data() {
- return {
- date: dayjs().toDate(),
- }
- },
- })
- wrapper.vm.emitUpdateEvent()
- const emittedEvent = wrapper.emitted('update:model-value')
- expect(emittedEvent).toBeTruthy()
- if (emittedEvent) {
- expect(emittedEvent[0]).toEqual([
- wrapper.vm.formatDate(wrapper.vm.date),
- ])
- }
- })
-
- it('adds correct classes to textFieldClasses', () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- warningRules: [notAfterToday],
- noPrependIcon: true,
- appendIcon: true,
- textFieldClass: 'custom-class',
- },
- })
-
- const textFieldClasses = wrapper.vm.buildTextFieldClasses()
-
- expect(textFieldClasses).toContain('vd-warning-rules')
- expect(textFieldClasses).toContain('vd-no-prepend-icon')
- expect(textFieldClasses).toContain('vd-append-icon')
- expect(textFieldClasses).toContain('custom-class')
- })
-
- it('adds multiple custom classes to textFieldClasses when textFieldClass is an array', () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- textFieldClass: ['custom-class-1', 'custom-class-2'],
- },
- })
-
- const textFieldClasses = wrapper.vm.buildTextFieldClasses()
-
- expect(textFieldClasses).toContain('custom-class-1')
- expect(textFieldClasses).toContain('custom-class-2')
- })
-
- it('identifies weekends correctly', () => {
- const wrapper = shallowMount(DatePicker)
-
- const sunday = new Date(2023, 3, 9) // April 9, 2023 is a Sunday
- const monday = new Date(2023, 3, 10) // April 10, 2023 is a Monday
- const saturday = new Date(2023, 3, 8) // April 8, 2023 is a Saturday
-
- expect(wrapper.vm.isWeekend(sunday)).toBe(true)
- expect(wrapper.vm.isWeekend(monday)).toBe(false)
- expect(wrapper.vm.isWeekend(saturday)).toBe(true)
- })
-
- it('calls blockOpenOnclickGeneric with correct argument when blockOpenOnclickRangePicker is called', () => {
- const wrapper = shallowMount(DatePicker)
- const blockOpenOnclickGenericMock = vi.fn()
- wrapper.vm.blockOpenOnclickGeneric = blockOpenOnclickGenericMock
-
- wrapper.vm.blockOpenOnclickRangePicker()
-
- expect(blockOpenOnclickGenericMock).toHaveBeenCalledWith(
- 'rangeDatePicker'
- )
- })
-
- it('calls blockOpenOnclickGeneric with correct argument when blockOpenOnclick is called', () => {
- const wrapper = shallowMount(DatePicker)
- const blockOpenOnclickGenericMock = vi.fn()
- wrapper.vm.blockOpenOnclickGeneric = blockOpenOnclickGenericMock
- wrapper.vm.blockOpenOnclick()
- expect(blockOpenOnclickGenericMock).toHaveBeenCalledWith('datePicker')
- })
-
- it('sets isCalOpen to false when handleClose is called', () => {
- const wrapper = shallowMount(DatePicker, {
- data() {
- return {
- isCalOpen: true,
- }
- },
- })
-
- wrapper.vm.handleClose()
-
- expect(wrapper.vm.isCalOpen).toBe(false)
- })
-
- it('calls handleIconClickGeneric with correct arguments when rangeHandleIconClick is called', () => {
- const wrapper = shallowMount(DatePicker)
- const handleIconClickGenericMock = vi.fn()
- wrapper.vm.handleIconClickGeneric = handleIconClickGenericMock
- const mockEvent = { preventDefault: vi.fn() }
- wrapper.vm.rangeHandleIconClick(mockEvent)
- expect(handleIconClickGenericMock).toHaveBeenCalledWith(
- mockEvent,
- 'rangeDatePicker'
- )
- })
-
- it('calls handleIconClick with correct arguments', () => {
- const wrapper = shallowMount(DatePicker)
- const handleIconClickGenericMock = vi.fn()
- wrapper.vm.handleIconClickGeneric = handleIconClickGenericMock
- const mockEvent = { preventDefault: vi.fn() }
- wrapper.vm.handleIconClick(mockEvent)
- expect(handleIconClickGenericMock).toHaveBeenCalledWith(
- mockEvent,
- 'datePicker'
- )
- })
-
- it('returns correct variant', () => {
- let wrapper = shallowMount(DatePicker, {
- propsData: {
- disabled: false,
- noPrependIcon: false,
- outlined: true,
- },
- })
-
- expect(wrapper.vm.determineVariant()).toEqual('outlined')
-
- wrapper = shallowMount(DatePicker, {
- propsData: {
- disabled: true,
- noPrependIcon: false,
- outlined: true,
- },
- })
-
- expect(wrapper.vm.determineVariant()).toEqual('underlined')
-
- wrapper = shallowMount(DatePicker, {
- propsData: {
- disabled: false,
- noPrependIcon: true,
- outlined: true,
- },
- })
-
- expect(wrapper.vm.determineVariant()).toEqual('underlined')
-
- wrapper = shallowMount(DatePicker, {
- propsData: {
- disabled: false,
- noPrependIcon: false,
- outlined: false,
- },
- })
-
- expect(wrapper.vm.determineVariant()).toEqual('underlined')
- })
-
- it('returns correct formatted date when formatDate is called', () => {
- const wrapper = shallowMount(DatePicker)
- const date = new Date(2023, 3, 15) // April 15, 2023
- const formattedDate = wrapper.vm.formatDate(date)
- expect(formattedDate).toBe('15/04/2023')
- })
-
- it('returns correct formatted date when formatDate is called with an array', () => {
- const wrapper = shallowMount(DatePicker)
- const date = [new Date(2023, 3, 15), new Date(2023, 3, 20)] // April 15, 2023 - April 20, 2023
- const formattedDate = wrapper.vm.formatDate(date)
- expect(formattedDate).toStrictEqual(['15/04/2023', '20/04/2023'])
- })
-
- it('returns correct formatted date when formatDate is null', () => {
- const wrapper = shallowMount(DatePicker)
- const date = null
- const formattedDate = wrapper.vm.formatDate(date)
- expect(formattedDate).toBeUndefined()
- })
-
- it('returns correct formatted date when formatDate is called with an invalid date', () => {
- const wrapper = shallowMount(DatePicker)
- const date = new Date('invalid date')
- const formattedDate = wrapper.vm.formatDate(date)
- expect(formattedDate).toBeNull()
- })
-
- it('returns correct formatted date when formatDate is called with an array', () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- range: true,
- },
- })
- const date = [new Date(2023, 3, 15), new Date(2023, 3, 20)] // April 15, 2023 - April 20, 2023
- const formattedDate = wrapper.vm.formatDate(date)
- expect(formattedDate).toStrictEqual(['15/04/2023', '20/04/2023'])
- })
-
- it('trims the last character of indexedThis[historyKey] if value.data is null', async () => {
- const wrapper = shallowMount(DatePicker)
- wrapper.vm.updateInputValue({ data: null }, 'inputValue')
- expect(wrapper.vm.indexedThis.inputValue).toBe('')
- })
- it('trims indexedThis[historyKey] to 10 characters if its length is more than 10', async () => {
- const wrapper = shallowMount(DatePicker)
- wrapper.vm.indexedThis.inputValue = '12345678901'
- await wrapper.vm.updateInputValue({ data: '1' }, 'inputValue')
- expect(wrapper.vm.indexedThis.inputValue).toBe('1234567890')
- })
- it('trims indexedThis[historyKey] to 10 characters if its length is more than 10', async () => {
- const wrapper = shallowMount(DatePicker)
- wrapper.vm.indexedThis.inputValue = '12345678901'
- await wrapper.vm.updateInputValue({ data: '1' }, 'inputValue')
- expect(wrapper.vm.indexedThis.inputValue).toBe('1234567890')
- })
- it('trims indexedThis[historyKey] to 10 characters if its length is more than 10', async () => {
- const wrapper = shallowMount(DatePicker)
- wrapper.vm.indexedThis.inputValue = '12345678901'
- await wrapper.vm.updateInputValue({ data: '1' }, 'inputValue')
- expect(wrapper.vm.indexedThis.inputValue).toBe('1234567890')
- })
- it('trims indexedThis[historyKey] to 10 characters if its length is more than 10', async () => {
- const wrapper = shallowMount(DatePicker)
- wrapper.vm.indexedThis.inputValue = '12345678901'
- await wrapper.vm.updateInputValue({ data: '1' }, 'inputValue')
- expect(wrapper.vm.indexedThis.inputValue).toBe('1234567890')
- })
- it('trims indexedThis[historyKey] to 10 characters if its length is more than 10', async () => {
- const wrapper = shallowMount(DatePicker)
- wrapper.vm.indexedThis.inputValue = '12345678901'
- await wrapper.vm.updateInputValue({ data: '1' }, 'inputValue')
- expect(wrapper.vm.indexedThis.inputValue).toBe('1234567890')
- })
- it('trims indexedThis[historyKey] to 10 characters if its length is more than 10', async () => {
- const wrapper = shallowMount(DatePicker)
- wrapper.vm.indexedThis.inputValue = '12345678901'
- await wrapper.vm.updateInputValue({ data: '1' }, 'inputValue')
- expect(wrapper.vm.indexedThis.inputValue).toBe('1234567890')
- })
- it('calls updateInputValue with correct arguments when getInput is called', async () => {
- const wrapper = shallowMount(DatePicker)
- const updateInputValueMock = vi.fn()
- wrapper.vm.updateInputValue = updateInputValueMock
- const mockValue = { data: '1' }
- wrapper.vm.getInput(mockValue)
- expect(updateInputValueMock).toHaveBeenCalledWith(
- mockValue,
- 'inputValue'
- )
- })
-
- it('trims indexedThis.inputValue to 10 characters when stopInput is called', async () => {
- const wrapper = shallowMount(DatePicker)
- wrapper.vm.indexedThis.inputValue = '12345678901'
- wrapper.vm.stopInput()
- expect(wrapper.vm.indexedThis.inputValue).toBe('1234567890')
- })
-
- it('createDateRegEx should create a correct regex for DD/MM/YYYY format', () => {
- const wrapper = shallowMount(DatePicker)
- const regex = wrapper.vm.createDateRegEx('DD/MM/YYYY')
- expect(regex).toEqual(
- /^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$/
- )
- })
-
- it('should create a correct regex for MM-DD-YYYY format', () => {
- const wrapper = shallowMount(DatePicker)
- const regex = wrapper.vm.createDateRegEx('MM-DD-YYYY')
- expect(regex).toEqual(
- /^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$/
- )
- })
-
- it('should throw an error for unsupported date format', () => {
- const wrapper = shallowMount(DatePicker)
- expect(() => wrapper.vm.createDateRegEx('DD-YY-MM')).toThrow(
- 'Unsupported date format part: YY'
- )
- })
-})
-describe('Watchers', () => {
- it('emits value event when date changes', () => {
- const wrapper = shallowMount(DatePicker)
-
- wrapper.vm.$watch('date', () => {
- wrapper.vm.emitUpdateEvent()
- })
-
- wrapper.vm.date = new Date(2023, 3, 15) // April 15, 2023
- wrapper.vm.emitUpdateEvent()
- const emittedEvent = wrapper.emitted('update:model-value')
- expect(emittedEvent).toBeTruthy()
- })
-
- it('emits value event when date changes and date is an array', () => {
- const wrapper = shallowMount(DatePicker)
-
- wrapper.vm.$watch('date', () => {
- wrapper.vm.emitUpdateEvent()
- })
-
- wrapper.vm.date = [new Date(2023, 3, 15), new Date(2023, 3, 20)] // April 15, 2023 - April 20, 2023
- wrapper.vm.emitUpdateEvent()
- const emittedEvent = wrapper.emitted('update:model-value')
- expect(emittedEvent).toBeTruthy()
- })
-
- it('emits value event when date changes and date is a string', () => {
- const wrapper = shallowMount(DatePicker)
-
- wrapper.vm.$watch('date', () => {
- wrapper.vm.emitUpdateEvent()
- })
-
- wrapper.vm.date = '15/04/2023'
- wrapper.vm.emitUpdateEvent()
- const emittedEvent = wrapper.emitted('update:model-value')
- expect(emittedEvent).toBeTruthy()
- })
-
- it('updates date correctly when newVal is an array with more than one element', async () => {
- const wrapper = shallowMount(DatePicker)
- const newVal = [
- dayjs().format('DD/MM/YYYY'),
- dayjs().add(1, 'day').format('DD/MM/YYYY'),
- ]
- await wrapper.setProps({ modelValue: newVal })
- expect(wrapper.vm.modelValue).toEqual(newVal)
- })
- it('updates date correctly when newVal is not an array', async () => {
- const wrapper = shallowMount(DatePicker)
- const newVal = dayjs().format('DD/MM/YYYY')
- await wrapper.setProps({ modelValue: newVal })
- expect(wrapper.vm.modelValue).toEqual(newVal)
- })
-
- it('trims the last character of inputValue if it is not a digit or a slash', async () => {
- const wrapper = shallowMount(DatePicker)
- await wrapper.setData({ inputValue: '12/34/567a' })
- expect(wrapper.vm.inputValue).toBe('12/34/567')
- })
-
- it('trims inputValue to 10 characters if its length is more than 10', async () => {
- const wrapper = shallowMount(DatePicker)
- await wrapper.setData({ inputValue: '12/34/56789/123' })
- expect(wrapper.vm.inputValue).toBe('12/34/5678')
- })
- it('sets lastTypeAddedDate to inputValue', async () => {
- const wrapper = shallowMount(DatePicker)
- await wrapper.setData({ inputValue: '12/34/5678' })
- expect(wrapper.vm.lastTypeAddedDate).toBe('inputValue')
- })
- it('updates date correctly when modelValue changes and is a string with dateFormatReturn not equal to DD/MM/YYYY', async () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- dateFormatReturn: 'YYYY/MM/DD',
- },
- })
-
- const newVal = '15/04/2023' // April 15, 2023
- await wrapper.setProps({ modelValue: newVal })
-
- const expectedDate = dayjs(newVal, 'DD/MM/YYYY').toDate()
- expect(wrapper.vm.date).toEqual(expectedDate)
- })
-
- it('does not update date when modelValue changes to an invalid date string and dateFormatReturn not equal to DD/MM/YYYY', async () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- dateFormatReturn: 'YYYY/MM/DD',
- },
- })
-
- const newVal = 'invalid date'
- await wrapper.setProps({ modelValue: newVal })
-
- expect(wrapper.vm.date).toBeNull()
- })
- it('updates date correctly when modelValue changes and is an array of strings with dateFormatReturn not equal to DD/MM/YYYY', async () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- dateFormatReturn: 'YYYY/MM/DD',
- },
- })
-
- const newVal = ['15/04/2023', '16/04/2023'] // April 15, 2023 and April 16, 2023
- await wrapper.setProps({ modelValue: newVal })
-
- const expectedDate = newVal.map((date) =>
- dayjs(date, 'DD/MM/YYYY').format('YYYY/MM/DD')
- )
- expect(wrapper.vm.date).toEqual(expectedDate)
- })
-})
-describe('Mounted', () => {
- it('update modelValue', () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- modelValue: '15/04/2023',
- },
- })
-
- expect(wrapper.vm.date).toEqual(new Date(2023, 3, 15))
- })
- it('adds error message when error prop is true', () => {
- const wrapper = shallowMount(DatePicker, {
- propsData: {
- error: true,
- },
- })
-
- expect(wrapper.vm.errorMessages).toContain('Une erreur est survenue')
- })
-
- it('handleCut method updates state and clipboard correctly', async () => {
- const wrapper = shallowMount(DatePicker)
- const mockEvent = {
- clipboardData: { getData: vi.fn(() => '07/07/1990') },
- }
- await wrapper.vm.handleCut(mockEvent as any)
- expect(wrapper.vm.inputValue).toBe('')
- expect(wrapper.vm.date).toBeNull()
- })
-
- it('handlePaste method updates state and clipboard correctly', async () => {
- const wrapper = shallowMount(DatePicker)
- const mockEvent = {
- clipboardData: { getData: vi.fn(() => '07/07/1990') },
- }
- await wrapper.vm.handlePaste(mockEvent as any)
- expect(wrapper.vm.inputValue).toBe('07/07/1990')
- expect(wrapper.vm.date).toBe('07/07/1990')
- })
-
- it('resets error messages correctly', () => {
- const wrapper = shallowMount(DatePicker, {
- data() {
- return {
- errorMessages: ["La date saisie n'est pas valide"],
- warningErrorMessages: ['Warning message'],
- isNotValid: true,
- }
- },
- })
-
- wrapper.vm.resetErrorMessages()
-
- expect(wrapper.vm.errorMessages).toEqual([])
- expect(wrapper.vm.warningErrorMessages).toEqual([])
- expect(wrapper.vm.isNotValid).toBe(false)
- })
-
- it('emits update:model-value event and resets error messages when date is valid', () => {
- const wrapper = shallowMount(DatePicker, {
- data() {
- return {
- date: new Date(2023, 3, 15), // April 15, 2023
- }
- },
- })
-
- const resetErrorMessagesMock = vi.spyOn(
- wrapper.vm,
- 'resetErrorMessages'
- )
- wrapper.vm.emitUpdateEvent()
-
- expect(resetErrorMessagesMock).toHaveBeenCalled()
- const emittedEvent = wrapper.emitted('update:model-value')
- expect(emittedEvent).toBeTruthy()
- expect(emittedEvent?.[0]).toEqual(['15/04/2023'])
- })
-
- it('handles paste event correctly and resets error messages when date is valid', async () => {
- const wrapper = shallowMount(DatePicker)
- const mockEvent = {
- clipboardData: { getData: vi.fn(() => '07/07/1990') },
- }
-
- const resetErrorMessagesMock = vi.spyOn(
- wrapper.vm,
- 'resetErrorMessages'
- )
- await wrapper.vm.handlePaste(mockEvent as any)
-
- expect(resetErrorMessagesMock).toHaveBeenCalled()
- expect(wrapper.vm.inputValue).toBe('07/07/1990')
- expect(wrapper.vm.date).toBe('07/07/1990')
- expect(wrapper.vm.isNotValid).toBe(false)
- })
-
- it('clears error messages when inputValue is set to an empty string', async () => {
- const wrapper = shallowMount(DatePicker, {
- data() {
- return {
- warningErrorMessages: ['Warning message'],
- errorMessages: ['Error message'],
- inputValue: '07/07/1990',
- }
- },
- })
-
- await wrapper.setData({ inputValue: '' })
-
- expect(wrapper.vm.warningErrorMessages).toEqual([])
- expect(wrapper.vm.errorMessages).toEqual([])
- })
-
- it('calls removeLastCharacter when value.data is null', () => {
- const wrapper = shallowMount(DatePicker)
- const removeLastCharacterMock = vi.fn()
- wrapper.vm.removeLastCharacter = removeLastCharacterMock
- wrapper.vm.updateInputValue({ data: null }, 'inputValue')
- expect(removeLastCharacterMock).toHaveBeenCalledWith('inputValue')
- })
-
- it('does nothing if input length is 10 characters', () => {
- const wrapper = shallowMount(DatePicker)
- wrapper.vm.isMaxLength = vi.fn(() => true)
- const appendCharacterMock = vi.fn()
- wrapper.vm.appendCharacter = appendCharacterMock
- wrapper.vm.updateInputValue({ data: '1' }, 'inputValue')
- expect(appendCharacterMock).not.toHaveBeenCalled()
- })
-
- it('adds a separator if necessary', () => {
- const wrapper = shallowMount(DatePicker)
- wrapper.vm.shouldAddSeparator = vi.fn(() => true)
- const addSeparatorMock = vi.fn()
- wrapper.vm.addSeparator = addSeparatorMock
- wrapper.vm.updateInputValue({ data: '1' }, 'inputValue')
- expect(addSeparatorMock).toHaveBeenCalledWith('inputValue')
- })
-
- it('appends the character if it is not a separator', () => {
- const wrapper = shallowMount(DatePicker)
- wrapper.vm.isNotSeparator = vi.fn(() => true)
- const appendCharacterMock = vi.fn()
- wrapper.vm.appendCharacter = appendCharacterMock
- wrapper.vm.updateInputValue({ data: '1' }, 'inputValue')
- expect(appendCharacterMock).toHaveBeenCalledWith('inputValue', '1')
- })
-})
diff --git a/packages/synapse-bridge/src/patterns/DatePickerField/tests/DatePickerField.spec.ts b/packages/synapse-bridge/src/patterns/DatePicker/tests/DatePickerField.spec.ts
similarity index 98%
rename from packages/synapse-bridge/src/patterns/DatePickerField/tests/DatePickerField.spec.ts
rename to packages/synapse-bridge/src/patterns/DatePicker/tests/DatePickerField.spec.ts
index dbd08902e8..44e6b5921d 100644
--- a/packages/synapse-bridge/src/patterns/DatePickerField/tests/DatePickerField.spec.ts
+++ b/packages/synapse-bridge/src/patterns/DatePicker/tests/DatePickerField.spec.ts
@@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils'
import { describe, it, expect } from 'vitest'
-import DatePickerField from '../DatePickerField.vue'
+import DatePickerField from '../DatePicker.vue'
import { vuetify } from '@tests/unit/setup'
describe('DatePickerField', () => {
diff --git a/packages/synapse-bridge/src/patterns/DatePickerField/tests/__snapshots__/DatePickerField.spec.ts.snap b/packages/synapse-bridge/src/patterns/DatePicker/tests/__snapshots__/DatePickerField.spec.ts.snap
similarity index 100%
rename from packages/synapse-bridge/src/patterns/DatePickerField/tests/__snapshots__/DatePickerField.spec.ts.snap
rename to packages/synapse-bridge/src/patterns/DatePicker/tests/__snapshots__/DatePickerField.spec.ts.snap
diff --git a/packages/synapse-bridge/src/patterns/DatePickerField/DatePickerField.vue b/packages/synapse-bridge/src/patterns/DatePickerField/DatePickerField.vue
deleted file mode 100644
index 88b5cfa415..0000000000
--- a/packages/synapse-bridge/src/patterns/DatePickerField/DatePickerField.vue
+++ /dev/null
@@ -1,472 +0,0 @@
-
-
-
-
-
-
- {
- handleFocusChange(e)
- e ? onFocus() : onBlur()
- }
- "
- @click:clear="onClear"
- >
-
-
- {{ calendarIcon }}
-
-
-
-
-
-
-
- {{ hint }}
-
-
-
-
-
-
- {{ date.getDate() }}
-
-
-
-
-
-
-
-
-
diff --git a/packages/synapse-bridge/src/patterns/DatePickerField/config.ts b/packages/synapse-bridge/src/patterns/DatePickerField/config.ts
deleted file mode 100644
index 4698dee8fb..0000000000
--- a/packages/synapse-bridge/src/patterns/DatePickerField/config.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-export const config = {
- textField: {
- hideDetails: 'auto',
- persistentHint: true,
- validateOn: 'blur',
- color: '#0C419A',
- maxErrors: 5,
- },
- datePicker: {
- hideOffsetDates: true,
- dayNames: ['L', 'M', 'M', 'J', 'V', 'S', 'D'],
- locale: 'fr',
- },
- icon: {
- color: '#808080',
- },
-}
diff --git a/packages/synapse-bridge/src/patterns/DatePickerField/index.ts b/packages/synapse-bridge/src/patterns/DatePickerField/index.ts
deleted file mode 100644
index 63157f762c..0000000000
--- a/packages/synapse-bridge/src/patterns/DatePickerField/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { default } from './DatePickerField.vue'