import { describe, expect, it } from "vitest"; import { getToolcraftSegmentedStaticFitError, renderToolcraftSegmentedStaticFitDocumentationSentence, TOOLCRAFT_SEGMENTED_STATIC_FIT, } from "./segmented-control-fit"; const SEGMENTED_STATIC_FIT_ERROR = `segmented controls must preserve cell padding: use at most ${TOOLCRAFT_SEGMENTED_STATIC_FIT.maxOptions} short options (max ${TOOLCRAFT_SEGMENTED_STATIC_FIT.maxOptionLabelLength} characters per label and ${TOOLCRAFT_SEGMENTED_STATIC_FIT.maxTotalLabelLength} total) or shorten labels first; if the compact names still exceed the budget, use a select dropdown instead.`; describe("Toolcraft segmented static-fit policy", () => { it("publishes the canonical immutable limits", () => { expect(TOOLCRAFT_SEGMENTED_STATIC_FIT).toEqual({ maxOptionLabelLength: 9, maxOptions: 4, maxTotalLabelLength: 24, }); expect(Object.isFrozen(TOOLCRAFT_SEGMENTED_STATIC_FIT)).toBe(true); }); it("renders the canonical policy-derived documentation sentence", () => { expect(renderToolcraftSegmentedStaticFitDocumentationSentence()).toBe( "Text segmented controls allow at most 4 options, no option label longer than 9 characters, and no more than 24 total option-label characters.", ); }); it("accepts labels at every static-fit boundary", () => { expect( getToolcraftSegmentedStaticFitError({ options: [ { label: "Ink Drops" }, { label: "Default" }, { label: "Solar" }, { label: "RGB" }, ], type: "segmented", }), ).toBeNull(); }); it.each([ { name: "more than four options", options: ["One", "Two", "Three", "Four", "Five"], }, { name: "a trimmed label longer than nine characters", options: [" Ten letters "], }, { name: "a trimmed total label length longer than 24 characters", options: ["123456789", "123456789", "1234567"], }, ])("rejects $name", ({ options }) => { expect( getToolcraftSegmentedStaticFitError({ options: options.map((label) => ({ label })), type: "segmented", }), ).toBe(SEGMENTED_STATIC_FIT_ERROR); }); it("does not apply segmented limits to select controls", () => { expect( getToolcraftSegmentedStaticFitError({ options: [{ label: "A label beyond every segmented limit" }], type: "select", }), ).toBeNull(); }); });