66f3130de7
Two findings from Claude on08aa04c5+fa5ba9d6: - The mutual import between task-create-dialog-prop-builders.ts and task-create-dialog.tsx is purely type-level (TaskCreateDialogProps is an interface; useTaskCreateDialogSetup is consumed only through `ReturnType<typeof ...>`). Switch to `import type` so bundlers and analysis tools don't flag this as a runtime cycle. - computeHasAllBranches was a private function in task-create-dialog.tsx and didn't need its own test. Moving it to a sibling .ts utility makes it a public helper, and the SKILL.md convention is that public utilities carry their own tests. Add a table-driven unit test covering the three branches: noRepository short-circuit, useGitHubUrl branch validation, and the every-repo-has-a-branch case.
49 lines
2.0 KiB
TypeScript
49 lines
2.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { computeHasAllBranches } from "./task-create-dialog-prop-builders";
|
|
import type { DialogFormState } from "@/components/task-create-dialog-types";
|
|
|
|
// Minimal fs stub for computeHasAllBranches. The function only reads
|
|
// `noRepository`, `useGitHubUrl`, `githubBranch`, and `repositories[].branch`,
|
|
// so we cast a partial through `unknown` to avoid having to materialise the
|
|
// full DialogFormState surface in tests.
|
|
function fsStub(overrides: {
|
|
noRepository?: boolean;
|
|
useGitHubUrl?: boolean;
|
|
githubBranch?: string;
|
|
repositories?: Array<{ branch?: string }>;
|
|
}): DialogFormState {
|
|
return {
|
|
noRepository: false,
|
|
useGitHubUrl: false,
|
|
githubBranch: "",
|
|
repositories: [],
|
|
...overrides,
|
|
} as unknown as DialogFormState;
|
|
}
|
|
|
|
describe("computeHasAllBranches", () => {
|
|
it("returns true when the task is in no-repository mode (short-circuits the rest)", () => {
|
|
// noRepository mode doesn't need a branch — the backend skips the
|
|
// worktree/clone step entirely, so it always satisfies hasAllBranches.
|
|
expect(computeHasAllBranches(fsStub({ noRepository: true, repositories: [] }))).toBe(true);
|
|
});
|
|
|
|
it("treats the GitHub-URL mode as branched iff githubBranch is non-empty", () => {
|
|
expect(computeHasAllBranches(fsStub({ useGitHubUrl: true, githubBranch: "" }))).toBe(false);
|
|
expect(computeHasAllBranches(fsStub({ useGitHubUrl: true, githubBranch: "main" }))).toBe(true);
|
|
});
|
|
|
|
it("requires every selected repository row to carry a branch", () => {
|
|
expect(computeHasAllBranches(fsStub({ repositories: [] }))).toBe(false);
|
|
expect(computeHasAllBranches(fsStub({ repositories: [{ branch: "main" }] }))).toBe(true);
|
|
expect(
|
|
computeHasAllBranches(fsStub({ repositories: [{ branch: "main" }, { branch: "" }] })),
|
|
).toBe(false);
|
|
expect(
|
|
computeHasAllBranches(
|
|
fsStub({ repositories: [{ branch: "main" }, { branch: "feature/x" }] }),
|
|
),
|
|
).toBe(true);
|
|
});
|
|
});
|