|
1 | 1 | import { describe, expect, it } from "vitest"; |
2 | 2 | import { |
3 | 3 | buildRepositoryOptions, |
| 4 | + buildUserRepositoryOptions, |
4 | 5 | findRepositoryOption, |
5 | 6 | isRepositorySelectionComplete, |
| 7 | + repositoryLoadWarning, |
| 8 | + repositoryOptionsEqual, |
6 | 9 | toRepositorySelection, |
7 | 10 | } from "./repositorySelection"; |
8 | 11 |
|
@@ -59,6 +62,52 @@ describe("repositorySelection", () => { |
59 | 62 | }); |
60 | 63 | }); |
61 | 64 |
|
| 65 | + it.each([ |
| 66 | + [{ installation_id: "42", account: { name: "PostHog" } }, "PostHog"], |
| 67 | + [{ installation_id: "43" }, "GitHub 43"], |
| 68 | + ])( |
| 69 | + "builds user integration options with the expected label", |
| 70 | + (integration, integrationLabel) => { |
| 71 | + expect( |
| 72 | + buildUserRepositoryOptions([integration], { |
| 73 | + [integration.installation_id]: ["posthog/code"], |
| 74 | + }), |
| 75 | + ).toEqual([ |
| 76 | + { |
| 77 | + integrationId: Number(integration.installation_id), |
| 78 | + integrationLabel, |
| 79 | + repository: "posthog/code", |
| 80 | + }, |
| 81 | + ]); |
| 82 | + }, |
| 83 | + ); |
| 84 | + |
| 85 | + it("treats a changed label as a different repository option", () => { |
| 86 | + const option = { |
| 87 | + integrationId: 11, |
| 88 | + integrationLabel: "posthog", |
| 89 | + repository: "posthog/code", |
| 90 | + }; |
| 91 | + |
| 92 | + expect( |
| 93 | + repositoryOptionsEqual( |
| 94 | + [option], |
| 95 | + [{ ...option, integrationLabel: "PostHog GitHub" }], |
| 96 | + ), |
| 97 | + ).toBe(false); |
| 98 | + }); |
| 99 | + |
| 100 | + it.each([ |
| 101 | + [0, 2, null], |
| 102 | + [1, 2, "Some GitHub repositories could not be loaded. Pull to retry."], |
| 103 | + [2, 2, "Could not load GitHub repositories. Pull to retry."], |
| 104 | + ])( |
| 105 | + "maps repository failures to the expected warning", |
| 106 | + (failedCount, totalCount, expected) => { |
| 107 | + expect(repositoryLoadWarning(failedCount, totalCount)).toBe(expected); |
| 108 | + }, |
| 109 | + ); |
| 110 | + |
62 | 111 | it("converts an option into a repository selection", () => { |
63 | 112 | const selection = toRepositorySelection({ |
64 | 113 | integrationId: 11, |
|
0 commit comments