import { expect, test } from "bun:test"; import { humanReadableTime, ShowFile } from "./components"; const UUID = "00000000-0000-0000-0000-000000000000"; test("escapes filename in the file view (no stored XSS)", () => { const evil = ""; const html = ShowFile({ filename: evil, uuid: UUID, filetype: "none", deleteAt: null, size: 2, preview: { kind: "text", html: "hi" }, }); expect(html).not.toContain(evil); expect(html).toContain("<img"); }); test("escapes filename in the encrypted overlay (no stored XSS)", () => { const evil = ""; const html = ShowFile({ filename: evil, uuid: UUID, filetype: "none", deleteAt: null, size: null, preview: { kind: "await" }, }); expect(html).not.toContain(evil); expect(html).toContain("<script>"); }); test("humanReadableTime breaks a total down (no spurious 'expired')", () => { expect(humanReadableTime(4320)).toBe("3 days"); // exact multiple of a day expect(humanReadableTime(120)).toBe("2 hours"); // exact multiple of an hour expect(humanReadableTime(1)).toBe("1 minute"); expect(humanReadableTime(1501)).toBe("1 day 1 hour 1 minute"); expect(humanReadableTime(0)).toBe("expired"); expect(humanReadableTime(-5)).toBe("expired"); });