import React from "react"; import { shallow } from "enzyme"; import PositionedStreetView from "../components/screens/GamePanel/PositionedStreetView"; jest.mock("../domain/gameStore"); jest.mock("../components/screens/GamePanel/hooks"); import { usePanoStartPosition, usePanoStartPov, useTargetPoint, } from "../domain/gameStore"; import { usePano } from "../components/screens/GamePanel/hooks"; describe("PositionedStreetView", () => { it("renders", () => { usePanoStartPosition.mockReturnValue(); usePanoStartPov.mockReturnValue(); useTargetPoint.mockReturnValue(); const rendered = shallow(); 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(); 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(); 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(); expect(handle).toMatchSnapshot(); handle .find("div.resetButton") .first() .simulate("keydown", { key: "Escape" }); expect(setPosition).not.toHaveBeenCalled(); }); });