| Josh Bleecher Snyder | 7de3bdd | 2025-07-18 01:51:53 +0000 | [diff] [blame] | 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ |
| 2 | import { test, expect } from "@sand4rt/experimental-ct-web"; |
| 3 | import { SketchPushButton } from "./sketch-push-button"; |
| 4 | |
| 5 | test("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 | |
| 54 | test("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) => { |
| Autoformatter | 9db8c2a | 2025-07-18 02:15:29 +0000 | [diff] [blame] | 68 | (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 Snyder | 7de3bdd | 2025-07-18 01:51:53 +0000 | [diff] [blame] | 76 | (el as any)._selectedRemote = "nonexistent"; |
| 77 | (el as any)._branch = "test-branch"; |
| 78 | return (el as any)._computeBranchURL(); |
| 79 | }); |
| 80 | expect(invalidRemoteURL).toBe(""); |
| 81 | }); |