test(date) : couvre la saisie manuelle de MalioDate
This commit is contained in:
@@ -271,5 +271,84 @@ describe('MalioDate', () => {
|
|||||||
await wrapper.setProps({modelValue: '2026-05-19'})
|
await wrapper.setProps({modelValue: '2026-05-19'})
|
||||||
expect(wrapper.text()).not.toContain('Date invalide')
|
expect(wrapper.text()).not.toContain('Date invalide')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('par défaut (editable=false) l\'input reste readonly et affiche la valeur', () => {
|
||||||
|
const wrapper = mountDate({modelValue: '2026-05-19'})
|
||||||
|
const input = wrapper.get('[data-test="date-input"]')
|
||||||
|
expect(input.attributes('readonly')).toBeDefined()
|
||||||
|
expect((input.element as HTMLInputElement).value).toBe('19/05/2026')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('editable=true : l\'input n\'est plus readonly', () => {
|
||||||
|
const wrapper = mountDate({editable: true})
|
||||||
|
expect(wrapper.get('[data-test="date-input"]').attributes('readonly')).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('émet l\'ISO sur saisie clavier valide au blur', async () => {
|
||||||
|
const wrapper = mountDate({editable: true})
|
||||||
|
const input = wrapper.get('[data-test="date-input"]')
|
||||||
|
await input.setValue('19/05/2026')
|
||||||
|
await input.trigger('blur')
|
||||||
|
expect(wrapper.emitted('update:modelValue')?.at(-1)).toEqual(['2026-05-19'])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('garde le texte et affiche « Date invalide » sur saisie invalide au blur', async () => {
|
||||||
|
const wrapper = mountDate({editable: true})
|
||||||
|
const input = wrapper.get('[data-test="date-input"]')
|
||||||
|
await input.setValue('32/13/2026')
|
||||||
|
await input.trigger('blur')
|
||||||
|
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
|
||||||
|
expect((input.element as HTMLInputElement).value).toBe('32/13/2026')
|
||||||
|
expect(input.attributes('aria-invalid')).toBe('true')
|
||||||
|
expect(wrapper.text()).toContain('Date invalide')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('passe en erreur si la date saisie est hors min/max', async () => {
|
||||||
|
const wrapper = mountDate({editable: true, min: '2026-05-10', max: '2026-05-20'})
|
||||||
|
const input = wrapper.get('[data-test="date-input"]')
|
||||||
|
await input.setValue('25/12/2026')
|
||||||
|
await input.trigger('blur')
|
||||||
|
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
|
||||||
|
expect(wrapper.text()).toContain('Date invalide')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('émet null sur saisie vidée au blur', async () => {
|
||||||
|
const wrapper = mountDate({editable: true, modelValue: '2026-05-19'})
|
||||||
|
const input = wrapper.get('[data-test="date-input"]')
|
||||||
|
await input.setValue('')
|
||||||
|
await input.trigger('blur')
|
||||||
|
expect(wrapper.emitted('update:modelValue')?.at(-1)).toEqual([null])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('efface l\'erreur de saisie quand on sélectionne une date au calendrier', async () => {
|
||||||
|
const wrapper = mountDate({editable: true})
|
||||||
|
const input = wrapper.get('[data-test="date-input"]')
|
||||||
|
await input.setValue('32/13/2026')
|
||||||
|
await input.trigger('blur')
|
||||||
|
expect(wrapper.text()).toContain('Date invalide')
|
||||||
|
await input.trigger('focus')
|
||||||
|
await wrapper.get('[data-test="day"][data-iso="2026-05-19"]').trigger('click')
|
||||||
|
expect(wrapper.emitted('update:modelValue')?.at(-1)).toEqual(['2026-05-19'])
|
||||||
|
expect(wrapper.text()).not.toContain('Date invalide')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('valide et ferme le popover sur Entrée', async () => {
|
||||||
|
const wrapper = mountDate({editable: true})
|
||||||
|
const input = wrapper.get('[data-test="date-input"]')
|
||||||
|
await input.trigger('focus')
|
||||||
|
expect(wrapper.find('[data-test="popover"]').exists()).toBe(true)
|
||||||
|
await input.setValue('19/05/2026')
|
||||||
|
await input.trigger('keydown.enter')
|
||||||
|
expect(wrapper.emitted('update:modelValue')?.at(-1)).toEqual(['2026-05-19'])
|
||||||
|
expect(wrapper.find('[data-test="popover"]').exists()).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('utilise le message invalidMessage personnalisé', async () => {
|
||||||
|
const wrapper = mountDate({editable: true, invalidMessage: 'Format incorrect'})
|
||||||
|
const input = wrapper.get('[data-test="date-input"]')
|
||||||
|
await input.setValue('99/99/9999')
|
||||||
|
await input.trigger('blur')
|
||||||
|
expect(wrapper.text()).toContain('Format incorrect')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user