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

140 lines
6.7 KiB
TypeScript
Raw Normal View History

2017-09-28 23:18:46 +00:00
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();
2017-11-29 22:03:58 +00:00
let action = new BaseAction("something");
2017-09-28 23:18:46 +00:00
let icon = new ActionIcon(bar, ship, action, 0);
check.same(icon.power_container.visible, false, "initial state");
2017-09-28 23:18:46 +00:00
icon.refresh();
check.same(icon.power_container.visible, false, "no change");
2017-09-28 23:18:46 +00:00
2017-12-04 19:01:50 +00:00
let cost = 3;
check.patch(action, "getPowerUsage", () => cost);
2017-09-28 23:18:46 +00:00
icon.refresh();
2017-12-04 19:01:50 +00:00
check.in("power cost = 3", check => {
check.equals(icon.power_container.visible, true);
2018-06-04 14:48:19 +00:00
check.equals(icon.power_text.text, "3\n-");
2017-12-04 19:01:50 +00:00
});
cost = -2;
icon.refresh();
check.in("power cost = -2", check => {
check.equals(icon.power_container.visible, true);
2018-06-04 14:48:19 +00:00
check.equals(icon.power_text.text, "2\n+");
2017-12-04 19:01:50 +00:00
});
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.setShipModel(ship, 100, 0, 5);
let action = TestTools.addWeapon(ship, 50, 3);
2017-09-28 23:18:46 +00:00
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");
2018-06-04 14:48:19 +00:00
check.equals(icon.power_bg.name, "battle-actionbar-consumption-enabled", "5/5");
check.same(icon.power_bg.visible, true, "5/5");
2017-10-26 21:47:13 +00:00
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");
2018-06-04 14:48:19 +00:00
check.equals(icon.power_bg.name, "battle-actionbar-consumption-enabled", "4/5");
check.same(icon.power_bg.visible, true, "4/5");
2017-10-26 21:47:13 +00:00
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");
2018-06-04 14:48:19 +00:00
check.equals(icon.power_bg.name, "battle-actionbar-consumption-enabled", "1/5");
check.same(icon.power_bg.visible, true, "1/5");
2017-10-26 21:47:13 +00:00
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");
2018-06-04 14:48:19 +00:00
check.equals(icon.power_bg.name, "battle-actionbar-consumption-disabled", "2/2");
check.same(icon.power_bg.visible, true, "2/2");
2017-10-26 21:47:13 +00:00
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");
2018-06-04 14:48:19 +00:00
check.equals(icon.power_bg.name, "battle-actionbar-consumption-disabled", "0/2");
check.same(icon.power_bg.visible, true, "0/2");
2017-10-26 21:47:13 +00:00
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.setShipModel(ship, 100, 0, 5);
let action = new ToggleAction("toggle", { power: 2 });
ship.actions.addCustom(action);
2017-10-01 16:33:48 +00:00
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");
2018-06-04 14:48:19 +00:00
check.equals(icon.power_bg.name, "battle-actionbar-consumption-enabled", "initial");
2018-05-15 14:57:45 +00:00
check.equals(icon.img_cooldown.name, "battle-actionbar-sticky-untoggled", "initial");
check.same(icon.img_cooldown.visible, true, "initial");
2017-10-01 16:33:48 +00:00
ship.actions.toggle(action, true);
2017-10-01 16:33:48 +00:00
icon.refresh();
2017-10-26 21:47:13 +00:00
check.equals(icon.img_bottom.name, "battle-actionbar-bottom-toggled", "initial");
2018-06-04 14:48:19 +00:00
check.equals(icon.power_bg.name, "battle-actionbar-consumption-toggled", "initial");
2018-05-15 14:57:45 +00:00
check.equals(icon.img_cooldown.name, "battle-actionbar-sticky-toggled", "initial");
check.same(icon.img_cooldown.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();
let action = new TriggerAction("weapon");
action.configureCooldown(1, 3);
TestTools.setShipModel(ship, 100, 0, 5, 1, [action]);
let icon = new ActionIcon(bar, ship, action, 0);
2018-05-15 14:57:45 +00:00
check.same(icon.img_cooldown.visible, false, "initial");
check.equals(icon.img_cooldown.name, "battle-actionbar-sticky-untoggled", "initial");
check.same(icon.img_cooldown_group.length, 1, "initial");
2017-09-28 23:18:46 +00:00
icon.refresh(action);
2018-05-15 14:57:45 +00:00
check.same(icon.img_cooldown.visible, true, "overheat");
check.equals(icon.img_cooldown.name, "battle-actionbar-sticky-overheat", "overheat");
check.same(icon.img_cooldown_group.length, 4, "overheat");
action.configureCooldown(1, 12);
TestTools.setShipModel(ship, 100, 0, 5, 1, [action]);
icon.refresh(action);
2018-05-15 14:57:45 +00:00
check.same(icon.img_cooldown.visible, true, "superheat");
check.equals(icon.img_cooldown.name, "battle-actionbar-sticky-overheat", "superheat");
check.same(icon.img_cooldown_group.length, 6, "superheat");
action.configureCooldown(1, 4);
TestTools.setShipModel(ship, 100, 0, 5, 1, [action]);
ship.actions.getCooldown(action).use();
icon.refresh(action);
2018-05-15 14:57:45 +00:00
check.same(icon.img_cooldown.visible, true, "cooling");
check.equals(icon.img_cooldown.name, "battle-actionbar-sticky-disabled", "cooling");
check.same(icon.img_cooldown_group.length, 5, "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.setShipModel(ship, 100, 0, 5);
let action = TestTools.addWeapon(ship, 50, 3);
2017-10-01 16:33:48 +00:00
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-11-29 22:03:58 +00:00
icon.refresh(new BaseAction("other"));
2017-10-26 21:47:13 +00:00
check.same(icon.img_targetting.visible, false, "other");
2017-09-28 23:18:46 +00:00
})
});
}