| 1 | import { EnvironmentId } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { loadPreferenceForWeight, summarizeLoadPreferences } from "./LoadBalancingSettings"; |
| 5 | |
| 6 | const machines = [ |
| 7 | { environmentId: EnvironmentId.make("a"), label: "alvin" }, |
| 8 | { environmentId: EnvironmentId.make("b"), label: "bb-1" }, |
| 9 | { environmentId: EnvironmentId.make("c"), label: "ProMini" }, |
| 10 | ]; |
| 11 | |
| 12 | describe("loadPreferenceForWeight", () => { |
| 13 | it("snaps legacy slider weights onto the four preferences", () => { |
| 14 | expect(loadPreferenceForWeight(undefined)).toBe(50); |
| 15 | expect(loadPreferenceForWeight(0)).toBe(0); |
| 16 | expect(loadPreferenceForWeight(10)).toBe(25); |
| 17 | expect(loadPreferenceForWeight(50)).toBe(50); |
| 18 | expect(loadPreferenceForWeight(80)).toBe(100); |
| 19 | }); |
| 20 | }); |
| 21 | |
| 22 | describe("summarizeLoadPreferences", () => { |
| 23 | it("is empty when every machine is at Normal", () => { |
| 24 | expect(summarizeLoadPreferences(machines, { a: 50 })).toBeNull(); |
| 25 | }); |
| 26 | |
| 27 | it("lists only the machines that differ from Normal, in list order", () => { |
| 28 | expect(summarizeLoadPreferences(machines, { b: 100, c: 0 })).toBe( |
| 29 | "bb-1 prefer · ProMini manual only", |
| 30 | ); |
| 31 | }); |
| 32 | }); |