Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: GPT-6 Sol <[email protected]>
153 lines
4.3 KiB
TypeScript
153 lines
4.3 KiB
TypeScript
import { describe, expect, it } from "vite-plus/test";
|
|
|
|
import {
|
|
filterNewTaskBranches,
|
|
resolveNewTaskBranchWorktreePath,
|
|
resolveNewTaskBranchLabel,
|
|
resolveNewTaskLocalWorkspaceSelection,
|
|
} from "./new-task-context-presentation";
|
|
|
|
describe("resolveNewTaskLocalWorkspaceSelection", () => {
|
|
it("waits for refs instead of carrying a worktree base into Current checkout", () => {
|
|
expect(
|
|
resolveNewTaskLocalWorkspaceSelection({
|
|
branches: [],
|
|
projectCwd: "/repo",
|
|
}),
|
|
).toEqual({
|
|
branch: null,
|
|
worktreePath: null,
|
|
awaitsCurrentBranch: true,
|
|
});
|
|
});
|
|
|
|
it("adopts the checkout's current branch once refs load", () => {
|
|
expect(
|
|
resolveNewTaskLocalWorkspaceSelection({
|
|
branches: [
|
|
{ name: "feature/worktree-base", current: false, worktreePath: "/worktree" },
|
|
{ name: "main", current: true, worktreePath: "/repo" },
|
|
],
|
|
projectCwd: "/repo",
|
|
}),
|
|
).toEqual({
|
|
branch: "main",
|
|
worktreePath: null,
|
|
awaitsCurrentBranch: false,
|
|
});
|
|
});
|
|
|
|
it("carries the worktree path when the current branch lives in another worktree", () => {
|
|
expect(
|
|
resolveNewTaskLocalWorkspaceSelection({
|
|
branches: [
|
|
{ name: "feature/split", current: true, worktreePath: "/repo/.t3/worktrees/split" },
|
|
{ name: "main", current: false, worktreePath: "/repo" },
|
|
],
|
|
projectCwd: "/repo",
|
|
}),
|
|
).toEqual({
|
|
branch: "feature/split",
|
|
worktreePath: "/repo/.t3/worktrees/split",
|
|
awaitsCurrentBranch: false,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("resolveNewTaskBranchWorktreePath", () => {
|
|
it("moves Current checkout to the selected existing worktree", () => {
|
|
expect(
|
|
resolveNewTaskBranchWorktreePath({
|
|
workspaceMode: "local",
|
|
projectCwd: "/repo",
|
|
branchWorktreePath: "/repo/.t3/worktrees/feature",
|
|
}),
|
|
).toBe("/repo/.t3/worktrees/feature");
|
|
});
|
|
|
|
it("keeps the project checkout represented by a null override", () => {
|
|
expect(
|
|
resolveNewTaskBranchWorktreePath({
|
|
workspaceMode: "local",
|
|
projectCwd: "/repo",
|
|
branchWorktreePath: "/repo",
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
|
|
it("does not reuse an existing worktree while creating a new one", () => {
|
|
expect(
|
|
resolveNewTaskBranchWorktreePath({
|
|
workspaceMode: "worktree",
|
|
projectCwd: "/repo",
|
|
branchWorktreePath: "/repo/.t3/worktrees/feature",
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("resolveNewTaskBranchLabel", () => {
|
|
it("shows the checked-out branch without a base-ref prefix", () => {
|
|
expect(
|
|
resolveNewTaskBranchLabel({
|
|
branchName: "feature/mobile",
|
|
startFromOrigin: true,
|
|
workspaceMode: "local",
|
|
}),
|
|
).toBe("feature/mobile");
|
|
});
|
|
|
|
it("labels a local worktree base with From", () => {
|
|
expect(
|
|
resolveNewTaskBranchLabel({
|
|
branchName: "main",
|
|
startFromOrigin: false,
|
|
workspaceMode: "worktree",
|
|
}),
|
|
).toBe("From main");
|
|
});
|
|
|
|
it("labels a remote worktree base with From origin", () => {
|
|
expect(
|
|
resolveNewTaskBranchLabel({
|
|
branchName: "main",
|
|
startFromOrigin: true,
|
|
workspaceMode: "worktree",
|
|
}),
|
|
).toBe("From origin/main");
|
|
});
|
|
|
|
it("prompts when no branch is available", () => {
|
|
expect(
|
|
resolveNewTaskBranchLabel({
|
|
branchName: null,
|
|
startFromOrigin: true,
|
|
workspaceMode: "worktree",
|
|
}),
|
|
).toBe("Choose branch");
|
|
});
|
|
});
|
|
|
|
describe("filterNewTaskBranches", () => {
|
|
const branches = [
|
|
{ name: "main", isRemote: false },
|
|
{ name: "Feature/Login-Page", isRemote: false },
|
|
{ name: "origin/fix/remote-only", isRemote: true },
|
|
];
|
|
const search = (query: string) =>
|
|
filterNewTaskBranches(branches, query).map((branch) => branch.name);
|
|
|
|
it("ignores case in both the query and the branch name", () => {
|
|
expect(search("feature/login")).toEqual(["Feature/Login-Page"]);
|
|
expect(search("MAIN")).toEqual(["main"]);
|
|
});
|
|
|
|
it("keeps remote-only branches searchable", () => {
|
|
expect(search("remote-only")).toEqual(["origin/fix/remote-only"]);
|
|
});
|
|
|
|
it("matches a typed space against the dash a branch name uses", () => {
|
|
expect(search(" login page ")).toEqual(["Feature/Login-Page"]);
|
|
});
|
|
});
|