annotate src/DML/MainVisBundle/Resources/assets/jasmine/marionette/[t]ContextModule.50-AppContextManager.js @ 1:f38015048f48 tip

Added GPL
author Daniel Wolff
date Sat, 13 Feb 2016 20:43:38 +0100
parents 493bcb69166c
children
rev   line source
Daniel@0 1 "use strict";
Daniel@0 2
Daniel@0 3 describe("ContextModule.AppContextManager", function() {
Daniel@0 4
Daniel@0 5 var serializedAppContexts = {
Daniel@0 6 "empty": {
Daniel@0 7 "stateHistory": {
Daniel@0 8 "currentSerializedState": {
Daniel@0 9 "musicCollectionGrid": {
Daniel@0 10 "entityConfigs": [],
Daniel@0 11 "viewConfigs": [],
Daniel@0 12 },
Daniel@0 13 "musicRecordingGrid": {
Daniel@0 14 "entityConfigs": [],
Daniel@0 15 "viewConfigs": [],
Daniel@0 16 }
Daniel@0 17 },
Daniel@0 18 "undoStack": [],
Daniel@0 19 "redoStack": []
Daniel@0 20 },
Daniel@0 21 "stateBookmarks": []
Daniel@0 22 },
Daniel@0 23
Daniel@0 24 "empty_faulty1": {
Daniel@0 25 },
Daniel@0 26 "empty_faulty2": 42,
Daniel@0 27 "empty_faulty3": null,
Daniel@0 28
Daniel@0 29 "empty_incomplete1": {
Daniel@0 30 "stateHistory": {
Daniel@0 31 "currentSerializedState": {
Daniel@0 32 "musicCollectionGrid": {
Daniel@0 33 "entityConfigs": [],
Daniel@0 34 "viewConfigs": [],
Daniel@0 35 },
Daniel@0 36 },
Daniel@0 37 "redoStack": []
Daniel@0 38 },
Daniel@0 39 "stateBookmarks": []
Daniel@0 40 },
Daniel@0 41 "empty_incomplete2": {
Daniel@0 42 "stateHistory": {
Daniel@0 43 "currentSerializedState": null,
Daniel@0 44 "undoStack": [],
Daniel@0 45 "redoStack": []
Daniel@0 46 },
Daniel@0 47 "stateBookmarks": []
Daniel@0 48 },
Daniel@0 49 };
Daniel@0 50
Daniel@0 51 beforeAll(function() {
Daniel@0 52 jasmine.helpers.dumpStorage();
Daniel@0 53 jasmine.helpers.clearStorage();
Daniel@0 54 });
Daniel@0 55
Daniel@0 56 beforeEach(function() {
Daniel@0 57 jasmine.helpers.clearStorage();
Daniel@0 58 });
Daniel@0 59
Daniel@0 60 afterAll(function() {
Daniel@0 61 jasmine.helpers.restoreStorageFromDump();
Daniel@0 62 });
Daniel@0 63
Daniel@0 64 it("is promptly created", function() {
Daniel@0 65 var testedAppContextManager = new App.ContextModule.AppContextManager();
Daniel@0 66
Daniel@0 67 expect(testedAppContextManager instanceof Backbone.Marionette.Object).toBe(true);
Daniel@0 68 });
Daniel@0 69
Daniel@0 70 it("restores context from default, saves it and reads it", function() {
Daniel@0 71 var testedAppContextManager = new App.ContextModule.AppContextManager();
Daniel@0 72 var testedAppContext = new App.ContextModule.AppContext();
Daniel@0 73
Daniel@0 74 testedAppContextManager.restoreDefault(testedAppContext);
Daniel@0 75
Daniel@0 76 var serializedAppContext = testedAppContext.serialize();
Daniel@0 77 expect(typeof serializedAppContext).toBe("object");
Daniel@0 78 expect(serializedAppContext.stateHistory.currentSerializedState.musicCollectionGrid.entityConfigs.length).toBe(2);
Daniel@0 79 expect(serializedAppContext.stateHistory.currentSerializedState.musicCollectionGrid.viewConfigs.length).toBe(2);
Daniel@0 80 expect(serializedAppContext.stateHistory.currentSerializedState.musicRecordingGrid.entityConfigs.length).toBe(0);
Daniel@0 81 expect(serializedAppContext.stateHistory.currentSerializedState.musicRecordingGrid.viewConfigs.length).toBe(0);
Daniel@0 82
Daniel@0 83 testedAppContextManager.saveToStorage(testedAppContext);
Daniel@0 84 var serializedAppContext = App.DataModule.Storage.getObjCache(App.ContextModule, "context");
Daniel@0 85 expect(typeof serializedAppContext).toBe("object");
Daniel@0 86 expect(serializedAppContext.stateHistory.currentSerializedState.musicCollectionGrid.entityConfigs.length).toBe(2);
Daniel@0 87 expect(serializedAppContext.stateHistory.currentSerializedState.musicCollectionGrid.viewConfigs.length).toBe(2);
Daniel@0 88 expect(serializedAppContext.stateHistory.currentSerializedState.musicRecordingGrid.entityConfigs.length).toBe(0);
Daniel@0 89 expect(serializedAppContext.stateHistory.currentSerializedState.musicRecordingGrid.viewConfigs.length).toBe(0);
Daniel@0 90
Daniel@0 91 serializedAppContext.stateHistory.currentSerializedState.musicCollectionGrid.entityConfigs.pop();
Daniel@0 92 serializedAppContext.stateHistory.currentSerializedState.musicRecordingGrid.viewConfigs.push({parameters: {x: 1}});
Daniel@0 93
Daniel@0 94 App.DataModule.Storage.setObjCache(App.ContextModule, "context", serializedAppContext);
Daniel@0 95 testedAppContextManager.restoreFromStorage(testedAppContext);
Daniel@0 96 var serializedAppContext = testedAppContext.serialize();
Daniel@0 97 expect(typeof serializedAppContext).toBe("object");
Daniel@0 98 expect(serializedAppContext.stateHistory.currentSerializedState.musicCollectionGrid.entityConfigs.length).toBe(1);
Daniel@0 99 expect(serializedAppContext.stateHistory.currentSerializedState.musicCollectionGrid.viewConfigs.length).toBe(2);
Daniel@0 100 expect(serializedAppContext.stateHistory.currentSerializedState.musicRecordingGrid.entityConfigs.length).toBe(0);
Daniel@0 101 expect(serializedAppContext.stateHistory.currentSerializedState.musicRecordingGrid.viewConfigs.length).toBe(1);
Daniel@0 102 });
Daniel@0 103 });