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