Ver código fonte

add RoundSummary tests

Kirk Trombley 4 anos atrás
pai
commit
71e797d9e4

+ 1 - 1
client/src/components/screens/RoundSummary/RoundSummary.jsx

@@ -12,7 +12,7 @@ import DelayedButton from "../../util/DelayedButton";
 import styles from "./RoundSummary.module.css";
 import useClickToCheckScore from "./useClickToCheckScore";
 
-const NextRoundButton = () => {
+export const NextRoundButton = () => {
   // check the current round to see if game is done
   const currentRound = useCurrentRound();
 

+ 77 - 0
client/src/tests/RoundSummary.test.js

@@ -0,0 +1,77 @@
+import React from "react";
+import { mount, shallow } from "enzyme";
+import RoundSummary, {
+  NextRoundButton,
+} from "../components/screens/RoundSummary/RoundSummary";
+
+jest.mock("../domain/gameStore");
+jest.mock("../hooks/useMap");
+jest.mock("../hooks/usePreventNavigation");
+jest.mock("../hooks/useGameInfo");
+jest.mock("../hooks/useMarkersFromGuesses");
+jest.mock("../components/screens/RoundSummary/useClickToCheckScore");
+
+import { dispatch, useCurrentRound, useLastRound } from "../domain/gameStore";
+import useMap from "../hooks/useMap";
+import usePreventNavigation from "../hooks/usePreventNavigation";
+import { usePlayers } from "../hooks/useGameInfo";
+import useMarkersFromGuesses from "../hooks/useMarkersFromGuesses";
+import useClickToCheckScore from "../components/screens/RoundSummary/useClickToCheckScore";
+
+describe("RoundSummary", () => {
+  it("renders", () => {
+    useLastRound.mockReturnValue({
+      roundNum: "round",
+      score: 5000,
+      totalScore: 10000,
+      targetPoint: "target",
+    });
+    useMap.mockReturnValue("map");
+    usePlayers.mockReturnValue("players");
+    const rendered = shallow(<RoundSummary />);
+    expect(rendered).toMatchSnapshot();
+    expect(usePreventNavigation).toHaveBeenCalled();
+    expect(useMarkersFromGuesses).toHaveBeenCalledWith(
+      "map",
+      "players",
+      "round",
+      "target"
+    );
+    expect(useClickToCheckScore).toHaveBeenCalledWith("map", "target");
+  });
+
+  describe("NextRoundButton", () => {
+    it("renders when there is not a next round", () => {
+      useCurrentRound.mockReturnValue(null);
+      const rendered = shallow(<NextRoundButton />);
+      expect(rendered).toMatchSnapshot();
+    });
+
+    it("proceeds to summary when clicked if there is not a next round", () => {
+      useCurrentRound.mockReturnValue(null);
+      const rendered = shallow(<NextRoundButton />);
+      rendered.find("button").first().simulate("click");
+      expect(dispatch.goToSummary).toHaveBeenCalled();
+    });
+
+    it("renders when there is a next round", () => {
+      useCurrentRound.mockReturnValue("round");
+      const rendered = shallow(<NextRoundButton />);
+      expect(rendered).toMatchSnapshot();
+    });
+
+    it("handles click if there is a next round", () => {
+      useCurrentRound.mockReturnValue("round");
+      const rendered = mount(<NextRoundButton />);
+      rendered.find("button").first().simulate("click");
+      expect(rendered).toMatchSnapshot();
+    });
+
+    it("proceeds to next round when button ends", () => {
+      useCurrentRound.mockReturnValue("round");
+      const rendered = mount(<NextRoundButton />);
+      rendered.find("DelayedButton").first().prop("onEnd")();
+      expect(dispatch.startRound).toHaveBeenCalled();
+    });
+  });
+});

+ 79 - 0
client/src/tests/__snapshots__/RoundSummary.test.js.snap

@@ -0,0 +1,79 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`RoundSummary NextRoundButton handles click if there is a next round 1`] = `
+<NextRoundButton>
+  <DelayedButton
+    autoFocus={true}
+    buttonClass="next"
+    countDownFormatter={[Function]}
+    onEnd={[MockFunction]}
+  >
+    <CountdownButton
+      autoFocus={true}
+      buttonClass="next"
+      formatter={[Function]}
+      onCancelled={[Function]}
+      onEnd={[MockFunction]}
+      seconds={3}
+    >
+      <button
+        autoFocus={true}
+        className="next"
+        onClick={[Function]}
+        type="button"
+      >
+        Click to cancel, 3s...
+      </button>
+    </CountdownButton>
+  </DelayedButton>
+</NextRoundButton>
+`;
+
+exports[`RoundSummary NextRoundButton renders when there is a next round 1`] = `
+<DelayedButton
+  autoFocus={true}
+  buttonClass="next"
+  countDownFormatter={[Function]}
+  onEnd={[MockFunction]}
+>
+  Next Round
+</DelayedButton>
+`;
+
+exports[`RoundSummary NextRoundButton renders when there is not a next round 1`] = `
+<button
+  autoFocus={true}
+  className="next"
+  onClick={[Function]}
+  type="button"
+>
+  View Summary
+</button>
+`;
+
+exports[`RoundSummary renders 1`] = `
+<div>
+  <div
+    className="map"
+  />
+  <div
+    className="panel"
+  >
+    <span
+      className="score"
+    >
+      Score for Round 
+      round
+      : 
+      5000
+    </span>
+    <span
+      className="score"
+    >
+      Running Total: 
+      10000
+    </span>
+    <NextRoundButton />
+  </div>
+</div>
+`;