module TK.SpaceTac.Specs { testing("MainStory", test => { function checkPart(story: Mission, index: number, title: RegExp, completed = false) { let result = story.checkStatus(); test.check.in(`part ${index}`, check => { check.same(story.parts.indexOf(story.current_part), index); check.regex(title, story.current_part.title); check.same(story.completed, completed); check.same(result, !completed); }); } function goTo(session: GameSession, location: StarLocation, win_encounter = true) { session.fleet.setLocation(location); let battle = session.getBattle(); if (battle) { battle.endBattle(win_encounter ? session.fleet : battle.fleets[1]); if (win_encounter) { session.exitBattle(); location.clearEncounter(); } else { session.revertBattle(); } } } test.case("can be completed", check => { let session = new GameSession(); session.startNewGame(true, true); let fleet = nn(session.player.fleet); let missions = session.player.missions; let story = nn(missions.main); let fleet_size = fleet.ships.length; checkPart(story, 0, /^Travel to Terranax galaxy$/); (story.current_part).skip(); checkPart(story, 1, /^Find your contact in .*$/); goTo(session, (story.current_part).destination); checkPart(story, 2, /^Speak with your contact/); (story.current_part).skip(); checkPart(story, 3, /^Go with .* in .* system$/); check.same(fleet.ships.length, fleet_size + 1); check.same(fleet.ships[fleet_size].critical, true); check.greater(fleet.ships[fleet_size].getAttribute("hull_capacity"), 0); goTo(session, (story.current_part).destination); checkPart(story, 4, /^Listen to .*$/); (story.current_part).skip(); check.equals(session.getBattle(), null); checkPart(story, 5, /^Fight the arrived fleet$/); check.notequals(session.getBattle(), null); nn(session.getBattle()).endBattle(fleet); session.setBattleEnded(); check.same(story.checkStatus(), false, "story not complete"); }) }) }