1
0
Fork 0
spacetac/src/ui/battle/BattleView.spec.ts

130 lines
6.1 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("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);
check.equals(battleview.turn_plannings.length, 2);
check.equals(battleview.turn_plannings[0].collectAllActions(), [
{ action: action.id, category: action.getCategory(), distance: undefined, angle: undefined }
]);
check.equals(battleview.turn_plannings[1].collectAllActions(), []);
battleview.applyPlayerAction(action, Target.newFromLocation(ship.arena_x + 50, ship.arena_y));
check.equals(battleview.turn_plannings.length, 2);
check.equals(battleview.turn_plannings[0].collectAllActions(), [
{ action: action.id, category: action.getCategory(), distance: 50, angle: 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];
const mockSetPhase = check.patch(battleview.infobar, "setPhase");
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);
check.called(mockSetPhase, [[1, BattleInfoBarPhase.RESOLUTION]]);
});
battleview.actual_battle.applyDiffs([new TurnEndDiff(1)]);
battleview.log_processor.processPending();
check.in("end 1", check => {
check.equals(battleview.interacting, true);
check.called(mockSetPhase, [[2, BattleInfoBarPhase.PLANNING]]);
});
battleview.actual_battle.applyDiffs([new TurnStartDiff([])]);
battleview.log_processor.processPending();
check.in("start 2", check => {
check.equals(battleview.interacting, false);
check.called(mockSetPhase, [[2, BattleInfoBarPhase.RESOLUTION]]);
});
battleview.actual_battle.endBattle(null);
battleview.actual_battle.applyDiffs([new TurnEndDiff(2)]);
battleview.log_processor.processPending();
check.in("end 2", check => {
check.equals(battleview.interacting, false);
check.called(mockSetPhase, [[3, BattleInfoBarPhase.END]]);
});
});
});
}