Repository navigation
Expand file tree
/
Copy pathpullRequestNavigation.test.ts
More file actions
79 lines (73 loc) · 3.11 KB
/
Copy pathpullRequestNavigation.test.ts
File metadata and controls
79 lines (73 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { EnvironmentId, ProjectId, SourceControlProviderKind } from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";
import { nativePullRequestDestination as destination } from "../../lib/pullRequestNavigation";
const context = { environmentId: "remote", projectId: "project" };
const project = (id: string, canonicalKey: string, provider: string, remoteUrl: string) => ({
id: ProjectId.make(id),
environmentId: EnvironmentId.make("remote"),
repositoryIdentity: {
canonicalKey,
locator: { source: "git-remote" as const, remoteName: "origin", remoteUrl },
displayName: canonicalKey.split("/").slice(1).join("/"),
provider: SourceControlProviderKind.make(provider),
},
});
const projects = [
project("project", "github.com/org/repo", "github", "git@github.com:org/repo.git"),
project("gitlab", "git.example/group/sub/repo", "gitlab", "git@git.example:group/sub/repo.git"),
project("forgejo", "forgejo.test/org/repo", "forgejo", "http://forgejo.test:3000/org/repo.git"),
];
const nativePullRequestDestination = (
url: string,
linkContext: typeof context | null,
linkProjects: typeof projects,
configLoaded: Parameters<typeof destination>[3] = () => true,
) => destination(url, linkContext, linkProjects, configLoaded);
describe("native PR entry points", () => {
it("keeps a thread link in its own environment and handles renamed host path shapes", () => {
expect(
nativePullRequestDestination(
"https://github.com/org/repo/pull/12/files#diff",
context,
projects,
),
).toEqual({
...context,
host: "github.com",
repository: "org/repo",
number: 12,
navigationUrl: "https://github.com/org/repo/pull/12/files#diff",
});
expect(
nativePullRequestDestination(
"https://git.example/group/sub/repo/-/merge_requests/9",
context,
projects,
),
).toMatchObject({ projectId: "gitlab", repository: "group/sub/repo" });
expect(
nativePullRequestDestination("http://forgejo.test:3000/org/repo/pulls/3", context, projects)
?.host,
).toBe("forgejo.test:3000");
});
it("opens a repository nobody has checked out under a project on its host, as web does", () => {
expect(
nativePullRequestDestination("https://github.com/someone/else/pull/12", context, projects),
).toEqual({ ...context, host: "github.com", repository: "someone/else", number: 12 });
});
it("leaves links to the external opener when the environment cannot show them", () => {
const url = "https://github.com/org/repo/pull/12";
expect(nativePullRequestDestination(url, context, projects, () => false)).toBeNull();
});
it("leaves issues, unknown sites, and unscoped links to the external opener", () => {
expect(
nativePullRequestDestination("https://github.com/org/repo/issues/12", context, projects),
).toBeNull();
expect(
nativePullRequestDestination("https://example.com/org/repo/pull/12", context, projects),
).toBeNull();
expect(
nativePullRequestDestination("https://github.com/org/repo/pull/12", null, projects),
).toBeNull();
});
});