|
4 | 4 | ThreadId, |
5 | 5 | type ScopedThreadRef, |
6 | 6 | type PullRequestDetailView, |
| 7 | + type PullRequestSummary, |
7 | 8 | type ThreadPullRequestLink, |
8 | 9 | } from "@t3tools/contracts"; |
9 | 10 | import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings"; |
@@ -41,16 +42,17 @@ vi.mock("~/lib/sourceControlActions", () => ({ |
41 | 42 | usePreparePullRequestThreadAction: () => ({ run: prepareThread }), |
42 | 43 | })); |
43 | 44 | vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: () => vi.fn() })); |
44 | | -vi.mock("~/state/pullRequests", () => ({ |
| 45 | +vi.mock("~/state/pullRequests", async (importOriginal) => ({ |
| 46 | + ...(await importOriginal<typeof import("~/state/pullRequests")>()), |
45 | 47 | pullRequestEnvironment: { detail: () => "detail", activity: () => "activity" }, |
46 | 48 | usePullRequestTurnRefresh: () => 0, |
47 | | - useSharedPullRequestSummary: () => null, |
| 49 | + useSharedPullRequestSummary: () => observedSummary, |
48 | 50 | })); |
49 | 51 | vi.mock("~/state/vcs", () => ({ vcsEnvironment: { listRefs: () => null } })); |
50 | 52 | vi.mock("~/state/query", () => ({ |
51 | 53 | useEnvironmentQuery: (query: string) => ({ |
52 | | - data: query === "detail" ? detail : null, |
53 | | - isPending: false, |
| 54 | + data: query === "detail" ? loadedDetail : null, |
| 55 | + isPending: query === "detail" && loadedDetail === null, |
54 | 56 | isSuccess: true, |
55 | 57 | error: null, |
56 | 58 | refresh, |
@@ -202,8 +204,12 @@ const threadRef: ScopedThreadRef = { |
202 | 204 | const draftId = DraftId.make("draft-1"); |
203 | 205 | const newDraftId = DraftId.make("new-draft"); |
204 | 206 | let renderer: ReactTestRenderer; |
| 207 | +let loadedDetail: PullRequestDetailView | null = detail; |
| 208 | +let observedSummary: PullRequestSummary | null = null; |
205 | 209 |
|
206 | 210 | beforeEach(() => { |
| 211 | + loadedDetail = detail; |
| 212 | + observedSummary = null; |
207 | 213 | vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true); |
208 | 214 | vi.stubGlobal("window", { addEventListener: vi.fn(), removeEventListener: vi.fn() }); |
209 | 215 | useComposerDraftStore.setState({ draftsByThreadKey: {} }); |
@@ -335,3 +341,53 @@ describe.each([ |
335 | 341 | } |
336 | 342 | }); |
337 | 343 | }); |
| 344 | + |
| 345 | +describe("PR list status in the sidebar detail", () => { |
| 346 | + const panel = () => ( |
| 347 | + <PullRequestDetailPanel |
| 348 | + environmentId={threadRef.environmentId} |
| 349 | + reference={detail} |
| 350 | + shortcutsEnabled={false} |
| 351 | + getShortcutContext={() => ({ |
| 352 | + terminalFocus: false, |
| 353 | + terminalOpen: false, |
| 354 | + previewFocus: false, |
| 355 | + previewOpen: false, |
| 356 | + isWeb: true, |
| 357 | + isDesktop: false, |
| 358 | + })} |
| 359 | + /> |
| 360 | + ); |
| 361 | + |
| 362 | + it("shows the known title and conflict before full detail arrives", async () => { |
| 363 | + loadedDetail = null; |
| 364 | + observedSummary = detail; |
| 365 | + await act(async () => { |
| 366 | + renderer = create(panel()); |
| 367 | + }); |
| 368 | + expect( |
| 369 | + renderer.root.findAll((node) => node.children.includes("Conflicts with main")), |
| 370 | + ).toHaveLength(1); |
| 371 | + expect(renderer.root.findAll((node) => node.children.includes(detail.title))).toHaveLength(1); |
| 372 | + expect(renderer.root.findAllByType("button")).toHaveLength(0); |
| 373 | + }); |
| 374 | + |
| 375 | + it("uses the list conflict while an older detail snapshot is displayed", async () => { |
| 376 | + loadedDetail = { ...detail, mergeability: "mergeable" }; |
| 377 | + await act(async () => { |
| 378 | + renderer = create(panel()); |
| 379 | + }); |
| 380 | + expect( |
| 381 | + renderer.root.findAll((node) => node.children.includes("Resolve conflicts")), |
| 382 | + ).toHaveLength(0); |
| 383 | + |
| 384 | + loadedDetail = null; |
| 385 | + observedSummary = detail; |
| 386 | + await act(async () => { |
| 387 | + renderer.update(panel()); |
| 388 | + }); |
| 389 | + expect( |
| 390 | + renderer.root.findAll((node) => node.children.includes("Resolve conflicts")).length, |
| 391 | + ).toBeGreaterThan(0); |
| 392 | + }); |
| 393 | +}); |
0 commit comments