2024-10-15 13:23:59 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
|
|
|
import { createCustomRenderer, createMockRouter } from "test/test-utils";
|
|
|
|
|
|
2025-12-02 12:11:10 +00:00
|
|
|
import PATHS from "router/paths";
|
2024-10-15 13:23:59 +00:00
|
|
|
|
2025-12-02 12:11:10 +00:00
|
|
|
import GenericMsgWithNavButton from "./GenericMsgWithNavButton";
|
|
|
|
|
|
|
|
|
|
describe("GenericMsgWithNavButton", () => {
|
|
|
|
|
it("renders with passed in header and info", () => {
|
|
|
|
|
render(
|
|
|
|
|
<GenericMsgWithNavButton
|
|
|
|
|
header="Manage your hosts"
|
|
|
|
|
info="MDM must be turned on to change settings on your hosts."
|
|
|
|
|
path={PATHS.ADMIN_INTEGRATIONS_MDM}
|
|
|
|
|
buttonText="Turn on"
|
|
|
|
|
router={createMockRouter()}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2024-10-15 13:23:59 +00:00
|
|
|
|
|
|
|
|
expect(screen.getByText("Manage your hosts")).toBeInTheDocument();
|
|
|
|
|
expect(
|
|
|
|
|
screen.getByText(
|
|
|
|
|
"MDM must be turned on to change settings on your hosts."
|
|
|
|
|
)
|
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders "Turn on" button for global admin pushes to /settings/integrration/mdm when "Turn on" button is clicked', () => {
|
|
|
|
|
const customRender = createCustomRenderer({
|
|
|
|
|
context: {
|
|
|
|
|
app: {
|
|
|
|
|
isGlobalAdmin: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-02 12:11:10 +00:00
|
|
|
customRender(
|
|
|
|
|
<GenericMsgWithNavButton
|
|
|
|
|
header="test"
|
|
|
|
|
info="test"
|
|
|
|
|
buttonText="Turn on"
|
|
|
|
|
path={PATHS.ADMIN_INTEGRATIONS_MDM}
|
|
|
|
|
router={createMockRouter()}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Turn on" }));
|
2024-10-15 13:23:59 +00:00
|
|
|
|
|
|
|
|
expect(createMockRouter().push).toHaveBeenCalledWith(
|
2025-12-02 12:11:10 +00:00
|
|
|
PATHS.ADMIN_INTEGRATIONS_MDM
|
2024-10-15 13:23:59 +00:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-02 12:11:10 +00:00
|
|
|
it("does not render the button for non-global admin", () => {
|
2024-10-15 13:23:59 +00:00
|
|
|
const customRender = createCustomRenderer({
|
|
|
|
|
context: {
|
|
|
|
|
app: {
|
|
|
|
|
isGlobalAdmin: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-02 12:11:10 +00:00
|
|
|
customRender(
|
|
|
|
|
<GenericMsgWithNavButton
|
|
|
|
|
header="test"
|
|
|
|
|
info="test"
|
|
|
|
|
path={"test"}
|
|
|
|
|
buttonText="Turn on"
|
|
|
|
|
router={createMockRouter()}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2024-10-15 13:23:59 +00:00
|
|
|
|
|
|
|
|
expect(screen.queryByText("Turn on")).not.toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
});
|