blob: aa109e5f7f9b70f908781fbbaa793228417df8ca [file] [log] [blame]
Josh Bleecher Snyder7de3bdd2025-07-18 01:51:53 +00001import { test, expect } from "@sand4rt/experimental-ct-web";
2import { SketchPushButton } from "./sketch-push-button";
3
4test("does not show GitHub link for non-GitHub remotes", async ({ mount }) => {
5 const component = await mount(SketchPushButton, {});
6
7 // Test GitHub remote (should return URL)
8 const githubURL = await component.evaluate((el: SketchPushButton) => {
9 const githubRemote = {
10 name: "origin",
11 url: "https://github.com/user/repo.git",
12 display_name: "user/repo",
13 is_github: true,
14 };
15 (el as any)._remotes = [githubRemote];
16 (el as any)._selectedRemote = "origin";
17 (el as any)._branch = "test-branch";
18 return (el as any)._computeBranchURL();
19 });
20 expect(githubURL).toBe("https://github.com/user/repo/tree/test-branch");
21
22 // Test GitLab remote (should return empty string)
23 const gitlabURL = await component.evaluate((el: SketchPushButton) => {
24 const gitlabRemote = {
25 name: "gitlab",
26 url: "https://gitlab.com/user/repo.git",
27 display_name: "gitlab.com/user/repo",
28 is_github: false,
29 };
30 (el as any)._remotes = [gitlabRemote];
31 (el as any)._selectedRemote = "gitlab";
32 (el as any)._branch = "test-branch";
33 return (el as any)._computeBranchURL();
34 });
35 expect(gitlabURL).toBe("");
36
37 // Test self-hosted remote (should return empty string)
38 const selfHostedURL = await component.evaluate((el: SketchPushButton) => {
39 const selfHostedRemote = {
40 name: "self",
41 url: "https://git.company.com/user/repo.git",
42 display_name: "git.company.com/user/repo",
43 is_github: false,
44 };
45 (el as any)._remotes = [selfHostedRemote];
46 (el as any)._selectedRemote = "self";
47 (el as any)._branch = "test-branch";
48 return (el as any)._computeBranchURL();
49 });
50 expect(selfHostedURL).toBe("");
51});
52
53test("handles missing remote gracefully", async ({ mount }) => {
54 const component = await mount(SketchPushButton, {});
55
56 // Test with no remotes
57 const noRemotesURL = await component.evaluate((el: SketchPushButton) => {
58 (el as any)._remotes = [];
59 (el as any)._selectedRemote = "";
60 (el as any)._branch = "test-branch";
61 return (el as any)._computeBranchURL();
62 });
63 expect(noRemotesURL).toBe("");
64
65 // Test with selected remote that doesn't exist
66 const invalidRemoteURL = await component.evaluate((el: SketchPushButton) => {
Autoformatter9db8c2a2025-07-18 02:15:29 +000067 (el as any)._remotes = [
68 {
69 name: "origin",
70 url: "https://github.com/user/repo.git",
71 display_name: "user/repo",
72 is_github: true,
73 },
74 ];
Josh Bleecher Snyder7de3bdd2025-07-18 01:51:53 +000075 (el as any)._selectedRemote = "nonexistent";
76 (el as any)._branch = "test-branch";
77 return (el as any)._computeBranchURL();
78 });
79 expect(invalidRemoteURL).toBe("");
80});