feat: support creating worktrees from GitHub pull requests
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { GitHubSearchItem } from "@server/shared/messages";
|
||||
import { pickerItemToCheckoutRequest, type PickerItem } from "./new-workspace-picker-item";
|
||||
|
||||
const prItem: GitHubSearchItem = {
|
||||
kind: "pr",
|
||||
number: 42,
|
||||
title: "Add picker",
|
||||
url: "https://example.com/pull/42",
|
||||
state: "open",
|
||||
body: null,
|
||||
labels: [],
|
||||
baseRefName: "main",
|
||||
headRefName: "feature/picker",
|
||||
};
|
||||
|
||||
describe("pickerItemToCheckoutRequest", () => {
|
||||
it("returns undefined for no selection (null)", () => {
|
||||
expect(pickerItemToCheckoutRequest(null)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("maps a branch row to branch-off with the branch name", () => {
|
||||
const item: PickerItem = { kind: "branch", name: "dev" };
|
||||
expect(pickerItemToCheckoutRequest(item)).toEqual({
|
||||
action: "branch-off",
|
||||
refName: "dev",
|
||||
});
|
||||
});
|
||||
|
||||
it("maps a github-pr row to checkout using the head ref and pr number", () => {
|
||||
const item: PickerItem = {
|
||||
kind: "github-pr",
|
||||
item: prItem,
|
||||
};
|
||||
expect(pickerItemToCheckoutRequest(item)).toEqual({
|
||||
action: "checkout",
|
||||
refName: "feature/picker",
|
||||
githubPrNumber: 42,
|
||||
});
|
||||
});
|
||||
|
||||
it("handles a github-pr with a null baseRef", () => {
|
||||
const item: PickerItem = {
|
||||
kind: "github-pr",
|
||||
item: {
|
||||
...prItem,
|
||||
number: 7,
|
||||
title: "Orphan branch",
|
||||
baseRefName: null,
|
||||
headRefName: "orphan",
|
||||
},
|
||||
};
|
||||
expect(pickerItemToCheckoutRequest(item)).toEqual({
|
||||
action: "checkout",
|
||||
refName: "orphan",
|
||||
githubPrNumber: 7,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user