Files
t3code/apps/web/src/components/chat/ThreadDetailsPrRow.test.tsx
T
+36 de34391427 feat(orchestrator): introduce new orchestrator (#2829)
Co-authored-by: maria-rcks <[email protected]>
Co-authored-by: Bilal Bakr <[email protected]>
Co-authored-by: shivam <[email protected]>
Co-authored-by: Vitalii Yehorov <[email protected]>
Co-authored-by: Jake Leventhal <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: Alex Southwell <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Nicholas Wasmiller <[email protected]>
Co-authored-by: PB <[email protected]>
Co-authored-by: Exotic <[email protected]>
Co-authored-by: Yash Singh <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Theo Browne <[email protected]>
Co-authored-by: Gabriel De Andrade <[email protected]>
Co-authored-by: Dara Adedeji <[email protected]>
Co-authored-by: scratchyone <[email protected]>
Co-authored-by: Dominic Roy <[email protected]>
Co-authored-by: chukfinley <[email protected]>
Co-authored-by: Primož Ajdišek <[email protected]>
Co-authored-by: benthecarman <[email protected]>
Co-authored-by: NaveDanan <[email protected]>
Co-authored-by: aaditagrawal <[email protected]>
Co-authored-by: Aditya Garud <[email protected]>
Co-authored-by: Nick Anisimov <[email protected]>
Co-authored-by: MacKinley Smith <[email protected]>
Co-authored-by: Yordis Prieto <[email protected]>
Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com>
Co-authored-by: AKolenda <[email protected]>
Co-authored-by: Guillermo Casanova <[email protected]>
Co-authored-by: Otavio Salvador <[email protected]>
Co-authored-by: Shirish Pothi <[email protected]>
Co-authored-by: Ishaan Kothari <[email protected]>
Co-authored-by: Bob Fowler <[email protected]>
Co-authored-by: Anton Bezdenezhnykh <[email protected]>
Co-authored-by: ValeraZSD <[email protected]>
Co-authored-by: Ephraim <[email protected]>
Co-authored-by: Ryan Ilano <[email protected]>
Co-authored-by: Alex <[email protected]>
Co-authored-by: maco <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Tristan Knight <[email protected]>
Co-authored-by: PR Batch Tester <[email protected]>
Co-authored-by: oliver <[email protected]>
Co-authored-by: kamkm <[email protected]>
Signed-off-by: Yordis Prieto <[email protected]>
2026-10-02 12:22:22 -07:00

152 lines
5.1 KiB
TypeScript

import { EnvironmentId, type PullRequestCheck } from "@t3tools/contracts";
import { act, cloneElement, type ReactElement, type ReactNode } from "react";
import { create, type ReactTestRenderer } from "react-test-renderer";
import { afterEach, expect, it, vi } from "vite-plus/test";
const state = vi.hoisted(() => ({
status: "success" as PullRequestCheck["status"],
extraStatus: null as PullRequestCheck["status"] | null,
perform: vi.fn(),
}));
vi.mock("~/state/entities", () => ({ useServerConfigs: () => new Map() }));
vi.mock("~/state/pullRequests", () => ({ pullRequestEnvironment: {} }));
vi.mock("~/hooks/useLiveRefresh", () => ({ useLiveRefresh: () => {} }));
vi.mock("~/state/query", () => ({
useEnvironmentQuery: () => ({
data: {
number: 1,
title: "Test PR",
state: "open",
isDraft: false,
mergeability: "mergeable",
headBranch: "feature",
baseBranch: "main",
changedFiles: 1,
additions: 1,
deletions: 0,
checks: [state.status, ...(state.extraStatus ? [state.extraStatus] : [])].map((status) => ({
name: `CI-${status}`,
status,
description: null,
url: null,
})),
capabilities: { actions: ["merge"], mergeMethods: ["merge"] },
viewerPermissions: { actions: ["merge"] },
mergeCapabilities: { merge: true, squash: false, rebase: false },
},
dataUpdatedAt: 1,
isPending: false,
refresh: vi.fn(),
}),
}));
vi.mock("../pullRequest/usePullRequestActions", () => ({
usePullRequestActionRunner: () => ({ actionPending: false, perform: state.perform }),
usePullRequestHandoffs: () => ({ handoff: null, startHandoff: vi.fn() }),
}));
vi.mock("../ui/popover", () => ({
Popover: ({ children }: { children: ReactNode }) => children,
PopoverTrigger: ({ render, children }: { render: ReactElement; children: ReactNode }) =>
cloneElement(render, undefined, children),
PopoverPopup: () => null,
}));
vi.mock("../ui/tooltip", () => ({
Tooltip: ({ children }: { children: ReactNode }) => children,
TooltipTrigger: ({ render, children }: { render: ReactElement; children: ReactNode }) =>
cloneElement(render, undefined, children),
TooltipPopup: () => null,
}));
vi.mock("../ui/alert-dialog", () => ({
AlertDialog: ({ open, children }: { open: boolean; children: ReactNode }) =>
open ? <div role="alertdialog">{children}</div> : null,
AlertDialogPopup: ({ children }: { children: ReactNode }) => children,
AlertDialogHeader: ({ children }: { children: ReactNode }) => children,
AlertDialogTitle: ({ children }: { children: ReactNode }) => <h2>{children}</h2>,
AlertDialogDescription: ({ children }: { children: ReactNode }) => children,
AlertDialogFooter: ({ children }: { children: ReactNode }) => children,
AlertDialogClose: () => null,
}));
import { ThreadDetailsPrRow } from "./ThreadDetailsPrRow";
let renderer: ReactTestRenderer;
afterEach(() => {
act(() => renderer?.unmount());
vi.unstubAllGlobals();
state.status = "success";
state.extraStatus = null;
});
it("requires a new merge click after passing checks become pending and pass again", () => {
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
const render = () => (
<ThreadDetailsPrRow
environmentId={EnvironmentId.make("environment")}
pr={null}
number={1}
status={null}
project={null}
label="Test PR"
openAriaLabel="Open PR"
onOpen={vi.fn()}
/>
);
const clickMerge = () =>
act(() => {
renderer.root
.findAllByType("button")
.find((button) => button.children.includes("Merge"))!
.props.onClick();
});
const dialogs = () => renderer.root.findAllByProps({ role: "alertdialog" });
act(() => {
renderer = create(render());
});
clickMerge();
expect(dialogs()).toHaveLength(1);
act(() => {
state.status = "pending";
renderer.update(render());
});
expect(dialogs()).toHaveLength(0);
act(() => {
state.status = "success";
renderer.update(render());
});
expect(dialogs()).toHaveLength(0);
clickMerge();
expect(dialogs()).toHaveLength(1);
expect(state.perform).not.toHaveBeenCalled();
});
it.each<[PullRequestCheck["status"], PullRequestCheck["status"], string]>([
["success", "skipped", ""],
["failure", "cancelled", ""],
["success", "action-required", ""],
["success", "pending", "1/2"],
["failure", "pending", "1/2"],
])("shows a count only while checks run (%s, %s)", (status, extraStatus, count) => {
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
state.status = status;
state.extraStatus = extraStatus;
act(() => {
renderer = create(
<ThreadDetailsPrRow
environmentId={EnvironmentId.make("environment")}
pr={null}
number={1}
status={null}
project={null}
label="Test PR"
openAriaLabel="Open PR"
onOpen={vi.fn()}
/>,
);
});
const text = renderer.root
.findAllByType("span")
.map((span) => span.children.filter((child) => typeof child === "string").join(""));
expect(text.filter((value) => /^\d+\/\d+$/.test(value))).toEqual(count ? [count] : []);
});