Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import type { EnvironmentProject } from "@t3tools/client-runtime/state/models";
4import { EnvironmentId, ProjectId } from "@t3tools/contracts";
5
6import { issueFilterProjects, issueListTargets, issuesSearchFromUrl } from "./issuesSearch.logic";
7
8describe("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 it("cuts a long search before an emoji the limit would split", () => {
32 expect(issuesSearchFromUrl({ q: `${"a".repeat(199)}😀 rest` }).q).toBe("a".repeat(199));
33 });
34});
35
36describe("issueListTargets", () => {
37 it("leaves hidden projects out and skips an environment with every project hidden", () => {
38 const laptop = EnvironmentId.make("laptop");
39 const vps = EnvironmentId.make("vps");
40 const projects = [
41 { environmentId: laptop, id: ProjectId.make("web") },
42 { environmentId: laptop, id: ProjectId.make("api") },
43 { environmentId: vps, id: ProjectId.make("docs") },
44 ];
45 const input = { state: "open" } as const;
46 const hidden = [
47 [laptop, ProjectId.make("api")],
48 [laptop, ProjectId.make("removed")],
49 [vps, ProjectId.make("docs")],
50 ] as const;
51 expect(issueListTargets([laptop, vps], projects, hidden, input)).toEqual([
52 { environmentId: laptop, input: { state: "open", excludeProjectIds: ["api"] } },
53 ]);
54 // Before the project list loads, the saved choice still leaves its projects out.
55 expect(issueListTargets([laptop, vps], [], hidden, input)).toEqual([
56 { environmentId: laptop, input: { state: "open", excludeProjectIds: ["api", "removed"] } },
57 { environmentId: vps, input: { state: "open", excludeProjectIds: ["docs"] } },
58 ]);
59 expect(issueListTargets([laptop, vps], projects, undefined, input)).toEqual([
60 { environmentId: laptop, input },
61 { environmentId: vps, input },
62 ]);
63 });
64});
65
66describe("issueFilterProjects", () => {
67 it("keeps every project, scratch ones too, as its own choice", () => {
68 const environmentId = EnvironmentId.make("env");
69 const project = (id: string, isScratch = false) =>
70 ({
71 id: ProjectId.make(id),
72 environmentId,
73 title: "t3code",
74 workspaceRoot: `/work/${id}`,
75 repositoryIdentity: { canonicalKey: "github.com/pingdotgg/t3code" },
76 isScratch,
77 }) as unknown as EnvironmentProject;
78 const choices = issueFilterProjects(
79 [project("main"), project("worktree"), project("scratch", true)],
80 new Map([[environmentId, "laptop"]]),
81 );
82 expect(choices.map((choice) => [choice.id, choice.title])).toEqual([
83 ["main", "t3code · laptop · /work/main"],
84 ["scratch", "t3code · laptop · /work/scratch"],
85 ["worktree", "t3code · laptop · /work/worktree"],
86 ]);
87 });
88});