import { describe, expect, it } from "vitest"; import { buildBrushDabs, clampBrushOptions, hexToRgb } from "./brush-painter"; describe("brush painter pure helpers", () => { it("parses valid hex colors and falls back to black", () => { expect(hexToRgb("#ff8040")).toEqual({ r: 255, g: 128, b: 64 }); expect(hexToRgb("00aaee")).toEqual({ r: 0, g: 170, b: 238 }); expect(hexToRgb("nope")).toEqual({ r: 0, g: 0, b: 0 }); }); it("clamps invalid brush options", () => { expect(clampBrushOptions({ color: "#fff", size: 0, opacity: 2, hardness: -1 })).toEqual({ color: "#fff", size: 1, opacity: 1, hardness: 0, }); expect(clampBrushOptions({ color: "#000", size: Number.NaN, opacity: Number.NaN, hardness: Number.NaN })).toEqual({ color: "#000", size: 1, opacity: 1, hardness: 1, }); }); it("interpolates brush dabs including endpoints", () => { expect(buildBrushDabs(0, 0, 4, 0, 4)).toEqual([ { x: 0, y: 0 }, { x: 1, y: 0 }, { x: 2, y: 0 }, { x: 3, y: 0 }, { x: 4, y: 0 }, ]); expect(buildBrushDabs(2, 3, 2, 3, 10)).toEqual([{ x: 2, y: 3 }, { x: 2, y: 3 }]); }); });