Files
paseo/packages/app/src/workspace-pins/target.test.ts
T
3e8dce7d7c Hide browser shortcuts outside the desktop app (#2116)
* fix: hide browser pin on non-Electron web

Browser is desktop-only, but the pinned shortcut bar still rendered a
New browser pin on web where createBrowser is a silent no-op.

Skip browser pins in usePinnedLaunchers when not Electron, and drop
browser from default pinned targets so new users only get terminal.

* fix(app): preserve browser pin defaults on desktop

Keep platform availability in the pinned-target policy so regular web hides browser shortcuts without changing Electron defaults.

---------

Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
2026-07-16 12:36:20 +00:00

72 lines
2.8 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
isPinnedTargetAvailable,
isTargetPinned,
pinnedTargetKey,
togglePinnedTarget,
} from "./target";
describe("isPinnedTargetAvailable", () => {
it("only offers browser targets in Electron", () => {
const browser = { kind: "browser" } as const;
expect(isPinnedTargetAvailable(browser, { isElectron: true })).toBe(true);
expect(isPinnedTargetAvailable(browser, { isElectron: false })).toBe(false);
});
it("offers cross-platform targets outside Electron", () => {
const environment = { isElectron: false };
expect(isPinnedTargetAvailable({ kind: "draft" }, environment)).toBe(true);
expect(isPinnedTargetAvailable({ kind: "terminal" }, environment)).toBe(true);
expect(isPinnedTargetAvailable({ kind: "profile", profileId: "claude" }, environment)).toBe(
true,
);
});
});
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);
});
});