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)", async () => {
const evil = "
";
const html = await ShowFile(
evil,
UUID,
new TextEncoder().encode("hi"),
"none",
null,
);
expect(html).not.toContain(evil);
expect(html).toContain("<img");
});
test("escapes filename in the encrypted overlay (no stored XSS)", async () => {
const evil = "";
const html = await ShowFile(evil, UUID, null, "none", null);
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");
});