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

78 lines
2.7 KiB
TypeScript
Raw Normal View History

/// <reference path="../TestGame.ts"/>
2017-09-24 22:23:22 +00:00
module TK.SpaceTac.UI.Specs {
2017-10-26 21:47:13 +00:00
testing("ActionBar", 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("lists available actions for selected ship", check => {
2017-10-09 21:13:56 +00:00
var bar = testgame.view.action_bar;
// Ship not owned by current battleview player
2017-02-09 00:00:35 +00:00
var ship = new Ship();
bar.setShip(ship);
2017-10-26 21:47:13 +00:00
check.equals(bar.action_icons.length, 0);
// Ship with no equipment (only endturn action)
2017-10-09 21:13:56 +00:00
testgame.view.player = ship.getPlayer();
bar.setShip(ship);
2017-10-26 21:47:13 +00:00
check.equals(bar.action_icons.length, 1);
check.equals(bar.action_icons[0].action.code, "endturn");
// Add an engine, with move action
TestTools.addEngine(ship, 50);
bar.setShip(ship);
2017-10-26 21:47:13 +00:00
check.equals(bar.action_icons.length, 2);
check.equals(bar.action_icons[0].action.code, "move");
// Add a weapon, with fire action
TestTools.addWeapon(ship, 10, 1, 100);
bar.setShip(ship);
2017-10-26 21:47:13 +00:00
check.equals(bar.action_icons.length, 3);
check.equals(bar.action_icons[1].action.code, "fire-equipment");
});
2017-10-26 21:47:13 +00:00
test.case("updates power points display", check => {
2017-10-09 21:13:56 +00:00
let bar = testgame.view.action_bar;
2017-10-26 21:47:13 +00:00
function checkpoints(available = 0, using = 0, used = 0) {
check.same(bar.power_icons.children.length, available + using + used);
2017-09-28 23:18:46 +00:00
bar.power_icons.children.forEach((child, idx) => {
let img = <Phaser.Image>child;
if (idx < available) {
2017-10-26 21:47:13 +00:00
check.equals(img.name, "battle-actionbar-power-available");
} else if (idx < available + using) {
2017-10-26 21:47:13 +00:00
check.equals(img.name, "battle-actionbar-power-move");
} else {
2017-10-26 21:47:13 +00:00
check.equals(img.name, "battle-actionbar-power-used");
}
});
}
// not owned ship
let ship = new Ship();
TestTools.setShipAP(ship, 8);
bar.setShip(ship);
2017-10-26 21:47:13 +00:00
checkpoints();
// owned ship
2017-10-09 21:13:56 +00:00
ship.fleet = testgame.view.player.fleet;
bar.setShip(ship);
2017-10-26 21:47:13 +00:00
checkpoints(8);
// used points
ship.setValue("power", 6);
2017-10-09 21:13:56 +00:00
testgame.view.log_processor.jumpToEnd();
2017-10-26 21:47:13 +00:00
checkpoints(6, 0, 2);
// using points
bar.updatePower(5);
2017-10-26 21:47:13 +00:00
checkpoints(1, 5, 2);
// decrease
ship.setAttribute("power_capacity", 3);
2017-10-09 21:13:56 +00:00
testgame.view.log_processor.jumpToEnd();
2017-10-26 21:47:13 +00:00
checkpoints(3);
});
});
}