1
0
Fork 0

Switched to new testing tools

This commit is contained in:
Michaël Lemaire 2017-10-29 22:08:55 +01:00
parent dc89acd8a2
commit 046c476c0a
60 changed files with 279 additions and 243 deletions

View file

@ -12,7 +12,7 @@ module TK.SpaceTac.UI.Specs {
}
testing("MainUI", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("saves games in local browser storage", check => {
let ui = testgame.ui;
@ -27,7 +27,7 @@ module TK.SpaceTac.UI.Specs {
result = ui.saveGame("spacetac-test-save");
check.equals(result, true);
expect(ui.storage.getItem("spacetac-test-save")).toBeTruthy();
check.equals(bool(ui.storage.getItem("spacetac-test-save")), true);
ui.session = new GameSession();
check.notsame(ui.session.universe.stars.length, systems);

@ -1 +1 @@
Subproject commit f867187f0da83bbd4c4eb9d8221982a2b6e6e027
Subproject commit 639fcb0ac311767b413067f6854f6c2aecd41e5a

View file

@ -113,25 +113,33 @@ module TK.SpaceTac {
var battle = new Battle(fleet1, fleet2);
spyOn(ship1, "startTurn").and.callThrough();
spyOn(ship2, "startTurn").and.callThrough();
spyOn(ship3, "startTurn").and.callThrough();
let mock1 = check.patch(ship1, "startTurn");
let mock2 = check.patch(ship2, "startTurn");
let mock3 = check.patch(ship3, "startTurn");
// Force play order
var gen = new SkewedRandomGenerator([0.3, 0.2, 0.1]);
battle.throwInitiative(gen);
battle.advanceToNextShip();
expect(ship1.startTurn).toHaveBeenCalledWith();
check.called(mock1, 1);
check.called(mock2, 0);
check.called(mock3, 0);
battle.advanceToNextShip();
expect(ship2.startTurn).toHaveBeenCalledWith();
check.called(mock1, 0);
check.called(mock2, 1);
check.called(mock3, 0);
battle.advanceToNextShip();
expect(ship3.startTurn).toHaveBeenCalledWith();
check.called(mock1, 0);
check.called(mock2, 0);
check.called(mock3, 1);
battle.advanceToNextShip();
expect(ship1.startTurn).toHaveBeenCalledWith();
check.called(mock1, 1);
check.called(mock2, 0);
check.called(mock3, 0);
});
test.case("detects victory condition and logs a final EndBattleEvent", check => {
@ -291,7 +299,7 @@ module TK.SpaceTac {
test.case("gets the number of turns before a specific ship plays", check => {
let battle = new Battle();
spyOn(battle, "checkEndBattle").and.returnValue(false);
check.patch(battle, "checkEndBattle", () => false);
battle.play_order = [new Ship(), new Ship(), new Ship()];
battle.advanceToNextShip();

View file

@ -28,7 +28,9 @@ module TK.SpaceTac.Specs {
check.equals(ship.listEquipment(), []);
battle.cheats.equip("Iron Hull");
check.equals(ship.listEquipment(), [<any>jasmine.objectContaining({ name: "Iron Hull", level: 1 })]);
let result = ship.listEquipment();
check.equals(result.length, 1);
check.containing(result[0], { name: "Iron Hull", level: 1 });
})
})
}

View file

@ -40,7 +40,7 @@ module TK.SpaceTac.Specs {
template.setSkillsRequirements({ "skill_photons": istep(4) });
template.addAttributeEffect("power_capacity", istep(1));
looter.templates = [template];
spyOn(outcome, "getLootGenerator").and.returnValue(looter);
check.patch(outcome, "getLootGenerator", () => looter);
outcome.createLoot(battle, random);

View file

@ -59,14 +59,18 @@ module TK.SpaceTac {
let [drone, effect] = newTestDrone(0, 0, 5, owner);
drone.duration = 3;
let removeDrone = spyOn(battle, "removeDrone").and.callThrough();
let removeDrone = check.patch(battle, "removeDrone", null);
drone.activate();
expect(removeDrone).not.toHaveBeenCalled();
check.called(removeDrone, 0);
drone.activate();
expect(removeDrone).not.toHaveBeenCalled();
check.called(removeDrone, 0);
drone.activate();
expect(removeDrone).toHaveBeenCalledWith(drone, true);
check.called(removeDrone, [
[drone, true]
]);
});
test.case("logs each activation", check => {

View file

@ -49,11 +49,11 @@ module TK.SpaceTac.Specs {
let battle = nn(session.getBattle());
battle.endBattle(session.player.fleet);
let spyloot = spyOn(battle.outcome, "createLoot").and.stub();
let spyloot = check.patch(battle.outcome, "createLoot", null);
session.setBattleEnded();
check.notequals(session.getBattle(), null);
check.equals(location1.encounter, null);
expect(spyloot).toHaveBeenCalledTimes(1);
check.called(spyloot, 1);
// Defeat case
let location2 = new StarLocation(location1.star);
@ -64,11 +64,11 @@ module TK.SpaceTac.Specs {
battle = nn(session.getBattle());
battle.endBattle(null);
spyloot = spyOn(battle.outcome, "createLoot").and.stub();
spyloot = check.patch(battle.outcome, "createLoot", null);
session.setBattleEnded();
check.notequals(session.getBattle(), null);
check.notequals(location2.encounter, null);
expect(spyloot).toHaveBeenCalledTimes(0);
check.called(spyloot, 0);
});
test.case("generates a new campaign", check => {

View file

@ -34,8 +34,8 @@ module TK.SpaceTac.Specs {
check.same(result.can_fire, true, 'can_fire');
check.same(result.total_fire_ap, 3, 'total_fire_ap');
check.equals(<any[]>result.parts, [
{ action: jasmine.objectContaining({ code: "fire-equipment" }), target: new Target(ship.arena_x + 5, ship.arena_y, null), ap: 3, possible: true }
check.equals(result.parts, [
{ action: action, target: new Target(ship.arena_x + 5, ship.arena_y, null), ap: 3, possible: true }
]);
});
@ -48,8 +48,8 @@ module TK.SpaceTac.Specs {
check.same(result.can_fire, false, 'can_fire');
check.same(result.total_fire_ap, 3, 'total_fire_ap');
check.equals(<any[]>result.parts, [
{ action: jasmine.objectContaining({ code: "fire-equipment" }), target: new Target(ship.arena_x + 5, ship.arena_y, null), ap: 3, possible: false }
check.equals(result.parts, [
{ action: action, target: new Target(ship.arena_x + 5, ship.arena_y, null), ap: 3, possible: false }
]);
});
@ -65,9 +65,10 @@ module TK.SpaceTac.Specs {
check.same(result.can_fire, true, 'can_fire');
check.same(result.total_fire_ap, 3, 'total_fire_ap');
check.equals(<any[]>result.parts, [
{ action: jasmine.objectContaining({ code: "move" }), target: new Target(ship.arena_x + 5, ship.arena_y, null), ap: 1, possible: true },
{ action: jasmine.objectContaining({ code: "fire-equipment" }), target: new Target(ship.arena_x + 15, ship.arena_y, null), ap: 3, possible: true }
let move_action = ship.listEquipment(SlotType.Engine)[0].action;
check.equals(result.parts, [
{ action: move_action, target: new Target(ship.arena_x + 5, ship.arena_y, null), ap: 1, possible: true },
{ action: action, target: new Target(ship.arena_x + 15, ship.arena_y, null), ap: 3, possible: true }
]);
});
@ -120,7 +121,7 @@ module TK.SpaceTac.Specs {
ship1.setArenaPosition(420, 200);
spyOn(simulator, "scanCircle").and.returnValue(iarray([
check.patch(simulator, "scanCircle", () => iarray([
new Target(400, 200),
new Target(410, 200),
new Target(410, 230),
@ -142,9 +143,10 @@ module TK.SpaceTac.Specs {
check.same(result.can_fire, false, 'can_fire');
check.same(result.total_fire_ap, 2, 'total_fire_ap');
check.equals(<any[]>result.parts, [
{ action: jasmine.objectContaining({ code: "move" }), target: new Target(ship.arena_x + 10, ship.arena_y, null), ap: 2, possible: true },
{ action: jasmine.objectContaining({ code: "fire-equipment" }), target: new Target(ship.arena_x + 18, ship.arena_y, null), ap: 2, possible: false }
let move_action = ship.listEquipment(SlotType.Engine)[0].action;
check.equals(result.parts, [
{ action: move_action, target: new Target(ship.arena_x + 10, ship.arena_y, null), ap: 2, possible: true },
{ action: action, target: new Target(ship.arena_x + 18, ship.arena_y, null), ap: 2, possible: false }
]);
});

View file

@ -1,14 +1,14 @@
module TK.SpaceTac.Specs {
testing("ShipModel", test => {
test.case("picks random models from default collection", check => {
spyOn(console, "error").and.stub();
spyOn(ShipModel, "getDefaultCollection").and.returnValues(
check.patch(console, "error", null);
check.patch(ShipModel, "getDefaultCollection", iterator([
[new ShipModel("a")],
[],
[new ShipModel("a"), new ShipModel("b")],
[new ShipModel("a")],
[],
);
]));
check.equals(ShipModel.getRandomModel(), new ShipModel("a"), "pick from a one-item list");
check.equals(ShipModel.getRandomModel(), new ShipModel(), "pick from an empty list");

View file

@ -3,7 +3,7 @@ module TK.SpaceTac.Specs {
test.case("generates a stock", check => {
let shop = new Shop();
check.equals((<any>shop).stock.length, 0);
expect(shop.getStock().length).toBeGreaterThan(20);
check.greater(shop.getStock().length, 20);
});
test.case("buys and sells items", check => {
@ -14,7 +14,7 @@ module TK.SpaceTac.Specs {
let shop = new Shop(1, [equ1, equ2], 0);
let fleet = new Fleet();
fleet.credits = 1000;
spyOn(shop, "getPrice").and.returnValue(800);
check.patch(shop, "getPrice", () => 800);
let result = shop.sellToFleet(equ1, fleet);
check.equals(result, true);

View file

@ -3,7 +3,7 @@ module TK.SpaceTac {
test.case("check if equipment can be used with remaining AP", check => {
var equipment = new Equipment(SlotType.Hull);
var action = new BaseAction("test", "Test", equipment);
spyOn(action, "getActionPointsUsage").and.returnValue(3);
check.patch(action, "getActionPointsUsage", () => 3);
var ship = new Ship();
ship.addSlot(SlotType.Hull).attach(equipment);
ship.values.power.setMaximal(10);
@ -73,7 +73,7 @@ module TK.SpaceTac {
let equipment = new Equipment(SlotType.Weapon);
let action = new BaseAction("test", "Test", equipment);
spyOn(action, "checkTarget").and.callFake((ship: Ship, target: Target) => target);
check.patch(action, "checkTarget", (ship: Ship, target: Target) => target);
check.equals(power.wear, 0);
check.equals(equipment.wear, 0);

View file

@ -1,7 +1,7 @@
module TK.SpaceTac.Specs {
testing("EndTurnAction", test => {
test.case("can't be applied to non-playing ship", check => {
spyOn(console, "warn").and.stub();
let mock_warn = check.patch(console, "warn", null);
let battle = Battle.newQuickRandom();
let action = new EndTurnAction();
@ -12,8 +12,9 @@ module TK.SpaceTac.Specs {
let ship = battle.play_order[1];
let result = action.apply(battle.play_order[1]);
check.equals(result, false);
expect(console.warn).toHaveBeenCalledWith("Action rejected - ship not playing", ship, action, Target.newFromShip(ship));
check.called(mock_warn, [
["Action rejected - ship not playing", ship, action, Target.newFromShip(ship)]
]);
});
test.case("ends turn when applied", check => {

View file

@ -47,7 +47,7 @@ module TK.SpaceTac {
var action = new MoveAction(engine, 1);
TestTools.setShipPlaying(battle, ship);
spyOn(console, "warn").and.stub();
check.patch(console, "warn", null);
var result = action.apply(ship, Target.newFromLocation(10, 10));
check.equals(result, true);

View file

@ -14,7 +14,7 @@ module TK.SpaceTac {
let ship = new Ship(fleet, "ship");
let equipment = new Equipment(SlotType.Weapon, "testweapon");
let effect = new BaseEffect("testeffect");
let mock_apply = spyOn(effect, "applyOnShip").and.stub();
let mock_apply = check.patch(effect, "applyOnShip", null);
let action = new TriggerAction(equipment, [effect], 5, 100, 10);
TestTools.setShipAP(ship, 10);
@ -33,8 +33,9 @@ module TK.SpaceTac {
fleet.setBattle(battle);
action.apply(ship, Target.newFromLocation(50, 50));
expect(mock_apply).toHaveBeenCalledTimes(1);
expect(mock_apply).toHaveBeenCalledWith(ship2, ship);
check.called(mock_apply, [
[ship2, ship]
]);
})
test.case("transforms ship target in location target, when the weapon has blast radius", check => {
@ -105,7 +106,7 @@ module TK.SpaceTac {
let ship = new Ship();
let weapon = TestTools.addWeapon(ship, 1, 0, 100, 30);
let action = nn(weapon.action);
spyOn(action, "checkTarget").and.callFake((ship: Ship, target: Target) => target);
check.patch(action, "checkTarget", (ship: Ship, target: Target) => target);
check.equals(ship.arena_angle, 0);
let result = action.apply(ship, Target.newFromLocation(10, 20));

View file

@ -16,8 +16,8 @@ module TK.SpaceTac.Specs {
let producer = (...scores: number[]) => imap(iarray(scores), score => new FixedManeuver(score));
let applied: number[] = [];
beforeEach(function () {
spyOn(console, "log").and.stub();
test.setup(function () {
test.check.patch(console, "log", null);
applied = [];
});
@ -28,14 +28,14 @@ module TK.SpaceTac.Specs {
ship.playing = true;
let ai = new TacticalAI(ship, Timer.synchronous);
spyOn(ai, "getDefaultProducers").and.returnValue([
check.patch(ai, "getDefaultProducers", () => [
producer(1, -8, 4),
producer(3, 7, 0, 6, 1)
]);
spyOn(ai, "getDefaultEvaluators").and.returnValue([
check.patch(ai, "getDefaultEvaluators", () => [
(maneuver: Maneuver) => (<FixedManeuver>maneuver).score
]);
spyOn(ai, "applyManeuver").and.callFake((maneuver: FixedManeuver) => applied.push(maneuver.score));
check.patch(ai, "applyManeuver", (maneuver: FixedManeuver) => applied.push(maneuver.score));
ai.play();
check.equals(applied, [7]);

View file

@ -53,14 +53,14 @@ module TK.SpaceTac.Specs {
check.equals(damage.getEffectiveDamage(ship), [200, 0]);
spyOn(ship, "ieffects").and.returnValues(
check.patch(ship, "ieffects", iterator([
isingle(new DamageModifierEffect(-15)),
isingle(new DamageModifierEffect(20)),
isingle(new DamageModifierEffect(-150)),
isingle(new DamageModifierEffect(180)),
iarray([new DamageModifierEffect(10), new DamageModifierEffect(-15)]),
isingle(new DamageModifierEffect(3))
);
]));
check.equals(damage.getEffectiveDamage(ship), [170, 0]);
check.equals(damage.getEffectiveDamage(ship), [240, 0]);

View file

@ -39,7 +39,7 @@ module TK.SpaceTac.Specs {
"Surely do something",
]);
spyOn(missions.secondary[0].current_part, "checkCompleted").and.returnValue(true);
check.patch(missions.secondary[0].current_part, "checkCompleted", () => true);
missions.checkStatus();
check.equals(missions.getCurrent().map(mission => mission.current_part.title), [
@ -47,7 +47,7 @@ module TK.SpaceTac.Specs {
"Surely do something",
]);
spyOn(missions.main.current_part, "checkCompleted").and.returnValue(true);
check.patch(missions.main.current_part, "checkCompleted", () => true);
missions.checkStatus();
check.equals(missions.getCurrent().map(mission => mission.current_part.title), [

View file

@ -1,9 +1,9 @@
module TK.SpaceTac.Specs {
testing("MainStory", test => {
function checkPart(story: Mission, index: number, title: string, completed = false) {
function checkPart(story: Mission, index: number, title: RegExp, completed = false) {
let result = story.checkStatus();
test.check.same(story.parts.indexOf(story.current_part), index);
expect(story.current_part.title).toMatch(title);
test.check.regex(title, story.current_part.title);
test.check.same(story.completed, completed);
test.check.same(result, !completed);
}
@ -29,24 +29,24 @@ module TK.SpaceTac.Specs {
let story = nn(missions.main);
let fleet_size = fleet.ships.length;
checkPart(story, 0, "^Travel to Terranax galaxy$");
checkPart(story, 0, /^Travel to Terranax galaxy$/);
(<MissionPartConversation>story.current_part).skip();
checkPart(story, 1, "^Find your contact in .*$");
checkPart(story, 1, /^Find your contact in .*$/);
goTo(fleet, (<MissionPartGoTo>story.current_part).destination);
checkPart(story, 2, "^Speak with your contact");
checkPart(story, 2, /^Speak with your contact/);
(<MissionPartConversation>story.current_part).skip();
checkPart(story, 3, "^Go with .* in .* system$");
checkPart(story, 3, /^Go with .* in .* system$/);
check.same(fleet.ships.length, fleet_size + 1);
goTo(fleet, (<MissionPartEscort>story.current_part).destination);
checkPart(story, 4, "^Listen to .*$");
checkPart(story, 4, /^Listen to .*$/);
(<MissionPartConversation>story.current_part).skip();
check.equals(session.getBattle(), null);
checkPart(story, 5, "^Fight the arrived fleet$");
checkPart(story, 5, /^Fight the arrived fleet$/);
check.notequals(session.getBattle(), null);
nn(session.getBattle()).endBattle(fleet);

View file

@ -13,7 +13,7 @@ module TK.SpaceTac.Specs {
check.equals(result, true);
check.same(mission.current_part, mission.parts[0]);
spyOn(mission.parts[0], "checkCompleted").and.returnValues(false, true);
check.patch(mission.parts[0], "checkCompleted", iterator([false, true]));
result = mission.checkStatus();
check.equals(result, true);
@ -25,7 +25,7 @@ module TK.SpaceTac.Specs {
check.equals(result, true);
check.same(mission.current_part, mission.parts[1]);
spyOn(mission.parts[1], "checkCompleted").and.returnValue(true);
check.patch(mission.parts[1], "checkCompleted", () => true);
result = mission.checkStatus();
check.equals(result, false);

View file

@ -9,7 +9,7 @@ module TK.SpaceTac.Multi.Specs {
await storage.upsert("sessioninfo", { token: token }, {});
spyOn(connection, "generateToken").and.returnValues(token, "123456");
check.patch(connection, "generateToken", iterator([token, "123456"]));
let other = await connection.getUnusedToken(5);
check.equals(other, "123456");

View file

@ -13,14 +13,14 @@ module TK.SpaceTac.Multi.Specs {
return [storage, peer1, peer2];
}
beforeEach(function () {
spyOn(console, "log").and.stub();
test.setup(function () {
test.check.patch(console, "log", null);
});
test.acase("says hello on start", async check => {
let [storage, peer1, peer2] = newExchange("abc");
spyOn(peer1, "getNextId").and.returnValues("1A", "1B", "1C");
spyOn(peer2, "getNextId").and.returnValues("2A", "2B", "2C");
check.patch(peer1, "getNextId", iterator(["1A", "1B", "1C"]));
check.patch(peer2, "getNextId", iterator(["2A", "2B", "2C"]));
check.equals(peer1.next, "hello");
check.equals(peer2.next, "hello");
@ -49,8 +49,8 @@ module TK.SpaceTac.Multi.Specs {
// same peers, new message chain
[storage, peer1, peer2] = newExchange("abc", storage);
spyOn(peer1, "getNextId").and.returnValues("1R", "1S", "1T");
spyOn(peer2, "getNextId").and.returnValues("2R", "2S", "2T");
check.patch(peer1, "getNextId", iterator(["1R", "1S", "1T"]));
check.patch(peer2, "getNextId", iterator(["2R", "2S", "2T"]));
await Promise.all([peer1.start(), peer2.start()]);

View file

@ -2,7 +2,7 @@
module TK.SpaceTac.UI.Specs {
testing("AssetLoading", test => {
let testgame = setupSingleView(() => [new AssetLoading(), []]);
let testgame = setupSingleView(test, () => [new AssetLoading(), []]);
test.case("loads correctly", check => {
check.equals(testgame.ui.state.current, "test");

View file

@ -2,7 +2,7 @@
module TK.SpaceTac.UI.Specs {
testing("BaseView", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("initializes variables", check => {
let view = <BaseView>testgame.ui.state.getCurrentState();

View file

@ -3,7 +3,7 @@
module TK.SpaceTac.UI.Specs {
testing("Boot", test => {
let testgame = setupSingleView(() => [new Boot(), []]);
let testgame = setupSingleView(test, () => [new Boot(), []]);
test.case("places empty loading background", check => {
check.equals(testgame.ui.world.children.length, 1);

View file

@ -3,7 +3,7 @@
module TK.SpaceTac.UI.Specs {
testing("Router", test => {
let testgame = setupSingleView(() => [new Router(), []]);
let testgame = setupSingleView(test, () => [new Router(), []]);
test.case("loads correctly", check => {
check.equals(testgame.ui.state.current, "test");

View file

@ -19,19 +19,20 @@ module TK.SpaceTac.UI.Specs {
/**
* Setup a headless test UI, with a single view started.
*/
export function setupSingleView<T extends Phaser.State>(buildView: () => [T, any[]]) {
export function setupSingleView<T extends Phaser.State>(test: TestSuite, buildView: () => [T, any[]]) {
let testgame = new TestGame<T>();
beforeEach(function (done) {
spyOn(console, "log").and.stub();
spyOn(console, "warn").and.stub();
test.asetup(() => new Promise((resolve, reject) => {
let check = new TestContext(); // TODO Should be taken from test suite
check.patch(console, "log", null);
check.patch(console, "warn", null);
if (!test_ui) {
test_ui = new MainUI(true);
if (test_ui.load) {
spyOn(test_ui.load, 'image').and.stub();
spyOn(test_ui.load, 'audio').and.stub();
check.patch(test_ui.load, 'image', null);
check.patch(test_ui.load, 'audio', null);
}
}
@ -43,20 +44,20 @@ module TK.SpaceTac.UI.Specs {
if (state instanceof BaseView) {
testgame.multistorage = new Multi.FakeRemoteStorage();
let connection = new Multi.Connection(RandomGenerator.global.id(12), testgame.multistorage);
spyOn(state, "getConnection").and.returnValue(connection);
check.patch(state, "getConnection", () => connection);
}
let orig_create = bound(state, "create");
spyOn(state, "create").and.callFake(() => {
check.patch(state, "create", () => {
orig_create();
done();
resolve();
});
testgame.ui.state.add("test", state);
testgame.ui.state.start("test", true, false, ...stateargs);
testgame.state = "test_initial";
spyOn(testgame.ui.state, "start").and.callFake((name: string) => {
check.patch(testgame.ui.state, "start", (name: string) => {
testgame.state = name;
});
@ -66,7 +67,7 @@ module TK.SpaceTac.UI.Specs {
}
testgame.view = state;
});
}));
return testgame;
}
@ -74,8 +75,8 @@ module TK.SpaceTac.UI.Specs {
/**
* Test setup of an empty BaseView
*/
export function setupEmptyView(): TestGame<BaseView> {
return setupSingleView(() => {
export function setupEmptyView(test: TestSuite): TestGame<BaseView> {
return setupSingleView(test, () => {
return [new BaseView(), []];
});
}
@ -83,8 +84,8 @@ module TK.SpaceTac.UI.Specs {
/**
* Test setup of a battleview bound to a battle, to be called inside a "describe" block.
*/
export function setupBattleview(): TestGame<BattleView> {
return setupSingleView(() => {
export function setupBattleview(test: TestSuite): TestGame<BattleView> {
return setupSingleView(test, () => {
let view = new BattleView();
view.splash = false;
@ -98,8 +99,8 @@ module TK.SpaceTac.UI.Specs {
/**
* Test setup of a mapview bound to a universe, to be called inside a "describe" block.
*/
export function setupMapview(): TestGame<UniverseMapView> {
return setupSingleView(() => {
export function setupMapview(test: TestSuite): TestGame<UniverseMapView> {
return setupSingleView(test, () => {
let mapview = new UniverseMapView();
let session = new GameSession();
session.startNewGame();

View file

@ -2,7 +2,7 @@
module TK.SpaceTac.UI.Specs {
testing("ActionBar", test => {
let testgame = setupBattleview();
let testgame = setupBattleview(test);
test.case("lists available actions for selected ship", check => {
var bar = testgame.view.action_bar;

View file

@ -2,7 +2,7 @@
module TK.SpaceTac.UI.Specs {
testing("ActionIcon", test => {
let testgame = setupBattleview();
let testgame = setupBattleview(test);
test.case("displays power usage", check => {
let bar = testgame.view.action_bar;
@ -14,7 +14,7 @@ module TK.SpaceTac.UI.Specs {
icon.refresh();
check.same(icon.img_power.visible, false, "no change");
spyOn(action, "getActionPointsUsage").and.returnValue(3);
check.patch(action, "getActionPointsUsage", () => 3);
icon.refresh();
check.equals(icon.img_power.visible, true);
check.equals(icon.text_power.text, "3");

View file

@ -2,7 +2,7 @@
module TK.SpaceTac.UI.Specs {
testing("ActionTooltip", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("displays action information", check => {
let tooltip = new Tooltip(testgame.view);

View file

@ -2,7 +2,7 @@
module TK.SpaceTac.UI.Specs {
testing("ArenaShip", test => {
let testgame = setupBattleview();
let testgame = setupBattleview(test);
test.case("adds effects display", check => {
let ship = nn(testgame.view.battle.playing_ship);

View file

@ -2,11 +2,11 @@
module TK.SpaceTac.UI.Specs {
testing("BattleView", test => {
let testgame = setupBattleview();
let testgame = setupBattleview(test);
test.case("handles ship hovering to display tooltip", check => {
let battleview = testgame.view;
expect(battleview.ship_hovered).toBeNull("initial state");
check.equals(battleview.ship_hovered, null, "initial state");
let ship = nn(battleview.battle.playing_ship);
battleview.cursorHovered(ship.location, ship);
@ -17,7 +17,7 @@ module TK.SpaceTac.UI.Specs {
check.same(battleview.ship_hovered, ship, "ship2 hovered");
battleview.cursorHovered(new ArenaLocation(0, 0), null);
expect(battleview.ship_hovered).toBeNull("out");
check.equals(battleview.ship_hovered, null, "out");
battleview.cursorOnShip(ship);
check.same(battleview.ship_hovered, ship, "force on");
@ -26,7 +26,7 @@ module TK.SpaceTac.UI.Specs {
check.same(battleview.ship_hovered, ship, "force off on wrong ship");
battleview.cursorOffShip(ship);
expect(battleview.ship_hovered).toBeNull("force off");
check.equals(battleview.ship_hovered, null, "force off");
});
test.case("forwards cursor hovering and click to targetting", check => {
@ -47,11 +47,11 @@ module TK.SpaceTac.UI.Specs {
check.equals(battleview.targetting.target, Target.newFromLocation(ship.arena_x, ship.arena_y));
check.equals(battleview.ship_hovered, null);
spyOn(battleview.targetting, "validate").and.stub();
let validate = check.patch(battleview.targetting, "validate", null);
expect(battleview.targetting.validate).toHaveBeenCalledTimes(0);
check.called(validate, 0);
battleview.cursorClicked();
expect(battleview.targetting.validate).toHaveBeenCalledTimes(1);
check.called(validate, 1);
battleview.exitTargettingMode();
check.equals(battleview.targetting.active, false);

View file

@ -21,7 +21,7 @@ module TK.SpaceTac.UI.Specs {
}
testing("LogProcessor", test => {
let testgame = setupBattleview();
let testgame = setupBattleview(test);
test.case("steps forward and backward in time", check => {
let battle = testgame.view.battle;

View file

@ -2,13 +2,17 @@
module TK.SpaceTac.UI.Specs {
testing("ShipList", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
function createList(): ShipList {
let view = testgame.view;
let battle = new Battle();
let tactical_mode = new Toggle();
let ship_buttons = jasmine.createSpyObj("ship_buttons", ["cursorOnShip", "cursorOffShip", "cursorClicked"]);
let ship_buttons = {
cursorOnShip: nop,
cursorOffShip: nop,
cursorClicked: nop,
};
let list = new ShipList(view, battle, battle.fleets[0].player, tactical_mode, ship_buttons);
return list;
}
@ -43,7 +47,7 @@ module TK.SpaceTac.UI.Specs {
list.refresh(false);
check.equals(nn(list.findItem(battle.play_order[0])).position, new Phaser.Point(2, 843));
check.equals(nn(list.findItem(battle.play_order[1])).position, new Phaser.Point(-18, 962));
battle.fleets[1].addShip();
battle.throwInitiative();
battle.advanceToNextShip();

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("ShipTooltip", test => {
let testgame = setupBattleview();
let testgame = setupBattleview(test);
test.case("fills ship details", check => {
let tooltip = new ShipTooltip(testgame.view);

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("Targetting", test => {
let testgame = setupBattleview();
let testgame = setupBattleview(test);
function newTargetting(): Targetting {
return new Targetting(testgame.view,
@ -18,7 +18,7 @@ module TK.SpaceTac.UI.Specs {
let engine = TestTools.addEngine(ship, 12);
targetting.setAction(weapon.action);
let drawvector = spyOn(targetting, "drawVector").and.stub();
let drawvector = check.patch(targetting, "drawVector", null);
let part = {
action: nn(weapon.action),
@ -27,18 +27,21 @@ module TK.SpaceTac.UI.Specs {
possible: true
};
targetting.drawPart(part, true, null);
expect(drawvector).toHaveBeenCalledTimes(1);
expect(drawvector).toHaveBeenCalledWith(0xdc6441, 10, 20, 50, 30, 0);
check.called(drawvector, [
[0xdc6441, 10, 20, 50, 30, 0]
]);
targetting.drawPart(part, false, null);
expect(drawvector).toHaveBeenCalledTimes(2);
expect(drawvector).toHaveBeenCalledWith(0x8e8e8e, 10, 20, 50, 30, 0);
check.called(drawvector, [
[0x8e8e8e, 10, 20, 50, 30, 0]
]);
targetting.action = engine.action;
part.action = nn(engine.action);
targetting.drawPart(part, true, null);
expect(drawvector).toHaveBeenCalledTimes(3);
expect(drawvector).toHaveBeenCalledWith(0xe09c47, 10, 20, 50, 30, 12);
check.called(drawvector, [
[0xe09c47, 10, 20, 50, 30, 12]
]);
})
test.case("updates impact indicators on ships inside the blast radius", check => {
@ -47,28 +50,32 @@ module TK.SpaceTac.UI.Specs {
let impacts = targetting.impact_indicators;
let action = new TriggerAction(new Equipment(), [], 1, 0, 50);
let collect = spyOn(action, "getImpactedShips").and.returnValues(
let collect = check.patch(action, "getImpactedShips", iterator([
[new Ship(), new Ship(), new Ship()],
[new Ship(), new Ship()],
[]);
[]
]));
targetting.updateImpactIndicators(impacts, ship, action, new Target(20, 10));
expect(collect).toHaveBeenCalledTimes(1);
expect(collect).toHaveBeenCalledWith(ship, new Target(20, 10), ship.location);
check.called(collect, [
[ship, new Target(20, 10), ship.location]
])
check.equals(targetting.impact_indicators.children.length, 3);
check.equals(targetting.impact_indicators.visible, true);
targetting.updateImpactIndicators(impacts, ship, action, new Target(20, 11));
expect(collect).toHaveBeenCalledTimes(2);
expect(collect).toHaveBeenCalledWith(ship, new Target(20, 11), ship.location);
check.called(collect, [
[ship, new Target(20, 11), ship.location]
])
check.equals(targetting.impact_indicators.children.length, 2);
check.equals(targetting.impact_indicators.visible, true);
targetting.updateImpactIndicators(impacts, ship, action, new Target(20, 12));
expect(collect).toHaveBeenCalledTimes(3);
expect(collect).toHaveBeenCalledWith(ship, new Target(20, 12), ship.location);
check.called(collect, [
[ship, new Target(20, 12), ship.location]
])
check.equals(targetting.impact_indicators.visible, false);
})
@ -81,7 +88,7 @@ module TK.SpaceTac.UI.Specs {
targetting.setAction(weapon.action);
targetting.setTarget(Target.newFromLocation(156, 65));
spyOn(targetting, "simulate").and.callFake(() => {
check.patch(targetting, "simulate", () => {
let result = new MoveFireResult();
result.success = true;
result.complete = true;
@ -153,8 +160,8 @@ module TK.SpaceTac.UI.Specs {
let move = TestTools.addEngine(ship, 100).action;
let fire = TestTools.addWeapon(ship, 50, 2, 300, 100).action;
let last_call: any = null;
spyOn(targetting.range_hint, "clear").and.callFake(() => last_call = null);
spyOn(targetting.range_hint, "update").and.callFake((ship: Ship, action: BaseAction, radius: number) => last_call = [ship, action, radius]);
check.patch(targetting.range_hint, "clear", () => last_call = null);
check.patch(targetting.range_hint, "update", (ship: Ship, action: BaseAction, radius: number) => last_call = [ship, action, radius]);
// move action
targetting.setAction(move);

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("WeaponEffect", test => {
let testgame = setupBattleview();
let testgame = setupBattleview(test);
let clock = test.clock();
function checkEmitters(step: string, expected: number) {
@ -56,24 +56,27 @@ module TK.SpaceTac.UI.Specs {
let weapon = new Equipment();
weapon.action = new TriggerAction(weapon, [new DamageEffect()], 1, 500);
spyOn(weapon.action, "getImpactedShips").and.returnValue([ship]);
check.patch(weapon.action, "getImpactedShips", () => [ship]);
let effect = new WeaponEffect(battleview.arena, new Ship(), Target.newFromShip(ship), weapon);
spyOn(effect, "getEffectForWeapon").and.returnValue(() => 100);
let dest = new Ship();
let effect = new WeaponEffect(battleview.arena, dest, Target.newFromShip(dest), weapon);
check.patch(effect, "getEffectForWeapon", () => (() => 100));
let mock_shield_impact = spyOn(effect, "shieldImpactEffect").and.stub();
let mock_hull_impact = spyOn(effect, "hullImpactEffect").and.stub();
let mock_shield_impact = check.patch(effect, "shieldImpactEffect", null);
let mock_hull_impact = check.patch(effect, "hullImpactEffect", null);
effect.start();
expect(mock_shield_impact).toHaveBeenCalledTimes(0);
expect(mock_hull_impact).toHaveBeenCalledTimes(1);
expect(mock_hull_impact).toHaveBeenCalledWith(jasmine.objectContaining({ x: 0, y: 0 }), jasmine.objectContaining({ x: 50, y: 30 }), 40, 400);
check.called(mock_shield_impact, 0);
check.called(mock_hull_impact, [
[dest.location, battleview.arena.findShipSprite(ship), 40, 400]
]);
sprite.shield_bar.setValue(10, 10);
effect.start();
expect(mock_shield_impact).toHaveBeenCalledTimes(1);
expect(mock_shield_impact).toHaveBeenCalledWith(jasmine.objectContaining({ x: 0, y: 0 }), jasmine.objectContaining({ x: 50, y: 30 }), 40, 800, false);
expect(mock_hull_impact).toHaveBeenCalledTimes(1);
check.called(mock_shield_impact, [
[dest.location, battleview.arena.findShipSprite(ship), 40, 800, false]
]);
check.called(mock_hull_impact, 0);
});
test.case("removes particle emitters when done", check => {

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("CharacterCargo", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("checks conditions for adding/removing equipment", check => {
let view = testgame.view;

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("CharacterEquipment", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
class FakeContainer implements CharacterEquipmentContainer {
name: string;
@ -45,17 +45,17 @@ module TK.SpaceTac.UI.Specs {
}
}
function createBasicCase(positions: number[]): [CharacterSheet, CharacterEquipment, FakeContainer[], Function] {
function createBasicCase(positions: number[]): [CharacterSheet, CharacterEquipment, FakeContainer[], Mock] {
let view = testgame.view;
let sheet = new CharacterSheet(view);
sheet.show(new Ship());
let refresh = spyOn(sheet, "refresh").and.stub();
let refresh = test.check.patch(sheet, "refresh", null);
let containers = positions.map((x, idx) => new FakeContainer(`container${idx + 1}`, x));
let equipment = new CharacterEquipment(sheet, new Equipment(), containers[0]);
containers[0].inside = equipment;
equipment.setupDragDrop();
spyOn(sheet, "iEquipmentContainers").and.returnValue(iarray(containers));
test.check.patch(sheet, "iEquipmentContainers", () => iarray(containers));
return [sheet, equipment, containers, refresh];
}
@ -77,7 +77,7 @@ module TK.SpaceTac.UI.Specs {
equipment.events.onDragStop.dispatch();
check.same(equipment.container, container1);
check.equals(equipment.x, 0);
expect(refresh).toHaveBeenCalledTimes(0);
check.called(refresh, 0);
// drop on accepting destination
equipment.events.onDragStart.dispatch();
@ -87,7 +87,7 @@ module TK.SpaceTac.UI.Specs {
check.equals(equipment.x, 100);
check.equals(container1.inside, null);
check.same(container2.inside, equipment);
expect(refresh).toHaveBeenCalledTimes(1);
check.called(refresh, 1);
// drop on refusing destination
equipment.events.onDragStart.dispatch();
@ -97,45 +97,50 @@ module TK.SpaceTac.UI.Specs {
check.equals(equipment.x, 100);
check.same(container2.inside, equipment);
check.equals(container3.inside, null);
expect(refresh).toHaveBeenCalledTimes(1);
check.called(refresh, 0);
// broken destination, should return to source
let log = spyOn(console, "error").and.stub();
spyOn(container3, "addEquipment").and.callFake((equ: any, src: any, test: boolean) => { return { success: test } });
let log = check.patch(console, "error", null);
check.patch(container3, "addEquipment", (equ: any, src: any, test: boolean) => { return { success: test } });
equipment.events.onDragStart.dispatch();
equipment.x = 200;
equipment.events.onDragStop.dispatch();
check.same(equipment.container, container2);
check.equals(equipment.x, 100);
expect(refresh).toHaveBeenCalledTimes(1);
expect(log).toHaveBeenCalledWith('Destination container refused to accept equipment', equipment, container2, container3);
check.called(refresh, 0);
check.called(log, [
['Destination container refused to accept equipment', equipment, container2, container3]
]);
// broken destination and source, item is lost !
spyOn(container2, "addEquipment").and.callFake((equ: any, src: any, test: boolean) => { return { success: test } });
check.patch(container2, "addEquipment", (equ: any, src: any, test: boolean) => { return { success: test } });
equipment.events.onDragStart.dispatch();
equipment.x = 200;
equipment.events.onDragStop.dispatch();
check.same(equipment.container, container3);
check.equals(equipment.x, 200);
expect(refresh).toHaveBeenCalledTimes(2);
expect(log).toHaveBeenCalledWith('Equipment lost in bad exchange!', equipment, container2, container3);
check.called(refresh, 1);
check.called(log, [
['Destination container refused to accept equipment', equipment, container2, container3],
['Equipment lost in bad exchange!', equipment, container2, container3]
]);
});
test.case("defines the sheet's action message", check => {
let [sheet, equipment, [container1, container2], refresh] = createBasicCase([0, 1]);
spyOn(container1, "removeEquipment").and.returnValues(
check.patch(container1, "removeEquipment", iterator([
{ success: true, info: "detach" },
{ success: false, info: "detach", error: "cannot detach" },
{ success: true, info: "detach" },
{ success: false, info: "detach", error: "cannot detach" }
)
spyOn(container2, "addEquipment").and.returnValues(
]))
check.patch(container2, "addEquipment", iterator([
{ success: true, info: "attach" },
{ success: true, info: "attach" },
{ success: false, info: "attach", error: "cannot attach" },
{ success: false, info: "attach", error: "cannot attach" }
)
]))
check.equals(sheet.action_message.text, "");
equipment.events.onDragStart.dispatch();

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("CharacterFleetMember", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("transfers equipment to another ship", check => {
let view = testgame.view;

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("CharacterLootSlot", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("takes or discard loot", check => {
let view = testgame.view;

View file

@ -2,7 +2,7 @@ module TK.SpaceTac.UI.Specs {
testing("CharacterSheet", test => {
testing("in UI", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("displays fleet and ship information", check => {
let view = testgame.view;

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("CharacterShopSlot", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("buys and sell if bound to a shop", check => {
let view = testgame.view;
@ -15,7 +15,7 @@ module TK.SpaceTac.UI.Specs {
let equ2 = new Equipment(SlotType.Weapon, "equ2");
let shop = <any>new Shop(1, [equ2], 0);
spyOn(shop, "getPrice").and.returnValue(120);
check.patch(shop, "getPrice", () => 120);
sheet.setShop(shop);
sheet.show(ship);

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("CharacterSlot", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("allows dragging equipment", check => {
let view = testgame.view;

View file

@ -2,7 +2,7 @@
module TK.SpaceTac.UI.Specs {
testing("FleetCreationView", test => {
let testgame = setupSingleView(() => [new FleetCreationView, []]);
let testgame = setupSingleView(test, () => [new FleetCreationView, []]);
test.case("has a basic equipment shop with infinite stock", check => {
let shop = testgame.view.infinite_shop;

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("Animations", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("shows and hides objects", check => {
let obj = { visible: false, alpha: 0.5 };
@ -36,20 +36,21 @@ module TK.SpaceTac.UI.Specs {
});
test.case("blocks input while object is hidden", check => {
let obj = { visible: true, alpha: 1, input: { enabled: true }, changeStateFrame: jasmine.createSpy("changeStateFrame"), freezeFrames: false };
let changeStateFrame = check.mockfunc("changeStateFrame");
let obj = { visible: true, alpha: 1, input: { enabled: true }, changeStateFrame: changeStateFrame.func, freezeFrames: false };
testgame.view.animations.setVisible(obj, false, 0);
check.equals(obj.visible, false);
check.equals(obj.alpha, 0);
check.equals(obj.input.enabled, false);
expect(obj.changeStateFrame).toHaveBeenCalledWith("Out");
check.called(changeStateFrame, [["Out"]])
check.equals(obj.freezeFrames, true);
testgame.view.animations.setVisible(obj, true, 0);
check.equals(obj.visible, true);
check.equals(obj.alpha, 1);
check.equals(obj.input.enabled, true);
expect(obj.changeStateFrame).toHaveBeenCalledTimes(1);
check.called(changeStateFrame, 0);
check.equals(obj.freezeFrames, false);
});

View file

@ -1,25 +1,22 @@
module TK.SpaceTac.UI.Specs {
testing("InputManager", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
let clock = test.clock();
test.case("handles hover and click on desktops and mobile targets", check => {
let inputs = testgame.view.inputs;
let pointer = new Phaser.Pointer(testgame.ui, 0);
function newButton(): [Phaser.Button, any] {
var button = new Phaser.Button(testgame.ui);
var funcs = {
enter: () => null,
leave: () => null,
click: () => null,
function newButton(): [Phaser.Button, { enter: Mock, leave: Mock, click: Mock }] {
let button = new Phaser.Button(testgame.ui);
let mocks = {
enter: check.mockfunc("enter"),
leave: check.mockfunc("leave"),
click: check.mockfunc("click"),
};
spyOn(funcs, "enter");
spyOn(funcs, "leave");
spyOn(funcs, "click");
inputs.setHoverClick(button, funcs.enter, funcs.leave, funcs.click, 50, 100);
inputs.setHoverClick(button, mocks.enter.func, mocks.leave.func, mocks.click.func, 50, 100);
(<any>inputs).hovered = null;
return [button, funcs];
return [button, mocks];
}
let enter = (button: Phaser.Button) => (<any>button.input)._pointerOverHandler(pointer);
let leave = (button: Phaser.Button) => (<any>button.input)._pointerOutHandler(pointer);
@ -28,73 +25,73 @@ module TK.SpaceTac.UI.Specs {
let destroy = (button: Phaser.Button) => button.events.onDestroy.dispatch();
// Simple click on desktop
let [button, funcs] = newButton();
let [button, mocks] = newButton();
enter(button);
press(button);
release(button);
expect(funcs.enter).toHaveBeenCalledTimes(0);
expect(funcs.leave).toHaveBeenCalledTimes(0);
expect(funcs.click).toHaveBeenCalledTimes(1);
check.called(mocks.enter, 0);
check.called(mocks.leave, 0);
check.called(mocks.click, 1);
// Simple click on mobile
[button, funcs] = newButton();
[button, mocks] = newButton();
press(button);
release(button);
expect(funcs.enter).toHaveBeenCalledTimes(1);
expect(funcs.leave).toHaveBeenCalledTimes(1);
expect(funcs.click).toHaveBeenCalledTimes(1);
check.called(mocks.enter, 1);
check.called(mocks.leave, 1);
check.called(mocks.click, 1);
// Leaves on destroy
[button, funcs] = newButton();
[button, mocks] = newButton();
press(button);
clock.forward(150);
expect(funcs.enter).toHaveBeenCalledTimes(1);
expect(funcs.leave).toHaveBeenCalledTimes(0);
expect(funcs.click).toHaveBeenCalledTimes(0);
check.called(mocks.enter, 1);
check.called(mocks.leave, 0);
check.called(mocks.click, 0);
destroy(button);
expect(funcs.enter).toHaveBeenCalledTimes(1);
expect(funcs.leave).toHaveBeenCalledTimes(1);
expect(funcs.click).toHaveBeenCalledTimes(0);
check.called(mocks.enter, 0);
check.called(mocks.leave, 1);
check.called(mocks.click, 0);
press(button);
release(button);
expect(funcs.enter).toHaveBeenCalledTimes(1);
expect(funcs.leave).toHaveBeenCalledTimes(1);
expect(funcs.click).toHaveBeenCalledTimes(0);
check.called(mocks.enter, 0);
check.called(mocks.leave, 0);
check.called(mocks.click, 0);
// Force-leave when hovering another button without clean leaving a first one
let [button1, funcs1] = newButton();
let [button2, funcs2] = newButton();
enter(button1);
clock.forward(150);
expect(funcs1.enter).toHaveBeenCalledTimes(1);
expect(funcs1.leave).toHaveBeenCalledTimes(0);
expect(funcs1.click).toHaveBeenCalledTimes(0);
check.called(funcs1.enter, 1);
check.called(funcs1.leave, 0);
check.called(funcs1.click, 0);
enter(button2);
expect(funcs1.enter).toHaveBeenCalledTimes(1);
expect(funcs1.leave).toHaveBeenCalledTimes(1);
expect(funcs1.click).toHaveBeenCalledTimes(0);
expect(funcs2.enter).toHaveBeenCalledTimes(0);
expect(funcs2.leave).toHaveBeenCalledTimes(0);
expect(funcs2.click).toHaveBeenCalledTimes(0);
check.called(funcs1.enter, 0);
check.called(funcs1.leave, 1);
check.called(funcs1.click, 0);
check.called(funcs2.enter, 0);
check.called(funcs2.leave, 0);
check.called(funcs2.click, 0);
clock.forward(150);
expect(funcs1.enter).toHaveBeenCalledTimes(1);
expect(funcs1.leave).toHaveBeenCalledTimes(1);
expect(funcs1.click).toHaveBeenCalledTimes(0);
expect(funcs2.enter).toHaveBeenCalledTimes(1);
expect(funcs2.leave).toHaveBeenCalledTimes(0);
expect(funcs2.click).toHaveBeenCalledTimes(0);
check.called(funcs1.enter, 0);
check.called(funcs1.leave, 0);
check.called(funcs1.click, 0);
check.called(funcs2.enter, 1);
check.called(funcs2.leave, 0);
check.called(funcs2.click, 0);
// Hold to hover on mobile
[button, funcs] = newButton();
[button, mocks] = newButton();
button.onInputDown.dispatch(button, pointer);
clock.forward(150);
expect(funcs.enter).toHaveBeenCalledTimes(1);
expect(funcs.leave).toHaveBeenCalledTimes(0);
expect(funcs.click).toHaveBeenCalledTimes(0);
check.called(mocks.enter, 1);
check.called(mocks.leave, 0);
check.called(mocks.click, 0);
button.onInputUp.dispatch(button, pointer);
expect(funcs.enter).toHaveBeenCalledTimes(1);
expect(funcs.leave).toHaveBeenCalledTimes(1);
expect(funcs.click).toHaveBeenCalledTimes(0);
check.called(mocks.enter, 0);
check.called(mocks.leave, 1);
check.called(mocks.click, 0);
});
test.case("handles drag and drop", check => {

View file

@ -175,7 +175,7 @@ module TK.SpaceTac.UI {
*
* Returns functions that may be used to force the behavior
*/
setHoverClick(obj: Phaser.Button, enter = nop, leave = nop, click = nop, hovertime = 300, holdtime = 600) {
setHoverClick(obj: Phaser.Button, enter: Function = nop, leave: Function = nop, click: Function = nop, hovertime = 300, holdtime = 600) {
let holdstart = Timer.nowMs();
let enternext: Function | null = null;
let entercalled = false;

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("ParticleBuilder", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("builds composed particles", check => {
let builder = new ParticleBuilder(testgame.view);

View file

@ -1,17 +1,17 @@
module TK.SpaceTac.UI.Specs {
testing("Tooltip", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
let clock = test.clock();
test.case("shows near the hovered button", check => {
let button = testgame.view.add.button();
spyOn(button, "getBounds").and.returnValue({ x: 100, y: 50, width: 50, height: 25 });
check.patch(button, "getBounds", () => ({ x: 100, y: 50, width: 50, height: 25 }));
let tooltip = new Tooltip(testgame.view);
tooltip.bind(button, filler => true);
let container = <Phaser.Group>(<any>tooltip).container;
spyOn((<any>container).content, "getBounds").and.returnValue({ x: 0, y: 0, width: 32, height: 32 });
check.patch((<any>container).content, "getBounds", () => ({ x: 0, y: 0, width: 32, height: 32 }));
check.equals(container.visible, false);
button.onInputOver.dispatch();

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("UIBuilder", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
function get(path: (number | string)[]): [string, any] {
let spath = `[${path.join(" -> ")}]`;
@ -145,7 +145,7 @@ module TK.SpaceTac.UI.Specs {
builder.image("test-image", 100, 50);
checkcomp(["View layers", "base", 0], Phaser.Image, "test-image", { x: 100, y: 50, key: "__missing", inputEnabled: null });
spyOn(testgame.view, "getFirstImage").and.callFake((...images: string[]) => images[1]);
check.patch(testgame.view, "getFirstImage", (...images: string[]) => images[1]);
builder.image(["test-image1", "test-image2", "test-image3"]);
checkcomp(["View layers", "base", 1], Phaser.Image, "test-image2");
})

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("UIComponent", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("controls visibility", check => {
let component = new UIComponent(testgame.view, 50, 50);

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("UIDialog", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("sets up an overlay", check => {
let view = testgame.view;

View file

@ -1,7 +1,7 @@
module TK.SpaceTac.UI.Specs {
testing("UITools", test => {
testing("in UI", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("destroys children", check => {
let parent = testgame.view.add.group();

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("ValueBar", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("computes proportional value", check => {
var bar = new ValueBar(testgame.view, "default", ValueBarOrientation.EAST);

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("ActiveMissionsDisplay", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("displays active missions", check => {
let view = testgame.view;

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("FleetDisplay", test => {
let testgame = setupMapview();
let testgame = setupMapview(test);
test.case("orbits the fleet around its current location", check => {
let mapview = testgame.view;

View file

@ -1,13 +1,13 @@
module TK.SpaceTac.UI.Specs {
testing("MissionsDialog", test => {
let testgame = setupEmptyView();
let testgame = setupEmptyView(test);
test.case("displays active and proposed missions", check => {
let universe = new Universe();
let player = new Player();
let shop = new Shop();
let shop_missions: Mission[] = [];
spyOn(shop, "getMissions").and.callFake(() => shop_missions);
check.patch(shop, "getMissions", () => shop_missions);
function checkTexts(dialog: MissionsDialog, expected: string[]) {
let i = 0;

View file

@ -1,6 +1,6 @@
module TK.SpaceTac.UI.Specs {
testing("StarSystemDisplay", test => {
let testgame = setupMapview();
let testgame = setupMapview(test);
test.case("displays a badge with the current state for a star location", check => {
let mapview = testgame.view;

View file

@ -3,7 +3,7 @@
module TK.SpaceTac.UI.Specs {
testing("LoadDialog", test => {
let testgame = setupSingleView(() => [new MainMenu(), []]);
let testgame = setupSingleView(test, () => [new MainMenu(), []]);
test.acase("joins remote sessions as spectator", async check => {
return new Promise((resolve, reject) => {
@ -16,7 +16,7 @@ module TK.SpaceTac.UI.Specs {
let dialog = new LoadDialog(view);
dialog.token_input.setContent(token);
spyOn(view.gameui, "setSession").and.callFake((joined: GameSession) => {
check.patch(view.gameui, "setSession", (joined: GameSession) => {
test.check.equals(joined.id, session.id);
check.equals(joined.primary, false);
check.equals(joined.spectator, true);

View file

@ -3,7 +3,7 @@
module TK.SpaceTac.UI.Specs {
testing("MainMenu", test => {
let testgame = setupSingleView(() => [new MainMenu(), []]);
let testgame = setupSingleView(test, () => [new MainMenu(), []]);
test.case("adds moving stars, a title and three buttons", check => {
let view = <MainMenu>testgame.ui.state.getCurrentState();