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

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

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

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

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

  it("renders for FROZEN game", () => {
    useIsFinished.mockReturnValue(false);
    useGameConfig.mockReturnValue({
      gameMode: FROZEN,
      clockMode: NORMAL,
      scoreMethod: DISTANCE,
      roundPointCap: null,
    });
    const rendered = shallow(<GamePanel />);
    expect(rendered).toMatchSnapshot();
    expect(usePreventNavigation).toHaveBeenCalled();
    expect(useGameConfig).toHaveBeenCalled();
  });

  it("renders for RACE game", () => {
    useIsFinished.mockReturnValue(false);
    useGameConfig.mockReturnValue({
      gameMode: NORMAL,
      clockMode: RACE,
      scoreMethod: DISTANCE,
      roundPointCap: null,
    });
    const rendered = shallow(<GamePanel />);
    expect(rendered).toMatchSnapshot();
    expect(usePreventNavigation).toHaveBeenCalled();
    expect(useGameConfig).toHaveBeenCalled();
  });
});
