The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients"; |
| 2 | import { EnvironmentId, ProjectId } from "@t3tools/contracts"; |
| 3 | import { expect, it, vi } from "vite-plus/test"; |
| 4 | import { page } from "vite-plus/test/browser"; |
| 5 | |
| 6 | const state = vi.hoisted(() => ({ detail: "" })); |
| 7 | |
| 8 | vi.mock(import("~/state/use-atom-command"), async () => { |
| 9 | const { PullRequestOperationError } = await import("@t3tools/contracts"); |
| 10 | const { Cause } = await import("effect"); |
| 11 | const { AsyncResult } = await import("effect/reactivity"); |
| 12 | return { |
| 13 | useAtomCommand: (() => async () => |
| 14 | AsyncResult.failure( |
| 15 | Cause.fail(new PullRequestOperationError({ operation: "runAction", detail: state.detail })), |
| 16 | )) as never, |
| 17 | }; |
| 18 | }); |
| 19 | |
| 20 | import "~/index.css"; |
| 21 | import { render } from "../../../test/render"; |
| 22 | import { ToastProvider } from "../ui/toast"; |
| 23 | import { PullRequestStackMenu } from "./PullRequestStackMenu"; |
| 24 | |
| 25 | function setup(detail: string) { |
| 26 | state.detail = detail; |
| 27 | } |
| 28 | |
| 29 | const HEAD_MOVED = "The stack head moved. Refresh the stack before trying again."; |
| 30 | |
| 31 | it.each([ |
| 32 | { label: "Merge stack", detail: HEAD_MOVED, description: HEAD_MOVED }, |
| 33 | { label: "Rebase stack", detail: HEAD_MOVED, description: HEAD_MOVED }, |
| 34 | { |
| 35 | label: "Rebase stack", |
| 36 | detail: "GitHub CLI command failed.", |
| 37 | description: |
| 38 | "The host refused the rebase. A rebase stops at the first commit that does not apply cleanly.", |
| 39 | }, |
| 40 | ])("$label refused with $detail shows $description", async (row) => { |
| 41 | setup(row.detail); |
| 42 | await using screen = await render( |
| 43 | <ToastProvider> |
| 44 | <PullRequestStackMenu |
| 45 | environmentId={EnvironmentId.make("environment")} |
| 46 | reference={{ |
| 47 | projectId: ProjectId.make("project"), |
| 48 | repository: "owner/repository", |
| 49 | number: 2, |
| 50 | }} |
| 51 | hostLabel="GitHub" |
| 52 | terminology={sourceControlClients.get("github").changeRequest} |
| 53 | stack={{ |
| 54 | id: "stack", |
| 55 | number: 1, |
| 56 | url: "https://github.com/owner/repository/stack/1", |
| 57 | base: "main", |
| 58 | layers: [{ number: 2, headBranch: "feature", headSha: "abc123", state: "open" }], |
| 59 | }} |
| 60 | canMerge |
| 61 | stale={false} |
| 62 | canRebase |
| 63 | mergeMethod="squash" |
| 64 | onActed={() => {}} |
| 65 | /> |
| 66 | </ToastProvider>, |
| 67 | ); |
| 68 | if (row.label === "Rebase stack") { |
| 69 | await screen.getByRole("button", { name: "Stack 1, layer 1 of 1" }).click(); |
| 70 | await page.getByRole("menuitem", { name: row.label }).click(); |
| 71 | } else { |
| 72 | await screen.getByRole("button", { name: row.label, exact: true }).click(); |
| 73 | } |
| 74 | await page.getByRole("dialog").getByRole("button", { name: row.label, exact: true }).click(); |
| 75 | await expect.element(page.getByText(row.description, { exact: true })).toBeInTheDocument(); |
| 76 | }); |