Em dashes (—) and en dashes (–) had spread across comments, docs, tests, and a few UI strings, reading as AI-generated boilerplate rather than house style. Replaced each with punctuation matching its context: colon for explanatory clauses, comma for asides, plain hyphen for numeric/legal ranges (e.g. "21-23§"), "to"/"till" for date ranges, parentheses for paired-dash asides. messages/en.json and messages/sv.json were fixed by hand together to keep sv/en in sync. Left untouched where the dash is the functional subject rather than decorative punctuation: date-range-parser.ts's separator regex, charset-repair.ts's CP1252 byte-mapping table (and its test), the SIE encoding mojibake docs, generic-csv.ts's minus-sign normalizer, the agent system-prompt files that already instruct against em dashes, and a golden iXBRL test fixture compared byte-for-byte. Also fixes two bugs surfaced along the way: an off-by-one in ApiKeysPanel's scope-label split (a leftover from an earlier partial pass), and a charset-repair test that had lost the literal en-dash it exists to verify. Regenerated the agent atom seed migration (skills:generate) since 27 SKILL.md files changed. Added a CLAUDE.md rule against em/en dashes, with an explicit carve-out for the functional-dash cases above. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
105 lines
3.8 KiB
TypeScript
105 lines
3.8 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import {
|
|
computeSuggestedPeriod,
|
|
suggestSeedDate,
|
|
resolveCurrentPeriodId,
|
|
} from '../suggest-fiscal-period'
|
|
|
|
type Range = { period_start: string; period_end: string }
|
|
|
|
const FY2024: Range = { period_start: '2024-01-01', period_end: '2024-12-31' }
|
|
const FY2026: Range = { period_start: '2026-01-01', period_end: '2026-12-31' }
|
|
|
|
describe('computeSuggestedPeriod', () => {
|
|
it('suggests a calendar year around the entry date when there are no periods', () => {
|
|
expect(computeSuggestedPeriod('2025-06-15', [])).toEqual({
|
|
name: 'Räkenskapsår 2025',
|
|
period_start: '2025-01-01',
|
|
period_end: '2025-12-31',
|
|
})
|
|
})
|
|
|
|
it('suggests a backfill year before the earliest period', () => {
|
|
expect(computeSuggestedPeriod('2025-06-15', [FY2026])).toEqual({
|
|
name: 'Räkenskapsår 2025',
|
|
period_start: '2025-01-01',
|
|
period_end: '2025-12-31',
|
|
})
|
|
})
|
|
|
|
it('suggests the missing year when the entry date is in an interior gap', () => {
|
|
// FY 2024 + FY 2026 exist, 2025 is the hole (interior-gap scenario).
|
|
expect(computeSuggestedPeriod('2025-06-15', [FY2024, FY2026])).toEqual({
|
|
name: 'Räkenskapsår 2025',
|
|
period_start: '2025-01-01',
|
|
period_end: '2025-12-31',
|
|
})
|
|
})
|
|
|
|
it('caps the gap suggestion so it never overlaps the right neighbour', () => {
|
|
// A six-month hole (Jan-Jun 2025) before a short FY 2025 H2 period.
|
|
const fy2025h2: Range = { period_start: '2025-07-01', period_end: '2025-12-31' }
|
|
expect(computeSuggestedPeriod('2025-03-15', [FY2024, fy2025h2])).toEqual({
|
|
name: 'Räkenskapsår 2025',
|
|
period_start: '2025-01-01',
|
|
period_end: '2025-06-30',
|
|
})
|
|
})
|
|
|
|
it('suggests the next forward year after the latest period', () => {
|
|
expect(computeSuggestedPeriod('2025-06-15', [FY2024])).toEqual({
|
|
name: 'Räkenskapsår 2025',
|
|
period_start: '2025-01-01',
|
|
period_end: '2025-12-31',
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('suggestSeedDate', () => {
|
|
const today = '2026-06-16'
|
|
|
|
it('returns today when there are no periods', () => {
|
|
expect(suggestSeedDate([], today)).toBe('2026-06-16')
|
|
})
|
|
|
|
it('returns the start of the earliest gap when one exists', () => {
|
|
expect(suggestSeedDate([FY2024, FY2026], today)).toBe('2025-01-01')
|
|
})
|
|
|
|
it('returns the day after the latest period when there is no gap', () => {
|
|
const fy2025: Range = { period_start: '2025-01-01', period_end: '2025-12-31' }
|
|
expect(suggestSeedDate([FY2024, fy2025], today)).toBe('2026-01-01')
|
|
})
|
|
|
|
it('returns the day after the only period for a single period', () => {
|
|
expect(suggestSeedDate([FY2024], today)).toBe('2025-01-01')
|
|
})
|
|
})
|
|
|
|
describe('resolveCurrentPeriodId', () => {
|
|
const P2024 = { id: 'p2024', period_start: '2024-01-01', period_end: '2024-12-31' }
|
|
const P2025 = { id: 'p2025', period_start: '2025-01-01', period_end: '2025-12-31' }
|
|
const P2026 = { id: 'p2026', period_start: '2026-01-01', period_end: '2026-12-31' }
|
|
|
|
it('returns null when there are no periods', () => {
|
|
expect(resolveCurrentPeriodId([], '2026-06-29')).toBeNull()
|
|
})
|
|
|
|
it('returns the period that contains today', () => {
|
|
expect(resolveCurrentPeriodId([P2024, P2025, P2026], '2026-06-29')).toBe('p2026')
|
|
})
|
|
|
|
it('is order-independent', () => {
|
|
expect(resolveCurrentPeriodId([P2026, P2024, P2025], '2025-03-01')).toBe('p2025')
|
|
})
|
|
|
|
it('falls back to the most recent started period when today sits in a gap after the last year', () => {
|
|
// Today is in 2027 but only periods up to 2026 exist (next year not created yet).
|
|
expect(resolveCurrentPeriodId([P2024, P2025, P2026], '2027-02-15')).toBe('p2026')
|
|
})
|
|
|
|
it('falls back to the earliest period when every period is still upcoming', () => {
|
|
expect(resolveCurrentPeriodId([P2025, P2026], '2024-06-01')).toBe('p2025')
|
|
})
|
|
})
|