annotate src/DML/MainVisBundle/Resources/assets/jasmine/marionette/[t]ContextModule.10-ConfigGrid.js @ 0:493bcb69166c

added public content
author Daniel Wolff
date Tue, 09 Feb 2016 20:54:02 +0100
parents
children
rev   line source
Daniel@0 1 "use strict";
Daniel@0 2
Daniel@0 3 describe("ContextModule.ConfigGrid", function() {
Daniel@0 4
Daniel@0 5 var testEntityConfigs = null;
Daniel@0 6 var testViewConfigs = null;
Daniel@0 7 var testIrrelevantEntityConfigs = null;
Daniel@0 8 var testIrrelevantViewConfigs = null;
Daniel@0 9
Daniel@0 10 beforeEach(function() {
Daniel@0 11 testEntityConfigs = [
Daniel@0 12 new App.ContextModule.Config({parameters: {x: 10, y: "test"}}),
Daniel@0 13 new App.ContextModule.Config({parameters: {x: 10, y: "test"}}),
Daniel@0 14 new App.ContextModule.Config({parameters: {x: 20}}),
Daniel@0 15 ];
Daniel@0 16
Daniel@0 17 testViewConfigs = [
Daniel@0 18 new App.ContextModule.Config({parameters: {x: 10, y: "test"}}),
Daniel@0 19 new App.ContextModule.Config({parameters: {x: 10, y: "test"}}),
Daniel@0 20 new App.ContextModule.Config({parameters: {x: 20}}),
Daniel@0 21 ];
Daniel@0 22
Daniel@0 23 testIrrelevantEntityConfigs = [
Daniel@0 24 new App.ContextModule.Config({parameters: {x: 10, y: "test"}}),
Daniel@0 25 ];
Daniel@0 26 testIrrelevantViewConfigs = [
Daniel@0 27 new App.ContextModule.Config({parameters: {x: 10, y: "test"}}),
Daniel@0 28 ];
Daniel@0 29 });
Daniel@0 30
Daniel@0 31 it("is promptly created", function() {
Daniel@0 32 var testedConfigGrid = new App.ContextModule.ConfigGrid();
Daniel@0 33
Daniel@0 34 expect(testedConfigGrid).not.toBe(null);
Daniel@0 35
Daniel@0 36 expect(testedConfigGrid.entityConfigs).not.toBe(null);
Daniel@0 37 expect(testedConfigGrid.entityConfigs.size()).toEqual(0);
Daniel@0 38
Daniel@0 39 expect(testedConfigGrid.viewConfigs).not.toBe(null);
Daniel@0 40 expect(testedConfigGrid.viewConfigs.size()).toEqual(0);
Daniel@0 41
Daniel@0 42 expect(testedConfigGrid.getType()).toBe(undefined);
Daniel@0 43 });
Daniel@0 44
Daniel@0 45 it("is promptly created with type", function() {
Daniel@0 46 var testedConfigGrid = new App.ContextModule.ConfigGrid("abc");
Daniel@0 47
Daniel@0 48 expect(testedConfigGrid).not.toBe(null);
Daniel@0 49
Daniel@0 50 expect(testedConfigGrid.getType()).toBe("abc");
Daniel@0 51 });
Daniel@0 52
Daniel@0 53 it("can add parameter bags", function() {
Daniel@0 54 var testedConfigGrid = new App.ContextModule.ConfigGrid();
Daniel@0 55
Daniel@0 56 testedConfigGrid.entityConfigs.add(testEntityConfigs[0]);
Daniel@0 57 testedConfigGrid.entityConfigs.add(testEntityConfigs[1]);
Daniel@0 58 testedConfigGrid.entityConfigs.add(testEntityConfigs[2]);
Daniel@0 59
Daniel@0 60 testedConfigGrid.viewConfigs.add(testViewConfigs[0]);
Daniel@0 61 testedConfigGrid.viewConfigs.add(testViewConfigs[1]);
Daniel@0 62 testedConfigGrid.viewConfigs.add(testViewConfigs[2]);
Daniel@0 63
Daniel@0 64 expect(testedConfigGrid.viewConfigs.size()).toEqual(3);
Daniel@0 65 expect(testedConfigGrid.entityConfigs.size()).toEqual(3);
Daniel@0 66
Daniel@0 67 // Can't add what's already there
Daniel@0 68 testedConfigGrid.entityConfigs.add(testEntityConfigs[2]);
Daniel@0 69 testedConfigGrid.viewConfigs.add(testViewConfigs[2]);
Daniel@0 70
Daniel@0 71 expect(testedConfigGrid.viewConfigs.size()).toEqual(3);
Daniel@0 72 expect(testedConfigGrid.entityConfigs.size()).toEqual(3);
Daniel@0 73 });
Daniel@0 74
Daniel@0 75 it("can add parameter bags at a particular place", function() {
Daniel@0 76 var testedConfigGrid = new App.ContextModule.ConfigGrid();
Daniel@0 77
Daniel@0 78 testedConfigGrid.entityConfigs.add(testEntityConfigs[0]);
Daniel@0 79 testedConfigGrid.entityConfigs.add(testEntityConfigs[1]);
Daniel@0 80 testedConfigGrid.entityConfigs.add(testEntityConfigs[2], {at: 0});
Daniel@0 81
Daniel@0 82 testedConfigGrid.viewConfigs.add(testViewConfigs[0]);
Daniel@0 83 testedConfigGrid.viewConfigs.add(testViewConfigs[1]);
Daniel@0 84 testedConfigGrid.viewConfigs.add(testViewConfigs[2], {at: 1});
Daniel@0 85
Daniel@0 86 expect(testedConfigGrid.viewConfigs.size()).toEqual(3);
Daniel@0 87 expect(testedConfigGrid.entityConfigs.size()).toEqual(3);
Daniel@0 88
Daniel@0 89 expect(testedConfigGrid.entityConfigs.at(0)).toEqual(testEntityConfigs[2]);
Daniel@0 90 expect(testedConfigGrid.entityConfigs.at(1)).toEqual(testEntityConfigs[0]);
Daniel@0 91 expect(testedConfigGrid.entityConfigs.at(2)).toEqual(testEntityConfigs[1]);
Daniel@0 92
Daniel@0 93 expect(testedConfigGrid.viewConfigs.at(0)).toEqual(testViewConfigs[0]);
Daniel@0 94 expect(testedConfigGrid.viewConfigs.at(1)).toEqual(testViewConfigs[2]);
Daniel@0 95 expect(testedConfigGrid.viewConfigs.at(2)).toEqual(testViewConfigs[1]);
Daniel@0 96 });
Daniel@0 97
Daniel@0 98 it("can reset", function() {
Daniel@0 99 var testedConfigGrid = new App.ContextModule.ConfigGrid();
Daniel@0 100
Daniel@0 101 testedConfigGrid.entityConfigs.add(testEntityConfigs[0]);
Daniel@0 102 testedConfigGrid.entityConfigs.add(testEntityConfigs[1]);
Daniel@0 103 testedConfigGrid.entityConfigs.add(testEntityConfigs[2]);
Daniel@0 104
Daniel@0 105 testedConfigGrid.viewConfigs.add(testViewConfigs[0]);
Daniel@0 106 testedConfigGrid.viewConfigs.add(testViewConfigs[1]);
Daniel@0 107 testedConfigGrid.viewConfigs.add(testViewConfigs[2]);
Daniel@0 108
Daniel@0 109 expect(testedConfigGrid.entityConfigs.size()).toEqual(3);
Daniel@0 110 expect(testedConfigGrid.viewConfigs.size()).toEqual(3);
Daniel@0 111
Daniel@0 112 testedConfigGrid.entityConfigs.reset();
Daniel@0 113 testedConfigGrid.viewConfigs.reset();
Daniel@0 114
Daniel@0 115 expect(testedConfigGrid.entityConfigs.size()).toEqual(0);
Daniel@0 116 expect(testedConfigGrid.viewConfigs.size()).toEqual(0);
Daniel@0 117
Daniel@0 118 testedConfigGrid.entityConfigs.add(testEntityConfigs[0]);
Daniel@0 119 testedConfigGrid.entityConfigs.add(testEntityConfigs[1]);
Daniel@0 120 testedConfigGrid.entityConfigs.add(testEntityConfigs[2]);
Daniel@0 121
Daniel@0 122 testedConfigGrid.viewConfigs.add(testViewConfigs[0]);
Daniel@0 123 testedConfigGrid.viewConfigs.add(testViewConfigs[1]);
Daniel@0 124 testedConfigGrid.viewConfigs.add(testViewConfigs[2]);
Daniel@0 125 });
Daniel@0 126
Daniel@0 127 it("retreives neighbour entityConfigs and viewConfigs", function() {
Daniel@0 128 var testedConfigGrid = new App.ContextModule.ConfigGrid();
Daniel@0 129
Daniel@0 130 testedConfigGrid.entityConfigs.add(testEntityConfigs[0]);
Daniel@0 131 testedConfigGrid.entityConfigs.add(testEntityConfigs[1]);
Daniel@0 132 testedConfigGrid.entityConfigs.add(testEntityConfigs[2]);
Daniel@0 133
Daniel@0 134 testedConfigGrid.viewConfigs.add(testViewConfigs[0]);
Daniel@0 135 testedConfigGrid.viewConfigs.add(testViewConfigs[1]);
Daniel@0 136 testedConfigGrid.viewConfigs.add(testViewConfigs[2]);
Daniel@0 137
Daniel@0 138 expect(testedConfigGrid.getPrevEntityNeighbour(testEntityConfigs[0])).toBe(undefined);
Daniel@0 139 expect(testedConfigGrid.getPrevEntityNeighbour(testEntityConfigs[1])).toEqual(testEntityConfigs[0]);
Daniel@0 140 expect(testedConfigGrid.getPrevEntityNeighbour(testEntityConfigs[2])).toEqual(testEntityConfigs[1]);
Daniel@0 141 expect(testedConfigGrid.getNextEntityNeighbour(testEntityConfigs[0])).toEqual(testEntityConfigs[1]);
Daniel@0 142 expect(testedConfigGrid.getNextEntityNeighbour(testEntityConfigs[1])).toEqual(testEntityConfigs[2]);
Daniel@0 143 expect(testedConfigGrid.getNextEntityNeighbour(testEntityConfigs[2])).toBe(undefined);
Daniel@0 144
Daniel@0 145 expect(function(){testedConfigGrid.getPrevEntityNeighbour(testIrrelevantEntityConfigs[0]);}).toThrow();
Daniel@0 146 expect(function(){testedConfigGrid.getNextEntityNeighbour(testIrrelevantEntityConfigs[0]);}).toThrow();
Daniel@0 147 expect(function(){testedConfigGrid.getPrevEntityNeighbour(testViewConfigs[0]);}).toThrow();
Daniel@0 148 expect(function(){testedConfigGrid.getNextEntityNeighbour(testViewConfigs[0]);}).toThrow();
Daniel@0 149
Daniel@0 150 expect(testedConfigGrid.getPrevViewNeighbour(testViewConfigs[0])).toEqual(undefined);
Daniel@0 151 expect(testedConfigGrid.getPrevViewNeighbour(testViewConfigs[1])).toEqual(testViewConfigs[0]);
Daniel@0 152 expect(testedConfigGrid.getPrevViewNeighbour(testViewConfigs[2])).toEqual(testViewConfigs[1]);
Daniel@0 153 expect(testedConfigGrid.getNextViewNeighbour(testViewConfigs[0])).toEqual(testViewConfigs[1]);
Daniel@0 154 expect(testedConfigGrid.getNextViewNeighbour(testViewConfigs[1])).toEqual(testViewConfigs[2]);
Daniel@0 155 expect(testedConfigGrid.getNextViewNeighbour(testViewConfigs[2])).toEqual(undefined);
Daniel@0 156
Daniel@0 157 expect(function(){testedConfigGrid.getPrevViewNeighbour(testIrrelevantViewConfigs[0]);}).toThrow();
Daniel@0 158 expect(function(){testedConfigGrid.getNextViewNeighbour(testIrrelevantViewConfigs[0]);}).toThrow();
Daniel@0 159 expect(function(){testedConfigGrid.getPrevViewNeighbour(testEntityConfigs[0]);}).toThrow();
Daniel@0 160 expect(function(){testedConfigGrid.getNextViewNeighbour(testEntityConfigs[0]);}).toThrow();
Daniel@0 161 });
Daniel@0 162
Daniel@0 163 it("relocates entityConfigs and viewConfigs", function() {
Daniel@0 164 var testedConfigGrid = new App.ContextModule.ConfigGrid();
Daniel@0 165
Daniel@0 166 _.each([
Daniel@0 167 {
Daniel@0 168 configCollection: testedConfigGrid.entityConfigs,
Daniel@0 169 relocateFunctionName: "relocateEntityConfig",
Daniel@0 170 relevantConfigs: testEntityConfigs,
Daniel@0 171 irrelevantConfigs: testIrrelevantEntityConfigs,
Daniel@0 172 },
Daniel@0 173 {
Daniel@0 174 configCollection: testedConfigGrid.viewConfigs,
Daniel@0 175 relocateFunctionName: "relocateViewConfig",
Daniel@0 176 relevantConfigs: testViewConfigs,
Daniel@0 177 irrelevantConfigs: testIrrelevantViewConfigs
Daniel@0 178 }
Daniel@0 179 ], function(currentDimension) {
Daniel@0 180
Daniel@0 181 currentDimension.configCollection.add(currentDimension.relevantConfigs[0]);
Daniel@0 182 currentDimension.configCollection.add(currentDimension.relevantConfigs[1]);
Daniel@0 183 currentDimension.configCollection.add(currentDimension.relevantConfigs[2]);
Daniel@0 184 expect(currentDimension.configCollection.size()).toEqual(3);
Daniel@0 185
Daniel@0 186 // index
Daniel@0 187 testedConfigGrid[currentDimension.relocateFunctionName](currentDimension.relevantConfigs[1], 0);
Daniel@0 188 expect(currentDimension.configCollection.at(0)).toEqual(currentDimension.relevantConfigs[1]);
Daniel@0 189 expect(currentDimension.configCollection.at(1)).toEqual(currentDimension.relevantConfigs[0]);
Daniel@0 190 expect(currentDimension.configCollection.at(2)).toEqual(currentDimension.relevantConfigs[2]);
Daniel@0 191
Daniel@0 192 // config
Daniel@0 193 testedConfigGrid[currentDimension.relocateFunctionName](currentDimension.relevantConfigs[1], currentDimension.relevantConfigs[2]);
Daniel@0 194 expect(currentDimension.configCollection.at(0)).toEqual(currentDimension.relevantConfigs[0]);
Daniel@0 195 expect(currentDimension.configCollection.at(1)).toEqual(currentDimension.relevantConfigs[1]);
Daniel@0 196 expect(currentDimension.configCollection.at(2)).toEqual(currentDimension.relevantConfigs[2]);
Daniel@0 197
Daniel@0 198 // config cid
Daniel@0 199 testedConfigGrid[currentDimension.relocateFunctionName](currentDimension.relevantConfigs[2], currentDimension.relevantConfigs[0].getClientId());
Daniel@0 200 expect(currentDimension.configCollection.at(0)).toEqual(currentDimension.relevantConfigs[2]);
Daniel@0 201 expect(currentDimension.configCollection.at(1)).toEqual(currentDimension.relevantConfigs[0]);
Daniel@0 202 expect(currentDimension.configCollection.at(2)).toEqual(currentDimension.relevantConfigs[1]);
Daniel@0 203
Daniel@0 204 // exceptional cases
Daniel@0 205 expect(function(){testedConfigGrid[currentDimension.relocateFunctionName](currentDimension.irrelevantConfigs[1], 0);}).toThrow();
Daniel@0 206 expect(function(){testedConfigGrid[currentDimension.relocateFunctionName](relevantConfigs[1], currentDimension.irrelevantConfigs[1]);}).toThrow();
Daniel@0 207 expect(function(){testedConfigGrid[currentDimension.relocateFunctionName](currentDimension.relevantConfigs[1], -1);}).toThrow();
Daniel@0 208 expect(function(){testedConfigGrid[currentDimension.relocateFunctionName](currentDimension.relevantConfigs[1], 4);}).toThrow();
Daniel@0 209
Daniel@0 210 // index - last
Daniel@0 211 testedConfigGrid[currentDimension.relocateFunctionName](currentDimension.relevantConfigs[1], 3);
Daniel@0 212 expect(currentDimension.configCollection.at(0)).toEqual(currentDimension.relevantConfigs[2]);
Daniel@0 213 expect(currentDimension.configCollection.at(1)).toEqual(currentDimension.relevantConfigs[0]);
Daniel@0 214 expect(currentDimension.configCollection.at(2)).toEqual(currentDimension.relevantConfigs[1]);
Daniel@0 215
Daniel@0 216 // clone of a config
Daniel@0 217 var clone = new App.ContextModule.Config(currentDimension.relevantConfigs[1].serialize());
Daniel@0 218 expect(function(){testedConfigGrid[currentDimension.relocateFunctionName](clone, 0);}).toThrow();
Daniel@0 219 });
Daniel@0 220 });
Daniel@0 221
Daniel@0 222 xit("works with selectedEntityConfigClientId and selectedViewConfigClientId", function() {
Daniel@0 223 });
Daniel@0 224
Daniel@0 225 xit("performs combined actions: addEntityAndSelectIt, addViewAndSelectIt", function() {
Daniel@0 226 });
Daniel@0 227
Daniel@0 228 xit("performs combined actions: removeEntityAndSelectNeighbour, removeViewAndSelectNeighbour", function() {
Daniel@0 229 });
Daniel@0 230
Daniel@0 231 it("serializes and unserializes itself", function() {
Daniel@0 232 var testedConfigGrid = new App.ContextModule.ConfigGrid();
Daniel@0 233
Daniel@0 234 var originalSerializedObject = {
Daniel@0 235 entityConfigs: [
Daniel@0 236 testEntityConfigs[1].serialize(),
Daniel@0 237 testEntityConfigs[2].serialize(),
Daniel@0 238 testEntityConfigs[0].serialize(),
Daniel@0 239 ],
Daniel@0 240 viewConfigs: [
Daniel@0 241 testViewConfigs[0].serialize(),
Daniel@0 242 testViewConfigs[1].serialize()
Daniel@0 243 ],
Daniel@0 244 };
Daniel@0 245 testedConfigGrid.unserialize(originalSerializedObject);
Daniel@0 246
Daniel@0 247 expect(testedConfigGrid.entityConfigs.size()).toEqual(3);
Daniel@0 248 expect(testedConfigGrid.viewConfigs.size()).toEqual(2);
Daniel@0 249
Daniel@0 250 expect(testedConfigGrid.entityConfigs.at(0).getClientId()).toEqual(testEntityConfigs[1].getClientId());
Daniel@0 251 expect(testedConfigGrid.entityConfigs.at(1).getClientId()).toEqual(testEntityConfigs[2].getClientId());
Daniel@0 252 expect(testedConfigGrid.entityConfigs.at(2).getClientId()).toEqual(testEntityConfigs[0].getClientId());
Daniel@0 253
Daniel@0 254 expect(testedConfigGrid.viewConfigs.at(0).getClientId()).toEqual(testViewConfigs[0].getClientId());
Daniel@0 255 expect(testedConfigGrid.viewConfigs.at(1).getClientId()).toEqual(testViewConfigs[1].getClientId());
Daniel@0 256
Daniel@0 257 expect(testedConfigGrid.serialize()).toEqual(originalSerializedObject);
Daniel@0 258
Daniel@0 259 testedConfigGrid.relocateEntityConfig(testedConfigGrid.entityConfigs.at(2), 0);
Daniel@0 260 testedConfigGrid.entityConfigs.remove(testedConfigGrid.entityConfigs.at(2));
Daniel@0 261 testedConfigGrid.entityConfigs.add(testIrrelevantEntityConfigs[0]);
Daniel@0 262
Daniel@0 263 testedConfigGrid.viewConfigs.add(testViewConfigs[2]);
Daniel@0 264 testedConfigGrid.relocateViewConfig(testedConfigGrid.viewConfigs.at(2), 0);
Daniel@0 265 testedConfigGrid.relocateViewConfig(testedConfigGrid.viewConfigs.at(1), 3);
Daniel@0 266 testedConfigGrid.viewConfigs.add(testIrrelevantViewConfigs[0]);
Daniel@0 267
Daniel@0 268 var newSerializedObject = {
Daniel@0 269 entityConfigs: [
Daniel@0 270 testEntityConfigs[0].serialize(),
Daniel@0 271 testEntityConfigs[1].serialize(),
Daniel@0 272 testIrrelevantEntityConfigs[0].serialize()
Daniel@0 273 ],
Daniel@0 274 viewConfigs: [
Daniel@0 275 testViewConfigs[2].serialize(),
Daniel@0 276 testViewConfigs[1].serialize(),
Daniel@0 277 testViewConfigs[0].serialize(),
Daniel@0 278 testIrrelevantViewConfigs[0].serialize()
Daniel@0 279 ],
Daniel@0 280 };
Daniel@0 281 expect(testedConfigGrid.serialize()).toEqual(newSerializedObject);
Daniel@0 282 });
Daniel@0 283
Daniel@0 284 it("unserializes itself from faulty serialized objects", function() {
Daniel@0 285 var faultySerializedObjects = [
Daniel@0 286 null,
Daniel@0 287 undefined,
Daniel@0 288 42,
Daniel@0 289 "test",
Daniel@0 290 {entityConfigs: 42},
Daniel@0 291 {viewConfigs: [testViewConfigs[1].serialize()], "foo": "bar"},
Daniel@0 292 ];
Daniel@0 293
Daniel@0 294 var testedConfigGrid = new App.ContextModule.ConfigGrid();
Daniel@0 295
Daniel@0 296 _.each(faultySerializedObjects, function(faultySerializedObject) {
Daniel@0 297 expect(function() {
Daniel@0 298 testedConfigGrid.unserialize(faultySerializedObject);
Daniel@0 299 }).not.toThrow();
Daniel@0 300 });
Daniel@0 301 });
Daniel@0 302
Daniel@0 303 it("triggers events when real changes occur", function() {
Daniel@0 304 var testedConfigGrid = new App.ContextModule.ConfigGrid();
Daniel@0 305
Daniel@0 306 _.each([
Daniel@0 307 {
Daniel@0 308 configCollection: testedConfigGrid.entityConfigs,
Daniel@0 309 relocateFunctionName: "relocateEntityConfig",
Daniel@0 310 relevantConfigs: testEntityConfigs,
Daniel@0 311 irrelevantConfigs: testIrrelevantEntityConfigs,
Daniel@0 312
Daniel@0 313 changeLayoutEventName: "change_layout",
Daniel@0 314 changeConfigEventPrefix: "change_entity:",
Daniel@0 315 changeConfigNeighboursPrefix: "change_entity_neighbours:",
Daniel@0 316 },
Daniel@0 317 {
Daniel@0 318 configCollection: testedConfigGrid.viewConfigs,
Daniel@0 319 relocateFunctionName: "relocateViewConfig",
Daniel@0 320 relevantConfigs: testViewConfigs,
Daniel@0 321 irrelevantConfigs: testIrrelevantViewConfigs,
Daniel@0 322
Daniel@0 323 changeLayoutEventName: "change_layout",
Daniel@0 324 changeConfigEventPrefix: "change_view:",
Daniel@0 325 changeConfigNeighboursPrefix: "change_view_neighbours:",
Daniel@0 326 }
Daniel@0 327 ], function(currentDimension) {
Daniel@0 328
Daniel@0 329 var spyNames = [
Daniel@0 330 "change",
Daniel@0 331 "changeCollection",
Daniel@0 332 "changeConfig0",
Daniel@0 333 "changeConfig1",
Daniel@0 334 "changeConfig2",
Daniel@0 335 "changeConfigNeighbours0",
Daniel@0 336 "changeConfigNeighbours1",
Daniel@0 337 "changeConfigNeighbours2"
Daniel@0 338 ];
Daniel@0 339 var spy = jasmine.createSpyObj("listener", spyNames);
Daniel@0 340
Daniel@0 341 testedConfigGrid.on("change", spy.change, spy);
Daniel@0 342 testedConfigGrid.on(currentDimension.changeLayoutEventName, spy.changeCollection, spy);
Daniel@0 343 testedConfigGrid.on(currentDimension.changeConfigEventPrefix + currentDimension.relevantConfigs[0].getClientId(), spy.changeConfig0, spy);
Daniel@0 344 testedConfigGrid.on(currentDimension.changeConfigEventPrefix + currentDimension.relevantConfigs[1].getClientId(), spy.changeConfig1, spy);
Daniel@0 345 testedConfigGrid.on(currentDimension.changeConfigEventPrefix + currentDimension.relevantConfigs[2].getClientId(), spy.changeConfig2, spy);
Daniel@0 346
Daniel@0 347 testedConfigGrid.on(currentDimension.changeConfigNeighboursPrefix + currentDimension.relevantConfigs[0].getClientId(), spy.changeConfigNeighbours0, spy);
Daniel@0 348 testedConfigGrid.on(currentDimension.changeConfigNeighboursPrefix + currentDimension.relevantConfigs[1].getClientId(), spy.changeConfigNeighbours1, spy);
Daniel@0 349 testedConfigGrid.on(currentDimension.changeConfigNeighboursPrefix + currentDimension.relevantConfigs[2].getClientId(), spy.changeConfigNeighbours2, spy);
Daniel@0 350
Daniel@0 351 var expectSpyCallCount = function() {
Daniel@0 352 _.each(arguments, function(arg, i) {
Daniel@0 353 //console.log("___", i, "--->", spy[spyNames[i]].calls.count(), arg);
Daniel@0 354 expect(spy[spyNames[i]].calls.count()).toEqual(arg);
Daniel@0 355 });
Daniel@0 356 for (var i = arguments.length; i < spyNames.length; i++) {
Daniel@0 357 expect(spy[spyNames[i]].calls.count()).toEqual(0);
Daniel@0 358 }
Daniel@0 359 };
Daniel@0 360 var resetSpyCallCount = function() {
Daniel@0 361 _.each(spyNames, function(spyName) {
Daniel@0 362 spy[spyName].calls.reset();
Daniel@0 363 });
Daniel@0 364 };
Daniel@0 365 expectSpyCallCount(0);
Daniel@0 366 resetSpyCallCount();
Daniel@0 367
Daniel@0 368 testedConfigGrid.unserialize(null);
Daniel@0 369 resetSpyCallCount();
Daniel@0 370
Daniel@0 371 // Unserialize the whole grid
Daniel@0 372 var defaultSerializedState = {
Daniel@0 373 entityConfigs: [
Daniel@0 374 testEntityConfigs[0].serialize(),
Daniel@0 375 testEntityConfigs[1].serialize(),
Daniel@0 376 testEntityConfigs[2].serialize(),
Daniel@0 377 ],
Daniel@0 378 viewConfigs: [
Daniel@0 379 testViewConfigs[0].serialize(),
Daniel@0 380 testViewConfigs[1].serialize(),
Daniel@0 381 testViewConfigs[2].serialize(),
Daniel@0 382 ],
Daniel@0 383 };
Daniel@0 384 testedConfigGrid.unserialize(defaultSerializedState);
Daniel@0 385 expectSpyCallCount(1, 1);
Daniel@0 386
Daniel@0 387 resetSpyCallCount();
Daniel@0 388 testedConfigGrid.unserialize(defaultSerializedState);
Daniel@0 389 expectSpyCallCount(0, 0);
Daniel@0 390
Daniel@0 391 // Modify parameters
Daniel@0 392 resetSpyCallCount();
Daniel@0 393 expectSpyCallCount(0);
Daniel@0 394
Daniel@0 395 currentDimension.configCollection.at(1).updateParameter("my", 1);
Daniel@0 396 expectSpyCallCount(1, 0,
Daniel@0 397 0, 1, 0,
Daniel@0 398 1, 0, 1);
Daniel@0 399
Daniel@0 400 resetSpyCallCount();
Daniel@0 401 currentDimension.configCollection.at(2).planParameterUpdate("my", 1);
Daniel@0 402 expectSpyCallCount(1, 0,
Daniel@0 403 0, 0, 1,
Daniel@0 404 0, 1, 0);
Daniel@0 405
Daniel@0 406 resetSpyCallCount();
Daniel@0 407 currentDimension.configCollection.remove(currentDimension.configCollection.at(2));
Daniel@0 408 expect(currentDimension.configCollection.size()).toEqual(2);
Daniel@0 409 expectSpyCallCount(1, 1,
Daniel@0 410 0, 0, 0,
Daniel@0 411 0, 1, 0);
Daniel@0 412
Daniel@0 413 resetSpyCallCount();
Daniel@0 414 testedConfigGrid.unserialize(defaultSerializedState);
Daniel@0 415 expectSpyCallCount(1, 1,
Daniel@0 416 0, 1, 0,
Daniel@0 417 1, 1, 0);
Daniel@0 418
Daniel@0 419 resetSpyCallCount();
Daniel@0 420
Daniel@0 421 expect(function() {
Daniel@0 422 testedConfigGrid.relocateEntityConfig(testEntityConfigs[2], 0);
Daniel@0 423 }).toThrow();
Daniel@0 424 expect(function() {
Daniel@0 425 testedConfigGrid.relocateViewConfig(testViewConfigs[2], 0);
Daniel@0 426 }).toThrow();
Daniel@0 427
Daniel@0 428 testedConfigGrid.relocateEntityConfig(testedConfigGrid.entityConfigs.at(1), 0);
Daniel@0 429 testedConfigGrid.relocateViewConfig(testedConfigGrid.viewConfigs.at(1), 0);
Daniel@0 430 expectSpyCallCount(2, 2,
Daniel@0 431 0, 0, 0,
Daniel@0 432 1, 1, 1);
Daniel@0 433
Daniel@0 434 resetSpyCallCount();
Daniel@0 435 testedConfigGrid.unserialize(defaultSerializedState);
Daniel@0 436 expectSpyCallCount(1, 1,
Daniel@0 437 0, 0, 0,
Daniel@0 438 1, 1, 1);
Daniel@0 439
Daniel@0 440 resetSpyCallCount();
Daniel@0 441 currentDimension.configCollection.add(currentDimension.irrelevantConfigs[0], {at: 0});
Daniel@0 442 expectSpyCallCount(1, 1,
Daniel@0 443 0, 0, 0,
Daniel@0 444 1, 0, 0);
Daniel@0 445 });
Daniel@0 446 });
Daniel@0 447 });