5349c3c4d5
- Poids/DSD en champs texte verrouillés sur les chiffres et désactivés. - Boutons de pesée : icône mdi:weight à gauche + gap-8. - Bloc « Poids à vide » réagencé en 3 lignes (contrepartie / Date-Poids-DSD-Immat / Tout format). - Omission des clés null dans les payloads (compact) : requis vides → message NotBlank métier au lieu d'une erreur de type. - Pesée obligatoire (RG-5.07) signalée inline sous Poids/DSD ; toutes les violations affichées d'un seul aller-retour. - Erreur d'immatriculation affichée uniquement sur le bloc « Poids à vide » (plus de doublon sur le bloc plein).
192 lines
8.8 KiB
TypeScript
192 lines
8.8 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest'
|
|
|
|
// `todayIso` est importé par le composable : on le stubbe pour une date déterministe.
|
|
vi.mock('~/shared/utils/date', () => ({ todayIso: () => '2026-06-22' }))
|
|
|
|
const { useWeighingTicketForm } = await import('../useWeighingTicketForm')
|
|
|
|
describe('useWeighingTicketForm', () => {
|
|
it('initialise les 2 blocs à la date du jour (RG-5.07), sans poids ni DSD', () => {
|
|
const form = useWeighingTicketForm()
|
|
expect(form.empty.date).toBe('2026-06-22')
|
|
expect(form.full.date).toBe('2026-06-22')
|
|
expect(form.empty.weight).toBeNull()
|
|
expect(form.empty.dsd).toBeNull()
|
|
expect(form.counterpartyType.value).toBeNull()
|
|
})
|
|
|
|
// ── Omission des requis vides (compact) ──────────────────────────────────
|
|
it('buildCreatePayload omet les clés null (requis vides absents, pas envoyés à null)', () => {
|
|
const form = useWeighingTicketForm()
|
|
// Formulaire vierge : counterpartyType / immatriculation non remplis.
|
|
const payload = form.buildCreatePayload()
|
|
// Absents (et non null) → le back applique NotBlank (message métier) plutôt
|
|
// qu'une erreur de type opaque (« doit être de type string »).
|
|
expect(payload).not.toHaveProperty('counterpartyType')
|
|
expect(payload).not.toHaveProperty('immatriculation')
|
|
expect(payload).not.toHaveProperty('emptyWeight')
|
|
// Les non-null restent : date du jour + booléen Tout format.
|
|
expect(payload.emptyDate).toBe('2026-06-22')
|
|
expect(payload.plateFreeFormat).toBe(false)
|
|
})
|
|
|
|
// ── Pesée obligatoire front-only (RG-5.07) ───────────────────────────────
|
|
it('missingWeighingFields liste Poids/DSD manquants, puis vide après pesée', () => {
|
|
const form = useWeighingTicketForm()
|
|
expect(form.missingWeighingFields('empty')).toEqual(['emptyWeight', 'emptyDsd'])
|
|
expect(form.missingWeighingFields('full')).toEqual(['fullWeight', 'fullDsd'])
|
|
|
|
form.applyReading(form.empty, { weight: 7150, dsd: 1, mode: 'AUTO' })
|
|
expect(form.missingWeighingFields('empty')).toEqual([])
|
|
})
|
|
|
|
// ── Contrepartie conditionnelle (RG-5.03) ────────────────────────────────
|
|
it('CLIENT : ne conserve que le client, purge supplier et otherLabel', () => {
|
|
const form = useWeighingTicketForm()
|
|
form.supplierIri.value = '/api/suppliers/3'
|
|
form.otherLabel.value = 'Particulier'
|
|
|
|
form.setCounterpartyType('CLIENT')
|
|
form.clientIri.value = '/api/clients/629'
|
|
|
|
expect(form.counterpartyField.value).toBe('client')
|
|
expect(form.supplierIri.value).toBeNull()
|
|
expect(form.otherLabel.value).toBeNull()
|
|
|
|
const payload = form.buildCreatePayload()
|
|
expect(payload.counterpartyType).toBe('CLIENT')
|
|
expect(payload.client).toBe('/api/clients/629')
|
|
expect(payload).not.toHaveProperty('supplier')
|
|
expect(payload).not.toHaveProperty('otherLabel')
|
|
})
|
|
|
|
it('FOURNISSEUR : ne conserve que le supplier', () => {
|
|
const form = useWeighingTicketForm()
|
|
form.clientIri.value = '/api/clients/1'
|
|
form.setCounterpartyType('FOURNISSEUR')
|
|
form.supplierIri.value = '/api/suppliers/7'
|
|
|
|
expect(form.counterpartyField.value).toBe('supplier')
|
|
expect(form.clientIri.value).toBeNull()
|
|
expect(form.buildCreatePayload().supplier).toBe('/api/suppliers/7')
|
|
})
|
|
|
|
it('AUTRE : ne conserve que le libellé libre', () => {
|
|
const form = useWeighingTicketForm()
|
|
form.clientIri.value = '/api/clients/1'
|
|
form.setCounterpartyType('AUTRE')
|
|
form.otherLabel.value = 'Reprise interne'
|
|
|
|
expect(form.counterpartyField.value).toBe('other')
|
|
expect(form.clientIri.value).toBeNull()
|
|
expect(form.buildCreatePayload().otherLabel).toBe('Reprise interne')
|
|
})
|
|
|
|
// ── Immatriculation / « Tout format » partagés entre blocs (RG-5.01) ──────
|
|
it('immatriculation et plateFreeFormat sont partagés (une seule valeur)', () => {
|
|
const form = useWeighingTicketForm()
|
|
form.immatriculation.value = 'AB-123-CD'
|
|
form.plateFreeFormat.value = true
|
|
|
|
// Les 2 payloads (création + finalisation) reflètent la même valeur.
|
|
expect(form.buildCreatePayload().immatriculation).toBe('AB-123-CD')
|
|
expect(form.buildCreatePayload().plateFreeFormat).toBe(true)
|
|
expect(form.buildFullPayload().immatriculation).toBe('AB-123-CD')
|
|
expect(form.buildFullPayload().plateFreeFormat).toBe(true)
|
|
})
|
|
|
|
// ── Application d'une lecture de pesée ────────────────────────────────────
|
|
it('applyReading remplit poids / DSD / mode du bloc visé', () => {
|
|
const form = useWeighingTicketForm()
|
|
form.applyReading(form.empty, { weight: 7150, dsd: 1, mode: 'AUTO' })
|
|
expect(form.empty.weight).toBe(7150)
|
|
expect(form.empty.dsd).toBe(1)
|
|
expect(form.empty.mode).toBe('AUTO')
|
|
expect(form.empty.manualNumber).toBeNull()
|
|
|
|
form.applyReading(form.full, { weight: 14300, dsd: 2, mode: 'MANUAL', manualNumber: 'PAP-555' })
|
|
expect(form.full.weight).toBe(14300)
|
|
expect(form.full.manualNumber).toBe('PAP-555')
|
|
})
|
|
|
|
it('buildCreatePayload porte la pesée à vide, buildFullPayload la pesée à plein', () => {
|
|
const form = useWeighingTicketForm()
|
|
form.setCounterpartyType('CLIENT')
|
|
form.clientIri.value = '/api/clients/1'
|
|
form.applyReading(form.empty, { weight: 7150, dsd: 1, mode: 'AUTO' })
|
|
form.applyReading(form.full, { weight: 14300, dsd: 2, mode: 'AUTO' })
|
|
|
|
const create = form.buildCreatePayload()
|
|
expect(create.emptyWeight).toBe(7150)
|
|
expect(create.emptyDsd).toBe(1)
|
|
expect(create.emptyMode).toBe('AUTO')
|
|
expect(create).not.toHaveProperty('fullWeight')
|
|
|
|
const full = form.buildFullPayload()
|
|
expect(full.fullWeight).toBe(14300)
|
|
expect(full.fullDsd).toBe(2)
|
|
expect(full.fullMode).toBe('AUTO')
|
|
})
|
|
|
|
// ── Pré-remplissage (écran Modification, ERP-190) ─────────────────────────
|
|
it('hydrate pré-remplit l\'état depuis le détail (dates ISO ramenées à YYYY-MM-DD)', () => {
|
|
const form = useWeighingTicketForm()
|
|
form.hydrate({
|
|
id: 9,
|
|
counterpartyType: 'CLIENT',
|
|
client: { '@id': '/api/clients/629' },
|
|
immatriculation: 'AB-123-CD',
|
|
plateFreeFormat: false,
|
|
emptyDate: '2026-06-17T09:00:00+02:00',
|
|
emptyWeight: 7150,
|
|
emptyDsd: 1,
|
|
emptyMode: 'AUTO',
|
|
fullDate: '2026-06-17T09:12:00+02:00',
|
|
fullWeight: 14300,
|
|
fullDsd: 2,
|
|
fullMode: 'AUTO',
|
|
})
|
|
|
|
expect(form.ticketId.value).toBe(9)
|
|
expect(form.counterpartyType.value).toBe('CLIENT')
|
|
expect(form.counterpartyField.value).toBe('client')
|
|
expect(form.clientIri.value).toBe('/api/clients/629')
|
|
expect(form.immatriculation.value).toBe('AB-123-CD')
|
|
// Date datetime back -> date seule pour MalioDate.
|
|
expect(form.empty.date).toBe('2026-06-17')
|
|
expect(form.full.date).toBe('2026-06-17')
|
|
expect(form.empty.weight).toBe(7150)
|
|
expect(form.full.weight).toBe(14300)
|
|
})
|
|
|
|
it('hydrate gère les champs null omis (skip_null_values) avec des défauts', () => {
|
|
const form = useWeighingTicketForm()
|
|
form.hydrate({ id: 5, counterpartyType: 'AUTRE', otherLabel: 'Reprise' })
|
|
expect(form.otherLabel.value).toBe('Reprise')
|
|
expect(form.supplierIri.value).toBeNull()
|
|
expect(form.plateFreeFormat.value).toBe(false)
|
|
// Pas de date back -> repli sur le jour (stub 2026-06-22).
|
|
expect(form.empty.date).toBe('2026-06-22')
|
|
expect(form.empty.weight).toBeNull()
|
|
})
|
|
|
|
it('buildUpdatePayload fusionne contrepartie + véhicule + les 2 pesées', () => {
|
|
const form = useWeighingTicketForm()
|
|
form.hydrate({
|
|
id: 9,
|
|
counterpartyType: 'CLIENT',
|
|
client: { '@id': '/api/clients/629' },
|
|
immatriculation: 'AB-123-CD',
|
|
emptyWeight: 7150, emptyDsd: 1, emptyMode: 'AUTO',
|
|
fullWeight: 14300, fullDsd: 2, fullMode: 'AUTO',
|
|
})
|
|
|
|
const payload = form.buildUpdatePayload()
|
|
expect(payload.counterpartyType).toBe('CLIENT')
|
|
expect(payload.client).toBe('/api/clients/629')
|
|
expect(payload.emptyWeight).toBe(7150)
|
|
expect(payload.fullWeight).toBe(14300)
|
|
expect(payload.immatriculation).toBe('AB-123-CD')
|
|
})
|
|
})
|