Files
accounted/lib/reports/__tests__/report-search.test.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01: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(/[,;]/)
}
})
})