Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

issuesSearch.logic.test.ts

46 lines1.9 KB

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, 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 });
23});
24​
25describe("issueFilterProjects", () => {
26 it("keeps every project on one repository as its own choice", () => {
27 const environmentId = EnvironmentId.make("env");
28 const project = (id: string, isScratch = false) =>
29 ({
30 id: ProjectId.make(id),
31 environmentId,
32 title: "t3code",
33 workspaceRoot: `/work/${id}`,
34 repositoryIdentity: { canonicalKey: "github.com/pingdotgg/t3code" },
35 isScratch,
36 }) as unknown as EnvironmentProject;
37 const choices = issueFilterProjects(
38 [project("main"), project("worktree"), project("scratch", true)],
39 new Map([[environmentId, "laptop"]]),
40 );
41 expect(choices.map((choice) => [choice.id, choice.title])).toEqual([
42 ["main", "t3code · laptop · /work/main"],
43 ["worktree", "t3code · laptop · /work/worktree"],
44 ]);
45 });
46});