mirror of
https://github.com/fleetdm/fleet
synced 2026-05-22 00:18:27 +00:00
relates to #23136 This is the UI for the creating of policies when adding fleet maintained software. This includes only the creating of the policy and there will be another PR for viewing more information on the software titles details page. **new install type options. this determines if a policy should be created or not.**  there are also some new icons for the software titles. - [] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. - [x] Manual QA for all new/changed functionality
112 lines
2.8 KiB
TypeScript
112 lines
2.8 KiB
TypeScript
import React from "react";
|
|
import { noop } from "lodash";
|
|
import { render, screen, fireEvent } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
|
|
import Radio from "./Radio";
|
|
|
|
describe("Radio - component", () => {
|
|
it("renders the radio label text from the label prop", () => {
|
|
render(
|
|
<Radio
|
|
checked
|
|
label="Radio Label"
|
|
value="radioValue"
|
|
id="test-radio"
|
|
onChange={noop}
|
|
/>
|
|
);
|
|
|
|
const labelText = screen.getByText("Radio Label");
|
|
expect(labelText).toBeInTheDocument();
|
|
});
|
|
|
|
it("passes the radio input value when checked", async () => {
|
|
const user = userEvent.setup();
|
|
const changeHandlerSpy = jest.fn();
|
|
|
|
render(
|
|
<Radio
|
|
label="Radio Label"
|
|
value="radioValue"
|
|
id="test-radio"
|
|
onChange={changeHandlerSpy}
|
|
/>
|
|
);
|
|
|
|
const radio = screen.getByRole("radio", { name: "Radio Label" });
|
|
await user.click(radio);
|
|
|
|
expect(changeHandlerSpy).toHaveBeenCalled();
|
|
expect(changeHandlerSpy).toHaveBeenCalledWith("radioValue");
|
|
});
|
|
|
|
it("renders the correct selected state from checked prop", () => {
|
|
render(
|
|
<Radio
|
|
checked
|
|
label="Radio Label"
|
|
value="radioValue"
|
|
id="test-radio"
|
|
onChange={noop}
|
|
/>
|
|
);
|
|
|
|
const radio = screen.getByRole("radio", { name: "Radio Label" });
|
|
expect(radio).toBeChecked();
|
|
});
|
|
|
|
it("renders the correct disabled state from disabled prop", () => {
|
|
render(
|
|
<Radio
|
|
disabled
|
|
label="Radio Label"
|
|
value="radioValue"
|
|
id="test-radio"
|
|
onChange={noop}
|
|
testId="radio-input"
|
|
/>
|
|
);
|
|
|
|
const radio = screen.getByRole("radio", { name: "Radio Label" });
|
|
expect(radio).toBeDisabled();
|
|
|
|
// Also adds a disabled class to the componet
|
|
const radioComponent = screen.getByTestId("radio-input");
|
|
expect(radioComponent).toHaveClass("radio__disabled");
|
|
});
|
|
|
|
it("render a tooltip from the tooltip prop", async () => {
|
|
render(
|
|
<Radio
|
|
disabled
|
|
label="Radio Label"
|
|
value="radioValue"
|
|
id="test-radio"
|
|
onChange={noop}
|
|
tooltip="A Test Radio Tooltip"
|
|
/>
|
|
);
|
|
|
|
await fireEvent.mouseEnter(screen.getByText("Radio Label"));
|
|
const tooltip = screen.getByText("A Test Radio Tooltip");
|
|
expect(tooltip).toBeInTheDocument();
|
|
});
|
|
|
|
it("adds the custom class name from the className prop", () => {
|
|
render(
|
|
<Radio
|
|
disabled
|
|
label="Radio Label"
|
|
value="radioValue"
|
|
id="test-radio"
|
|
onChange={noop}
|
|
className="radio-button"
|
|
testId="radio-input"
|
|
/>
|
|
);
|
|
|
|
const radioComponent = screen.getByTestId("radio-input");
|
|
expect(radioComponent).toHaveClass("radio-button");
|
|
});
|
|
});
|