import React from "react"; import Radio from "./radio"; import { fireEvent, render } from "@testing-library/react-native"; import { ThemeProvider } from "../../../theme/src/theme-context"; import RadioGroup from "./radio-group"; import Stack from "../../atoms/stack/stack"; jest.useFakeTimers(); describe("Molecules/Radio", () => { it("passes the snapshot test for basic setup", async () => { const tree = await render( Check me! ).toJSON(); expect(tree).toMatchSnapshot(); }); it("passes the snapshot test for different sizes", async () => { const tree = await render( Small Radio Regular Radio Large Radio Extra Large Radio ).toJSON(); expect(tree).toMatchSnapshot(); }); it("passes the snapshot test for different variants", async () => { const tree = await render( Filled Radio Outline Radio ).toJSON(); expect(tree).toMatchSnapshot(); }); it("passes the snapshot test when in a checked state", async () => { const tree = await render( Checked Radio Checked Radio ).toJSON(); expect(tree).toMatchSnapshot(); }); it("passes the snapshot test when in an error state", async () => { const tree = await render( Error Radio ).toJSON(); expect(tree).toMatchSnapshot(); }); it("passes the snapshot test for different color schemes", async () => { const tree = await render( Primary Radio Secondary Radio ).toJSON(); expect(tree).toMatchSnapshot(); }); it("passes the snapshot test when using style props", async () => { const onPress = jest.fn(); const tree = await render( Button press ).toJSON(); expect(tree).toMatchSnapshot(); }); it("captures the onPress event", async () => { const onPress = jest.fn(); const component = await render( Check me ); const tree = component.toJSON(); if ( (tree as any).children[0].children[0].children[0].type !== "RNGestureHandlerButton" ) { const pressableInstance = component.getByTestId("radio"); fireEvent.press(pressableInstance); expect(onPress).toHaveBeenCalledTimes(1); } }); it("changes the active value successfully when used in a group", async () => { const onChange = jest.fn(); const component = await render( Value 1 Value 2 Value 3 Value 4 ); const tree = component.toJSON(); if ( (tree as any).children[0].children[0].children[0].children[0].children[0] .children[0].type !== "RNGestureHandlerButton" ) { const radio1 = component.getByTestId("radio1"); fireEvent.press(radio1); expect(onChange).toHaveBeenCalledTimes(1); expect(onChange).toBeCalledWith("1"); const radio2 = component.getByTestId("radio2"); fireEvent.press(radio2); expect(onChange).toHaveBeenCalledTimes(2); expect(onChange).toBeCalledWith("2"); const radio3 = component.getByTestId("radio3"); fireEvent.press(radio3); expect(onChange).toHaveBeenCalledTimes(3); expect(onChange).toBeCalledWith(3); const radio4 = component.getByTestId("radio4"); fireEvent.press(radio4); expect(onChange).toHaveBeenCalledTimes(4); expect(onChange).toBeCalledWith(4); } }); it("doesn't capture the onPress event when the radio is disabled ", async () => { const onPress = jest.fn(); const component = await render( Check me ); const tree = component.toJSON(); if ( (tree as any).children[0].children[0].children[0].type !== "RNGestureHandlerButton" ) { const pressableInstance = component.getByTestId("radio"); fireEvent.press(pressableInstance); expect(onPress).toHaveBeenCalledTimes(0); } }); });