import test from 'node:test'; import assert from 'node:assert/strict'; import { selectTrendPeriod } from '../src/trendPeriodSelection.ts'; const current={year:2026,month:9,quarter:3,period:'month'}; test('clicking the selected month returns to annual scope; another month selects that month',()=>{ assert.deepEqual(selectTrendPeriod('2026-09',current),{...current,period:'year'}); assert.deepEqual(selectTrendPeriod('2026-08',current),{...current,month:8}); assert.deepEqual(selectTrendPeriod('08月',current),{...current,month:8}); }); test('quarter selection and toggling preserve the selected year',()=>{ assert.deepEqual(selectTrendPeriod('2025-Q4',current),{...current,year:2025,quarter:4,period:'quarter'}); assert.deepEqual(selectTrendPeriod('2026-Q3',{...current,period:'quarter'}),{...current,period:'year'}); }); test('annual selection and invalid values cannot produce an invalid month',()=>{ assert.deepEqual(selectTrendPeriod('2025',current),{...current,year:2025,period:'year'}); assert.equal(selectTrendPeriod('2026-13',current),current); assert.equal(selectTrendPeriod('invalid',current),current); });