|
1 | 1 | import { describe, it, expect } from "vitest"; |
2 | | -import { groupByRepo, computePageLayout, slicePageGroups, type RepoGroup } from "../../src/app/lib/grouping"; |
| 2 | +import { groupByRepo, computePageLayout, slicePageGroups, isUserInvolved, type RepoGroup } from "../../src/app/lib/grouping"; |
3 | 3 |
|
4 | 4 | interface Item { |
5 | 5 | repoFullName: string; |
@@ -59,6 +59,43 @@ describe("groupByRepo", () => { |
59 | 59 | }); |
60 | 60 | }); |
61 | 61 |
|
| 62 | +describe("isUserInvolved", () => { |
| 63 | + const base = { repoFullName: "org/repo", userLogin: "author", assigneeLogins: [] as string[] }; |
| 64 | + const monitored = new Set(["org/monitored"]); |
| 65 | + |
| 66 | + it("returns true when surfacedBy includes user", () => { |
| 67 | + expect(isUserInvolved({ ...base, surfacedBy: ["me"] }, "me", monitored)).toBe(true); |
| 68 | + }); |
| 69 | + |
| 70 | + it("returns false when surfacedBy excludes user", () => { |
| 71 | + expect(isUserInvolved({ ...base, surfacedBy: ["other"] }, "me", monitored)).toBe(false); |
| 72 | + }); |
| 73 | + |
| 74 | + it("returns true for non-monitored item with no surfacedBy (fetched via involves:{user})", () => { |
| 75 | + expect(isUserInvolved(base, "me", monitored)).toBe(true); |
| 76 | + }); |
| 77 | + |
| 78 | + it("returns true for monitored repo item when user is author", () => { |
| 79 | + expect(isUserInvolved({ ...base, repoFullName: "org/monitored", userLogin: "me" }, "me", monitored)).toBe(true); |
| 80 | + }); |
| 81 | + |
| 82 | + it("returns true for monitored repo item when user is assignee", () => { |
| 83 | + expect(isUserInvolved({ ...base, repoFullName: "org/monitored", assigneeLogins: ["me"] }, "me", monitored)).toBe(true); |
| 84 | + }); |
| 85 | + |
| 86 | + it("returns false for monitored repo item when user is not author/assignee", () => { |
| 87 | + expect(isUserInvolved({ ...base, repoFullName: "org/monitored" }, "me", monitored)).toBe(false); |
| 88 | + }); |
| 89 | + |
| 90 | + it("returns true for monitored repo item when user is in reviewerLogins", () => { |
| 91 | + expect(isUserInvolved({ ...base, repoFullName: "org/monitored" }, "me", monitored, ["me"])).toBe(true); |
| 92 | + }); |
| 93 | + |
| 94 | + it("does not check reviewerLogins when not provided", () => { |
| 95 | + expect(isUserInvolved({ ...base, repoFullName: "org/monitored" }, "me", monitored)).toBe(false); |
| 96 | + }); |
| 97 | +}); |
| 98 | + |
62 | 99 | describe("computePageLayout", () => { |
63 | 100 | it("returns single page for empty groups", () => { |
64 | 101 | const result = computePageLayout([], 10); |
|
0 commit comments