import * as reactModule from "react";
import { shallow } from "enzyme";
import MultipleStatesComponent from "./MultipleStatesComponent";

describe("test multiple state in component", () => {
  let wrapper;
  let setDataLength;
  let setLoading;
  let setText;

  beforeEach(() => {
    setDataLength = jest.fn(x => {});
    setLoading = jest.fn(x => {});
    setText = jest.fn(x => {});

    reactModule.useState = jest
      .fn()
      .mockImplementationOnce(x => [x, setDataLength])
      .mockImplementationOnce(x => [x, setLoading])
      .mockImplementationOnce(x => [x, setText]);

    wrapper = shallow(<MultipleStatesComponent />);
  });

  it("should test button one", () => {
    wrapper
      .find("button")
      .at(0)
      .simulate("click");

    expect(setDataLength).toHaveBeenCalledWith(10);
  });

  it("should test button two", () => {
    wrapper
      .find("button")
      .at(1)
      .simulate("click");
    expect(setLoading).toHaveBeenCalledWith(true);
    expect(setText).toHaveBeenCalledWith("text set by button");
  });
});