Files
accounted/lib/reports/__tests__/report-search.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

62 lines
2.3 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { REPORT_CATALOG, reportMatchesQuery, getReport } from '@/lib/reports/catalog'
describe('reportMatchesQuery', () => {
it('returns everything for an empty query', () => {
expect(reportMatchesQuery('Huvudbok', '')).toBe(true)
expect(reportMatchesQuery('Huvudbok', ' ')).toBe(true)
})
it('requires every token, so extra words narrow', () => {
expect(reportMatchesQuery('Huvudbok verifikat per konto', 'verifikat konto')).toBe(true)
expect(reportMatchesQuery('Huvudbok verifikat per konto', 'verifikat faktura')).toBe(false)
})
it('ignores case and diacritics in both directions', () => {
expect(reportMatchesQuery('Stäm av bank', 'stam av')).toBe(true)
expect(reportMatchesQuery('Stam av bank', 'stäm')).toBe(true)
expect(reportMatchesQuery('Balansrapport', 'BALANS')).toBe(true)
})
it('matches on a substring so partial words still find the report', () => {
expect(reportMatchesQuery('Momsdeklaration', 'moms')).toBe(true)
})
})
describe('huvudbok is reachable by the words a bookkeeper uses', () => {
const huvudbok = getReport('huvudbok')!
const haystack = `Huvudbok ${huvudbok.searchTerms ?? ''}`
// The phrase from the churn report that returned zero hits before.
it.each([
'verifikat per konto',
'verifikationer',
'kontoanalys',
'kontokort',
'stäm av konto',
'account statement',
])('finds huvudbok for %j', (query) => {
expect(reportMatchesQuery(haystack, query)).toBe(true)
})
})
describe('catalog search terms', () => {
it('never lets searchTerms shadow another report by slug', () => {
// A report's synonyms must not be so broad that they swallow a query
// aimed squarely at a different report's own name.
const huvudbok = getReport('huvudbok')!
const terms = huvudbok.searchTerms ?? ''
for (const slug of ['balansrapport', 'resultatrapport', 'vat-declaration']) {
expect(reportMatchesQuery(terms, slug)).toBe(false)
}
})
it('keeps searchTerms lowercase-comparable and free of punctuation noise', () => {
for (const report of REPORT_CATALOG) {
if (!report.searchTerms) continue
expect(report.searchTerms).toBe(report.searchTerms.trim())
expect(report.searchTerms).not.toMatch(/[,;]/)
}
})
})