Skip to content

Commit

Permalink
more comprehensive tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabalafou committed Nov 22, 2024
1 parent e067009 commit 02ecd55
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions test/artifacts/ArtifactsList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand All @@ -14,27 +14,43 @@ const ARTIFACTS = [
describe("<ArtifactList />", () => {
it("should render component", () => {
render(mockTheme(<ArtifactList artifacts={ARTIFACTS} />));

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(<ArtifactList artifacts={ARTIFACTS} />));
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(
<PrefContext.Provider
value={{
...prefDefault,
apiUrl
}}
>
<ArtifactList artifacts={ARTIFACTS} />
</PrefContext.Provider>
)
);
expect(screen.getByText("Show lockfile")).toHaveAttribute(
"href",
expectedArtifactUrl
);
});
});
}
});

0 comments on commit 02ecd55

Please sign in to comment.