feat(transport) : immatriculations LIOT sur 3 colonnes + filtre saisie (lettres/chiffres/tiret/point-virgule) (ERP-193)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { clampPercent, sanitizeDecimal } from '../numberInput'
|
||||
import { clampPercent, sanitizeDecimal, sanitizeLiotPlates } from '../numberInput'
|
||||
|
||||
describe('numberInput — saisie volume / indexation (ERP-170)', () => {
|
||||
it('sanitizeDecimal : ne garde que chiffres + un seul point', () => {
|
||||
@@ -19,4 +19,12 @@ describe('numberInput — saisie volume / indexation (ERP-170)', () => {
|
||||
expect(clampPercent('12,5')).toBe('12,5') // ≤ 100 → inchangé
|
||||
expect(clampPercent('')).toBe('')
|
||||
})
|
||||
|
||||
it('sanitizeLiotPlates : garde lettres/chiffres/tiret/point-virgule, retire espaces et reste', () => {
|
||||
expect(sanitizeLiotPlates('AB-123-CD;EF-456-GH')).toBe('AB-123-CD;EF-456-GH')
|
||||
expect(sanitizeLiotPlates('ab-123-cd ; ef-456-gh')).toBe('ab-123-cd;ef-456-gh') // espaces retirés
|
||||
expect(sanitizeLiotPlates('AB 123 CD')).toBe('AB123CD') // espaces retirés
|
||||
expect(sanitizeLiotPlates('AB.123/CD#42')).toBe('AB123CD42') // . / # retirés
|
||||
expect(sanitizeLiotPlates('')).toBe('')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -26,3 +26,13 @@ export function clampPercent(value: string): string {
|
||||
const n = Number(String(value ?? '').replace(',', '.').replace(/\s/g, ''))
|
||||
return (!Number.isNaN(n) && n > 100) ? '100' : value
|
||||
}
|
||||
|
||||
/**
|
||||
* Restreint la saisie des immatriculations LIOT : ne garde que lettres, chiffres,
|
||||
* tiret et point-virgule (séparateur de plaques). Les espaces et tout autre
|
||||
* caractère sont supprimés à la frappe / au collage. La normalisation finale
|
||||
* (majuscules + « ; » espacé) reste au back (RG-4.13).
|
||||
*/
|
||||
export function sanitizeLiotPlates(value: string): string {
|
||||
return (value ?? '').replace(/[^A-Za-z0-9;-]/g, '')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user