2017-07-11 22:56:06 +00:00
|
|
|
/// <reference path="ui/TestGame.ts" />
|
|
|
|
|
2017-02-10 00:08:28 +00:00
|
|
|
if (typeof window != "undefined") {
|
|
|
|
(<any>window).describe = (<any>window).describe || function () { };
|
|
|
|
}
|
|
|
|
|
2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac.UI.Specs {
|
2017-02-10 00:08:28 +00:00
|
|
|
class FakeStorage {
|
2017-05-02 21:33:58 +00:00
|
|
|
data: any = {}
|
2017-02-10 00:08:28 +00:00
|
|
|
getItem(name: string) {
|
|
|
|
return this.data[name];
|
|
|
|
}
|
|
|
|
setItem(name: string, value: string) {
|
|
|
|
this.data[name] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe("MainUI", () => {
|
2017-07-11 22:56:06 +00:00
|
|
|
let testgame = setupEmptyView();
|
2017-02-10 00:08:28 +00:00
|
|
|
|
|
|
|
it("saves games in local browser storage", function () {
|
2017-07-11 22:56:06 +00:00
|
|
|
let ui = testgame.ui;
|
2017-02-10 00:08:28 +00:00
|
|
|
ui.storage = <any>new FakeStorage();
|
|
|
|
|
|
|
|
let result = ui.loadGame("spacetac-test-save");
|
|
|
|
expect(result).toBe(false);
|
|
|
|
|
|
|
|
ui.session.startNewGame();
|
|
|
|
let systems = ui.session.universe.stars.length;
|
|
|
|
let links = ui.session.universe.starlinks.length;
|
|
|
|
|
|
|
|
result = ui.saveGame("spacetac-test-save");
|
|
|
|
expect(result).toBe(true);
|
|
|
|
expect(ui.storage.getItem("spacetac-test-save")).toBeTruthy();
|
|
|
|
|
|
|
|
ui.session = new GameSession();
|
|
|
|
expect(ui.session.universe.stars.length).not.toBe(systems);
|
|
|
|
|
|
|
|
result = ui.loadGame("spacetac-test-save");
|
|
|
|
expect(result).toBe(true);
|
|
|
|
expect(ui.session.universe.stars.length).toBe(systems);
|
|
|
|
expect(ui.session.universe.starlinks.length).toBe(links);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|