import { describe, expect, it } from 'vitest'
import { clampPercent, sanitizeDecimal } from '../numberInput'

describe('numberInput — saisie volume / indexation (ERP-170)', () => {
    it('sanitizeDecimal : ne garde que chiffres + un seul point', () => {
        expect(sanitizeDecimal('30')).toBe('30')
        expect(sanitizeDecimal('30.5')).toBe('30.5')
        expect(sanitizeDecimal('30,5 kg')).toBe('30.5') // virgule FR → point ; espace + lettres retirés
        expect(sanitizeDecimal('1.2.3')).toBe('1.23') // un seul point conservé
        expect(sanitizeDecimal('abc12.3x')).toBe('12.3')
        expect(sanitizeDecimal('')).toBe('')
    })

    it('clampPercent : plafonne à 100, laisse le reste tel quel', () => {
        expect(clampPercent('50')).toBe('50')
        expect(clampPercent('100')).toBe('100')
        expect(clampPercent('150')).toBe('100')
        expect(clampPercent('100.01')).toBe('100')
        expect(clampPercent('12,5')).toBe('12,5') // ≤ 100 → inchangé
        expect(clampPercent('')).toBe('')
    })
})
