import React from "react";
import { shallow } from "enzyme";
import { FROZEN, NORMAL, RACE } from "../domain/ruleSets";
import GamePanel from "../components/screens/GamePanel";

jest.mock("../hooks/usePreventNavigation");
jest.mock("../hooks/useGameInfo");
jest.mock("../components/screens/GamePanel/useIsFinished");

import usePreventNavigation from "../hooks/usePreventNavigation";
import { useGameConfig } from "../hooks/useGameInfo";
import useIsFinished from "../components/screens/GamePanel/useIsFinished";

describe("GamePanel", () => {
  it("renders for NORMAL game", () => {
    useIsFinished.mockReturnValue(false);
    useGameConfig.mockReturnValue({ ruleSet: NORMAL });
    const rendered = shallow(<GamePanel />);
    expect(rendered).toMatchSnapshot();
    expect(usePreventNavigation).toHaveBeenCalled();
    expect(useGameConfig).toHaveBeenCalled();
  });

  it("renders for end of game", () => {
    useIsFinished.mockReturnValue(true);
    useGameConfig.mockReturnValue({ ruleSet: NORMAL });
    const rendered = shallow(<GamePanel />);
    expect(rendered).toMatchSnapshot();
    expect(usePreventNavigation).toHaveBeenCalled();
    expect(useGameConfig).toHaveBeenCalled();
  });

  it("renders for FROZEN game", () => {
    useIsFinished.mockReturnValue(false);
    useGameConfig.mockReturnValue({ ruleSet: FROZEN });
    const rendered = shallow(<GamePanel />);
    expect(rendered).toMatchSnapshot();
    expect(usePreventNavigation).toHaveBeenCalled();
    expect(useGameConfig).toHaveBeenCalled();
  });

  it("renders for RACE game", () => {
    useIsFinished.mockReturnValue(false);
    useGameConfig.mockReturnValue({ ruleSet: RACE });
    const rendered = shallow(<GamePanel />);
    expect(rendered).toMatchSnapshot();
    expect(usePreventNavigation).toHaveBeenCalled();
    expect(useGameConfig).toHaveBeenCalled();
  });
});
