Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 resolveNewTaskBranchWorktreePath,
5 resolveNewTaskBranchLabel,
6 resolveNewTaskLocalWorkspaceSelection,
7} from "./new-task-context-presentation";
8
9describe("resolveNewTaskLocalWorkspaceSelection", () => {
10 it("waits for refs instead of carrying a worktree base into Current checkout", () => {
11 expect(
12 resolveNewTaskLocalWorkspaceSelection({
13 branches: [],
14 projectCwd: "/repo",
15 }),
16 ).toEqual({
17 branch: null,
18 worktreePath: null,
19 awaitsCurrentBranch: true,
20 });
21 });
22
23 it("adopts the checkout's current branch once refs load", () => {
24 expect(
25 resolveNewTaskLocalWorkspaceSelection({
26 branches: [
27 { name: "feature/worktree-base", current: false, worktreePath: "/worktree" },
28 { name: "main", current: true, worktreePath: "/repo" },
29 ],
30 projectCwd: "/repo",
31 }),
32 ).toEqual({
33 branch: "main",
34 worktreePath: null,
35 awaitsCurrentBranch: false,
36 });
37 });
38
39 it("carries the worktree path when the current branch lives in another worktree", () => {
40 expect(
41 resolveNewTaskLocalWorkspaceSelection({
42 branches: [
43 { name: "feature/split", current: true, worktreePath: "/repo/.t3/worktrees/split" },
44 { name: "main", current: false, worktreePath: "/repo" },
45 ],
46 projectCwd: "/repo",
47 }),
48 ).toEqual({
49 branch: "feature/split",
50 worktreePath: "/repo/.t3/worktrees/split",
51 awaitsCurrentBranch: false,
52 });
53 });
54});
55
56describe("resolveNewTaskBranchWorktreePath", () => {
57 it("moves Current checkout to the selected existing worktree", () => {
58 expect(
59 resolveNewTaskBranchWorktreePath({
60 workspaceMode: "local",
61 projectCwd: "/repo",
62 branchWorktreePath: "/repo/.t3/worktrees/feature",
63 }),
64 ).toBe("/repo/.t3/worktrees/feature");
65 });
66
67 it("keeps the project checkout represented by a null override", () => {
68 expect(
69 resolveNewTaskBranchWorktreePath({
70 workspaceMode: "local",
71 projectCwd: "/repo",
72 branchWorktreePath: "/repo",
73 }),
74 ).toBeNull();
75 });
76
77 it("does not reuse an existing worktree while creating a new one", () => {
78 expect(
79 resolveNewTaskBranchWorktreePath({
80 workspaceMode: "worktree",
81 projectCwd: "/repo",
82 branchWorktreePath: "/repo/.t3/worktrees/feature",
83 }),
84 ).toBeNull();
85 });
86});
87
88describe("resolveNewTaskBranchLabel", () => {
89 it("shows the checked-out branch without a base-ref prefix", () => {
90 expect(
91 resolveNewTaskBranchLabel({
92 branchName: "feature/mobile",
93 startFromOrigin: true,
94 workspaceMode: "local",
95 }),
96 ).toBe("feature/mobile");
97 });
98
99 it("labels a local worktree base with From", () => {
100 expect(
101 resolveNewTaskBranchLabel({
102 branchName: "main",
103 startFromOrigin: false,
104 workspaceMode: "worktree",
105 }),
106 ).toBe("From main");
107 });
108
109 it("labels a remote worktree base with From origin", () => {
110 expect(
111 resolveNewTaskBranchLabel({
112 branchName: "main",
113 startFromOrigin: true,
114 workspaceMode: "worktree",
115 }),
116 ).toBe("From origin/main");
117 });
118
119 it("prompts when no branch is available", () => {
120 expect(
121 resolveNewTaskBranchLabel({
122 branchName: null,
123 startFromOrigin: true,
124 workspaceMode: "worktree",
125 }),
126 ).toBe("Choose branch");
127 });
128});