- Hooks: per-instance timers in useReady; cleanup for useIntersectionObserver; useWebSocket no longer reconnects after unmount/refresh, drains the queue and dispatches non-JSON messages - Modal/Popover/Dropdown: onClose only on close, Escape to close, no stray DOM props, hooks before early return, scrollbar-aware positioning, top-left/top-right dropdown positions - Elements: Toast/Search/StarRating per-instance timers, Pagination labels and empty state, Breadcrumbs titles, LinkList dividers/props, segment-wise active-link matching (new utils/link-matches-path), Table object cells - Form: Select with a default option is changeable, Input clear notifies controlled parents and copy works on textareas, Checkbox random label, NumberInputButtons runaway interval, upload prop/spread fixes - Layout: Button disabled while loading, Stack gap and Span truncate via inline styles, Img fallbackImageSrc, className/JSDoc fixes - Editors/MDX/AI: TinyMCE id/cleanup/stale handler/duplicate scripts, AceEditor debounce, markdown heights and frontmatter regex, last assistant message, AIPromptBlock prompt ref - Utils: fetchApi headers/FormData/fetchOptions/no mutation, base64 file names and read errors, slugify underscore trim, serializeQuery zero values - Tests for fetchApi, link matching, slugify and serializeQuery - AGENTS.md updated for the package layout Co-Authored-By: Claude Opus 5.5 <[email protected]>
66 lines
2.1 KiB
TypeScript
66 lines
2.1 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import twuiSerializeQuery from "./serialize-query";
|
|
|
|
describe("twuiSerializeQuery", () => {
|
|
test("returns '?' for non-object input", () => {
|
|
expect(twuiSerializeQuery("string" as any)).toBe("?");
|
|
});
|
|
|
|
test("returns '?' for array input", () => {
|
|
expect(twuiSerializeQuery([1, 2] as any)).toBe("?");
|
|
});
|
|
|
|
test("returns '?' for null input", () => {
|
|
expect(twuiSerializeQuery(null as any)).toBe("?");
|
|
});
|
|
|
|
test("serializes simple object", () => {
|
|
const result = twuiSerializeQuery({ foo: "bar" });
|
|
expect(result).toBe("?foo=bar");
|
|
});
|
|
|
|
test("serializes multiple keys", () => {
|
|
const result = twuiSerializeQuery({ a: "1", b: "2" });
|
|
expect(result).toContain("a=1");
|
|
expect(result).toContain("b=2");
|
|
});
|
|
|
|
test("serializes numeric value", () => {
|
|
const result = twuiSerializeQuery({ page: 2 });
|
|
expect(result).toContain("page=2");
|
|
});
|
|
|
|
test("skips empty key", () => {
|
|
const result = twuiSerializeQuery({ "": "value", foo: "bar" });
|
|
expect(result).not.toContain("=value");
|
|
expect(result).toContain("foo=bar");
|
|
});
|
|
|
|
test("skips falsy value", () => {
|
|
const result = twuiSerializeQuery({ empty: "", foo: "bar" });
|
|
expect(result).not.toContain("empty=");
|
|
expect(result).toContain("foo=bar");
|
|
});
|
|
|
|
test("JSON-encodes object values", () => {
|
|
const result = twuiSerializeQuery({ filter: { field: "name" } });
|
|
expect(result).toContain("filter=");
|
|
expect(result).toContain("field");
|
|
});
|
|
|
|
test("URL-encodes values", () => {
|
|
const result = twuiSerializeQuery({ q: "hello world" });
|
|
expect(result).toContain("q=hello%20world");
|
|
});
|
|
|
|
test("serializes boolean value as string", () => {
|
|
const result = twuiSerializeQuery({ active: true as any });
|
|
expect(result).toContain("active=true");
|
|
});
|
|
|
|
test("keeps zero values", () => {
|
|
const result = twuiSerializeQuery({ page: 0, foo: "bar" });
|
|
expect(result).toContain("page=0");
|
|
});
|
|
});
|