import { describe, expect, it } from "vitest"; import { filterSavedIdentities, identityFilterLabel, resolveCustomIdentityKind, sortSavedIdentities, } from "./identity-helper"; const identities = [ { value: "alpha@example.com", type: "email" as const, lastUsed: 10, useCount: 2 }, { value: "beta", type: "username" as const, lastUsed: 30, useCount: 1 }, { value: "gamma@example.com", type: "email" as const, lastUsed: 30, useCount: 4 }, { value: "delta", type: "username" as const, lastUsed: 5, useCount: 9 }, ]; describe("identity-helper", () => { it("sorts identities by most recently used first", () => { expect(sortSavedIdentities(identities).map((identity) => identity.value)).toEqual([ "gamma@example.com", "beta", "alpha@example.com", "delta", ]); }); it("filters identities by type and search text", () => { expect(filterSavedIdentities(identities, "alpha", "both").map((identity) => identity.value)).toEqual([ "alpha@example.com", ]); expect(filterSavedIdentities(identities, "", "email").map((identity) => identity.value)).toEqual([ "gamma@example.com", "alpha@example.com", ]); expect(filterSavedIdentities(identities, "", "username").map((identity) => identity.value)).toEqual([ "beta", "delta", ]); }); it("treats no-match custom identity as username unless the field or text says email", () => { expect(resolveCustomIdentityKind("june", "both", "username")).toBe("username"); expect(resolveCustomIdentityKind("june@example.com", "both", "username")).toBe("email"); expect(resolveCustomIdentityKind("june", "email", "username")).toBe("email"); expect(resolveCustomIdentityKind("june", "username", "email")).toBe("username"); }); it("labels the filter modes clearly", () => { expect(identityFilterLabel("both")).toBe("Both"); expect(identityFilterLabel("email")).toBe("Emails"); expect(identityFilterLabel("username")).toBe("Usernames"); }); });