Files
paseo/packages/app/src/workspace-pins/target.test.ts
T
Mohamed Boudra 713a042dc5 Add pinnable new-tab targets to the tab row and sidebar
Any new-tab target (new agent, terminal, browser, or a terminal profile)
can be pinned as a quick-launch button. Pins are global client app state
(persisted), not daemon config, so the same set shows on every workspace;
profile pins resolve per host and are dropped where that profile is absent.

The sidebar mirror launches via a navigate-then-launch intent store rather
than calling the create handlers directly: terminal creation only works in
the mounted/focused workspace, so the sidebar requests the launch and the
workspace screen consumes it on focus.
2026-06-15 14:09:29 +07:00

48 lines
2.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { isTargetPinned, pinnedTargetKey, togglePinnedTarget } from "./target";
describe("pinnedTargetKey", () => {
it("uses the bare kind as the key for non-profile targets", () => {
expect(pinnedTargetKey({ kind: "draft" })).toBe("draft");
expect(pinnedTargetKey({ kind: "terminal" })).toBe("terminal");
expect(pinnedTargetKey({ kind: "browser" })).toBe("browser");
});
it("namespaces a profile target by its profile id", () => {
expect(pinnedTargetKey({ kind: "profile", profileId: "claude" })).toBe("profile:claude");
});
it("gives two profiles with different ids different keys", () => {
const claude = pinnedTargetKey({ kind: "profile", profileId: "claude" });
const codex = pinnedTargetKey({ kind: "profile", profileId: "codex" });
expect(claude).not.toBe(codex);
});
});
describe("togglePinnedTarget / isTargetPinned", () => {
it("pins a target that is not yet pinned", () => {
const pinned = togglePinnedTarget([], { kind: "terminal" });
expect(isTargetPinned(pinned, { kind: "terminal" })).toBe(true);
});
it("unpins a target that is already pinned", () => {
const pinned = togglePinnedTarget([{ kind: "browser" }], { kind: "browser" });
expect(isTargetPinned(pinned, { kind: "browser" })).toBe(false);
});
it("treats profiles with different ids as independent pins", () => {
const pinned = togglePinnedTarget([], { kind: "profile", profileId: "claude" });
expect(isTargetPinned(pinned, { kind: "profile", profileId: "claude" })).toBe(true);
expect(isTargetPinned(pinned, { kind: "profile", profileId: "codex" })).toBe(false);
});
it("unpins only the matching profile id", () => {
let pinned = togglePinnedTarget([], { kind: "profile", profileId: "claude" });
pinned = togglePinnedTarget(pinned, { kind: "profile", profileId: "codex" });
pinned = togglePinnedTarget(pinned, { kind: "profile", profileId: "claude" });
expect(isTargetPinned(pinned, { kind: "profile", profileId: "claude" })).toBe(false);
expect(isTargetPinned(pinned, { kind: "profile", profileId: "codex" })).toBe(true);
});
});