Fixed jasmine being unable to single-run UI specs
This commit is contained in:
parent
1f4ca3e7b5
commit
bf4b4add9d
|
@ -1,8 +1,10 @@
|
|||
/// <reference path="ui/TestGame.ts" />
|
||||
|
||||
if (typeof window != "undefined") {
|
||||
(<any>window).describe = (<any>window).describe || function () { };
|
||||
}
|
||||
|
||||
module TS.SpaceTac.Specs {
|
||||
module TS.SpaceTac.UI.Specs {
|
||||
class FakeStorage {
|
||||
data: any = {}
|
||||
getItem(name: string) {
|
||||
|
@ -14,14 +16,10 @@ module TS.SpaceTac.Specs {
|
|||
}
|
||||
|
||||
describe("MainUI", () => {
|
||||
beforeEach(function () {
|
||||
spyOn(console, "log").and.stub();
|
||||
spyOn(console, "warn").and.stub();
|
||||
spyOn(console, "error").and.stub();
|
||||
});
|
||||
let testgame = setupEmptyView();
|
||||
|
||||
it("saves games in local browser storage", function () {
|
||||
let ui = new MainUI(true);
|
||||
let ui = testgame.ui;
|
||||
ui.storage = <any>new FakeStorage();
|
||||
|
||||
let result = ui.loadGame("spacetac-test-save");
|
||||
|
|
|
@ -113,7 +113,7 @@ module TS.SpaceTac {
|
|||
console.log("Game loaded");
|
||||
return true;
|
||||
} else {
|
||||
console.error("No saved game found");
|
||||
console.warn("No saved game found");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
/// <reference path="TestGame.ts" />
|
||||
/// <reference path="BaseView.ts" />
|
||||
|
||||
module TS.SpaceTac.UI.Specs {
|
||||
describe("BaseView", function () {
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
/// <reference path="map/UniverseMapView.ts"/>
|
||||
|
||||
module TS.SpaceTac.UI.Specs {
|
||||
let test_ui: MainUI;
|
||||
|
||||
/**
|
||||
* Class to hold references to test objects (used as singleton in "describe" blocks)
|
||||
*
|
||||
|
@ -27,13 +29,17 @@ module TS.SpaceTac.UI.Specs {
|
|||
|
||||
jasmine.clock().install();
|
||||
|
||||
testgame.ui = new MainUI(true);
|
||||
if (!test_ui) {
|
||||
test_ui = new MainUI(true);
|
||||
|
||||
if (testgame.ui.load) {
|
||||
spyOn(testgame.ui.load, 'image').and.stub();
|
||||
spyOn(testgame.ui.load, 'audio').and.stub();
|
||||
if (test_ui.load) {
|
||||
spyOn(test_ui.load, 'image').and.stub();
|
||||
spyOn(test_ui.load, 'audio').and.stub();
|
||||
}
|
||||
}
|
||||
|
||||
testgame.ui = test_ui;
|
||||
|
||||
let [state, stateargs] = buildView(testgame);
|
||||
|
||||
if (state instanceof BaseView) {
|
||||
|
@ -50,16 +56,14 @@ module TS.SpaceTac.UI.Specs {
|
|||
|
||||
testgame.ui.state.add("test", state);
|
||||
testgame.ui.state.start("test", true, false, ...stateargs);
|
||||
|
||||
if (!testgame.ui.isBooted) {
|
||||
testgame.ui.device.canvas = true;
|
||||
testgame.ui.boot();
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
let ui = testgame.ui;
|
||||
window.requestAnimationFrame(() => {
|
||||
if (ui) {
|
||||
ui.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
jasmine.clock().uninstall();
|
||||
});
|
||||
|
||||
|
|
|
@ -7,12 +7,10 @@ module TS.SpaceTac.UI.Specs {
|
|||
spyOn(button, "getBounds").and.returnValue({ x: 100, y: 50, width: 50, height: 25 });
|
||||
|
||||
let tooltip = new Tooltip(testgame.baseview);
|
||||
tooltip.bind(button, filler => {
|
||||
filler.addImage(22, 12, "fake");
|
||||
return true;
|
||||
});
|
||||
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 });
|
||||
expect(container.visible).toBe(false);
|
||||
|
||||
button.onInputOver.dispatch();
|
||||
|
|
Loading…
Reference in a new issue