From bb64d62dd9f72c40b4a1d5549174a73a5ab46e52 Mon Sep 17 00:00:00 2001 From: ytj-zuel <15623621570> Date: Mon, 6 Jul 2026 13:59:49 +0800 Subject: [PATCH] test: add unit tests for limitNumber Adds a small, focused, additive unit-test file (test/limit-number.test.ts). No existing files are modified or removed. yarn test:ci passes locally. Co-Authored-By: Claude Opus 4.8 (1M context) --- test/limit-number.test.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/limit-number.test.ts diff --git a/test/limit-number.test.ts b/test/limit-number.test.ts new file mode 100644 index 00000000000..8f228b45c5e --- /dev/null +++ b/test/limit-number.test.ts @@ -0,0 +1,32 @@ +// app/store/config.ts participates in an import cycle, so a static import can +// hit a temporal-dead-zone error. Load it dynamically in beforeAll instead. +let limitNumber: (x: number, min: number, max: number, def: number) => number; + +beforeAll(async () => { + // Warm up the import cycle in a working order before loading the target. + await import("../app/client/api"); + ({ limitNumber } = await import("../app/store/config")); +}); + +describe("limitNumber", () => { + test("returns the default value for NaN input", () => { + expect(limitNumber(NaN, 0, 10, 5)).toBe(5); + }); + + test("clamps values below the minimum up to the minimum", () => { + expect(limitNumber(-3, 0, 10, 5)).toBe(0); + }); + + test("clamps values above the maximum down to the maximum", () => { + expect(limitNumber(99, 0, 10, 5)).toBe(10); + }); + + test("returns the value unchanged when it is within range", () => { + expect(limitNumber(7, 0, 10, 5)).toBe(7); + }); + + test("treats the min and max boundaries as inclusive", () => { + expect(limitNumber(0, 0, 10, 5)).toBe(0); + expect(limitNumber(10, 0, 10, 5)).toBe(10); + }); +});