@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 106 lines 3.34 KB
Raw
1 import { SourceControlProviderKind, type VcsStatusResult } from "@t3tools/contracts";
2 import { describe, expect, it } from "vite-plus/test";
3
4 import { sourceControlClients } from "../sourceControlClients.ts";
5 import {
6 buildMenuItems,
7 getGitActionDisabledReason,
8 resolveDefaultBranchActionDialogCopy,
9 resolveQuickAction,
10 } from "./gitActions.ts";
11
12 function status(overrides: Partial<VcsStatusResult> = {}): VcsStatusResult {
13 return {
14 isRepo: true,
15 hasPrimaryRemote: true,
16 isDefaultRef: false,
17 refName: "feature/test",
18 hasWorkingTreeChanges: false,
19 workingTree: { files: [], insertions: 0, deletions: 0 },
20 hasUpstream: true,
21 aheadCount: 0,
22 behindCount: 0,
23 pr: null,
24 ...overrides,
25 };
26 }
27
28 const gitLab = {
29 sourceControlProvider: {
30 kind: SourceControlProviderKind.make("gitlab"),
31 name: "GitLab",
32 baseUrl: "https://gitlab.com",
33 },
34 };
35
36 const openPr = {
37 number: 7,
38 title: "Feature",
39 url: "https://example.com/pr/7",
40 baseRef: "main",
41 headRef: "feature/test",
42 state: "open" as const,
43 };
44
45 describe("git action copy", () => {
46 it("says PR for a GitHub ref", () => {
47 expect(resolveQuickAction(status({ aheadCount: 1 }), false).label).toBe("Push & create PR");
48 expect(resolveQuickAction(status({ pr: openPr }), false).label).toBe("View PR");
49 const [, , prItem] = buildMenuItems(status(), false);
50 expect(prItem?.label).toBe("Create PR");
51 expect(
52 getGitActionDisabledReason({
53 item: prItem!,
54 gitStatus: status(),
55 isBusy: false,
56 hasOriginRemote: true,
57 }),
58 ).toBe("No local commits to include in a PR.");
59 });
60
61 it("says MR for a GitLab ref", () => {
62 expect(resolveQuickAction(status({ ...gitLab, aheadCount: 1 }), false).label).toBe(
63 "Push & create MR",
64 );
65 expect(
66 resolveQuickAction(status({ ...gitLab, hasWorkingTreeChanges: true }), false).label,
67 ).toBe("Commit, push & MR");
68 expect(resolveQuickAction(status({ ...gitLab, pr: openPr }), false).label).toBe("View MR");
69 const [, , prItem] = buildMenuItems(status(gitLab), false);
70 expect(prItem?.label).toBe("Create MR");
71 expect(
72 getGitActionDisabledReason({
73 item: prItem!,
74 gitStatus: status(gitLab),
75 isBusy: false,
76 hasOriginRemote: true,
77 }),
78 ).toBe("No local commits to include in an MR.");
79 });
80
81 it("offers creating a PR after the feature branch has been fully pushed", () => {
82 const pushed = status({ aheadCount: 0, behindCount: 0, aheadOfDefaultCount: 1 });
83 expect(resolveQuickAction(pushed, false)).toMatchObject({
84 disabled: false,
85 kind: "run_action",
86 action: "create_pr",
87 });
88 expect(resolveQuickAction({ ...pushed, isDefaultRef: true }, false, true).disabled).toBe(true);
89 });
90
91 it("names the host's change request in the default-branch dialog", () => {
92 const input = { action: "commit_push_pr", branchName: "main", includesCommit: true } as const;
93 expect(
94 resolveDefaultBranchActionDialogCopy({
95 ...input,
96 terminology: sourceControlClients.get("github").changeRequest,
97 }).title,
98 ).toBe("Commit, push & create PR from default branch?");
99 expect(
100 resolveDefaultBranchActionDialogCopy({
101 ...input,
102 terminology: sourceControlClients.get("gitlab").changeRequest,
103 }).continueLabel,
104 ).toBe("Commit, push & create MR");
105 });
106 });