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

132 lines
6.3 KiB
TypeScript
Raw Normal View History

2017-09-28 23:18:46 +00:00
/// <reference path="../TestGame.ts"/>
module TK.SpaceTac.UI.Specs {
2017-10-26 21:47:13 +00:00
testing("ActionIcon", test => {
2017-10-29 21:08:55 +00:00
let testgame = setupBattleview(test);
2017-09-28 23:18:46 +00:00
2017-10-26 21:47:13 +00:00
test.case("displays power usage", check => {
2017-10-09 21:13:56 +00:00
let bar = testgame.view.action_bar;
2017-09-28 23:18:46 +00:00
let ship = new Ship();
let action = new BaseAction("something", "Do something");
let icon = new ActionIcon(bar, ship, action, 0);
2017-10-26 21:47:13 +00:00
check.same(icon.img_power.visible, false, "initial state");
2017-09-28 23:18:46 +00:00
icon.refresh();
2017-10-26 21:47:13 +00:00
check.same(icon.img_power.visible, false, "no change");
2017-09-28 23:18:46 +00:00
2017-10-29 21:08:55 +00:00
check.patch(action, "getActionPointsUsage", () => 3);
2017-09-28 23:18:46 +00:00
icon.refresh();
2017-10-26 21:47:13 +00:00
check.equals(icon.img_power.visible, true);
check.equals(icon.text_power.text, "3");
2017-09-28 23:18:46 +00:00
})
2017-10-26 21:47:13 +00:00
test.case("displays disabled and fading states", check => {
2017-10-09 21:13:56 +00:00
let bar = testgame.view.action_bar;
2017-09-28 23:18:46 +00:00
let ship = new Ship();
TestTools.setShipAP(ship, 5);
let action = nn(TestTools.addWeapon(ship, 50, 3).action);
let icon = new ActionIcon(bar, ship, action, 0);
2017-10-26 21:47:13 +00:00
check.equals(icon.container.name, "battle-actionbar-frame-enabled", "5/5");
check.equals(icon.img_power.name, "battle-actionbar-consumption-enabled", "5/5");
check.same(icon.img_power.visible, true, "5/5");
check.equals(icon.img_bottom.name, "battle-actionbar-bottom-enabled", "5/5");
2017-09-28 23:18:46 +00:00
icon.refresh(null, 1);
2017-10-26 21:47:13 +00:00
check.equals(icon.container.name, "battle-actionbar-frame-enabled", "4/5");
check.equals(icon.img_power.name, "battle-actionbar-consumption-enabled", "4/5");
check.same(icon.img_power.visible, true, "4/5");
check.equals(icon.img_bottom.name, "battle-actionbar-bottom-enabled", "4/5");
2017-09-28 23:18:46 +00:00
icon.refresh(null, 4);
2017-10-26 21:47:13 +00:00
check.equals(icon.container.name, "battle-actionbar-frame-fading", "1/5");
check.equals(icon.img_power.name, "battle-actionbar-consumption-enabled", "1/5");
check.same(icon.img_power.visible, true, "1/5");
check.equals(icon.img_bottom.name, "battle-actionbar-bottom-enabled", "1/5");
2017-09-28 23:18:46 +00:00
ship.setValue("power", 2);
icon.refresh();
2017-10-26 21:47:13 +00:00
check.equals(icon.container.name, "battle-actionbar-frame-disabled", "2/2");
check.equals(icon.img_power.name, "battle-actionbar-consumption-disabled", "2/2");
check.same(icon.img_power.visible, true, "2/2");
check.equals(icon.img_bottom.name, "battle-actionbar-bottom-disabled", "2/2");
2017-09-28 23:18:46 +00:00
icon.refresh(null, 6);
2017-10-26 21:47:13 +00:00
check.equals(icon.container.name, "battle-actionbar-frame-disabled", "0/2");
check.equals(icon.img_power.name, "battle-actionbar-consumption-disabled", "0/2");
check.same(icon.img_power.visible, true, "0/2");
check.equals(icon.img_bottom.name, "battle-actionbar-bottom-disabled", "0/2");
2017-09-28 23:18:46 +00:00
})
2017-10-26 21:47:13 +00:00
test.case("displays toggle state", check => {
2017-10-09 21:13:56 +00:00
let bar = testgame.view.action_bar;
2017-10-01 16:33:48 +00:00
let ship = new Ship();
TestTools.setShipAP(ship, 5);
let equipment = new Equipment(SlotType.Weapon);
ship.addSlot(SlotType.Weapon).attach(equipment);
let action = new ToggleAction(equipment, 2);
equipment.action = action;
let icon = new ActionIcon(bar, ship, action, 0);
2017-09-28 23:18:46 +00:00
2017-10-26 21:47:13 +00:00
check.equals(icon.img_bottom.name, "battle-actionbar-bottom-enabled", "initial");
check.equals(icon.img_power.name, "battle-actionbar-consumption-enabled", "initial");
check.equals(icon.img_sticky.name, "battle-actionbar-sticky-untoggled", "initial");
check.same(icon.img_sticky.visible, true, "initial");
2017-10-01 16:33:48 +00:00
action.activated = true;
icon.refresh();
2017-10-26 21:47:13 +00:00
check.equals(icon.img_bottom.name, "battle-actionbar-bottom-toggled", "initial");
check.equals(icon.img_power.name, "battle-actionbar-consumption-toggled", "initial");
check.equals(icon.img_sticky.name, "battle-actionbar-sticky-toggled", "initial");
check.same(icon.img_sticky.visible, true, "initial");
2017-09-28 23:18:46 +00:00
})
2017-10-26 21:47:13 +00:00
test.case("displays overheat/cooldown", check => {
2017-10-09 21:13:56 +00:00
let bar = testgame.view.action_bar;
let ship = new Ship();
TestTools.setShipAP(ship, 5);
let action = nn(TestTools.addWeapon(ship, 50, 3).action);
action.cooldown.configure(1, 3);
let icon = new ActionIcon(bar, ship, action, 0);
2017-10-26 21:47:13 +00:00
check.same(icon.img_sticky.visible, false, "initial");
check.equals(icon.img_sticky.name, "battle-actionbar-sticky-untoggled", "initial");
check.same(icon.img_sticky.children.length, 0, "initial");
2017-09-28 23:18:46 +00:00
icon.refresh(action);
2017-10-26 21:47:13 +00:00
check.same(icon.img_sticky.visible, true, "overheat");
check.equals(icon.img_sticky.name, "battle-actionbar-sticky-overheat", "overheat");
check.same(icon.img_sticky.children.length, 3, "overheat");
action.cooldown.configure(1, 12);
icon.refresh(action);
2017-10-26 21:47:13 +00:00
check.same(icon.img_sticky.visible, true, "superheat");
check.equals(icon.img_sticky.name, "battle-actionbar-sticky-overheat", "superheat");
check.same(icon.img_sticky.children.length, 5, "superheat");
action.cooldown.configure(1, 4);
action.cooldown.use();
icon.refresh(action);
2017-10-26 21:47:13 +00:00
check.same(icon.img_sticky.visible, true, "cooling");
check.equals(icon.img_sticky.name, "battle-actionbar-sticky-disabled", "cooling");
check.same(icon.img_sticky.children.length, 4, "cooling");
2017-09-28 23:18:46 +00:00
})
2017-10-26 21:47:13 +00:00
test.case("displays currently targetting", check => {
2017-10-09 21:13:56 +00:00
testgame.view.animations.setImmediate();
2017-10-01 16:33:48 +00:00
2017-10-09 21:13:56 +00:00
let bar = testgame.view.action_bar;
2017-10-01 16:33:48 +00:00
let ship = new Ship();
TestTools.setShipAP(ship, 5);
let action = nn(TestTools.addWeapon(ship, 50, 3).action);
let icon = new ActionIcon(bar, ship, action, 0);
2017-10-26 21:47:13 +00:00
check.same(icon.img_targetting.visible, false, "initial");
2017-10-01 16:33:48 +00:00
icon.refresh(action);
2017-10-26 21:47:13 +00:00
check.same(icon.img_targetting.visible, true, "selected");
2017-09-28 23:18:46 +00:00
2017-10-01 16:33:48 +00:00
icon.refresh(new BaseAction("other", "Other action"));
2017-10-26 21:47:13 +00:00
check.same(icon.img_targetting.visible, false, "other");
2017-09-28 23:18:46 +00:00
})
});
}