502d1a216b
- composable useFormErrors + util mapViolationsToRecord (shared) - formulaire Client (new + edit) : erreurs inline par champ (scalaires) et par ligne pour les collections (contacts / adresses / RIB) - blocs ClientContactBlock / ClientAddressBlock : prop errors - migration de useCategoryForm sur useFormErrors - convention documentee dans .claude/rules/frontend.md
65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { mount } from '@vue/test-utils'
|
|
import { defineComponent, h, ref, computed } from 'vue'
|
|
import { emptyContact } from '~/modules/commercial/types/clientForm'
|
|
import ClientContactBlock from '../ClientContactBlock.vue'
|
|
|
|
// Auto-imports Nuxt/Vue utilises sans import explicite par le composant.
|
|
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
|
vi.stubGlobal('ref', ref)
|
|
vi.stubGlobal('computed', computed)
|
|
|
|
/**
|
|
* Stub d'un champ Malio qui re-expose la prop `error` recue dans un attribut
|
|
* data-* : permet de verifier que le bloc propage bien `:errors[champ]` sur le
|
|
* bon champ (ERP-101 — mapping erreur 422 par champ, par ligne de collection).
|
|
*/
|
|
function errorProbe(testid: string) {
|
|
return defineComponent({
|
|
name: `Probe-${testid}`,
|
|
props: {
|
|
modelValue: { type: [String, Number, null], default: undefined },
|
|
error: { type: String, default: '' },
|
|
label: { type: String, default: '' },
|
|
readonly: { type: Boolean, default: false },
|
|
},
|
|
setup(props) {
|
|
return () => h('div', { 'data-testid': testid, 'data-error': props.error })
|
|
},
|
|
})
|
|
}
|
|
|
|
function mountBlock(errors?: Record<string, string>) {
|
|
return mount(ClientContactBlock, {
|
|
props: {
|
|
modelValue: emptyContact(),
|
|
title: 'Contact 1',
|
|
...(errors ? { errors } : {}),
|
|
},
|
|
global: {
|
|
stubs: {
|
|
MalioButtonIcon: true,
|
|
MalioInputPhone: true,
|
|
MalioInputText: errorProbe('contact-text'),
|
|
MalioInputEmail: errorProbe('contact-email'),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
describe('ClientContactBlock — mapping erreur par champ (ERP-101)', () => {
|
|
it('affiche l\'erreur serveur sur le champ email via la prop errors', () => {
|
|
const wrapper = mountBlock({ email: 'Adresse e-mail invalide.' })
|
|
|
|
const email = wrapper.find('[data-testid="contact-email"]')
|
|
expect(email.attributes('data-error')).toBe('Adresse e-mail invalide.')
|
|
})
|
|
|
|
it('laisse les champs sans erreur quand errors est absent', () => {
|
|
const wrapper = mountBlock()
|
|
|
|
const email = wrapper.find('[data-testid="contact-email"]')
|
|
expect(email.attributes('data-error')).toBe('')
|
|
})
|
|
})
|