Files
tickte-system/tests/unit/creditFormat.test.mjs

39 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import test from 'node:test'
import assert from 'node:assert/strict'
import { loadModule } from './load.mjs'
// P6: Zeilen der Gutschriften (Liste und Detail) als reine Helfer, damit die Seiten keine Inline-Ausdruecke brauchen
const { creditStatus, creditActionLabel, creditStatusNote, checkGlyph, checkTone } = await loadModule('src/lib/creditFormat.js')
const NB = ' '
test('creditStatus: Tonnamen und Beschriftungen sind festgelegt', () => {
assert.deepEqual(creditStatus('offen'), { tone: 'warn', label: 'Zu prüfen' })
assert.deepEqual(creditStatus('rueckfrage'), { tone: 'muted', label: 'Rückfrage beim Kunden' })
assert.deepEqual(creditStatus('genehmigt'), { tone: 'ok', label: 'Genehmigt' })
assert.deepEqual(creditStatus('abgelehnt'), { tone: 'danger', label: 'Abgelehnt' })
assert.deepEqual(creditStatus('neu'), { tone: 'muted', label: 'neu' })
})
test('creditActionLabel: offene und rueckgefragte Antraege werden geprueft, alle anderen angesehen', () => {
assert.equal(creditActionLabel('offen'), 'Prüfen')
assert.equal(creditActionLabel('rueckfrage'), 'Prüfen')
for (const s of ['genehmigt', 'abgelehnt', 'neu', undefined]) assert.equal(creditActionLabel(s), 'Ansehen')
})
test('creditStatusNote: nur genehmigte Antraege tragen Betrag und Buchungsstand', () => {
assert.equal(creditStatusNote({ status: 'genehmigt', amountCents: 1250, appliedAt: '2026-10-01T10:00:00Z' }), `12,50${NB}€`)
assert.equal(creditStatusNote({ status: 'genehmigt', amountCents: 1250 }), `12,50${NB}€ · nicht gebucht`)
assert.equal(creditStatusNote({ status: 'offen', amountCents: 1250 }), '')
})
test('checkGlyph und checkTone: Zeichen und Ton der automatischen Pruefung', () => {
assert.equal(checkGlyph('ok'), '✓')
assert.equal(checkTone('ok'), 'ok')
assert.equal(checkGlyph('warn'), '!')
assert.equal(checkTone('warn'), 'warn')
assert.equal(checkGlyph('info'), 'i')
assert.equal(checkTone('info'), 'info')
assert.equal(checkGlyph(undefined), 'i')
assert.equal(checkTone(undefined), 'muted')
})