Skip to content

Commit

Permalink
Fix KVM checkbox when switching from other OS/Release to Ubuntu 18.04.
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb Ellis committed Apr 29, 2020
1 parent 9511b12 commit b22ff4c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ export const DeployFormFields = () => {

const user = useSelector(authSelectors.get);
const osOptions = useSelector(configSelectors.defaultOSystemOptions);
const releaseOptions = useSelector((state) =>
generalSelectors.osInfo.getOsReleases(state, values.oSystem)
const allReleaseOptions = useSelector(
generalSelectors.osInfo.getAllOsReleases
);
const releaseOptions = allReleaseOptions[values.oSystem];
const kernelOptions = useSelector((state) =>
generalSelectors.osInfo.getUbuntuKernelOptions(state, values.release)
);
Expand All @@ -35,7 +36,11 @@ export const DeployFormFields = () => {
options={osOptions}
onChange={(e) => {
handleChange(e);
if (e.target.value !== "ubuntu") {
const value = e.target.value;
if (allReleaseOptions[value] && allReleaseOptions[value].length) {
setFieldValue("release", allReleaseOptions[value][0].value);
}
if (value !== "ubuntu") {
setFieldValue("installKVM", false);
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,44 @@ describe("DeployFormFields", () => {
expect(wrapper.find("[data-test='kvm-warning']").exists()).toBe(false);
});

it("enables KVM checkbox when switching to Ubuntu 18.04 from a different OS/Release", async () => {
const state = { ...initialState };
state.general.osInfo.data.default_release = "bionic";
const store = mockStore(state);
const wrapper = mount(
<Provider store={store}>
<MemoryRouter
initialEntries={[{ pathname: "/machines/add", key: "testKey" }]}
>
<DeployForm />
</MemoryRouter>
</Provider>
);
// Initial selection is Ubuntu 18.04. Switch to CentOS 6 to CentOS 7 back to
// Ubuntu 18.04 and checkbox should be enabled.
await act(async () => {
wrapper
.find("Select[name='oSystem']")
.simulate("change", { target: { name: "oSystem", value: "centos" } });
});
wrapper.update();
await act(async () => {
wrapper
.find("Select[name='release']")
.simulate("change", { target: { name: "release", value: "centos70" } });
});
wrapper.update();
await act(async () => {
wrapper
.find("Select[name='oSystem']")
.simulate("change", { target: { name: "oSystem", value: "ubuntu" } });
});
wrapper.update();
expect(wrapper.find("Input[name='installKVM']").props().disabled).toBe(
false
);
});

it("displays a warning if user has no SSH keys", () => {
const state = { ...initialState };
state.user.auth.user.sshkeys_count = 0;
Expand Down

0 comments on commit b22ff4c

Please sign in to comment.