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

issueSavedViews.test.ts

52 lines1.9 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import * as Schema from "effect/Schema";
4​
5import { EnvironmentId, ProjectId } from "@t3tools/contracts";
6​
7import { issueListPreferences, IssueListPreferencesSchema } from "./issueListPreferences";
8import { issueViewMatches } from "./issueSavedViews";
9​
10const decodePreferences = Schema.decodeOption(IssueListPreferencesSchema);
11​
12const preferences = {
13 who: "assigned",
14 status: "open",
15 hideProjects: [
16 [EnvironmentId.make("env-1"), ProjectId.make("project-1")],
17 [EnvironmentId.make("env-1"), ProjectId.make("project-2")],
18 ],
19 host: "github.com",
20 q: "crash",
21 label: ["bug", "priority"],
22 assignee: "octocat",
23 order: "created",
24} as const;
25const view = { id: "mine", name: "Issues Assigned to Me", preferences };
26​
27describe("saved issue views", () => {
28 it("matches regardless of label order", () => {
29 expect(issueViewMatches(view, { ...preferences, label: ["priority", "bug"], q: "crash" })).toBe(
30 true,
31 );
32 expect(issueViewMatches(view, { ...preferences, assignee: undefined })).toBe(false);
33 expect(issueViewMatches(view, { ...preferences, label: ["bug"] })).toBe(false);
34 expect(
35 issueViewMatches(view, {
36 ...preferences,
37 hideProjects: preferences.hideProjects.toReversed(),
38 }),
39 ).toBe(true);
40 expect(issueViewMatches(view, { ...preferences, hideProjects: undefined })).toBe(false);
41 });
42​
43 it("keeps a selection of every project within what it reads back", () => {
44 const many = Array.from(
45 { length: 1_001 },
46 (_, index) => [EnvironmentId.make("env-1"), ProjectId.make(`project-${index}`)] as const,
47 );
48 const stored = issueListPreferences({ ...preferences, hideProjects: many });
49 const restored = decodePreferences(stored);
50 expect(restored._tag === "Some" && restored.value.hideProjects).toEqual(many.slice(0, 1_000));
51 });
52});