feat(email-renderer): generate bounded animated countdown images
This commit is contained in:
1 parent
1143da808f
commit
4df4173dfb
5 files changed
+83
-2
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { countdownLabel, renderCountdownGif } from "../src/countdown.ts";
|
||||
|
||||
test("countdown ticks across boundaries and stops at zero", () => {
|
||||
expect(countdownLabel(86401000, 0)).toBe("001D 00H 00M 01S");
|
||||
expect(countdownLabel(86401000, 2000)).toBe("000D 23H 59M 59S");
|
||||
expect(countdownLabel(1000, 2000)).toBe("000D 00H 00M 00S");
|
||||
expect(() => countdownLabel(NaN, 0)).toThrow();
|
||||
expect(() => renderCountdownGif(1000, 0, 61)).toThrow();
|
||||
});
|
||||
|
||||
test("countdown generates deterministic bounded non-looping GIF output", () => {
|
||||
const first = renderCountdownGif(60000, 0);
|
||||
expect(first).toEqual(renderCountdownGif(60000, 0));
|
||||
expect(new TextDecoder().decode(first.subarray(0,6))).toBe("GIF89a");
|
||||
expect(first[6]! + first[7]! * 256).toBe(320);
|
||||
expect(first[8]! + first[9]! * 256).toBe(64);
|
||||
expect(first.at(-1)).toBe(0x3b);
|
||||
expect(first.byteLength).toBeLessThan(100_000);
|
||||
expect(new TextDecoder().decode(first)).not.toContain("NETSCAPE2.0");
|
||||
expect(renderCountdownGif(0, 1000).byteLength).toBeLessThan(first.byteLength);
|
||||
});
|
||||
Reference in new issue
Block a user