import assert from "node:assert/strict"; import test from "node:test"; import { IMAGE_KEYS, deviceClass, readImageChoice, writeImageChoice } from "./mail-images.js"; function memory() { const data = {}; return { getItem: (key) => (key in data ? data[key] : null), setItem: (key, value) => { data[key] = value; } }; } test("pictures are asked for by default and the choice is kept per device kind", () => { const store = memory(); assert.equal(readImageChoice("touch", store), "ask"); assert.equal(writeImageChoice("desktop", "auto", store), "auto"); assert.equal(readImageChoice("desktop", store), "auto"); assert.equal(readImageChoice("touch", store), "ask"); assert.equal(writeImageChoice("touch", "anything", store), "ask"); assert.ok(IMAGE_KEYS.desktop !== IMAGE_KEYS.touch); }); test("a blocked store and a missing media query fall back to the safe choice", () => { const broken = { getItem() { throw new Error("blocked"); }, setItem() { throw new Error("blocked"); } }; assert.equal(readImageChoice("desktop", broken), "ask"); assert.equal(writeImageChoice("desktop", "auto", broken), "auto"); assert.equal(readImageChoice("desktop", null), "ask"); assert.equal(deviceClass(null), "desktop"); assert.equal(deviceClass(function () { return { matches: true }; }), "touch"); assert.equal(deviceClass(function () { throw new Error("x"); }), "desktop"); });