PositionedStreetView.test.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import React from "react";
  2. import { shallow } from "enzyme";
  3. import PositionedStreetView from "../components/screens/GamePanel/PositionedStreetView";
  4. jest.mock("../domain/gameStore");
  5. jest.mock("../components/screens/GamePanel/hooks");
  6. import {
  7. usePanoStartPosition,
  8. usePanoStartPov,
  9. useTargetPoint,
  10. } from "../domain/gameStore";
  11. import { usePano } from "../components/screens/GamePanel/hooks";
  12. describe("PositionedStreetView", () => {
  13. it("renders", () => {
  14. usePanoStartPosition.mockReturnValue();
  15. usePanoStartPov.mockReturnValue();
  16. useTargetPoint.mockReturnValue();
  17. const rendered = shallow(<PositionedStreetView />);
  18. expect(rendered).toMatchSnapshot();
  19. expect(usePano).toHaveBeenCalled();
  20. });
  21. it("resets", () => {
  22. usePanoStartPosition.mockReturnValue();
  23. usePanoStartPov.mockReturnValue();
  24. useTargetPoint.mockReturnValue("point");
  25. const setPosition = jest.fn();
  26. usePano.mockReturnValue({ current: { setPosition } });
  27. const handle = shallow(<PositionedStreetView />);
  28. expect(handle).toMatchSnapshot();
  29. handle.find("div.resetButton").first().simulate("click");
  30. expect(setPosition).toHaveBeenCalledWith("point");
  31. });
  32. it("resets on enter on button", () => {
  33. usePanoStartPosition.mockReturnValue();
  34. usePanoStartPov.mockReturnValue();
  35. useTargetPoint.mockReturnValue("point");
  36. const setPosition = jest.fn();
  37. usePano.mockReturnValue({ current: { setPosition } });
  38. const handle = shallow(<PositionedStreetView />);
  39. expect(handle).toMatchSnapshot();
  40. handle
  41. .find("div.resetButton")
  42. .first()
  43. .simulate("keydown", { key: "Enter" });
  44. expect(setPosition).toHaveBeenCalledWith("point");
  45. });
  46. it("does not reset on other keys on button", () => {
  47. usePanoStartPosition.mockReturnValue();
  48. usePanoStartPov.mockReturnValue();
  49. useTargetPoint.mockReturnValue("point");
  50. const setPosition = jest.fn();
  51. usePano.mockReturnValue({ current: { setPosition } });
  52. const handle = shallow(<PositionedStreetView />);
  53. expect(handle).toMatchSnapshot();
  54. handle
  55. .find("div.resetButton")
  56. .first()
  57. .simulate("keydown", { key: "Escape" });
  58. expect(setPosition).not.toHaveBeenCalled();
  59. });
  60. });