fix(downloads): a GIF's size warning judges the size it shows

This commit is contained in:
2026-11-11 02:19:56 +01:00
parent 27ccf253f5
commit 0b92b40db5
2 changed files with 22 additions and 5 deletions
+17 -3
View File
@@ -1,5 +1,11 @@
import { describe, expect, it } from "vitest";
import { estimateGif, GIF_MAX_BYTES, GIF_PREVIEW_MAX_BYTES, gifVerdict } from "./gif";
import {
estimateGif,
gifEstimateText,
GIF_MAX_BYTES,
GIF_PREVIEW_MAX_BYTES,
gifVerdict,
} from "./gif";
const MB = 1024 * 1024;
@@ -34,9 +40,17 @@ describe("gifVerdict", () => {
});
it("warns past the server's cap, then past the link preview's", () => {
expect(gifVerdict(10, { hi: GIF_MAX_BYTES + 1 })).toBe("may_fail");
expect(gifVerdict(10, { hi: GIF_MAX_BYTES + 0.6 * MB })).toBe("may_fail");
expect(gifVerdict(10, { hi: GIF_MAX_BYTES })).toBe("no_preview");
expect(gifVerdict(10, { hi: GIF_PREVIEW_MAX_BYTES + 1 })).toBe("no_preview");
expect(gifVerdict(10, { hi: GIF_PREVIEW_MAX_BYTES + 0.6 * MB })).toBe("no_preview");
expect(gifVerdict(10, { hi: GIF_PREVIEW_MAX_BYTES })).toBe("ok");
});
it("judges the size the reader is shown: a high end shown as 30 MB is not past 30 MB", () => {
// 30 s at 480 lands a hair over 30 MiB, and reads "about 12–30 MB".
const hi = GIF_MAX_BYTES + 0.4 * MB;
expect(gifEstimateText({ lo: 12 * MB, hi }, "en").hi).toBe("30");
expect(gifVerdict(30, { hi })).toBe("no_preview");
expect(gifVerdict(10, { hi: GIF_PREVIEW_MAX_BYTES + 0.4 * MB })).toBe("ok");
});
});