From 7f264983178e0a81ff75126e2f5bae8cbcc7b8b1 Mon Sep 17 00:00:00 2001 From: Ku6epXBOCTuK Date: Tue, 6 Oct 2026 16:12:27 +0500 Subject: [PATCH] test: add tests, update coverage --- web/src/lib/registry-schema.test.ts | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/web/src/lib/registry-schema.test.ts b/web/src/lib/registry-schema.test.ts index 265cea4..3fcb9ff 100644 --- a/web/src/lib/registry-schema.test.ts +++ b/web/src/lib/registry-schema.test.ts @@ -146,6 +146,49 @@ describe("registry-schema: maxFromSource", () => { ); expect(s.x).toBe(831); }); + + it("effectiveMax: без maxFromSource и без исходника — статический max", () => { + const plain = toolSchema<{ a: number; b: number }>({ + a: field.number({ min: 0, max: 100, default: 0 }), + b: field.number({ + min: 0, + max: 20000, + default: 0, + maxFromSource: "width", + }), + }); + const s = sanitizeSchemaParams( + plain, + { a: 500, b: 5000 }, + { source: { width: 832, height: 1216 } }, + ); + expect(s.a).toBe(100); + const noSource = sanitizeSchemaParams(plain, { b: 5000 }); + expect(noSource.b).toBe(5000); + }); + + it("clampSourceAwareMaxes: без исходника и без изменений — те же params", () => { + const noSource = clampSourceAwareMaxes(cropLike, { x: 5000 }); + expect(noSource).toEqual({ x: 5000 }); + const untouched = clampSourceAwareMaxes( + cropLike, + { x: "мусор", size: { width: 100, height: 100 } }, + img, + ); + expect(untouched).toEqual({ + x: "мусор", + size: { width: 100, height: 100 }, + }); + }); + + it("clampSourceAwareMaxes: dimension с мусором пропускается", () => { + const out = clampSourceAwareMaxes( + cropLike, + { size: "не-объект" as unknown as Dimension }, + img, + ); + expect(out).toEqual({ size: "не-объект" }); + }); }); describe("registry-schema: source-aware dimension defaults", () => {