import { describe, expect, it } from "vitest"; import { resolveToolcraftAppIdentity } from "./app-identity"; describe("resolveToolcraftAppIdentity", () => { it("normalizes an explicit app identity", () => { const identity = resolveToolcraftAppIdentity({ controlsTitle: "Controls", identity: { id: " My Visual Tool ", title: "My Visual Tool", }, legacyAppId: "legacy-settings-id", }); expect(identity).toEqual({ id: "my-visual-tool", title: "My Visual Tool", }); expect(Object.isFrozen(identity)).toBe(true); }); it("uses the legacy settings transfer app id only as a compatibility seed", () => { expect( resolveToolcraftAppIdentity({ controlsTitle: "Current Controls Title", legacyAppId: " Legacy Settings ID ", }), ).toEqual({ id: "legacy-settings-id", title: "Current Controls Title", }); }); it.each(["", "!!!"])( "does not fall through from an explicit normalization-empty id %j", (id) => { expect( resolveToolcraftAppIdentity({ controlsTitle: "Controls Fallback", identity: { id, title: "Explicit Title", }, legacyAppId: "legacy-fallback", }), ).toEqual({ id: "toolcraft-app", title: "Explicit Title", }); }, ); it("falls back to the controls title and stable defaults", () => { expect( resolveToolcraftAppIdentity({ controlsTitle: "Fallback Tool", }), ).toEqual({ id: "fallback-tool", title: "Fallback Tool", }); expect(resolveToolcraftAppIdentity({})).toEqual({ id: "toolcraft-app", title: "Toolcraft App", }); }); });