141 lines
6.7 KiB
TypeScript
141 lines
6.7 KiB
TypeScript
module TK.SpaceTac.UI.Specs {
|
|
testing("BattleView", test => {
|
|
let testgame = setupBattleview(test);
|
|
|
|
test.case("handles ship hovering to display tooltip", check => {
|
|
let battleview = testgame.view;
|
|
check.equals(battleview.ship_hovered, null, "initial state");
|
|
|
|
let ship = battleview.battle.fleets[0].ships[0];
|
|
battleview.cursorHovered(ship.location, ship);
|
|
check.same(battleview.ship_hovered, ship, "ship1 hovered");
|
|
|
|
ship = battleview.battle.fleets[1].ships[0];
|
|
battleview.cursorHovered(ship.location, ship);
|
|
check.same(battleview.ship_hovered, ship, "ship2 hovered");
|
|
|
|
battleview.cursorHovered(new ArenaLocation(0, 0), null);
|
|
check.equals(battleview.ship_hovered, null, "out");
|
|
|
|
battleview.cursorOnShip(ship);
|
|
check.same(battleview.ship_hovered, ship, "force on");
|
|
|
|
battleview.cursorOffShip(battleview.battle.fleets[1].ships[1]);
|
|
check.same(battleview.ship_hovered, ship, "force off on wrong ship");
|
|
|
|
battleview.cursorOffShip(ship);
|
|
check.equals(battleview.ship_hovered, null, "force off");
|
|
});
|
|
|
|
test.case("forwards cursor hovering and click to targetting", check => {
|
|
let battleview = testgame.view;
|
|
check.equals(battleview.targetting.active, false);
|
|
battleview.setInteractionEnabled(true);
|
|
|
|
let ship = battleview.battle.fleets[0].ships[0];
|
|
let weapon = TestTools.addWeapon(ship, 10);
|
|
battleview.enterTargettingMode(ship, weapon, ActionTargettingMode.SPACE);
|
|
check.equals(battleview.targetting.active, true);
|
|
|
|
battleview.cursorHovered(new ArenaLocation(5, 8), null);
|
|
check.equals(battleview.targetting.target, Target.newFromLocation(5, 8));
|
|
check.equals(battleview.ship_hovered, null);
|
|
|
|
ship = battleview.battle.fleets[1].ships[0];
|
|
battleview.cursorHovered(ship.location, ship);
|
|
check.equals(battleview.targetting.target, Target.newFromLocation(ship.arena_x, ship.arena_y));
|
|
check.equals(battleview.ship_hovered, null);
|
|
|
|
let validate = check.patch(battleview.targetting, "validate", null);
|
|
|
|
check.called(validate, 0);
|
|
battleview.cursorClicked();
|
|
check.called(validate, 1);
|
|
|
|
battleview.exitTargettingMode();
|
|
check.equals(battleview.targetting.active, false);
|
|
|
|
battleview.cursorHovered(new ArenaLocation(5, 8), null);
|
|
check.equals(battleview.targetting.target, null);
|
|
check.equals(battleview.ship_hovered, null);
|
|
|
|
battleview.cursorHovered(ship.location, ship);
|
|
check.equals(battleview.targetting.target, null);
|
|
check.same(battleview.ship_hovered, ship);
|
|
});
|
|
|
|
test.case("allows to choose an action and a target with shortcut keys", check => {
|
|
let battleview = testgame.view;
|
|
battleview.setInteractionEnabled(true);
|
|
battleview.setShipSelected(battleview.battle.fleets[0].ships[0]);
|
|
let action_icon = battleview.action_bar.action_icons[0];
|
|
|
|
check.equals(battleview.targetting.active, false);
|
|
check.equals(battleview.action_bar.hasActionSelected(), false);
|
|
battleview.numberPressed(battleview.action_bar.action_icons.indexOf(action_icon) + 1);
|
|
check.equals(battleview.action_bar.hasActionSelected(), true);
|
|
check.equals(battleview.targetting.active, true);
|
|
check.same(battleview.targetting.action, action_icon.action);
|
|
check.equals(battleview.targetting.target, action_icon.action.getDefaultTarget(action_icon.ship));
|
|
battleview.numberPressed(3);
|
|
check.equals(battleview.targetting.active, true);
|
|
check.same(battleview.targetting.action, action_icon.action);
|
|
check.equals(battleview.targetting.target, Target.newFromShip(battleview.battle.ships.list()[2]));
|
|
battleview.numberPressed(4);
|
|
check.equals(battleview.targetting.active, true);
|
|
check.same(battleview.targetting.action, action_icon.action);
|
|
check.equals(battleview.targetting.target, Target.newFromShip(battleview.battle.ships.list()[3]));
|
|
});
|
|
|
|
test.case("adds player actions to plan", check => {
|
|
let battleview = testgame.view;
|
|
check.equals(battleview.turn_plannings.length, 2);
|
|
check.equals(battleview.turn_plannings[0].collectAllActions(), []);
|
|
check.equals(battleview.turn_plannings[1].collectAllActions(), []);
|
|
|
|
let ship = battleview.battle.fleets[0].ships[0];
|
|
let action = nn(first(ship.actions.listAll(), action => action instanceof MoveAction));
|
|
|
|
battleview.setShipSelected(ship);
|
|
battleview.applyPlayerAction(action, Target.newFromLocation(0, 0));
|
|
check.equals(battleview.turn_plannings.length, 2);
|
|
check.equals(battleview.turn_plannings[0].collectAllActions(), [
|
|
{ action: action.id, category: action.getCategory(), target: Target.newFromLocation(0, 0) }
|
|
]);
|
|
check.equals(battleview.turn_plannings[1].collectAllActions(), []);
|
|
});
|
|
|
|
test.case("disables player interaction while resolution is playing", check => {
|
|
const battleview = testgame.view;
|
|
const ship = battleview.actual_battle.fleets[0].ships[0];
|
|
battleview.setShipSelected(ship);
|
|
check.in("initial", check => {
|
|
check.equals(battleview.interacting, true);
|
|
check.equals(battleview.ship_selected, ship);
|
|
});
|
|
battleview.actual_battle.applyDiffs([new TurnStartDiff([])]);
|
|
battleview.log_processor.processPending();
|
|
check.in("start 1", check => {
|
|
check.equals(battleview.interacting, false);
|
|
check.equals(battleview.ship_selected, null);
|
|
});
|
|
battleview.actual_battle.applyDiffs([new TurnEndDiff()]);
|
|
battleview.log_processor.processPending();
|
|
check.in("end 1", check => {
|
|
check.equals(battleview.interacting, true);
|
|
});
|
|
battleview.actual_battle.endBattle(null);
|
|
battleview.battle.applyDiffs([new TurnStartDiff([])]);
|
|
battleview.log_processor.processPending();
|
|
check.in("start 2", check => {
|
|
check.equals(battleview.interacting, false);
|
|
});
|
|
battleview.actual_battle.applyDiffs([new TurnEndDiff()]);
|
|
battleview.log_processor.processPending();
|
|
check.in("end 2", check => {
|
|
check.equals(battleview.interacting, false);
|
|
});
|
|
});
|
|
});
|
|
}
|