1
0
Fork 0
spacetac/src/MainUI.spec.ts

42 lines
1.3 KiB
TypeScript
Raw Normal View History

/// <reference path="../node_modules/phaser/types/phaser.d.ts"/>
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;
}
}
2017-10-26 21:47:13 +00:00
testing("MainUI", test => {
2017-10-29 21:08:55 +00:00
let testgame = setupEmptyView(test);
2017-02-10 00:08:28 +00:00
2017-10-26 21:47:13 +00:00
test.case("saves games in local browser storage", check => {
let ui = testgame.ui;
2017-02-10 00:08:28 +00:00
ui.storage = <any>new FakeStorage();
let result = ui.loadGame("spacetac-test-save");
2017-10-26 21:47:13 +00:00
check.equals(result, false);
2017-02-10 00:08:28 +00:00
ui.session.startNewGame();
let systems = ui.session.universe.stars.length;
let links = ui.session.universe.starlinks.length;
result = ui.saveGame("spacetac-test-save");
2017-10-26 21:47:13 +00:00
check.equals(result, true);
2017-10-29 21:08:55 +00:00
check.equals(bool(ui.storage.getItem("spacetac-test-save")), true);
2017-02-10 00:08:28 +00:00
ui.session = new GameSession();
2017-10-26 21:47:13 +00:00
check.notsame(ui.session.universe.stars.length, systems);
2017-02-10 00:08:28 +00:00
result = ui.loadGame("spacetac-test-save");
2017-10-26 21:47:13 +00:00
check.equals(result, true);
check.same(ui.session.universe.stars.length, systems);
check.same(ui.session.universe.starlinks.length, links);
2017-02-10 00:08:28 +00:00
});
});
}