* Add GitHub branch open target to workspace button (#96) * refactor: simplify workspace open targets to flat shape Collapse the editor/url discriminated union into a single OpenTarget { id, label, icon, onOpen } so the button renders targets uniformly and the mutation is shape-agnostic. Drop the heavily-mocked button test in favor of the URL builder tests, restore the decodeURIComponent guard for valid-syntax-but-invalid-UTF-8 pathnames, and note the SSH host alias limitation. --------- Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { buildGitHubBranchTreeUrl, parseGitHubRepoFromRemote } from "./github-repo-url";
|
|
|
|
describe("parseGitHubRepoFromRemote", () => {
|
|
it.each([
|
|
["https://github.com/acme/repo.git", "acme/repo"],
|
|
["https://github.com/acme/repo", "acme/repo"],
|
|
["git@github.com:acme/repo.git", "acme/repo"],
|
|
["ssh://git@github.com/acme/repo.git", "acme/repo"],
|
|
["https://github.com/acme/repo/", "acme/repo"],
|
|
])("extracts the repo from %s", (remoteUrl, expected) => {
|
|
expect(parseGitHubRepoFromRemote(remoteUrl)).toBe(expected);
|
|
});
|
|
|
|
it("returns null for non-GitHub remotes", () => {
|
|
expect(parseGitHubRepoFromRemote("git@gitlab.com:acme/repo.git")).toBeNull();
|
|
});
|
|
|
|
it("returns null for invalid URLs", () => {
|
|
expect(parseGitHubRepoFromRemote("not a url")).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("buildGitHubBranchTreeUrl", () => {
|
|
it("builds a branch-specific GitHub tree URL", () => {
|
|
expect(
|
|
buildGitHubBranchTreeUrl({
|
|
remoteUrl: "git@github.com:acme/repo.git",
|
|
branch: "feature/workspace-button",
|
|
}),
|
|
).toBe("https://github.com/acme/repo/tree/feature/workspace-button");
|
|
});
|
|
|
|
it("encodes reserved branch characters while preserving slash-separated branch names", () => {
|
|
expect(
|
|
buildGitHubBranchTreeUrl({
|
|
remoteUrl: "https://github.com/acme/repo.git",
|
|
branch: "feature/ship #42",
|
|
}),
|
|
).toBe("https://github.com/acme/repo/tree/feature/ship%20%2342");
|
|
});
|
|
|
|
it("returns null when the current branch is unavailable", () => {
|
|
expect(
|
|
buildGitHubBranchTreeUrl({
|
|
remoteUrl: "https://github.com/acme/repo.git",
|
|
branch: "HEAD",
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
});
|