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

130 lines
6.1 KiB
TypeScript
Raw Normal View History

2017-09-24 22:23:22 +00:00
module TK.SpaceTac.UI.Specs {
2017-10-26 21:47:13 +00:00
testing("BattleView", test => {
2017-10-29 21:08:55 +00:00
let testgame = setupBattleview(test);
2017-02-21 22:38:31 +00:00
2017-10-26 21:47:13 +00:00
test.case("handles ship hovering to display tooltip", check => {
2017-10-09 21:13:56 +00:00
let battleview = testgame.view;
2017-10-29 21:08:55 +00:00
check.equals(battleview.ship_hovered, null, "initial state");
2015-01-08 00:00:00 +00:00
let ship = battleview.battle.fleets[0].ships[0];
2017-09-19 15:09:06 +00:00
battleview.cursorHovered(ship.location, ship);
2017-10-26 21:47:13 +00:00
check.same(battleview.ship_hovered, ship, "ship1 hovered");
2015-01-08 00:00:00 +00:00
ship = battleview.battle.fleets[1].ships[0];
2017-09-19 15:09:06 +00:00
battleview.cursorHovered(ship.location, ship);
2017-10-26 21:47:13 +00:00
check.same(battleview.ship_hovered, ship, "ship2 hovered");
2015-01-08 00:00:00 +00:00
2017-09-19 15:09:06 +00:00
battleview.cursorHovered(new ArenaLocation(0, 0), null);
2017-10-29 21:08:55 +00:00
check.equals(battleview.ship_hovered, null, "out");
2015-01-08 00:00:00 +00:00
2017-09-19 15:09:06 +00:00
battleview.cursorOnShip(ship);
2017-10-26 21:47:13 +00:00
check.same(battleview.ship_hovered, ship, "force on");
2015-01-08 00:00:00 +00:00
battleview.cursorOffShip(battleview.battle.fleets[1].ships[1]);
2017-10-26 21:47:13 +00:00
check.same(battleview.ship_hovered, ship, "force off on wrong ship");
2015-01-08 00:00:00 +00:00
2017-09-19 15:09:06 +00:00
battleview.cursorOffShip(ship);
2017-10-29 21:08:55 +00:00
check.equals(battleview.ship_hovered, null, "force off");
2017-09-19 15:09:06 +00:00
});
2015-01-08 00:00:00 +00:00
2017-10-26 21:47:13 +00:00
test.case("forwards cursor hovering and click to targetting", check => {
2017-10-09 21:13:56 +00:00
let battleview = testgame.view;
2017-10-26 21:47:13 +00:00
check.equals(battleview.targetting.active, false);
2017-09-19 15:09:06 +00:00
battleview.setInteractionEnabled(true);
2015-01-08 00:00:00 +00:00
let ship = battleview.battle.fleets[0].ships[0];
let weapon = TestTools.addWeapon(ship, 10);
battleview.enterTargettingMode(ship, weapon, ActionTargettingMode.SPACE);
2017-10-26 21:47:13 +00:00
check.equals(battleview.targetting.active, true);
2015-01-08 00:00:00 +00:00
2017-09-19 15:09:06 +00:00
battleview.cursorHovered(new ArenaLocation(5, 8), null);
2017-10-26 21:47:13 +00:00
check.equals(battleview.targetting.target, Target.newFromLocation(5, 8));
check.equals(battleview.ship_hovered, null);
2015-01-08 00:00:00 +00:00
ship = battleview.battle.fleets[1].ships[0];
2017-09-19 15:09:06 +00:00
battleview.cursorHovered(ship.location, ship);
2017-10-26 21:47:13 +00:00
check.equals(battleview.targetting.target, Target.newFromLocation(ship.arena_x, ship.arena_y));
check.equals(battleview.ship_hovered, null);
2015-01-08 00:00:00 +00:00
2017-10-29 21:08:55 +00:00
let validate = check.patch(battleview.targetting, "validate", null);
2015-01-08 00:00:00 +00:00
2017-10-29 21:08:55 +00:00
check.called(validate, 0);
2015-01-08 00:00:00 +00:00
battleview.cursorClicked();
2017-10-29 21:08:55 +00:00
check.called(validate, 1);
2015-01-08 00:00:00 +00:00
battleview.exitTargettingMode();
2017-10-26 21:47:13 +00:00
check.equals(battleview.targetting.active, false);
2015-01-08 00:00:00 +00:00
2017-09-19 15:09:06 +00:00
battleview.cursorHovered(new ArenaLocation(5, 8), null);
2017-10-26 21:47:13 +00:00
check.equals(battleview.targetting.target, null);
check.equals(battleview.ship_hovered, null);
battleview.cursorHovered(ship.location, ship);
2017-10-26 21:47:13 +00:00
check.equals(battleview.targetting.target, null);
check.same(battleview.ship_hovered, ship);
2015-01-08 00:00:00 +00:00
});
2019-05-13 22:38:58 +00:00
test.case("adds player actions to plan", check => {
let battleview = testgame.view;
2019-05-16 16:39:56 +00:00
check.equals(battleview.turn_plannings.length, 2);
check.equals(battleview.turn_plannings[0].collectAllActions(), []);
check.equals(battleview.turn_plannings[1].collectAllActions(), []);
2019-05-13 22:38:58 +00:00
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);
2019-05-16 16:39:56 +00:00
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 }
2019-05-13 22:38:58 +00:00
]);
2019-05-16 16:39:56 +00:00
check.equals(battleview.turn_plannings[1].collectAllActions(), []);
2019-05-13 22:38:58 +00:00
});
test.case("disables player interaction while resolution is playing", check => {
const battleview = testgame.view;
const ship = battleview.actual_battle.fleets[0].ships[0];
2019-05-20 16:35:59 +00:00
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);
2019-05-20 16:35:59 +00:00
check.called(mockSetPhase, [[1, BattleInfoBarPhase.RESOLUTION]]);
});
2019-05-20 16:35:59 +00:00
battleview.actual_battle.applyDiffs([new TurnEndDiff(1)]);
battleview.log_processor.processPending();
check.in("end 1", check => {
check.equals(battleview.interacting, true);
2019-05-20 16:35:59 +00:00
check.called(mockSetPhase, [[2, BattleInfoBarPhase.PLANNING]]);
});
2019-05-20 16:35:59 +00:00
battleview.actual_battle.applyDiffs([new TurnStartDiff([])]);
battleview.log_processor.processPending();
check.in("start 2", check => {
check.equals(battleview.interacting, false);
2019-05-20 16:35:59 +00:00
check.called(mockSetPhase, [[2, BattleInfoBarPhase.RESOLUTION]]);
});
2019-05-20 16:35:59 +00:00
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);
2019-05-20 16:35:59 +00:00
check.called(mockSetPhase, [[3, BattleInfoBarPhase.END]]);
});
});
2015-01-08 00:00:00 +00:00
});
}