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

89 lines
4.1 KiB
TypeScript
Raw Normal View History

2017-09-24 22:23:22 +00:00
module TK.SpaceTac.UI.Specs {
2017-10-25 22:45:53 +00:00
testing("ShipList", test => {
2017-10-29 21:08:55 +00:00
let testgame = setupEmptyView(test);
2017-02-21 22:38:31 +00:00
2017-10-25 22:45:53 +00:00
function createList(): ShipList {
let view = testgame.view;
let battle = new Battle();
let player = new Player();
battle.fleets[0].setPlayer(player);
2017-10-25 22:45:53 +00:00
let tactical_mode = new Toggle();
2017-10-29 21:08:55 +00:00
let ship_buttons = {
cursorOnShip: nop,
cursorOffShip: nop,
cursorClicked: nop,
};
let list = new ShipList(view, battle, player, tactical_mode, ship_buttons);
2017-10-25 22:45:53 +00:00
return list;
}
2017-10-25 22:45:53 +00:00
test.case("handles play position of ships", check => {
let list = createList();
let battle = list.battle;
check.in("initial", check => {
check.equals(list.items.length, 0, "no item at first");
});
2017-02-16 22:59:41 +00:00
let ship = battle.fleets[0].addShip();
TestTools.setShipModel(ship, 10, 0);
2017-10-25 22:45:53 +00:00
list.setShipsFromBattle(battle, false);
check.in("one ship added but not in play order", check => {
check.equals(list.items.length, 1, "item count");
check.equals(list.items[0].visible, false, "ship card not visible");
});
2017-10-25 22:45:53 +00:00
battle.throwInitiative();
list.refresh(0);
check.in("ship now in play order", check => {
check.equals(list.items[0].visible, true, "ship card visible");
});
ship = battle.fleets[1].addShip();
TestTools.setShipModel(ship, 10, 0);
2017-10-25 22:45:53 +00:00
battle.throwInitiative();
list.setShipsFromBattle(battle, false);
check.in("ship added in the other fleet", check => {
check.equals(list.items.length, 2, "item count");
2018-05-15 14:57:45 +00:00
check.equals(nn(list.findItem(battle.play_order[0])).location, { x: 2, y: 843 }, "first ship position");
check.equals(nn(list.findItem(battle.play_order[1])).location, { x: 2, y: 744 }, "second ship position");
});
2017-10-25 22:45:53 +00:00
battle.setPlayingShip(battle.play_order[0]);
list.refresh(0);
check.in("started", check => {
2018-05-15 14:57:45 +00:00
check.equals(nn(list.findItem(battle.play_order[0])).location, { x: -14, y: 962 }, "first ship position");
check.equals(nn(list.findItem(battle.play_order[1])).location, { x: 2, y: 843 }, "second ship position");
});
2017-10-25 22:45:53 +00:00
battle.advanceToNextShip();
list.refresh(0);
check.in("end turn", check => {
2018-05-15 14:57:45 +00:00
check.equals(nn(list.findItem(battle.play_order[0])).location, { x: 2, y: 843 }, "first ship position");
check.equals(nn(list.findItem(battle.play_order[1])).location, { x: -14, y: 962 }, "second ship position");
});
2017-10-29 21:08:55 +00:00
ship = battle.fleets[1].addShip();
TestTools.setShipModel(ship, 10, 0);
2017-10-25 22:45:53 +00:00
battle.throwInitiative();
battle.setPlayingShip(battle.play_order[0]);
2017-10-25 22:45:53 +00:00
list.setShipsFromBattle(battle, false);
check.in("third ship added", check => {
check.equals(list.items.length, 3, "item count");
2018-05-15 14:57:45 +00:00
check.equals(nn(list.findItem(battle.play_order[0])).location, { x: -14, y: 962 }, "first ship position");
check.equals(nn(list.findItem(battle.play_order[1])).location, { x: 2, y: 843 }, "second ship position");
check.equals(nn(list.findItem(battle.play_order[2])).location, { x: 2, y: 744 }, "third ship position");
});
2017-10-25 22:45:53 +00:00
let dead = battle.play_order[1];
dead.setDead();
list.refresh(0);
check.in("ship dead", check => {
check.equals(list.items.length, 3, "item count");
2018-05-15 14:57:45 +00:00
check.equals(nn(list.findItem(battle.play_order[0])).location, { x: -14, y: 962 }, "first ship position");
check.equals(nn(list.findItem(dead)).location, { x: 200, y: 843 }, "dead ship position");
check.equals(nn(list.findItem(battle.play_order[1])).location, { x: 2, y: 843 }, "second ship position");
});
});
});
}