From 9f7e95f73c51715d8e521113eab76fa9837f3f53 Mon Sep 17 00:00:00 2001 From: Oliver Roick Date: Mon, 18 Nov 2024 16:09:00 +1100 Subject: [PATCH 1/2] Add test for profiles without options --- setupTests.js | 12 ++++++++++++ src/ProfileForm.test.js | 18 ++++++++++++++++++ src/state.js | 3 +++ 3 files changed, 33 insertions(+) diff --git a/setupTests.js b/setupTests.js index 980252d..e92b0c9 100644 --- a/setupTests.js +++ b/setupTests.js @@ -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: { @@ -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" + }, ]; diff --git a/src/ProfileForm.test.js b/src/ProfileForm.test.js index 34614b2..ab55146 100644 --- a/src/ProfileForm.test.js +++ b/src/ProfileForm.test.js @@ -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( + + + , + ); + + 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(); + }); }); diff --git a/src/state.js b/src/state.js index 5d261c1..f217caa 100644 --- a/src/state.js +++ b/src/state.js @@ -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), ); From c5d6d317ddf056eed1f934b8be69e22ff5b06d62 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 05:10:50 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- setupTests.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setupTests.js b/setupTests.js index e92b0c9..9f2c116 100644 --- a/setupTests.js +++ b/setupTests.js @@ -225,11 +225,11 @@ window.profileList = [ slug: "empty-options", description: "Profile with empty options", display_name: "Empty Options", - profile_options: {} + profile_options: {}, }, { slug: "no-options", description: "Profile with no options", - display_name: "No Options" + display_name: "No Options", }, ];