Open History to see the last commit
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
53 // regression: a pasted search over 200 characters reset every remembered filter
54 it("keeps every filter when long text is remembered", () => {
55 const [long, kept] = [`${"a".repeat(199)}${"😀".repeat(30)}`, "a".repeat(199)];
56 const label = Array.from({ length: 21 }, (_, index) => `label-${index}`);
57 const text = (value: string) => ({ host: value, q: value, assignee: value });
58 const stored = issueListPreferences({ ...preferences, ...text(long), label: [long, ...label] });
59 const restored = decodePreferences(stored);
60 const expected = { ...preferences, ...text(kept), label: [kept, ...label.slice(0, 19)] };
61 expect(restored._tag === "Some" && restored.value).toEqual(expected);
62 });
63});