UNPKG

modaq

Version:

Quiz Bowl Reader using TypeScript, React, and MobX

235 lines 11.5 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const ReorderPlayersDialogController = __importStar(require("src/components/dialogs/ReorderPlayersDialogController")); const AppState_1 = require("src/state/AppState"); const GameState_1 = require("src/state/GameState"); const PacketState_1 = require("src/state/PacketState"); const TeamState_1 = require("src/state/TeamState"); require("src/state/ReorderPlayersDialogState"); const defaultPacket = new PacketState_1.PacketState(); defaultPacket.setTossups([ new PacketState_1.Tossup("first q", "first a"), new PacketState_1.Tossup("second q", "second a"), new PacketState_1.Tossup("third q", "third a"), ]); const defaultTeamNames = ["First Team", "Team2"]; const firstTeamPlayers = [ new TeamState_1.Player("Alex", defaultTeamNames[0], true), new TeamState_1.Player("Anna", defaultTeamNames[0], true), new TeamState_1.Player("Ashok", defaultTeamNames[0], false), ]; const secondTeamPlayers = [ new TeamState_1.Player("Bob", defaultTeamNames[1], true), new TeamState_1.Player("Anna", defaultTeamNames[1], true), ]; const defaultExistingPlayers = [ firstTeamPlayers[0], firstTeamPlayers[1], secondTeamPlayers[0], secondTeamPlayers[1], firstTeamPlayers[2], ]; function initializeApp(players) { const gameState = new GameState_1.GameState(); gameState.loadPacket(defaultPacket); players = players !== null && players !== void 0 ? players : defaultExistingPlayers; gameState.addNewPlayers(players); AppState_1.AppState.resetInstance(); const appState = AppState_1.AppState.instance; appState.game = gameState; appState.uiState.dialogState.showReorderPlayersDialog(players); return { appState, players }; } function getReorderPlayersDialogState(appState) { if (appState.uiState.dialogState.reorderPlayersDialog == undefined) { chai_1.assert.fail("PendingNewPlayer should not be undefined"); } return appState.uiState.dialogState.reorderPlayersDialog; } describe("ReorderPlayersDialogControllerTests", () => { it("hideDialog", () => { const { appState } = initializeApp(); ReorderPlayersDialogController.hideDialog(); chai_1.expect(appState.uiState.dialogState.reorderPlayersDialog).to.be.undefined; }); describe("changeTeamName", () => { it("change to both teams", () => { const { appState } = initializeApp(); ReorderPlayersDialogController.changeTeamName(defaultTeamNames[1]); const dialog = getReorderPlayersDialogState(appState); chai_1.expect(dialog.teamName).to.equal(defaultTeamNames[1]); ReorderPlayersDialogController.changeTeamName(defaultTeamNames[0]); chai_1.expect(dialog.teamName).to.equal(defaultTeamNames[0]); }); }); it("submit", () => { const { appState, players } = initializeApp(); const dialog = getReorderPlayersDialogState(appState); dialog.movePlayerBackward(players[0]); ReorderPlayersDialogController.submit(); chai_1.expect(appState.uiState.dialogState.reorderPlayersDialog).to.be.undefined; chai_1.expect(appState.game.players).to.be.deep.equal([ firstTeamPlayers[1], firstTeamPlayers[0], secondTeamPlayers[0], secondTeamPlayers[1], firstTeamPlayers[2], ]); }); describe("moveBackward", () => { it("Move backwards from the end is no-op", () => { const { appState, players } = initializeApp(); ReorderPlayersDialogController.moveBackward(players[players.length - 1]); const dialog = getReorderPlayersDialogState(appState); chai_1.expect(dialog.players[players.length - 1]).to.equal(players[players.length - 1]); chai_1.expect(dialog.players).to.be.deep.equal(players); }); it("Move backwards from front moves player back", () => { const { appState } = initializeApp(); ReorderPlayersDialogController.moveBackward(firstTeamPlayers[0]); const dialog = getReorderPlayersDialogState(appState); chai_1.expect(dialog.players[0]).to.equal(firstTeamPlayers[1]); chai_1.expect(dialog.players[1]).to.equal(firstTeamPlayers[0]); chai_1.expect(dialog.players.slice(2)).to.be.deep.equal(defaultExistingPlayers.slice(2)); }); it("Move backwards for second team", () => { const { appState } = initializeApp(); ReorderPlayersDialogController.moveBackward(secondTeamPlayers[0]); const dialog = getReorderPlayersDialogState(appState); chai_1.expect(dialog.players).to.be.deep.equal([ firstTeamPlayers[0], firstTeamPlayers[1], secondTeamPlayers[1], secondTeamPlayers[0], firstTeamPlayers[2], ]); }); it("Move backwards with gap swaps correctly", () => { const { appState } = initializeApp(); ReorderPlayersDialogController.moveBackward(firstTeamPlayers[1]); const dialog = getReorderPlayersDialogState(appState); chai_1.expect(dialog.players).to.be.deep.equal([ firstTeamPlayers[0], firstTeamPlayers[2], secondTeamPlayers[0], secondTeamPlayers[1], firstTeamPlayers[1], ]); }); }); describe("moveForward", () => { it("Move forwards from 0 is no-op", () => { const { appState, players } = initializeApp(); ReorderPlayersDialogController.moveForward(players[0]); const dialog = getReorderPlayersDialogState(appState); chai_1.expect(dialog.players[0]).to.equal(players[0]); chai_1.expect(dialog.players).to.be.deep.equal(players); }); it("Move forwards from 1 swaps player to front", () => { const { appState } = initializeApp(); ReorderPlayersDialogController.moveForward(firstTeamPlayers[1]); const dialog = getReorderPlayersDialogState(appState); chai_1.expect(dialog.players[0]).to.equal(firstTeamPlayers[1]); chai_1.expect(dialog.players[1]).to.equal(firstTeamPlayers[0]); chai_1.expect(dialog.players.slice(2)).to.be.deep.equal(defaultExistingPlayers.slice(2)); }); it("Move forwards for second team", () => { const { appState } = initializeApp(); ReorderPlayersDialogController.moveForward(secondTeamPlayers[1]); const dialog = getReorderPlayersDialogState(appState); chai_1.expect(dialog.players).to.be.deep.equal([ firstTeamPlayers[0], firstTeamPlayers[1], secondTeamPlayers[1], secondTeamPlayers[0], firstTeamPlayers[2], ]); }); it("Move forwards with gap swaps correctly", () => { const { appState } = initializeApp(); ReorderPlayersDialogController.moveForward(firstTeamPlayers[2]); const dialog = getReorderPlayersDialogState(appState); chai_1.expect(dialog.players).to.be.deep.equal([ firstTeamPlayers[0], firstTeamPlayers[2], secondTeamPlayers[0], secondTeamPlayers[1], firstTeamPlayers[1], ]); }); }); // move ToIndex tests describe("movePlayerToIndex", () => { it("movePlayerToIndex to same index is no-op", () => { const { appState } = initializeApp(); ReorderPlayersDialogController.movePlayerToIndex(firstTeamPlayers[1], 1); const dialog = getReorderPlayersDialogState(appState); chai_1.expect(dialog.players).to.be.deep.equal(defaultExistingPlayers); }); it("movePlayerToIndex to negative index is no-op", () => { const { appState } = initializeApp(); ReorderPlayersDialogController.movePlayerToIndex(firstTeamPlayers[1], -1); const dialog = getReorderPlayersDialogState(appState); chai_1.expect(dialog.players).to.be.deep.equal(defaultExistingPlayers); }); it("movePlayerToIndex to overly large index is no-op", () => { const { appState } = initializeApp(); ReorderPlayersDialogController.movePlayerToIndex(firstTeamPlayers[1], firstTeamPlayers.length); const dialog = getReorderPlayersDialogState(appState); chai_1.expect(dialog.players).to.be.deep.equal(defaultExistingPlayers); }); it("movePlayerToIndex next player swap", () => { const { appState } = initializeApp(); ReorderPlayersDialogController.movePlayerToIndex(firstTeamPlayers[0], 1); const dialog = getReorderPlayersDialogState(appState); chai_1.expect(dialog.players[0]).to.equal(firstTeamPlayers[1]); chai_1.expect(dialog.players[1]).to.equal(firstTeamPlayers[0]); chai_1.expect(dialog.players.slice(2)).to.be.deep.equal(defaultExistingPlayers.slice(2)); }); it("movePlayerToIndex first to last player swap", () => { const { appState } = initializeApp(); ReorderPlayersDialogController.movePlayerToIndex(firstTeamPlayers[0], 2); const dialog = getReorderPlayersDialogState(appState); chai_1.expect(dialog.players).to.be.deep.equal([ firstTeamPlayers[1], secondTeamPlayers[0], secondTeamPlayers[1], firstTeamPlayers[2], firstTeamPlayers[0], ]); }); it("movePlayerToIndex last to first player swap", () => { const { appState } = initializeApp(); ReorderPlayersDialogController.movePlayerToIndex(firstTeamPlayers[2], 0); const dialog = getReorderPlayersDialogState(appState); chai_1.expect(dialog.players).to.be.deep.equal([ firstTeamPlayers[2], firstTeamPlayers[0], firstTeamPlayers[1], secondTeamPlayers[0], secondTeamPlayers[1], ]); }); }); }); //# sourceMappingURL=ReorderPlayersDialogControllerTests.js.map