|
1 | 1 | import { ProjectId, type PullRequestSummary, type VcsStatusResult } from "@t3tools/contracts"; |
2 | 2 | import { describe, expect, it } from "@effect/vitest"; |
3 | | -import { |
4 | | - GitMergeIcon, |
5 | | - GitPullRequestClosedIcon, |
6 | | - GitPullRequestDraftIcon, |
7 | | - GitPullRequestIcon, |
8 | | -} from "lucide-react"; |
9 | 3 |
|
10 | 4 | import { |
11 | 5 | ChangeRequestStatusIcon, |
12 | 6 | prStatusIndicator, |
13 | | - settledPrHoverColorClass, |
| 7 | + resolveThreadPullRequestBadgePresentation, |
14 | 8 | } from "./ThreadStatusIndicators"; |
15 | 9 | import { newestPullRequestSummary } from "../state/pullRequests"; |
| 10 | +import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons"; |
16 | 11 |
|
17 | 12 | describe("ChangeRequestStatusIcon", () => { |
18 | 13 | it.each([ |
19 | | - ["open", "open", false, GitPullRequestIcon], |
20 | | - ["draft", "open", true, GitPullRequestDraftIcon], |
21 | | - ["closed", "closed", false, GitPullRequestClosedIcon], |
22 | | - ["merged", "merged", false, GitMergeIcon], |
| 14 | + ["open", "open", false, PullRequestGlyph.pullRequest], |
| 15 | + ["draft", "open", true, PullRequestGlyph.draft], |
| 16 | + ["closed", "closed", false, PullRequestGlyph.closed], |
| 17 | + ["merged", "merged", false, PullRequestGlyph.merged], |
23 | 18 | ] as const)("uses the %s pull request glyph", (_label, state, isDraft, expectedIcon) => { |
24 | 19 | expect(ChangeRequestStatusIcon({ state, isDraft }).type).toBe(expectedIcon); |
25 | 20 | }); |
@@ -119,18 +114,131 @@ describe("prStatusIndicator", () => { |
119 | 114 | }); |
120 | 115 | }); |
121 | 116 |
|
122 | | -describe("settledPrHoverColorClass", () => { |
123 | | - it.each([ |
124 | | - ["open", "text-emerald-600"], |
125 | | - ["merged", "text-violet-600"], |
126 | | - ["closed", "text-red-600"], |
127 | | - ] as const)("restores the %s pull request color on row hover", (state, colorClass) => { |
128 | | - expect(settledPrHoverColorClass(state)).toContain(`group-hover/sidebar-row:${colorClass}`); |
| 117 | +describe("resolveThreadPullRequestBadgePresentation", () => { |
| 118 | + const url = "https://github.com/pingdotgg/t3code/pull/42"; |
| 119 | + |
| 120 | + it("returns the pending pull-request badge when no snapshot is available", () => { |
| 121 | + expect( |
| 122 | + resolveThreadPullRequestBadgePresentation({ |
| 123 | + badge: null, |
| 124 | + number: 42, |
| 125 | + url, |
| 126 | + status: null, |
| 127 | + }), |
| 128 | + ).toEqual({ |
| 129 | + Icon: PullRequestGlyph.pullRequest, |
| 130 | + toneClassName: "text-muted-foreground", |
| 131 | + label: "PR #42, status pending", |
| 132 | + text: 42, |
| 133 | + }); |
129 | 134 | }); |
130 | 135 |
|
131 | | - it("keeps draft pull requests gray on row hover", () => { |
132 | | - expect(settledPrHoverColorClass("open", true)).toContain( |
133 | | - "group-hover/sidebar-row:text-zinc-500", |
134 | | - ); |
| 136 | + it.each([ |
| 137 | + [ |
| 138 | + "open", |
| 139 | + { state: "open", isDraft: false }, |
| 140 | + PullRequestGlyph.pullRequest, |
| 141 | + "text-emerald-600 dark:text-emerald-300/90", |
| 142 | + "PR #42 - Open: PR branch", |
| 143 | + ], |
| 144 | + [ |
| 145 | + "draft", |
| 146 | + { state: "open", isDraft: true }, |
| 147 | + PullRequestGlyph.draft, |
| 148 | + "text-zinc-500 dark:text-zinc-400/80", |
| 149 | + "PR #42 - Draft: PR branch", |
| 150 | + ], |
| 151 | + [ |
| 152 | + "closed", |
| 153 | + { state: "closed", isDraft: false }, |
| 154 | + PullRequestGlyph.closed, |
| 155 | + "text-red-600 dark:text-red-300/90", |
| 156 | + "PR #42 - Closed: PR branch", |
| 157 | + ], |
| 158 | + [ |
| 159 | + "merged", |
| 160 | + { state: "merged", isDraft: false }, |
| 161 | + PullRequestGlyph.merged, |
| 162 | + "text-violet-600 dark:text-violet-300/90", |
| 163 | + "PR #42 - Merged: PR branch", |
| 164 | + ], |
| 165 | + ] as const)( |
| 166 | + "keeps the %s state for one linked pull request", |
| 167 | + (_state, prOverrides, expectedIcon, expectedToneClassName, expectedLabel) => { |
| 168 | + const fixture = status().pr; |
| 169 | + if (!fixture) throw new Error("Expected pull request fixture"); |
| 170 | + const prStatus = prStatusIndicator({ ...fixture, ...prOverrides }, undefined); |
| 171 | + if (!prStatus) throw new Error("Expected pull request status"); |
| 172 | + |
| 173 | + expect( |
| 174 | + resolveThreadPullRequestBadgePresentation({ |
| 175 | + badge: { kind: "pull-request", others: 0, state: "open" }, |
| 176 | + number: fixture.number, |
| 177 | + url: fixture.url, |
| 178 | + status: prStatus, |
| 179 | + }), |
| 180 | + ).toEqual({ |
| 181 | + Icon: expectedIcon, |
| 182 | + toneClassName: expectedToneClassName, |
| 183 | + label: expectedLabel, |
| 184 | + text: fixture.number, |
| 185 | + }); |
| 186 | + }, |
| 187 | + ); |
| 188 | + |
| 189 | + it.each([ |
| 190 | + ["open", "text-emerald-600 dark:text-emerald-300/90"], |
| 191 | + ["draft", "text-zinc-500 dark:text-zinc-400/80"], |
| 192 | + ["merged", "text-violet-600 dark:text-violet-300/90"], |
| 193 | + ] as const)( |
| 194 | + "uses a layers badge with the %s stack tone without a link identity", |
| 195 | + (state, expectedToneClassName) => { |
| 196 | + expect( |
| 197 | + resolveThreadPullRequestBadgePresentation({ |
| 198 | + badge: { kind: "stack", layers: 3, state }, |
| 199 | + status: null, |
| 200 | + }), |
| 201 | + ).toEqual({ |
| 202 | + Icon: PullRequestGlyph.stack, |
| 203 | + toneClassName: expectedToneClassName, |
| 204 | + label: `Stack of 3 pull requests, ${state}`, |
| 205 | + text: 3, |
| 206 | + }); |
| 207 | + }, |
| 208 | + ); |
| 209 | + |
| 210 | + it.each([ |
| 211 | + ["open", PullRequestGlyph.pullRequest, "text-emerald-600 dark:text-emerald-300/90"], |
| 212 | + ["draft", PullRequestGlyph.draft, "text-zinc-500 dark:text-zinc-400/80"], |
| 213 | + ["merged", PullRequestGlyph.merged, "text-violet-600 dark:text-violet-300/90"], |
| 214 | + ] as const)( |
| 215 | + "draws the count of unrelated linked pull requests with their %s aggregate state", |
| 216 | + (state, expectedIcon, expectedToneClassName) => { |
| 217 | + const fixture = status().pr; |
| 218 | + if (!fixture) throw new Error("Expected pull request fixture"); |
| 219 | + const closedStatus = prStatusIndicator( |
| 220 | + { ...fixture, state: "closed", isDraft: false }, |
| 221 | + undefined, |
| 222 | + ); |
| 223 | + if (!closedStatus) throw new Error("Expected pull request status"); |
| 224 | + |
| 225 | + expect( |
| 226 | + resolveThreadPullRequestBadgePresentation({ |
| 227 | + badge: { kind: "pull-request", others: 2, state }, |
| 228 | + number: fixture.number, |
| 229 | + url: fixture.url, |
| 230 | + status: closedStatus, |
| 231 | + }), |
| 232 | + ).toEqual({ |
| 233 | + Icon: expectedIcon, |
| 234 | + toneClassName: expectedToneClassName, |
| 235 | + label: `PR #42 - Closed: PR branch, and 2 more linked; overall ${state}`, |
| 236 | + text: "+3", |
| 237 | + }); |
| 238 | + }, |
| 239 | + ); |
| 240 | + |
| 241 | + it("omits the control when neither a stack nor a linked identity can be shown", () => { |
| 242 | + expect(resolveThreadPullRequestBadgePresentation({ badge: null, status: null })).toBeNull(); |
135 | 243 | }); |
136 | 244 | }); |
0 commit comments