UNPKG

modaq

Version:

Quiz Bowl Reader using TypeScript, React, and MobX

122 lines 6.48 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 TossupProtestDialogController = __importStar(require("src/components/dialogs/TossupProtestDialogController")); const GameFormats = __importStar(require("src/state/GameFormats")); 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/Cycle"); const defaultPacket = new PacketState_1.PacketState(); defaultPacket.setTossups([new PacketState_1.Tossup("first q", "first a"), new PacketState_1.Tossup("second q", "second a")]); defaultPacket.setBonuses([new PacketState_1.Bonus("Leadin", [])]); const defaultTeamNames = ["First Team", "Team2"]; const defaultExistingPlayers = [ new TeamState_1.Player("Frank", defaultTeamNames[0], true), new TeamState_1.Player("Faye", defaultTeamNames[0], true), new TeamState_1.Player("Saul", defaultTeamNames[1], true), ]; function initializeApp(buzzerProtests = true) { const gameState = new GameState_1.GameState(); gameState.loadPacket(defaultPacket); gameState.addNewPlayers(defaultExistingPlayers); AppState_1.AppState.resetInstance(); const appState = AppState_1.AppState.instance; appState.game = gameState; const buzzer = defaultExistingPlayers[0]; appState.game.cycles[0].addCorrectBuzz({ player: buzzer, position: 100, points: 10 }, 0, GameFormats.UndefinedGameFormat, 0, 3); const protestTeamName = buzzerProtests ? buzzer.teamName : defaultTeamNames[1]; appState.uiState.setPendingTossupProtest(protestTeamName, 0, 100); return appState; } describe("BonusQuestionDialogControllerTests", () => { function verifyBasicProtest(buzzerProtests) { const givenAnswer = "My answer"; const reason = "It is factually wrong"; const appState = initializeApp(buzzerProtests); if (appState.uiState.pendingTossupProtestEvent == undefined) { chai_1.assert.fail("Test wasn't initialized correctly"); } appState.uiState.pendingTossupProtestEvent.givenAnswer = givenAnswer; appState.uiState.pendingTossupProtestEvent.reason = reason; const protestCycle = appState.game.cycles[0]; TossupProtestDialogController.commit(protestCycle); if (protestCycle.tossupProtests == undefined) { chai_1.assert.fail("Bonus protests were undefined"); } chai_1.expect(protestCycle.tossupProtests.length).to.equal(1); const protest = protestCycle.tossupProtests[0]; chai_1.expect(protest.questionIndex).to.equal(0); chai_1.expect(protest.givenAnswer).to.equal(givenAnswer); chai_1.expect(protest.reason).to.equal(reason); chai_1.expect(protest.position).to.equal(100); const teamName = buzzerProtests ? defaultTeamNames[0] : defaultTeamNames[1]; chai_1.expect(protest.teamName).to.equal(teamName); } it("correct team protests bonus", () => { verifyBasicProtest(true); }); it("other team protests bonus", () => { verifyBasicProtest(false); }); it("Multiple protests", () => { const firstGivenAnswer = "My answer"; const secondGivenAnswer = "Other answer"; const firstReason = "It is factually wrong"; const secondReason = "You were wrong"; const appState = initializeApp(true); const cycle = appState.game.cycles[0]; cycle.addWrongBuzz({ player: defaultExistingPlayers[2], position: 50, points: 0 }, 0, GameFormats.UndefinedGameFormat); // Add an existing protest cycle.addTossupProtest(defaultTeamNames[1], 0, 50, firstGivenAnswer, firstReason); if (appState.uiState.pendingTossupProtestEvent == undefined) { chai_1.assert.fail("Test wasn't initialized correctly"); } appState.uiState.pendingTossupProtestEvent.givenAnswer = secondGivenAnswer; appState.uiState.pendingTossupProtestEvent.reason = secondReason; TossupProtestDialogController.commit(cycle); if (cycle.tossupProtests == undefined) { chai_1.assert.fail("Bonus protests were undefined"); } chai_1.expect(cycle.tossupProtests.length).to.equal(2); const originalProtest = cycle.tossupProtests[0]; chai_1.expect(originalProtest.questionIndex).to.equal(0); chai_1.expect(originalProtest.givenAnswer).to.equal(firstGivenAnswer); chai_1.expect(originalProtest.reason).to.equal(firstReason); chai_1.expect(originalProtest.teamName).to.equal(defaultTeamNames[1]); chai_1.expect(originalProtest.position).to.equal(50); const newProtest = cycle.tossupProtests[1]; chai_1.expect(newProtest.questionIndex).to.equal(0); chai_1.expect(newProtest.givenAnswer).to.equal(secondGivenAnswer); chai_1.expect(newProtest.reason).to.equal(secondReason); chai_1.expect(newProtest.teamName).to.equal(defaultTeamNames[0]); chai_1.expect(newProtest.position).to.equal(100); }); it("hideDialog", () => { const appState = initializeApp(); chai_1.expect(appState.uiState.pendingTossupProtestEvent).to.not.be.undefined; TossupProtestDialogController.cancel(); chai_1.expect(appState.uiState.pendingTossupProtestEvent).to.be.undefined; }); }); //# sourceMappingURL=TossupProtestDialogControllerTests.js.map