2017-01-11 17:31:21 +00:00
|
|
|
/// <reference path="battle/BattleView.ts"/>
|
2017-01-30 00:40:33 +00:00
|
|
|
/// <reference path="map/UniverseMapView.ts"/>
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac.UI.Specs {
|
2017-07-11 22:56:06 +00:00
|
|
|
let test_ui: MainUI;
|
|
|
|
|
2017-02-21 22:38:31 +00:00
|
|
|
/**
|
|
|
|
* Class to hold references to test objects (used as singleton in "describe" blocks)
|
|
|
|
*
|
|
|
|
* Attributes should only be accessed from inside corresponding "it" blocks (they are initialized by the setup).
|
|
|
|
*/
|
|
|
|
export class TestGame {
|
|
|
|
ui: MainUI;
|
2017-02-27 23:36:12 +00:00
|
|
|
baseview: BaseView;
|
2017-02-21 22:38:31 +00:00
|
|
|
battleview: BattleView;
|
|
|
|
mapview: UniverseMapView;
|
2017-05-04 23:19:28 +00:00
|
|
|
multistorage: Multi.FakeRemoteStorage;
|
2017-02-21 22:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup a headless test UI, with a single view started.
|
|
|
|
*/
|
|
|
|
export function setupSingleView(buildView: (testgame: TestGame) => [Phaser.State, any[]]) {
|
|
|
|
let testgame = new TestGame();
|
|
|
|
|
|
|
|
beforeEach(function (done) {
|
2015-02-26 00:00:00 +00:00
|
|
|
spyOn(console, "log").and.stub();
|
|
|
|
spyOn(console, "warn").and.stub();
|
|
|
|
|
2017-04-12 23:22:34 +00:00
|
|
|
jasmine.clock().install();
|
|
|
|
|
2017-07-11 22:56:06 +00:00
|
|
|
if (!test_ui) {
|
|
|
|
test_ui = new MainUI(true);
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2017-07-11 22:56:06 +00:00
|
|
|
if (test_ui.load) {
|
|
|
|
spyOn(test_ui.load, 'image').and.stub();
|
|
|
|
spyOn(test_ui.load, 'audio').and.stub();
|
|
|
|
}
|
2017-02-16 22:59:41 +00:00
|
|
|
}
|
2017-02-10 00:08:28 +00:00
|
|
|
|
2017-07-11 22:56:06 +00:00
|
|
|
testgame.ui = test_ui;
|
|
|
|
|
2017-02-21 22:38:31 +00:00
|
|
|
let [state, stateargs] = buildView(testgame);
|
2015-01-08 00:00:00 +00:00
|
|
|
|
2017-05-04 23:19:28 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-02-21 22:38:31 +00:00
|
|
|
let orig_create = bound(state, "create");
|
|
|
|
spyOn(state, "create").and.callFake(() => {
|
|
|
|
orig_create();
|
2015-01-08 00:00:00 +00:00
|
|
|
done();
|
2017-02-21 22:38:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
testgame.ui.state.add("test", state);
|
|
|
|
testgame.ui.state.start("test", true, false, ...stateargs);
|
2017-07-11 22:56:06 +00:00
|
|
|
|
|
|
|
if (!testgame.ui.isBooted) {
|
|
|
|
testgame.ui.device.canvas = true;
|
|
|
|
testgame.ui.boot();
|
|
|
|
}
|
2015-01-08 00:00:00 +00:00
|
|
|
});
|
2017-02-21 22:38:31 +00:00
|
|
|
|
|
|
|
afterEach(function () {
|
2017-04-12 23:22:34 +00:00
|
|
|
jasmine.clock().uninstall();
|
2017-02-21 22:38:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return testgame;
|
2015-01-08 00:00:00 +00:00
|
|
|
}
|
2015-02-26 00:00:00 +00:00
|
|
|
|
2017-02-21 22:38:31 +00:00
|
|
|
/**
|
|
|
|
* Test setup of an empty BaseView
|
|
|
|
*/
|
|
|
|
export function setupEmptyView(): TestGame {
|
2017-02-27 23:36:12 +00:00
|
|
|
return setupSingleView(testgame => {
|
|
|
|
testgame.baseview = new BaseView();
|
|
|
|
return [testgame.baseview, []];
|
|
|
|
});
|
2015-02-26 00:00:00 +00:00
|
|
|
}
|
2017-01-30 00:40:33 +00:00
|
|
|
|
2017-02-21 22:38:31 +00:00
|
|
|
/**
|
|
|
|
* Test setup of a battleview bound to a battle, to be called inside a "describe" block.
|
|
|
|
*/
|
|
|
|
export function setupBattleview(): TestGame {
|
|
|
|
return setupSingleView(testgame => {
|
|
|
|
testgame.battleview = new BattleView();
|
|
|
|
|
|
|
|
let battle = Battle.newQuickRandom();
|
2017-03-09 17:11:00 +00:00
|
|
|
let player = battle.playing_ship ? battle.playing_ship.getPlayer() : new Player();
|
2017-02-21 22:38:31 +00:00
|
|
|
|
|
|
|
return [testgame.battleview, [player, battle]];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test setup of a mapview bound to a universe, to be called inside a "describe" block.
|
|
|
|
*/
|
|
|
|
export function setupMapview(): TestGame {
|
|
|
|
return setupSingleView(testgame => {
|
|
|
|
testgame.mapview = new UniverseMapView();
|
|
|
|
|
|
|
|
let mapview = new UniverseMapView();
|
|
|
|
let session = new GameSession();
|
|
|
|
session.startNewGame();
|
|
|
|
|
|
|
|
return [testgame.mapview, [session.universe, session.player]];
|
|
|
|
});
|
2017-01-30 00:40:33 +00:00
|
|
|
}
|
2017-05-16 23:12:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check a given text node
|
|
|
|
*/
|
|
|
|
export function checkText(node: any, content: string): void {
|
|
|
|
expect(node instanceof Phaser.Text).toBe(true);
|
|
|
|
|
|
|
|
let tnode = <Phaser.Text>node;
|
|
|
|
expect(tnode.text).toEqual(content);
|
|
|
|
}
|
2017-06-08 17:32:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that a layer contains the given component at a given index
|
|
|
|
*/
|
|
|
|
export function checkComponentInLayer(layer: Phaser.Group, index: number, component: UIComponent) {
|
|
|
|
if (index >= layer.children.length) {
|
|
|
|
fail(`Not enough children in group ${layer.name} for ${component} at index ${index}`);
|
|
|
|
} else {
|
|
|
|
let child = layer.children[index];
|
|
|
|
if (child !== (<any>component).container) {
|
|
|
|
fail(`${component} is not at index ${index} in ${layer.name}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-08 00:00:00 +00:00
|
|
|
}
|