- Delete DynamicReport* components and pivot types (PivotConfig, PivotResult, PivotFieldId, etc.) - Remove getDynamicReportData/getDynamicFilterValues from reportService - Strip pivotConfig/pivotResult from useReports hook and ReportsPage - Drop "dynamic" from ReportTab union - Remove reports.pivot.* and reports.dynamic i18n keys in FR and EN - Add skeletons for /reports/highlights, /trends, /compare, /category pages - Register the 4 new sub-routes in App.tsx - Add reports.hub, reports.viewMode, reports.empty, common.underConstruction keys - New shared ContextMenu component with click-outside + Escape handling - Refactor ChartContextMenu to compose generic ContextMenu - New ViewModeToggle with localStorage persistence via storageKey - New Sparkline (Recharts LineChart) for compact trends - Unit tests for readViewMode helper Fixes #69 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
import { readViewMode } from "./ViewModeToggle";
|
|
|
|
describe("readViewMode", () => {
|
|
const store = new Map<string, string>();
|
|
const mockLocalStorage = {
|
|
getItem: vi.fn((key: string) => store.get(key) ?? null),
|
|
setItem: vi.fn((key: string, value: string) => {
|
|
store.set(key, value);
|
|
}),
|
|
removeItem: vi.fn((key: string) => {
|
|
store.delete(key);
|
|
}),
|
|
clear: vi.fn(() => store.clear()),
|
|
key: vi.fn(),
|
|
length: 0,
|
|
};
|
|
|
|
beforeEach(() => {
|
|
store.clear();
|
|
vi.stubGlobal("localStorage", mockLocalStorage);
|
|
});
|
|
|
|
it("returns fallback when key is missing", () => {
|
|
expect(readViewMode("reports-viewmode-highlights")).toBe("chart");
|
|
});
|
|
|
|
it("returns 'chart' when stored value is 'chart'", () => {
|
|
store.set("reports-viewmode-highlights", "chart");
|
|
expect(readViewMode("reports-viewmode-highlights")).toBe("chart");
|
|
});
|
|
|
|
it("returns 'table' when stored value is 'table'", () => {
|
|
store.set("reports-viewmode-highlights", "table");
|
|
expect(readViewMode("reports-viewmode-highlights")).toBe("table");
|
|
});
|
|
|
|
it("ignores invalid stored values and returns fallback", () => {
|
|
store.set("reports-viewmode-highlights", "bogus");
|
|
expect(readViewMode("reports-viewmode-highlights", "table")).toBe("table");
|
|
});
|
|
|
|
it("respects custom fallback when provided", () => {
|
|
expect(readViewMode("reports-viewmode-compare", "table")).toBe("table");
|
|
});
|
|
});
|