feat(downloads): make a GIF in the clip panel and the editor, and show a shared one as itself
The clip panel and the editor get a Video / GIF choice with the GIF's size, the size it is expected to come out at, and what that size means (no moving link preview over 15 MB, refused over 30 MB). A range longer than a GIF may be leaves Make unavailable with its reason. The editor makes one GIF per kept segment; Join says why it is unavailable instead of going dead. The share page shows a picture as itself with its Download, and a picture in a folder opens above the list.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { estimateGif, GIF_MAX_BYTES, GIF_PREVIEW_MAX_BYTES, gifVerdict } from "./gif";
|
||||
|
||||
const MB = 1024 * 1024;
|
||||
|
||||
describe("estimateGif", () => {
|
||||
it("gives the measured range for a 16:9 picture", () => {
|
||||
const e = estimateGif(30, 480, 16 / 9);
|
||||
expect(e.lo / MB).toBeCloseTo(12, 5);
|
||||
expect(e.hi / MB).toBeCloseTo(30, 5);
|
||||
});
|
||||
|
||||
it("grows with the length and the size", () => {
|
||||
expect(estimateGif(20, 480, 16 / 9).hi).toBeGreaterThan(estimateGif(10, 480, 16 / 9).hi);
|
||||
expect(estimateGif(10, 640, 16 / 9).hi).toBeGreaterThan(estimateGif(10, 480, 16 / 9).hi);
|
||||
});
|
||||
|
||||
it("counts the pixels of the shape: a square holds more than 16:9, a tall one as many", () => {
|
||||
const wide = estimateGif(10, 480, 16 / 9).hi;
|
||||
expect(estimateGif(10, 480, 1).hi).toBeCloseTo(wide * (16 / 9), 3);
|
||||
expect(estimateGif(10, 480, 9 / 16).hi).toBeCloseTo(wide, 3);
|
||||
});
|
||||
|
||||
it("falls back to 16:9 for a shape it cannot read", () => {
|
||||
expect(estimateGif(10, 480, 0).hi).toBe(estimateGif(10, 480, 16 / 9).hi);
|
||||
expect(estimateGif(10, 480, Number.NaN).hi).toBe(estimateGif(10, 480, 16 / 9).hi);
|
||||
});
|
||||
});
|
||||
|
||||
describe("gifVerdict", () => {
|
||||
it("refuses past the length cap, whatever the size", () => {
|
||||
expect(gifVerdict(30.2, { hi: 1 })).toBe("too_long");
|
||||
expect(gifVerdict(30, { hi: 1 })).toBe("ok");
|
||||
});
|
||||
|
||||
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 })).toBe("no_preview");
|
||||
expect(gifVerdict(10, { hi: GIF_PREVIEW_MAX_BYTES + 1 })).toBe("no_preview");
|
||||
expect(gifVerdict(10, { hi: GIF_PREVIEW_MAX_BYTES })).toBe("ok");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user