Files
accounted/lib/skatteverket/__tests__/interest-period.test.ts
T
Jakob WennbergandClaude Opus 5 fa394e3759 fix(skattekonto): look-alike beslut rows, the list-to-voucher round trip, makulerad rendering, huvudbok discoverability (#1297)
Four fixes from the exit mail Anders Orback (Center Node AB) sent hours
after churning. His five points were mostly one job: reconciling
skattekontot against banken before årsredovisningen.

Skattekonto look-alike rows. Skatteverket splits a retroactive
omprövningsbeslut across every month it re-charges and sends one
transaction per month, sharing date, text and amount; only
ranteberakningsdatum separates them, and we stored it but rendered it
nowhere. A real company posted 15 such vouchers (67 785 kr across Feb
2025-Apr 2026) unable to tell them from duplicates of the automatic
hämtning. Surface the field when it carries information: its month
differs from the Datum column, or another row in the same band is
otherwise indistinguishable.

The list-to-voucher round trip. The verifikat list collapsed to a
skeleton on every refetch and sprang back, moving rows under the
pointer; only the first load shows a skeleton now. Filter state is
React-only, so leaving the list loses it: add a hover-revealed
open-in-new-tab affordance on the voucher list and the skattekonto page,
where the link had been behind a hand-rolled opacity-0 that coarse
pointers never trigger.

Makulerad rendering. A stornoed verifikat now reads as struck out, per
data cell rather than on the row, because text-decoration propagates and
a child cannot opt out.

Vouchers-per-account discoverability. /reports/huvudbok?account=1930
already existed; the palette matcher requires every token and the entry
never contained the word "verifikat". Add ReportDescriptor.searchTerms
plus a report-library search box.

Also fixes a false "Saknar underlag" compliance chip that flashed before
attachment counts resolved, and a keyboard-access regression where
HOVER_REVEAL_CLASS carried focus-visible only, hiding controls inside a
non-focusable wrapper from keyboard users.

No migration. No write paths, storno paths or posted entries touched.

Follow-ups filed: #1300 #1301 #1302 #1303 #1304 #1305 #1306 #1307 #1308.
Open decision: #1305 (Omförd vs Makulerad).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 18:27:29 +02:00

95 lines
3.0 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import {
rowsNeedingInterestDate,
type InterestPeriodRow,
} from '@/lib/skatteverket/interest-period'
function row(overrides: Partial<InterestPeriodRow> & { id: string }): InterestPeriodRow {
return {
displayDate: '2026-05-07',
transaktionstext: 'Debiterad preliminärskatt',
belopp: -4519,
ranteberakningsdatum: '2026-05-12',
...overrides,
}
}
describe('rowsNeedingInterestDate', () => {
it('marks every row of a retroactive omprövningsbeslut', () => {
// The real Center Node AB case: one beslut dated 2026-05-07 re-charging
// preliminary tax across 15 months. Same date, text and amount on all of
// them; only ränteberäkningsdatum differs.
const rows = [
'2025-02-13',
'2025-03-13',
'2025-04-15',
'2026-03-13',
'2026-04-14',
].map((d, i) =>
row({
id: `r${i}`,
transaktionstext: 'Beslut 260506 debiterad preliminärskatt',
ranteberakningsdatum: d,
}),
)
const marked = rowsNeedingInterestDate(rows)
expect(marked.size).toBe(5)
for (const r of rows) expect(marked.has(r.id)).toBe(true)
})
it('leaves an ordinary row alone when the interest date is in the shown month', () => {
const marked = rowsNeedingInterestDate([
row({ id: 'a', displayDate: '2026-05-07', ranteberakningsdatum: '2026-05-12' }),
])
expect(marked.size).toBe(0)
})
it('marks a row whose interest date falls in another month', () => {
const marked = rowsNeedingInterestDate([
row({ id: 'a', displayDate: '2026-05-07', ranteberakningsdatum: '2025-11-13' }),
])
expect([...marked]).toEqual(['a'])
})
it('marks same-month twins that would otherwise render identically', () => {
// Guards the case the month rule alone would miss: a decision split
// inside one month still produces two indistinguishable rows.
const marked = rowsNeedingInterestDate([
row({ id: 'a', ranteberakningsdatum: '2026-05-12' }),
row({ id: 'b', ranteberakningsdatum: '2026-05-20' }),
])
expect(marked.has('a')).toBe(true)
expect(marked.has('b')).toBe(true)
})
it('does not mark rows that differ in amount or text', () => {
const marked = rowsNeedingInterestDate([
row({ id: 'a', belopp: -4519 }),
row({ id: 'b', belopp: -1570 }),
row({ id: 'c', transaktionstext: 'Intäktsränta' }),
])
expect(marked.size).toBe(0)
})
it('skips rows with no interest date rather than rendering an empty marker', () => {
const marked = rowsNeedingInterestDate([
row({ id: 'a', ranteberakningsdatum: null }),
row({ id: 'b', ranteberakningsdatum: null }),
])
expect(marked.size).toBe(0)
})
it('tolerates malformed dates without throwing', () => {
const marked = rowsNeedingInterestDate([
row({ id: 'a', displayDate: '', ranteberakningsdatum: '2026-05-12' }),
])
expect(marked.has('a')).toBe(true)
})
it('handles an empty band', () => {
expect(rowsNeedingInterestDate([]).size).toBe(0)
})
})