123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- import React from "react";
- import { shallow } from "enzyme";
- import Lobby, { GameInfo, PlayerList } from "../components/screens/Lobby/Lobby";
- import {
- COUNTRY_RACE,
- DISTANCE,
- FROZEN,
- NORMAL,
- RACE,
- TIME_BANK,
- } from "../domain/constants";
- jest.mock("iso-3166-1");
- jest.mock("../domain/gameStore");
- jest.mock("../hooks/useGameInfo");
- import iso from "iso-3166-1";
- import { useGameId } from "../domain/gameStore";
- import { useGameConfig, usePlayers } from "../hooks/useGameInfo";
- describe("Lobby", () => {
- it("renders while loading", () => {
- useGameId.mockReturnValue("test-game-id");
- usePlayers.mockReturnValue(null);
- const onStart = jest.fn();
- const rendered = shallow(<Lobby onStart={onStart} />);
- expect(rendered).toMatchSnapshot();
- });
- it("renders with no players", () => {
- useGameId.mockReturnValue("test-game-id");
- usePlayers.mockReturnValue([]);
- const onStart = jest.fn();
- const rendered = shallow(<Lobby onStart={onStart} />);
- expect(rendered).toMatchSnapshot();
- });
- it("renders", () => {
- useGameId.mockReturnValue("test-game-id");
- usePlayers.mockReturnValue([{ name: "foo", name: "bar" }]);
- const onStart = jest.fn();
- const rendered = shallow(<Lobby onStart={onStart} />);
- expect(rendered).toMatchSnapshot();
- });
- it("properly handles joining and starting", () => {
- useGameId.mockReturnValue("test-game-id");
- usePlayers.mockReturnValue([]);
- const onStart = jest.fn();
- const rendered = shallow(<Lobby onStart={onStart} />);
- rendered.find("JoinForm").first().prop("onJoined")();
- expect(rendered).toMatchSnapshot();
- rendered.find("StartGame").first().prop("onStart")();
- expect(onStart).toHaveBeenCalled();
- });
- describe("GameInfo", () => {
- it("renders while loading", () => {
- useGameConfig.mockReturnValue({});
- const rendered = shallow(<GameInfo />);
- expect(rendered).toMatchSnapshot();
- });
- it("renders", () => {
- useGameConfig.mockReturnValue({
- rounds: 5,
- timer: 300,
- gameMode: NORMAL,
- clockMode: NORMAL,
- scoreMethod: DISTANCE,
- roundPointCap: null,
- });
- const rendered = shallow(<GameInfo />);
- expect(rendered).toMatchSnapshot();
- });
- it("renders for single round", () => {
- useGameConfig.mockReturnValue({
- rounds: 1,
- timer: 300,
- gameMode: NORMAL,
- clockMode: NORMAL,
- scoreMethod: DISTANCE,
- roundPointCap: null,
- });
- const rendered = shallow(<GameInfo />);
- expect(rendered).toMatchSnapshot();
- });
- it("renders for COUNTRY_RACE", () => {
- useGameConfig.mockReturnValue({
- rounds: 5,
- timer: 300,
- gameMode: NORMAL,
- clockMode: NORMAL,
- scoreMethod: COUNTRY_RACE,
- roundPointCap: null,
- });
- const rendered = shallow(<GameInfo />);
- expect(rendered).toMatchSnapshot();
- });
- it("renders for FROZEN", () => {
- useGameConfig.mockReturnValue({
- rounds: 5,
- timer: 300,
- gameMode: FROZEN,
- clockMode: NORMAL,
- scoreMethod: DISTANCE,
- roundPointCap: null,
- });
- const rendered = shallow(<GameInfo />);
- expect(rendered).toMatchSnapshot();
- });
- it("renders for single round COUNTRY_RACE", () => {
- useGameConfig.mockReturnValue({
- rounds: 1,
- timer: 300,
- gameMode: NORMAL,
- clockMode: NORMAL,
- scoreMethod: COUNTRY_RACE,
- roundPointCap: null,
- });
- const rendered = shallow(<GameInfo />);
- expect(rendered).toMatchSnapshot();
- });
- it("renders for single round FROZEN", () => {
- useGameConfig.mockReturnValue({
- rounds: 1,
- timer: 300,
- gameMode: FROZEN,
- clockMode: NORMAL,
- scoreMethod: DISTANCE,
- roundPointCap: null,
- });
- const rendered = shallow(<GameInfo />);
- expect(rendered).toMatchSnapshot();
- });
- it("renders for TIME_BANK", () => {
- useGameConfig.mockReturnValue({
- rounds: 5,
- timer: 300,
- gameMode: NORMAL,
- clockMode: TIME_BANK,
- scoreMethod: DISTANCE,
- roundPointCap: null,
- });
- const rendered = shallow(<GameInfo />);
- expect(rendered).toMatchSnapshot();
- });
- it("renders for RACE", () => {
- useGameConfig.mockReturnValue({
- rounds: 5,
- timer: 300,
- gameMode: NORMAL,
- clockMode: RACE,
- scoreMethod: DISTANCE,
- roundPointCap: null,
- });
- const rendered = shallow(<GameInfo />);
- expect(rendered).toMatchSnapshot();
- });
- it("renders for NORMAL", () => {
- useGameConfig.mockReturnValue({
- rounds: 5,
- timer: 300,
- gameMode: NORMAL,
- clockMode: NORMAL,
- scoreMethod: DISTANCE,
- roundPointCap: null,
- });
- const rendered = shallow(<GameInfo />);
- expect(rendered).toMatchSnapshot();
- });
- it("renders with a round point cap", () => {
- useGameConfig.mockReturnValue({
- rounds: 5,
- timer: 300,
- gameMode: NORMAL,
- clockMode: NORMAL,
- scoreMethod: DISTANCE,
- roundPointCap: 10000,
- });
- const rendered = shallow(<GameInfo />);
- expect(rendered).toMatchSnapshot();
- });
- it("renders with country lock", () => {
- iso.whereAlpha2.mockReturnValue({ country: "test-country" });
- useGameConfig.mockReturnValue({
- rounds: 5,
- timer: 300,
- countryLock: "country",
- gameMode: NORMAL,
- clockMode: NORMAL,
- scoreMethod: DISTANCE,
- roundPointCap: null,
- });
- const rendered = shallow(<GameInfo />);
- expect(rendered).toMatchSnapshot();
- });
- });
- describe("PlayerList", () => {
- it("renders", () => {
- const playerNames = ["foo", "bar"];
- const rendered = shallow(<PlayerList playerNames={playerNames} />);
- expect(rendered).toMatchSnapshot();
- });
- });
- });
|