Commit 9c7778c6 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

ReactionOverlay must be created with valid data and Promises rejection

contains stacktrace
parent d8aa6fe3
......@@ -11,6 +11,7 @@
"author": "Piotr Gawron",
"devDependencies": {
"assert": "1.4.1",
"bluebird": "^3.4.6",
"browserify": "^13.1.1",
"chai": "^3.5.0",
"exorcist": "^0.4.0",
......@@ -25,7 +26,6 @@
"dependencies": {
"log4js": "0.6.38",
"pileup": "^0.6.8",
"promise": "^7.1.1",
"request": "^2.79.0",
"xmlhttprequest": "^1.8.0"
}
......
"use strict";
var Promise = require("bluebird");
var logger = require('./logger');
var request = require('request');
......
"use strict";
var Promise = require("bluebird");
var logger = require('../logger');
var functions = require('../Functions');
......@@ -605,12 +607,8 @@ AbstractCustomMap.prototype._showSelectedLayout = function(layoutId, index, leng
var layoutReaction = layoutReactions[j];
self.getModel().getReactionById(layoutReaction.getId()).then(function(reactionData) {
if (reactionData === null || reactionData === undefined) {
throw new Error("Cannot find data for reaction: " + layoutReaction.getId());
} else {
var reactionOverlay = new ReactionOverlay(layoutReaction, reactionData, self, length === 1);
self.selectedLayoutOverlays[layoutId].push(reactionOverlay);
}
var reactionOverlay = new ReactionOverlay(layoutReaction, reactionData, self, length === 1);
self.selectedLayoutOverlays[layoutId].push(reactionOverlay);
elementsProcessed++;
elementProcessedFun();
});
......
"use strict";
var Promise = require("bluebird");
var logger = require('../logger');
var functions = require('../Functions');
......@@ -1059,7 +1061,6 @@ CustomMap.prototype.addSelectedLayout = function(identifier) {
} else {
self.selectedLayouts[identifier] = true;
logger.debug("!");
self.getModel().initLayoutDataByLayoutId(identifier).then(function() {
self.refreshSelectedLayouts();
ServerConnector.setVisibleLayouts(JSON.stringify(self.getSelectedLayouts()));
......
"use strict";
var Promise = require("bluebird");
var logger = require('../../logger');
var LayoutAlias = require('./LayoutAlias');
......
"use strict";
var Promise = require("bluebird");
var logger = require('../../logger');
var Alias = require('./Alias');
......
......@@ -10,16 +10,16 @@ var AbstractOverlayElement = require('./AbstractOverlayElement');
* layout.
*
* @param layoutReaction
* {@link LayoutReaction} for which overlay is created
* {@link LayoutReaction} for which overlay is created
* @param reactionData
* {@link Reaction data} of the reaction
* {@link Reaction data} of the reaction
* @param map
* {@link AbstractCustomMap} where overlay should be placed
* {@link AbstractCustomMap} where overlay should be placed
* @param customized
* if true then coloring from layoutReaction is taken, if false then
* default is used. Second option is used when more than one layout
* is visualized (there is no simple way to visualize few layouts at
* the same time)
* if true then coloring from layoutReaction is taken, if false then
* default is used. Second option is used when more than one layout is
* visualized (there is no simple way to visualize few layouts at the
* same time)
*/
function ReactionOverlay(layoutReaction, reactionData, map, customized, id) {
// call super constructor
......@@ -36,21 +36,17 @@ function ReactionOverlay(layoutReaction, reactionData, map, customized, id) {
this.customized = customized;
if (layoutReaction !== undefined && layoutReaction !== null) {
if (layoutReaction.width) {
this.width = layoutReaction.width;
}
this.color = functions.overlayToColor(layoutReaction);
if (layoutReaction === undefined || layoutReaction === null || reactionData === undefined || reactionData === null) {
throw new Error("Reaction must be defined");
}
if (reactionData !== null && reactionData !== undefined) {
this.init();
this._id = reactionData.getId();
} else if (layoutReaction !== undefined && layoutReaction !== null) {
this._id = layoutReaction.getId();
} else {
this._id = id;
if (layoutReaction.width) {
this.width = layoutReaction.width;
}
this.color = functions.overlayToColor(layoutReaction);
this.init();
this._id = reactionData.getId();
}
ReactionOverlay.prototype = Object.create(AbstractOverlayElement.prototype);
......@@ -79,7 +75,7 @@ ReactionOverlay.prototype.getBounds = function() {
* Sets Google map to this {@link ReactionOverlay}.
*
* @param map
* map to set
* map to set
*/
ReactionOverlay.prototype.setMap = function(map) {
for (var i = 0; i < this.gmapObjects.length; i++) {
......@@ -101,8 +97,7 @@ ReactionOverlay.prototype.isShown = function() {
if (this.gmapObjects.length === 0) {
return false;
}
if (this.gmapObjects[0].getMap() === null
|| this.gmapObjects[0].getMap() === undefined) {
if (this.gmapObjects[0].getMap() === null || this.gmapObjects[0].getMap() === undefined) {
return false;
}
......@@ -129,7 +124,7 @@ ReactionOverlay.prototype.hide = function() {
* in customized mode.
*
* @param color
* new color value
* new color value
*/
ReactionOverlay.prototype.setColor = function(color) {
this.color = color;
......@@ -140,7 +135,7 @@ ReactionOverlay.prototype.setColor = function(color) {
* visualized in customized mode.
*
* @param width
* new width value
* new width value
*/
ReactionOverlay.prototype.setWidth = function(width) {
if (width !== undefined || width !== null) {
......@@ -179,15 +174,15 @@ ReactionOverlay.prototype.getWidth = function() {
* he should investigate the reaction manually.
*
* @param startX
* see {AliasOverlay} class for detailes, in this implementation the
* only important information is that when there are more than one
* layout visualized at least one of the two parameters (startX,endX)
* will differ from {0.0, 1.0} values
* see {AliasOverlay} class for detailes, in this implementation the
* only important information is that when there are more than one
* layout visualized at least one of the two parameters (startX,endX)
* will differ from {0.0, 1.0} values
* @param endX
* see {AliasOverlay} class for detailes, in this implementation the
* only important information is that when there are more than one
* layout visualized at least one of the two parameters (startX,endX)
* will differ from {0.0, 1.0} values
* see {AliasOverlay} class for detailes, in this implementation the
* only important information is that when there are more than one
* layout visualized at least one of the two parameters (startX,endX)
* will differ from {0.0, 1.0} values
*/
ReactionOverlay.prototype.setBoundsForAlias = function(startX, endX) {
if (this.isCustomized() && (startX > 0 || endX < 1)) {
......@@ -229,13 +224,13 @@ ReactionOverlay.prototype.changedToCustimzed = function() {
* Creates {google.maps.Polyline} from input data.
*
* @param line
* raw data about line taken from server
* raw data about line taken from server
* @param color
* color that should be used for visualization of the line
* color that should be used for visualization of the line
* @param width
* width that should be used for visualization of the line
* width that should be used for visualization of the line
* @param map
* {google.maps.Map} where line shoul dbe visualized
* {google.maps.Map} where line shoul dbe visualized
* @returns {google.maps.Polyline} from input data
*/
ReactionOverlay.createLine = function(line, color, width, map) {
......@@ -291,20 +286,17 @@ ReactionOverlay.prototype.init = function() {
var googleLine;
for (i = 0; i < this.reactionData.startLines.length; i++) {
line = this.reactionData.startLines[i];
googleLine = ReactionOverlay.createLine(line, this.color, this.width, this
.getCustomMap());
googleLine = ReactionOverlay.createLine(line, this.color, this.width, this.getCustomMap());
this.gmapObjects.push(googleLine);
}
for (i = 0; i < this.reactionData.endLines.length; i++) {
line = this.reactionData.endLines[i];
googleLine = ReactionOverlay.createLine(line, this.color, this.width, this
.getCustomMap());
googleLine = ReactionOverlay.createLine(line, this.color, this.width, this.getCustomMap());
this.gmapObjects.push(googleLine);
}
for (i = 0; i < this.reactionData.midLines.length; i++) {
line = this.reactionData.midLines[i];
googleLine = ReactionOverlay.createLine(line, this.color, this.width, this
.getCustomMap());
googleLine = ReactionOverlay.createLine(line, this.color, this.width, this.getCustomMap());
this.gmapObjects.push(googleLine);
}
if (!this.isCustomized()) {
......
......@@ -57,9 +57,16 @@ Helper.prototype.createLayoutAlias = function() {
return result;
};
Helper.prototype.createLayoutReaction = function() {
Helper.prototype.createLayoutReaction = function(reaction) {
var reactionId;
if (reaction instanceof Reaction) {
reactionId = reaction.getId();
} else {
reactionId = this.idCounter++;
}
var result = new LayoutReaction({
idObject : this.idCounter++,
idObject : reactionId,
width : 3.4,
color : {
a : 24,
......@@ -78,7 +85,27 @@ Helper.prototype.createReaction = function(map) {
}
var result = new Reaction({
idObject : this.idCounter++,
lines : [],
lines : [ {
start : {
x : 434.8904109589041,
y : 85.0
},
end : {
x : 410.8341500923087,
y : 104.95576185524392
},
type : "START"
}, {
start : {
x : 404.6769250286157,
y : 110.06345991944379
},
end : {
x : 380.62066416202026,
y : 130.0192217746877
},
type : "END"
} ],
centerPoint : new google.maps.Point(0, 0),
modelId : mapId,
});
......
......@@ -18,69 +18,40 @@ describe('ReactionOverlay', function() {
it("Constructor", function() {
var map = helper.createAbstractCustomMap();
var reaction = helper.createReaction(map);
var layoutReaction = helper.createLayoutReaction(reaction);
var reaction = new ReactionOverlay(null, null, map, false);
var reactionOverlay = new ReactionOverlay(layoutReaction, reaction, map, false);
assert.ok(reaction.gmapObjects);
assert.ok(reaction.getColor());
assert.ok(reaction.getWidth());
assert.ok(reaction.getBounds());
assert.ok(reactionOverlay.gmapObjects);
assert.ok(reactionOverlay.getColor());
assert.ok(reactionOverlay.getWidth());
assert.ok(reactionOverlay.getBounds());
assert.ok(reactionOverlay.getReactionData());
assert.ok(reactionOverlay.getCustomMap());
assert.ok(reactionOverlay.getId());
});
it("show", function() {
var map = helper.createAbstractCustomMap();
var reaction = helper.createReaction(map);
var layoutReaction = helper.createLayoutReaction(reaction);
var javaObject = {
lines : [ {
start : Object,
end : Object,
type : "START"
}, {
start : Object,
end : Object,
type : "END"
}, {
start : Object,
end : Object,
type : "MIDDLE"
} ],
modelId : 319,
idObject : "13178",
centerPoint : new google.maps.Point(1, 2)
};
var react = new Reaction(javaObject);
var reaction = new ReactionOverlay(null, react, map, false);
reaction.hide();
assert.equal(reaction.isShown(), false);
reaction.show();
assert.ok(reaction.isShown());
var reactionOverlay = new ReactionOverlay(layoutReaction, reaction, map, false);
assert.equal(logger.getWarnings().length, 0);
reaction.show();
assert.ok(reaction.isShown());
assert.equal(logger.getWarnings().length, 1);
reactionOverlay.hide();
assert.equal(reactionOverlay.isShown(), false);
});
reactionOverlay.show();
assert.ok(reactionOverlay.isShown());
it("Constructor 2", function() {
var map = helper.createAbstractCustomMap();
assert.equal(logger.getWarnings().length, 0);
var react = helper.createReaction();
var reaction = new ReactionOverlay(null, react, map, false);
reactionOverlay.show();
assert.ok(reactionOverlay.isShown());
assert.equal(logger.getWarnings().length, 1);
assert.ok(reaction.gmapObjects);
assert.ok(reaction.getColor());
assert.ok(reaction.getWidth());
assert.ok(reaction.getBounds());
assert.ok(reaction.getReactionData());
assert.ok(reaction.getCustomMap());
assert.ok(reaction.getId());
});
it("createline", function() {
......
"use strict";
var Promise = require("bluebird");
// GLOBAL configuration
var jsdom = require('jsdom');
global.document = jsdom.jsdom(undefined);
......@@ -22,6 +25,8 @@ global.navigator = {
var logger = require('./logger');
beforeEach(function() {
Promise.longStackTraces();
logger.flushBuffer();
global.testDiv = document.createElement("div");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment