import React from "react"; import "@testing-library/jest-dom"; import { render, screen } from "@testing-library/react"; import { ThemeProvider } from "constants/DefaultTheme"; import { StepComponent } from "./StepComponent"; import { lightTheme } from "selectors/themeSelectors"; import userEvent from "@testing-library/user-event"; import { noop } from "lodash"; describe(" - Keyboard navigation", () => { const getTestComponent = (handleOnChange: any = noop) => ( { return `${value}%`; }} max={100} min={0} onChange={handleOnChange} steps={5} value={50} /> ); it("Pressing tab should focus the component", () => { render(getTestComponent()); userEvent.tab(); expect(screen.getByTestId("step-wrapper")).toHaveFocus(); expect(screen.getByTestId("step-wrapper")).toHaveTextContent("50%"); }); it.each(["{ArrowUp}", "{ArrowRight}"])( "Pressing %s should increase the value", (k) => { const fn = jest.fn(); render(getTestComponent(fn)); userEvent.tab(); userEvent.keyboard(k); expect(fn).toBeCalledWith(55); }, ); it.each(["{ArrowDown}", "{ArrowLeft}"])( "Pressing %s should increase the value", (k) => { const fn = jest.fn(); render(getTestComponent(fn)); userEvent.tab(); userEvent.keyboard(k); expect(fn).toBeCalledWith(45); }, ); });