// to get rid of "[ts] could not find module ..." in vs code realod the window: f1 -> type "reload window" // official issue for this: https://github.com/Microsoft/TypeScript/issues/10346 import {expect} from "chai"; import { Direction } from "./MazeMap"; // import { describe, it } from "mocha"; import {navigate, startGame} from "./NavigationEndpoint"; describe("Scenario: Starting the game", function(){ describe("when the game is started", function(){ const position = startGame(); it("then the start position must exist", function(){ expect(position).to.be.not.null; }); it("then the position must have at least one pathway", function(){ expect(position.paths.length).to.be.greaterThan(0); }); }); }); describe("Scenario: Navigating in ongoing game", function(){ const startPosition = startGame(); describe("When player navigates in existing direction", function(){ const naviagtionDirection = startPosition.paths[0]; const nextPosition = navigate(startPosition.id, naviagtionDirection); it("then the new position has to have a different id", function(){ expect(nextPosition.id).to.not.equal(startPosition.id); }); it("then the new position must have pathway back", function(){ let hasOpposite:boolean = false; for (const dir of nextPosition.paths) { switch (dir) { case Direction.top: if(naviagtionDirection === Direction.bottom) { hasOpposite = true; } break; case Direction.left: if(naviagtionDirection === Direction.right) { hasOpposite = true; } break; case Direction.bottom: if(naviagtionDirection === Direction.top) { hasOpposite = true; } break; case Direction.right: if(naviagtionDirection === Direction.left) { hasOpposite = true; } break; default: throw new Error(`Direction "${dir}" not recognized.`); } } expect(hasOpposite).to.be.true; }); }); });