import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import { queryForLocation, loadedQueryPeriod } from '../src/queryLoadingScope.ts'; test('automatic current snapshots follow the next workspace release after a reload', () => { const urlQuery=queryForLocation({year:2026,view:'product',releaseId:'r1'}); const restored=JSON.parse(JSON.stringify(urlQuery)); assert.equal(restored.releaseId,undefined); assert.equal(restored.releaseId || 'r2','r2'); }); test('explicit historical links stay pinned across reloads and current-release changes', () => { const restored=JSON.parse(JSON.stringify(queryForLocation({year:2026,view:'product',releaseId:'r2'},'r1'))); assert.equal(restored.releaseId || 'r2','r1'); }); test('failed drilled trends cannot ready a replacement table or enable stale exports', () => { const stage=fs.readFileSync(new URL('../src/StageProductPage.tsx',import.meta.url),'utf8'); const query=fs.readFileSync(new URL('../src/QueryPage.tsx',import.meta.url),'utf8'); const readyExpression=stage.match(/const tableReady=([^;]+);/)[1]; const stageReady=new Function('current','drilledProduct','trendResponse','trendKey','trendLoading','trendError',`return ${readyExpression}`); assert.equal(stageReady({},'B',{key:'A'},'B',false,'offline'),false); assert.equal(stageReady({},'B',{key:'B'},'B',false,''),true); assert.equal(stageReady({},'',null,'B',false,'offline'),true); const exportExpression=query.match(/exporting=\{summaryExporting\} exportDisabled=\{([^\n]+)\}/)[1]; const disabled=new Function('queryBusy','summaryBusy','tableReady','summaryMetricsData','drilledProduct','trendLoading','currentTrendError','drilledTrendData','visibleRows',`return ${exportExpression}`); assert.equal(disabled(false,false,false,{},'B',false,'offline',Array(12).fill({}),[]),true); }); test('cross-year retained scope has a readable label when year is omitted',()=>{assert.equal(loadedQueryPeriod({}), '全部年份');});