mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #29657 # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [x] Added/updated automated tests - [x] QA'd all new/changed functionality manually
78 lines
2 KiB
TypeScript
78 lines
2 KiB
TypeScript
import React from "react";
|
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import { createCustomRenderer, createMockRouter } from "test/test-utils";
|
|
|
|
import PATHS from "router/paths";
|
|
|
|
import GenericMsgWithNavButton from "./GenericMsgWithNavButton";
|
|
|
|
describe("GenericMsgWithNavButton", () => {
|
|
it("renders with passed in header and info", () => {
|
|
render(
|
|
<GenericMsgWithNavButton
|
|
header="Additional configuration required"
|
|
info="MDM must be turned on to change settings on your hosts."
|
|
path={PATHS.ADMIN_INTEGRATIONS_MDM}
|
|
buttonText="Turn on"
|
|
router={createMockRouter()}
|
|
/>
|
|
);
|
|
|
|
expect(
|
|
screen.getByText("Additional configuration required")
|
|
).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,
|
|
},
|
|
},
|
|
});
|
|
|
|
customRender(
|
|
<GenericMsgWithNavButton
|
|
header="test"
|
|
info="test"
|
|
buttonText="Turn on"
|
|
path={PATHS.ADMIN_INTEGRATIONS_MDM}
|
|
router={createMockRouter()}
|
|
/>
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "Turn on" }));
|
|
|
|
expect(createMockRouter().push).toHaveBeenCalledWith(
|
|
PATHS.ADMIN_INTEGRATIONS_MDM
|
|
);
|
|
});
|
|
|
|
it("does not render the button for non-global admin", () => {
|
|
const customRender = createCustomRenderer({
|
|
context: {
|
|
app: {
|
|
isGlobalAdmin: false,
|
|
},
|
|
},
|
|
});
|
|
|
|
customRender(
|
|
<GenericMsgWithNavButton
|
|
header="test"
|
|
info="test"
|
|
path={"test"}
|
|
buttonText="Turn on"
|
|
router={createMockRouter()}
|
|
/>
|
|
);
|
|
|
|
expect(screen.queryByText("Turn on")).not.toBeInTheDocument();
|
|
});
|
|
});
|