Files
TREK/client/src/utils/pdfSwitch.test.ts
T
Maurice 12406bbbf4 feat(pdf): large text switch in the trip PDF preview (#2817)
A third switch next to the page break and transport notes switches scales the
day content's type by 1.35 and darkens its greys, for readers who print the
plan. Off by default and remembered per browser like the other two; the day
content's sizes and greys now come from three CSS variables on <body>.
2026-11-13 10:17:06 +01:00

43 lines
1.5 KiB
TypeScript

// FE-UTIL-PDFSWITCH-001 to FE-UTIL-PDFSWITCH-003
import { afterEach, describe, expect, it, vi } from 'vitest';
import { pdfSwitchOn, rememberPdfSwitch } from './pdfSwitch';
const KEY = 'trek_pdf_test_switch';
afterEach(() => {
vi.restoreAllMocks();
localStorage.removeItem(KEY);
});
describe('pdfSwitch', () => {
it('FE-UTIL-PDFSWITCH-001: a switch is on until it is turned off, and remembers either way', () => {
expect(pdfSwitchOn(KEY)).toBe(true);
rememberPdfSwitch(KEY, false);
expect(localStorage.getItem(KEY)).toBe('0');
expect(pdfSwitchOn(KEY)).toBe(false);
rememberPdfSwitch(KEY, true);
expect(localStorage.getItem(KEY)).toBe('1');
expect(pdfSwitchOn(KEY)).toBe(true);
});
it('FE-UTIL-PDFSWITCH-002: a blocked localStorage reads as on and drops the write without throwing', () => {
vi.spyOn(Storage.prototype, 'getItem').mockImplementation(() => {
throw new Error('blocked');
});
vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {
throw new Error('blocked');
});
expect(pdfSwitchOn(KEY)).toBe(true);
expect(pdfSwitchOn(KEY, false)).toBe(false);
expect(() => rememberPdfSwitch(KEY, false)).not.toThrow();
});
it('FE-UTIL-PDFSWITCH-003: a switch that defaults to off stays off until it is turned on', () => {
expect(pdfSwitchOn(KEY, false)).toBe(false);
rememberPdfSwitch(KEY, true);
expect(pdfSwitchOn(KEY, false)).toBe(true);
rememberPdfSwitch(KEY, false);
expect(pdfSwitchOn(KEY, false)).toBe(false);
});
});