fleet/frontend/components/forms/fields/Slider/Slider.tests.tsx
Gabriel Hernandez a5c69a60a4
Fix bug for not being to reenable end user migration in UI (#30106)
Fixes #30063

This fixes an issue added in the
[PR](https://github.com/fleetdm/fleet/pull/29968) where the user was not
able to reenable the end user migration form.

I've also added improved a11y attributes to the slider component,
ensured we are functionally disabling the form controls during gitops
mode and not just visually, and updated/added tests for the
EndUserMigrationSection component.


- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
- [x] Added/updated automated tests
- [x] Manual QA for all new/changed functionality
2025-06-20 17:04:30 +01:00

30 lines
951 B
TypeScript

import React from "react";
import { render, fireEvent, screen } from "@testing-library/react";
import Slider from "./Slider";
describe("Slider Component", () => {
const defaultProps = {
onChange: jest.fn(),
value: false,
inactiveText: "Off",
activeText: "On",
};
it("renders correctly with default props", () => {
render(<Slider {...defaultProps} />);
expect(screen.getByText("Off")).toBeInTheDocument();
expect(screen.getByRole("switch")).toHaveClass("fleet-slider");
});
it("renders active state correctly", () => {
render(<Slider {...defaultProps} value />);
expect(screen.getByText("On")).toBeInTheDocument();
expect(screen.getByRole("switch")).toHaveClass("fleet-slider--active");
});
it("calls onChange when clicked", () => {
render(<Slider {...defaultProps} />);
fireEvent.click(screen.getByRole("switch"));
expect(defaultProps.onChange).toHaveBeenCalledTimes(1);
});
});