From 6bf488ca0ca57cf34145169762830e424e095fa2 Mon Sep 17 00:00:00 2001 From: Gabriel Hernandez Date: Tue, 2 Dec 2025 12:09:32 +0000 Subject: [PATCH] fix issue with windows mdm manual enrollment setting (#36418) **Related issue:** Resolves #36303 Fixes an issue where a user could not update window mdm in fleet UI when they had automatic enrollment with auto migrate enabled and then select manual mdm enrollment - [x] QA'd all new/changed functionality manually --- .../WindowsMdmPage/WindowsMdmPage.tests.tsx | 74 +++++++++++++++++++ .../WindowsMdmPage/WindowsMdmPage.tsx | 1 + 2 files changed, 75 insertions(+) create mode 100644 frontend/pages/admin/IntegrationsPage/cards/MdmSettings/WindowsMdmPage/WindowsMdmPage.tests.tsx diff --git a/frontend/pages/admin/IntegrationsPage/cards/MdmSettings/WindowsMdmPage/WindowsMdmPage.tests.tsx b/frontend/pages/admin/IntegrationsPage/cards/MdmSettings/WindowsMdmPage/WindowsMdmPage.tests.tsx new file mode 100644 index 0000000000..d2b54f0096 --- /dev/null +++ b/frontend/pages/admin/IntegrationsPage/cards/MdmSettings/WindowsMdmPage/WindowsMdmPage.tests.tsx @@ -0,0 +1,74 @@ +import React from "react"; + +import { screen } from "@testing-library/react"; + +import { createMockRouter, createCustomRenderer } from "test/test-utils"; +import { createMockConfig, createMockMdmConfig } from "__mocks__/configMock"; +import WindowsMdmPage from "./WindowsMdmPage"; + +describe("WindowsMdmPage", () => { + it("renders only the windows mdm slider and description when on free tier", () => { + const render = createCustomRenderer({ + context: { + app: { + isPremiumTier: false, + config: createMockConfig(), + }, + }, + }); + + render(); + + // switch and description only shown + expect(screen.getByRole("switch")).toBeInTheDocument(); + expect( + screen.getByText( + "Turns on MDM for Windows hosts that enroll to Fleet (excluding servers)." + ) + ).toBeInTheDocument(); + + // no end user experience form + expect(screen.queryByLabelText("Automatic")).not.toBeInTheDocument(); + expect(screen.queryByLabelText("Manual")).not.toBeInTheDocument(); + }); + + it("renders the end user experience form as disabled when MDM is off", () => { + const render = createCustomRenderer({ + context: { + app: { + isPremiumTier: true, + config: createMockConfig({ + mdm: createMockMdmConfig({ windows_enabled_and_configured: false }), + }), + }, + }, + }); + + render(); + + expect(screen.getByLabelText("Automatic")).toBeDisabled(); + expect(screen.getByLabelText("Manual")).toBeDisabled(); + }); + + it("renders the automatically migrate checkbox if automatic mdm enrollment is selected", () => { + const render = createCustomRenderer({ + context: { + app: { + isPremiumTier: true, + config: createMockConfig({ + mdm: createMockMdmConfig({ + enable_turn_on_windows_mdm_manually: false, + windows_enabled_and_configured: true, + }), + }), + }, + }, + }); + + render(); + + // automatic is selected and the checkbox is visible + expect(screen.getByLabelText("Automatic")).toBeChecked(); + expect(screen.getByRole("checkbox")).toBeVisible(); + }); +}); diff --git a/frontend/pages/admin/IntegrationsPage/cards/MdmSettings/WindowsMdmPage/WindowsMdmPage.tsx b/frontend/pages/admin/IntegrationsPage/cards/MdmSettings/WindowsMdmPage/WindowsMdmPage.tsx index 1314699006..b8c2c87f70 100644 --- a/frontend/pages/admin/IntegrationsPage/cards/MdmSettings/WindowsMdmPage/WindowsMdmPage.tsx +++ b/frontend/pages/admin/IntegrationsPage/cards/MdmSettings/WindowsMdmPage/WindowsMdmPage.tsx @@ -103,6 +103,7 @@ const WindowsMdmPage = ({ router }: IWindowsMdmPageProps) => { }; const onChangeEnrollmentType = (value: string) => { + setAutoMigration(false); setEnrollmentType(value === "automaticEnrollment" ? "automatic" : "manual"); };