File size: 1,213 Bytes
7614202 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import { describe, expect, it } from "vitest";
import { decodeShareState, DEFAULT_SHARE_STATE, encodeShareState, type ShareState } from "./url-state";
describe("share URLs", () => {
it("keeps the default URL clean", () => {
expect(encodeShareState(DEFAULT_SHARE_STATE)).toBe("");
});
it("uses readable names and compact values", () => {
const state: ShareState = {
width: 5120,
height: 2880,
symbol: "π¦",
density: 160,
size: 1.2,
variation: 0.8,
spacing: 1.1,
rotation: 35,
seed: 42,
};
expect(decodeShareState(encodeShareState(state))).toEqual(state);
expect(decodeURIComponent(encodeShareState(state))).toBe(
"canvas=5k&symbol=π¦&density=160&size=1.2&variation=0.8&spacing=1.1&rotation=35&seed=42",
);
});
it("supports custom canvas sizes and joined emoji", () => {
expect(decodeShareState("?canvas=1440x900&symbol=π¨βπ©βπ§βπ¦")).toEqual({
width: 1440,
height: 900,
symbol: "π¨βπ©βπ§βπ¦",
});
});
it("ignores unknown and out-of-range values", () => {
expect(decodeShareState("?canvas=10x10&density=900&size=nope&other=1")).toEqual({});
});
});
|