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