| 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({}); | |
| }); | |
| }); | |