diff --git a/test/artifacts/ArtifactsList.test.tsx b/test/artifacts/ArtifactsList.test.tsx index 705a280f..da6b6b45 100644 --- a/test/artifacts/ArtifactsList.test.tsx +++ b/test/artifacts/ArtifactsList.test.tsx @@ -2,7 +2,7 @@ import React from "react"; import { render, screen } from "@testing-library/react"; import { ArtifactList } from "../../src/features/artifacts/components"; import { mockTheme } from "../testutils"; -import { prefGlobal, prefDefault } from "../../src/preferences"; +import { PrefContext, prefDefault } from "../../src/preferences"; const ARTIFACTS = [ { @@ -14,27 +14,43 @@ const ARTIFACTS = [ describe("", () => { it("should render component", () => { render(mockTheme()); - expect(screen.getByText("Logs and Artifacts")).toBeInTheDocument(); expect(screen.getByText("Show lockfile")).toBeVisible(); - - expect(prefGlobal.apiUrl).toBe("http://localhost:8080/conda-store/"); - expect(screen.getByText("Show lockfile")).toHaveAttribute( - "href", - "http://localhost:8080/conda-store/api/v1/build/1/lockfile/" - ); }); - it("should render correct URL if API base url lacks trailing slash", () => { - prefGlobal.set({ - ...prefDefault, - apiUrl: "http://localhost:8080/conda-store" - }); - - render(mockTheme()); - expect(screen.getByText("Show lockfile")).toHaveAttribute( - "href", + for (const [apiUrl, expectedArtifactUrl] of [ + [ + "http://localhost:8080/conda-store/", "http://localhost:8080/conda-store/api/v1/build/1/lockfile/" - ); - }); + ], + [ + "http://localhost:8080/conda-store", + "http://localhost:8080/conda-store/api/v1/build/1/lockfile/" + ], + ["http://localhost:8080", "http://localhost:8080/api/v1/build/1/lockfile/"], + ["/conda-store", "/conda-store/api/v1/build/1/lockfile/"], + ["/", "/api/v1/build/1/lockfile/"], + ["", "/api/v1/build/1/lockfile/"] + ]) { + describe(`with REACT_APP_API_URL set to ${apiUrl}`, () => { + it(`should render expected artifact URL ${expectedArtifactUrl}`, () => { + render( + mockTheme( + + + + ) + ); + expect(screen.getByText("Show lockfile")).toHaveAttribute( + "href", + expectedArtifactUrl + ); + }); + }); + } });