Rechtliches: Anzeige-Texte der Vertragsliste als Lib mit Test

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-10-06 14:41:26 +00:00
1 parent 625efc7f18
commit 313ead77f4
2 files changed
+96

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { loadModule } from './load.mjs'
const { costLabel, termLabel, noticeLabel, deadlineView } = await loadModule('src/lib/legalView.js')
const NB = ' '
const today = '2026-09-30'
const active = (noticeBy, periodEnd = '2027-03-12') => ({ state: 'active', noticeBy, periodEnd })
const v = (r) => deadlineView(r, today)
test('Vertragsliste: Kosten, Laufzeit, Frist wie bisher', () => {
assert.equal(costLabel({ cost: null }), '–')
assert.equal(costLabel({ cost: 12.5, costInterval: 'month' }), `12,50${NB}€/Monat`)
assert.equal(costLabel({ cost: 120, costInterval: 'year' }), `120,00${NB}€/Jahr`)
assert.equal(termLabel({}), '–')
assert.equal(termLabel({ termMonths: 0 }), 'jederzeit kündbar')
assert.equal(termLabel({ termMonths: 12, renewalMonths: 12 }), '12 Monate, dann je 12 Monate')
assert.equal(termLabel({ termMonths: 24, renewalMonths: 0 }), '24 Monate, endet danach')
assert.equal(noticeLabel({}), '–')
assert.equal(noticeLabel({ noticeValue: 1, noticeUnit: 'months' }), '1 Monate')
assert.equal(noticeLabel({ noticeValue: 14, noticeUnit: 'days' }), '14 Tage')
})
test('deadlineView: Badge nur bei rot und orange, Text wörtlich wie bisher', () => {
assert.deepEqual(v(active('2026-10-15')), {
text: 'kündbar bis 15.10.2026 (Periode endet 12.03.2027)',
lead: 'kündbar bis 15.10.2026', rest: '(Periode endet 12.03.2027)', badge: 'danger', muted: false,
})
assert.equal(v(active('2026-10-30')).badge, 'danger') // 30 Tage
assert.equal(v(active('2026-10-31')).badge, 'warn') // 31 Tage
assert.equal(v(active('2026-12-29')).badge, 'warn') // 90 Tage
const normal = v(active('2026-12-30')) // 91 Tage
assert.deepEqual([normal.badge, normal.lead === normal.text, normal.rest], [null, true, ''])
})
test('deadlineView: Text und Dämpfung der übrigen Zustände', () => {
assert.deepEqual([v({ state: 'anytime' }).text, v({ state: 'anytime' }).muted], ['jederzeit kündbar', false])
assert.equal(v({ state: 'ends', periodEnd: '2027-01-31' }).text, 'endet am 31.01.2027')
assert.deepEqual([v({ state: 'ended', periodEnd: '2026-01-31' }).text, v({ state: 'ended', periodEnd: '2026-01-31' }).muted], ['beendet seit 31.01.2026', true])
assert.equal(v({ state: 'cancelled', periodEnd: '2027-01-31' }).text, 'gekündigt zum 31.01.2027')
assert.equal(v({ state: 'cancelled', periodEnd: null }).text, 'gekündigt')
assert.deepEqual([v({ state: 'incomplete' }).text, v({ state: 'incomplete' }).muted], ['Fristen fehlen', true])
})