import React from "react";
import { shallow } from "enzyme";
import PositionedStreetView from "../components/screens/GamePanel/PositionedStreetView";

jest.mock("../domain/gameStore");
jest.mock("../components/screens/GamePanel/usePano");
jest.mock("../components/screens/GamePanel/useSavePanoSettings");

import {
  usePanoStartPosition,
  usePanoStartPov,
  useTargetPoint,
} from "../domain/gameStore";
import usePano from "../components/screens/GamePanel/usePano";

describe("PositionedStreetView", () => {
  it("renders", () => {
    usePanoStartPosition.mockReturnValue();
    usePanoStartPov.mockReturnValue();
    useTargetPoint.mockReturnValue();

    const rendered = shallow(<PositionedStreetView />);
    expect(rendered).toMatchSnapshot();
    expect(usePano).toHaveBeenCalled();
  });

  it("resets", () => {
    usePanoStartPosition.mockReturnValue();
    usePanoStartPov.mockReturnValue();
    useTargetPoint.mockReturnValue("point");
    const setPosition = jest.fn();
    usePano.mockReturnValue({ current: { setPosition } });

    const handle = shallow(<PositionedStreetView />);
    expect(handle).toMatchSnapshot();
    handle.find("div.resetButton").first().simulate("click");
    expect(setPosition).toHaveBeenCalledWith("point");
  });

  it("resets on enter on button", () => {
    usePanoStartPosition.mockReturnValue();
    usePanoStartPov.mockReturnValue();
    useTargetPoint.mockReturnValue("point");
    const setPosition = jest.fn();
    usePano.mockReturnValue({ current: { setPosition } });

    const handle = shallow(<PositionedStreetView />);
    expect(handle).toMatchSnapshot();
    handle
      .find("div.resetButton")
      .first()
      .simulate("keydown", { key: "Enter" });
    expect(setPosition).toHaveBeenCalledWith("point");
  });

  it("does not reset on other keys on button", () => {
    usePanoStartPosition.mockReturnValue();
    usePanoStartPov.mockReturnValue();
    useTargetPoint.mockReturnValue("point");
    const setPosition = jest.fn();
    usePano.mockReturnValue({ current: { setPosition } });

    const handle = shallow(<PositionedStreetView />);
    expect(handle).toMatchSnapshot();
    handle
      .find("div.resetButton")
      .first()
      .simulate("keydown", { key: "Escape" });
    expect(setPosition).not.toHaveBeenCalled();
  });
});
