fleet/frontend/components/forms/fields/Radio/Radio.tests.tsx
jacobshandling 06c48216f7
UI: Add Tooltip show delay across app (#33091)
## For #31869

- Add fine grain controls for tooltip show and hide delay behavior
- Default to 250ms show delay across app
- Update ~30 unit tests to expect new delay
- See
[note](https://github.com/fleetdm/fleet/issues/31869#issuecomment-3300660487)


https://github.com/user-attachments/assets/5969e0f7-c137-491f-8430-6f21d01b9350

- [x] Changes file added for user-visible changes in `changes/`
- [x] QA'd all new/changed functionality manually

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-09-18 09:42:30 -07:00

115 lines
2.9 KiB
TypeScript

import React from "react";
import { noop } from "lodash";
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { renderWithSetup } from "test/test-utils";
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 () => {
const { user } = renderWithSetup(
<Radio
disabled
label="Radio Label"
value="radioValue"
id="test-radio"
onChange={noop}
tooltip="A Test Radio Tooltip"
/>
);
await user.hover(screen.getByText("Radio Label"));
await waitFor(() => {
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");
});
});