Mercurial > hg > dml-open-vis
comparison src/DML/MainVisBundle/Resources/assets/jasmine/marionette/[t]ContextModule.11-State.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.State", function() { | |
4 | |
5 var serializedStates = { | |
6 "empty": { | |
7 "musicCollectionGrid": { | |
8 "entityConfigs": [], | |
9 "viewConfigs": [], | |
10 }, | |
11 "musicRecordingGrid": { | |
12 "entityConfigs": [], | |
13 "viewConfigs": [], | |
14 } | |
15 }, | |
16 | |
17 "empty_faulty1": { | |
18 | |
19 }, | |
20 "empty_faulty2": 42, | |
21 "empty_faulty3": null, | |
22 | |
23 "empty_incomplete1": { | |
24 "musicCollectionGrid": { | |
25 "entityConfigs": [], | |
26 "viewConfigs": [], | |
27 }, | |
28 }, | |
29 "empty_incomplete2": { | |
30 "musicRecordingGrid": { | |
31 "viewConfigs": [], | |
32 }, | |
33 }, | |
34 | |
35 "1by1": { | |
36 "musicCollectionGrid": { | |
37 "entityConfigs": [{clientId: "c10", parameters: {"ce": 1}, plannedParameterUpdates: {}}], | |
38 "viewConfigs": [{clientId: "c20", parameters: {"cv": 2}, plannedParameterUpdates: {}}], | |
39 }, | |
40 "musicRecordingGrid": { | |
41 "entityConfigs": [{clientId: "c30", parameters: {"re": 3}, plannedParameterUpdates: {}}], | |
42 "viewConfigs": [{clientId: "c40", parameters: {"rv": 4}, plannedParameterUpdates: {}}], | |
43 } | |
44 }, | |
45 "1by1_faulty1": { | |
46 "musicCollectionGrid": { | |
47 "entityConfigs": [{clientId: "c10", parameters: {"ce": 1}, plannedParameterUpdates: null}], | |
48 "viewConfigs": [{clientId: "c20", parameters: {"cv": 2}, plannedParameterUpdates: {}}], | |
49 }, | |
50 "musicRecordingGrid": { | |
51 "entityConfigs": [{clientId: "c30", parameters: {"re": 3}, plannedParameterUpdates: 42}], | |
52 "viewConfigs": [{clientId: "c40", parameters: {"rv": 4}, plannedParameterUpdates: {}}], | |
53 } | |
54 }, | |
55 "1by1_incomplete1": { | |
56 "musicCollectionGrid": { | |
57 "entityConfigs": [{clientId: "c10", parameters: {"ce": 1}, }], | |
58 "viewConfigs": [{clientId: "c20", parameters: {"cv": 2}, plannedParameterUpdates: {}}], | |
59 }, | |
60 "musicRecordingGrid": { | |
61 "entityConfigs": [{clientId: "c30", parameters: {"re": 3}, }], | |
62 "viewConfigs": [{clientId: "c40", parameters: {"rv": 4}, plannedParameterUpdates: {}}], | |
63 } | |
64 }, | |
65 | |
66 }; | |
67 | |
68 it("is promptly created", function() { | |
69 var testedState = new App.ContextModule.State(); | |
70 | |
71 expect(testedState).not.toBe(null); | |
72 | |
73 expect(testedState.get("musicCollectionGrid")).not.toBe(null); | |
74 expect(testedState.get("musicCollectionGrid") instanceof App.ContextModule.ConfigGrid).toBe(true); | |
75 | |
76 expect(testedState.get("musicRecordingGrid")).not.toBe(null); | |
77 expect(testedState.get("musicRecordingGrid") instanceof App.ContextModule.ConfigGrid).toBe(true); | |
78 | |
79 }); | |
80 | |
81 it("serializes and unserializes itself", function() { | |
82 var testedState = new App.ContextModule.State(); | |
83 | |
84 testedState.unserialize(serializedStates["empty"]); | |
85 expect(testedState.serialize()).toEqual(serializedStates["empty"]); | |
86 | |
87 testedState.unserialize(serializedStates["empty_faulty1"]); | |
88 expect(testedState.serialize()).toEqual(serializedStates["empty"]); | |
89 | |
90 testedState.unserialize(serializedStates["empty_faulty2"]); | |
91 expect(testedState.serialize()).toEqual(serializedStates["empty"]); | |
92 | |
93 testedState.unserialize(serializedStates["empty_faulty3"]); | |
94 expect(testedState.serialize()).toEqual(serializedStates["empty"]); | |
95 | |
96 testedState.unserialize(serializedStates["empty_incomplete1"]); | |
97 expect(testedState.serialize()).toEqual(serializedStates["empty"]); | |
98 | |
99 testedState.unserialize(serializedStates["empty_incomplete2"]); | |
100 expect(testedState.serialize()).toEqual(serializedStates["empty"]); | |
101 | |
102 testedState.unserialize(serializedStates["1by1"]); | |
103 expect(testedState.serialize()).toEqual(serializedStates["1by1"]); | |
104 | |
105 testedState.unserialize(serializedStates["1by1_faulty1"]); | |
106 expect(testedState.serialize()).toEqual(serializedStates["1by1"]); | |
107 | |
108 testedState.unserialize(serializedStates["1by1_incomplete1"]); | |
109 expect(testedState.serialize()).toEqual(serializedStates["1by1"]); | |
110 }); | |
111 | |
112 xit("returns grid by type", function() { | |
113 | |
114 }); | |
115 | |
116 xit("works with property musicRecordingsGridIsShown", function() { | |
117 | |
118 }); | |
119 | |
120 it("triggers change event when when config grids change", function() { | |
121 var testedState = new App.ContextModule.State(); | |
122 | |
123 var changeListener = jasmine.createSpy("changeListener"); | |
124 testedState.on("change", changeListener); | |
125 | |
126 expect(changeListener.calls.count()).toEqual(0); | |
127 | |
128 testedState.get("musicCollectionGrid").entityConfigs.add(new App.ContextModule.Config()); | |
129 expect(changeListener.calls.count()).toEqual(1); | |
130 changeListener.calls.reset(); | |
131 | |
132 testedState.get("musicRecordingGrid").entityConfigs.add(new App.ContextModule.Config()); | |
133 expect(changeListener.calls.count()).toEqual(1); | |
134 changeListener.calls.reset(); | |
135 | |
136 testedState.unserialize(serializedStates["empty"]); | |
137 expect(changeListener.calls.count()).toEqual(1); | |
138 changeListener.calls.reset(); | |
139 | |
140 testedState.unserialize(serializedStates["empty_faulty1"]); | |
141 expect(changeListener.calls.count()).toEqual(0); | |
142 changeListener.calls.reset(); | |
143 | |
144 testedState.unserialize(serializedStates["empty_incomplete1"]); | |
145 expect(changeListener.calls.count()).toEqual(0); | |
146 changeListener.calls.reset(); | |
147 | |
148 testedState.unserialize(serializedStates["1by1"]); | |
149 expect(changeListener.calls.count()).toEqual(1); | |
150 changeListener.calls.reset(); | |
151 testedState.unserialize(serializedStates["1by1"]); | |
152 expect(changeListener.calls.count()).toEqual(0); | |
153 changeListener.calls.reset(); | |
154 testedState.unserialize(serializedStates["1by1_incomplete1"]); | |
155 expect(changeListener.calls.count()).toEqual(0); | |
156 changeListener.calls.reset(); | |
157 }); | |
158 }); |