The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import type { EnvironmentProject } from "@t3tools/client-runtime/state/models"; |
| 4 | import { EnvironmentId, ProjectId } from "@t3tools/contracts"; |
| 5 | |
| 6 | import { issueFilterProjects, issueListTargets, issuesSearchFromUrl } from "./issuesSearch.logic"; |
| 7 | |
| 8 | describe("issuesSearchFromUrl", () => { |
| 9 | it("replaces a malformed filter instead of letting the raw value through", () => { |
| 10 | // The router lays the validated keys over the raw search, so a key left out keeps its raw value. |
| 11 | const raw = { label: true, order: "oldest", assignee: " ", host: true }; |
| 12 | const search = { ...raw, ...issuesSearchFromUrl(raw) }; |
| 13 | expect(search.host).toBeUndefined(); |
| 14 | expect(search.label).toBeUndefined(); |
| 15 | expect(search.assignee).toBeUndefined(); |
| 16 | expect(search.order).toBeUndefined(); |
| 17 | expect(issuesSearchFromUrl({ label: "bug" }).label).toEqual(["bug"]); |
| 18 | expect(issuesSearchFromUrl({ label: ["bug", " ui "], order: "created" })).toMatchObject({ |
| 19 | label: ["bug", "ui"], |
| 20 | order: "created", |
| 21 | }); |
| 22 | expect( |
| 23 | issuesSearchFromUrl({ hideProjects: [["env", "web"], ["env"], "api", ["env", 3]] }) |
| 24 | .hideProjects, |
| 25 | ).toEqual([ |
| 26 | ["env", "web"], |
| 27 | ["env", "3"], |
| 28 | ]); |
| 29 | }); |
| 30 | }); |
| 31 | |
| 32 | describe("issueListTargets", () => { |
| 33 | it("leaves hidden projects out and skips an environment with every project hidden", () => { |
| 34 | const laptop = EnvironmentId.make("laptop"); |
| 35 | const vps = EnvironmentId.make("vps"); |
| 36 | const projects = [ |
| 37 | { environmentId: laptop, id: ProjectId.make("web") }, |
| 38 | { environmentId: laptop, id: ProjectId.make("api") }, |
| 39 | { environmentId: vps, id: ProjectId.make("docs") }, |
| 40 | ]; |
| 41 | const input = { state: "open" } as const; |
| 42 | const hidden = [ |
| 43 | [laptop, ProjectId.make("api")], |
| 44 | [laptop, ProjectId.make("removed")], |
| 45 | [vps, ProjectId.make("docs")], |
| 46 | ] as const; |
| 47 | expect(issueListTargets([laptop, vps], projects, hidden, input)).toEqual([ |
| 48 | { environmentId: laptop, input: { state: "open", excludeProjectIds: ["api"] } }, |
| 49 | ]); |
| 50 | // Before the project list loads, the saved choice still leaves its projects out. |
| 51 | expect(issueListTargets([laptop, vps], [], hidden, input)).toEqual([ |
| 52 | { environmentId: laptop, input: { state: "open", excludeProjectIds: ["api", "removed"] } }, |
| 53 | { environmentId: vps, input: { state: "open", excludeProjectIds: ["docs"] } }, |
| 54 | ]); |
| 55 | expect(issueListTargets([laptop, vps], projects, undefined, input)).toEqual([ |
| 56 | { environmentId: laptop, input }, |
| 57 | { environmentId: vps, input }, |
| 58 | ]); |
| 59 | }); |
| 60 | }); |
| 61 | |
| 62 | describe("issueFilterProjects", () => { |
| 63 | it("keeps every project, scratch ones too, as its own choice", () => { |
| 64 | const environmentId = EnvironmentId.make("env"); |
| 65 | const project = (id: string, isScratch = false) => |
| 66 | ({ |
| 67 | id: ProjectId.make(id), |
| 68 | environmentId, |
| 69 | title: "t3code", |
| 70 | workspaceRoot: `/work/${id}`, |
| 71 | repositoryIdentity: { canonicalKey: "github.com/pingdotgg/t3code" }, |
| 72 | isScratch, |
| 73 | }) as unknown as EnvironmentProject; |
| 74 | const choices = issueFilterProjects( |
| 75 | [project("main"), project("worktree"), project("scratch", true)], |
| 76 | new Map([[environmentId, "laptop"]]), |
| 77 | ); |
| 78 | expect(choices.map((choice) => [choice.id, choice.title])).toEqual([ |
| 79 | ["main", "t3code · laptop · /work/main"], |
| 80 | ["scratch", "t3code · laptop · /work/scratch"], |
| 81 | ["worktree", "t3code · laptop · /work/worktree"], |
| 82 | ]); |
| 83 | }); |
| 84 | }); |