tests update

This commit is contained in:
jdescottes 2014-08-12 00:30:57 +02:00
parent 05e8f9adac
commit 6d6e80c762
2 changed files with 24 additions and 13 deletions

View File

@ -4,11 +4,12 @@
var SNAPSHOT_PERIOD = 50;
var LOAD_STATE_INTERVAL = 50;
ns.HistoryService = function (piskelController) {
this.piskelController = piskelController;
ns.HistoryService = function (piskelController, shortcutService) {
this.piskelController = piskelController || pskl.app.piskelController;
this.shortcutService = shortcutService || pskl.app.shortcutService;
this.stateQueue = [];
this.currentIndex = -1;
this.saveState__b = this.onSaveStateEvent.bind(this);
this.lastLoadState = -1;
@ -24,10 +25,10 @@
ns.HistoryService.REPLAY_NO_SNAPSHOT = 'REPLAY_NO_SNAPSHOT';
ns.HistoryService.prototype.init = function () {
$.subscribe(Events.PISKEL_SAVE_STATE, this.saveState__b);
$.subscribe(Events.PISKEL_SAVE_STATE, this.onSaveStateEvent.bind(this));
pskl.app.shortcutService.addShortcut('ctrl+Z', this.undo.bind(this));
pskl.app.shortcutService.addShortcut('ctrl+Y', this.redo.bind(this));
this.shortcutService.addShortcut('ctrl+Z', this.undo.bind(this));
this.shortcutService.addShortcut('ctrl+Y', this.redo.bind(this));
this.saveState({
type : ns.HistoryService.SNAPSHOT
@ -58,10 +59,6 @@
this.saveNextAsSnapshot = false;
}
if (isSnapshot) {
}
this.stateQueue.push(state);
};

View File

@ -1,8 +1,22 @@
describe("History Service suite", function() {
it("contains spec with an expectation", function() {
it("starts at -1", function() {
var mockPiskelController = {};
var historyService = new pskl.service.HistoryService(mockPiskelController);
var mockShortcutService = {};
var historyService = new pskl.service.HistoryService(mockPiskelController, mockShortcutService);
expect(historyService.currentIndex).toBe(-1);
});
it("is at 0 after init", function() {
var mockPiskelController = {
serialize : function () {
return 'serialized-piskel';
}
};
var mockShortcutService = {
addShortcut : function () {}
};
var historyService = new pskl.service.HistoryService(mockPiskelController, mockShortcutService);
historyService.init();
expect(historyService.currentIndex).toBe(0);
});
});