comparison src/DML/MainVisBundle/Resources/assets/jasmine/marionette/[t]ContextModule.50-AppContextManager.js @ 0:493bcb69166c

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