The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { EnvironmentId, ProjectId } from "@t3tools/contracts"; |
| 2 | import { savedViewNameError } from "@t3tools/client-runtime/saved-views"; |
| 3 | import { describe, expect, it } from "vite-plus/test"; |
| 4 | |
| 5 | import { |
| 6 | pullRequestListPreferences, |
| 7 | type PullRequestListPreferences, |
| 8 | } from "./pullRequestListPreferences"; |
| 9 | import { pullRequestSavedViewPatch, pullRequestViewMatches } from "./pullRequestSavedViews"; |
| 10 | |
| 11 | const preferences = { |
| 12 | involvement: "reviewing", |
| 13 | state: "open", |
| 14 | environmentId: EnvironmentId.make("remote"), |
| 15 | projectId: ProjectId.make("project"), |
| 16 | host: "github.example.com", |
| 17 | q: "label:bug authentication", |
| 18 | draft: "hide", |
| 19 | review: "review-required", |
| 20 | checks: "passing", |
| 21 | author: "me", |
| 22 | labels: ["bug", "priority"], |
| 23 | sort: "updated", |
| 24 | } as const satisfies PullRequestListPreferences; |
| 25 | const view = { id: "review", name: "PRs Requesting My Review", preferences }; |
| 26 | |
| 27 | describe("saved PR views", () => { |
| 28 | it("replaces all filters while preserving the selected PR", () => { |
| 29 | const current = { |
| 30 | ...preferences, |
| 31 | repository: "org/repo", |
| 32 | number: 42, |
| 33 | selectedHost: "github.com", |
| 34 | selectedEnvironmentId: EnvironmentId.make("other"), |
| 35 | selectedProjectId: ProjectId.make("other"), |
| 36 | }; |
| 37 | const restored = { |
| 38 | ...current, |
| 39 | ...pullRequestSavedViewPatch({ involvement: "all", state: "merged" }), |
| 40 | }; |
| 41 | expect(pullRequestListPreferences(restored)).toEqual({ involvement: "all", state: "merged" }); |
| 42 | expect(restored).toMatchObject({ |
| 43 | repository: "org/repo", |
| 44 | number: 42, |
| 45 | selectedHost: "github.com", |
| 46 | selectedEnvironmentId: "other", |
| 47 | selectedProjectId: "other", |
| 48 | }); |
| 49 | }); |
| 50 | |
| 51 | it("restores scoped filters without conflating a project on two environments", () => { |
| 52 | const previous = { involvement: "all", state: "closed" } as const; |
| 53 | expect( |
| 54 | pullRequestListPreferences({ |
| 55 | ...previous, |
| 56 | ...pullRequestSavedViewPatch(preferences), |
| 57 | }), |
| 58 | ).toEqual(preferences); |
| 59 | expect( |
| 60 | pullRequestViewMatches(view, { |
| 61 | ...preferences, |
| 62 | environmentId: EnvironmentId.make("another"), |
| 63 | }), |
| 64 | ).toBe(false); |
| 65 | }); |
| 66 | |
| 67 | it("matches default sorting and label sets regardless of selection or label order", () => { |
| 68 | const defaultView = { ...view, preferences: { ...preferences, sort: undefined } }; |
| 69 | expect( |
| 70 | pullRequestViewMatches(defaultView, { |
| 71 | ...preferences, |
| 72 | labels: ["priority", "bug"], |
| 73 | sort: "ready", |
| 74 | }), |
| 75 | ).toBe(true); |
| 76 | expect(pullRequestViewMatches(view, { ...preferences, q: "different" })).toBe(false); |
| 77 | expect(pullRequestViewMatches(view, { ...preferences, labels: ["bug"] })).toBe(false); |
| 78 | }); |
| 79 | |
| 80 | it("rejects blank and duplicate names while allowing a view to keep its own name", () => { |
| 81 | expect(savedViewNameError(" ", [view])).toBeTruthy(); |
| 82 | expect(savedViewNameError("x".repeat(81), [view])).toBeTruthy(); |
| 83 | expect(savedViewNameError(" PRS REQUESTING MY REVIEW ", [view])).toBeTruthy(); |
| 84 | expect(savedViewNameError(view.name, [view], view.id)).toBeNull(); |
| 85 | expect(savedViewNameError(" My PRs ", [view])).toBeNull(); |
| 86 | }); |
| 87 | }); |