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

View File

@ -1,8 +1,22 @@
describe("History Service suite", function() { describe("History Service suite", function() {
it("contains spec with an expectation", function() { it("starts at -1", function() {
var mockPiskelController = {}; 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); expect(historyService.currentIndex).toBe(0);
}); });
}); });