Skip to content

Commit

Permalink
Merge pull request #96 from 2i2c-org/no-options-test
Browse files Browse the repository at this point in the history
Add test for profiles without options
  • Loading branch information
yuvipanda authored Nov 19, 2024
2 parents 006ff81 + c5d6d31 commit b5f9c76
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ window.profileList = [
slug: "custom",
},
{
slug: "build-custom-environment",
description: "Dynamic Image building + unlisted choice",
display_name: "Build custom environment",
profile_options: {
Expand All @@ -220,4 +221,15 @@ window.profileList = [
},
},
},
{
slug: "empty-options",
description: "Profile with empty options",
display_name: "Empty Options",
profile_options: {},
},
{
slug: "no-options",
description: "Profile with no options",
display_name: "No Options",
},
];
18 changes: 18 additions & 0 deletions src/ProfileForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,22 @@ describe("Profile form with URL Params", () => {
expect(screen.getByLabelText("Repository").value).toEqual("org/repo");
expect(screen.getByLabelText("Git Ref").value).toEqual("v1.0");
});

test("no-option profiles are rendered", () => {
render(
<SpawnerFormProvider>
<ProfileForm />
</SpawnerFormProvider>,
);

const empty = screen.queryByRole("radio", {
name: "Empty Options Profile with empty options",
});
expect(empty).toBeInTheDocument();

const noObject = screen.queryByRole("radio", {
name: "No Options Profile with no options",
});
expect(noObject).toBeInTheDocument();
});
});
3 changes: 3 additions & 0 deletions src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export const SpawnerFormContext = createContext();

function isDynamicImageProfile(profile) {
const { profile_options } = profile;

if (!profile_options) return false;

return Object.entries(profile_options).some(([key, option]) =>
hasDynamicImageBuilding(key, option),
);
Expand Down

0 comments on commit b5f9c76

Please sign in to comment.