import { render, fireEvent, waitFor } from "../../../../config/test-utils";
import * as React from "react";
import ToggleSwitch from "../";

describe("core/Primitive/ToggleSwitch", () => {
  describe("<ToggleSwitch />", () => {
    test("renders correctly", () => {
      const container = render(<ToggleSwitch />);
      const _toggleSwitch = container.queryByText("EN");
      expect(_toggleSwitch).toBeNull();
    });

    test("renders onLabel & offLabel correctly", async () => {
      const eventMock = jest.fn();
      const container = render(
        <ToggleSwitch
          testID="toggleLanguage"
          onChange={eventMock}
          onLabel="EN"
          offLabel="ID"
        />
      );
      const _toggleSwitchEN = container.queryByText("EN");
      const _toggleSwitchID = container.queryByText("ID");
      const _togglePress = container.getByTestId("toggleLanguage");
      expect(_toggleSwitchEN).toBeTruthy();
      expect(_toggleSwitchID).toBeTruthy();

      fireEvent.press(_togglePress);

      await waitFor(() => expect(eventMock).toHaveBeenCalledTimes(1));
    });
  });
});
