module TK.SpaceTac.Specs { testing("BattlePlanning", test => { test.case("initializes from a battle state", check => { let battle = new Battle(); let planning = new BattlePlanning(battle); check.equals(planning.getBattlePlan(), { fleets: [ { fleet: battle.fleets[0].id, ships: [] }, { fleet: battle.fleets[1].id, ships: [] }, ] }); battle.fleets[0].addShip(); planning = new BattlePlanning(battle); check.equals(planning.getBattlePlan(), { fleets: [ { fleet: battle.fleets[0].id, ships: [ { ship: battle.fleets[0].ships[0].id, actions: [] }, ] }, { fleet: battle.fleets[1].id, ships: [] }, ] }); }); test.case("gets child fleet and ship plans", check => { const battle = new Battle(); battle.fleets[0].addShip(); battle.fleets[1].addShip(); battle.fleets[1].addShip(); const planning = new BattlePlanning(battle); check.equals(planning.getFleetPlan(battle.fleets[0]).fleet, battle.fleets[0].id); check.equals(planning.getFleetPlan(battle.fleets[1]).fleet, battle.fleets[1].id); check.equals(planning.getFleetPlan(new Fleet()).fleet, -1); check.equals(planning.getShipPlan(battle.fleets[0].ships[0]).ship, battle.fleets[0].ships[0].id); check.equals(planning.getShipPlan(battle.fleets[1].ships[0]).ship, battle.fleets[1].ships[0].id); check.equals(planning.getShipPlan(battle.fleets[1].ships[1]).ship, battle.fleets[1].ships[1].id); check.equals(planning.getShipPlan(new Ship()).ship, -1); }); test.case("adds an action and target to a ship plan", check => { const battle = new Battle(); const ship = battle.fleets[0].addShip(); const action1 = ship.actions.addCustom(new BaseAction()); const planning = new BattlePlanning(battle); check.equals(planning.getShipPlan(ship).actions, []); planning.addAction(ship, action1, Target.newFromShip(ship)); check.equals(planning.getShipPlan(ship).actions, [ { action: action1.id, target: Target.newFromShip(ship) } ]); }); }); }