mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
tests update
This commit is contained in:
@ -1,22 +1,86 @@
|
||||
describe("History Service suite", function() {
|
||||
it("starts at -1", function() {
|
||||
var mockPiskelController = {};
|
||||
var mockShortcutService = {};
|
||||
var historyService = new pskl.service.HistoryService(mockPiskelController, mockShortcutService);
|
||||
expect(historyService.currentIndex).toBe(-1);
|
||||
});
|
||||
var callFactory = function (method) {
|
||||
return {
|
||||
times : function (times) {
|
||||
var results = [];
|
||||
for (var i = 0 ; i < times ; i++) {
|
||||
results.push(method());
|
||||
}
|
||||
return results;
|
||||
},
|
||||
once : function () {
|
||||
return method();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
it("is at 0 after init", function() {
|
||||
describe("History Service suite", function() {
|
||||
var SERIALIZED_PISKEL = 'serialized-piskel';
|
||||
var historyService = null;
|
||||
|
||||
var getLastState = function () {
|
||||
return historyService.stateQueue[historyService.currentIndex];
|
||||
};
|
||||
|
||||
var createMockHistoryService = function () {
|
||||
var mockPiskelController = {
|
||||
serialize : function () {
|
||||
return 'serialized-piskel';
|
||||
return SERIALIZED_PISKEL;
|
||||
}
|
||||
};
|
||||
var mockShortcutService = {
|
||||
addShortcut : function () {}
|
||||
};
|
||||
var historyService = new pskl.service.HistoryService(mockPiskelController, mockShortcutService);
|
||||
return new pskl.service.HistoryService(mockPiskelController, mockShortcutService);
|
||||
};
|
||||
|
||||
it("starts at -1", function() {
|
||||
historyService = createMockHistoryService();
|
||||
expect(historyService.currentIndex).toBe(-1);
|
||||
});
|
||||
|
||||
it("is at 0 after init", function() {
|
||||
historyService = createMockHistoryService();
|
||||
historyService.init();
|
||||
expect(historyService.currentIndex).toBe(0);
|
||||
});
|
||||
|
||||
var sendSaveEvents = function (type) {
|
||||
return callFactory (function () {
|
||||
$.publish(Events.PISKEL_SAVE_STATE, {
|
||||
type : type,
|
||||
scope : {},
|
||||
replay : {}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
it("stores a piskel snapshot after 5 SAVE", function () {
|
||||
// BEFORE
|
||||
var SNAPSHOT_PERIOD_BACKUP = pskl.service.HistoryService.SNAPSHOT_PERIOD;
|
||||
pskl.service.HistoryService.SNAPSHOT_PERIOD = 5;
|
||||
|
||||
historyService = createMockHistoryService();
|
||||
historyService.init();
|
||||
|
||||
sendSaveEvents(pskl.service.HistoryService.REPLAY).times(5);
|
||||
|
||||
expect(historyService.currentIndex).toBe(5);
|
||||
|
||||
expect(getLastState().piskel).toBe(SERIALIZED_PISKEL);
|
||||
|
||||
sendSaveEvents(pskl.service.HistoryService.REPLAY).times(4);
|
||||
|
||||
sendSaveEvents(pskl.service.HistoryService.REPLAY_NO_SNAPSHOT).once();
|
||||
expect(getLastState().piskel).toBeUndefined();
|
||||
|
||||
sendSaveEvents(pskl.service.HistoryService.REPLAY_NO_SNAPSHOT).once();
|
||||
expect(getLastState().piskel).toBeUndefined();
|
||||
|
||||
sendSaveEvents(pskl.service.HistoryService.REPLAY).once();
|
||||
expect(getLastState().piskel).toBe(SERIALIZED_PISKEL);
|
||||
|
||||
// AFTER
|
||||
pskl.service.HistoryService.SNAPSHOT_PERIOD = SNAPSHOT_PERIOD_BACKUP;
|
||||
|
||||
})
|
||||
});
|
Reference in New Issue
Block a user