Commit 8e3c8aef authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when user load map that was removed and loaded again there will be no error due to caching

parent 390c28b6
......@@ -180,6 +180,12 @@ AbstractDbOverlay.prototype.searchByEncodedQuery = function (originalQuery, fitB
return this.searchNamesByTarget(query.target);
} else if (query.type === AbstractDbOverlay.QueryType.SEARCH_BY_COORDINATES) {
query.coordinates = new google.maps.Point(query.coordinates.x, query.coordinates.y);
if (this.getMap().getSubmapById(query.modelId) === null) {
//this can happen when cached data comes from project that was removed and something else
//was uploaded with the same name
logger.warn("Invalid search query. Model doesn't exist: " + query.modelId);
return Promise.resolve();
}
return this.searchByCoordinates(query);
} else {
throw new Error("Unknown type of query: " + query.type);
......
"use strict";
require('../../mocha-config.js');
var logger = require('../../logger');
......@@ -9,12 +10,12 @@ var AbstractDbOverlay = require('../../../../main/js/map/overlay/AbstractDbOverl
var assert = require('assert');
var Promise = require('bluebird');
describe('SearchDbOverlay', function() {
it("constructor 1", function() {
describe('SearchDbOverlay', function () {
it("constructor 1", function () {
var map = helper.createCustomMap();
var oc = new SearchDbOverlay({
map : map,
name : 'search'
map: map,
name: 'search'
});
assert.ok(oc);
assert.equal(oc.getName(), 'search');
......@@ -22,44 +23,44 @@ describe('SearchDbOverlay', function() {
assert.equal(logger.getWarnings.length, 0);
});
it("searchByCoordinates with too far alias as result", function() {
return ServerConnector.getProject().then(function(project) {
it("searchByCoordinates with too far alias as result", function () {
return ServerConnector.getProject().then(function (project) {
var map = helper.createCustomMap(project);
var searchDb = helper.createSearchDbOverlay(map);
var searchParams = {
modelId : map.getModel().getId(),
coordinates : new google.maps.Point(207.73, 479.18),
zoom : 4,
modelId: map.getModel().getId(),
coordinates: new google.maps.Point(207.73, 479.18),
zoom: 4,
};
return searchDb.searchByCoordinates(searchParams);
}).then(function(result) {
}).then(function (result) {
assert.equal(result.length, 0);
});
});
describe("searchByQuery", function() {
it("with perfectMatch", function() {
return ServerConnector.getProject().then(function(project) {
describe("searchByQuery", function () {
it("with perfectMatch", function () {
return ServerConnector.getProject().then(function (project) {
var map = helper.createCustomMap(project);
map.getModel().setId(15781);
var searchDb = helper.createSearchDbOverlay(map);
return searchDb.searchByQuery("s1", true);
}).then(function(result) {
}).then(function (result) {
assert.equal(result.length, 1);
assert.equal(result[0].length, 1);
});
});
it("check state when network problems", function() {
it("check state when network problems", function () {
var problematicQuery = "sxx1";
var searchDb;
return ServerConnector.getProject().then(function(project) {
return ServerConnector.getProject().then(function (project) {
var map = helper.createCustomMap(project);
searchDb = helper.createSearchDbOverlay(map);
return searchDb.searchByQuery(problematicQuery);
}).then(null, function() {
}).then(null, function () {
var queries = searchDb.getQueries();
var promises = [];
for (var i = 0; i < queries.length; i++) {
......@@ -70,119 +71,134 @@ describe('SearchDbOverlay', function() {
});
});
it("searchByEncodedQuery", function() {
return ServerConnector.getProject().then(function(project) {
var map = helper.createCustomMap(project);
var searchDb = helper.createSearchDbOverlay(map);
var point = new google.maps.Point(316.05, 253.61);
var queryType = AbstractDbOverlay.QueryType.SEARCH_BY_COORDINATES;
var query = searchDb.encodeQuery(queryType, map.getModel().getId(), point, 2);
return searchDb.searchByEncodedQuery(query);
}).then(function(result) {
assert.ok(result.length > 0);
describe("searchByEncodedQuery", function () {
it("search by coordinates", function () {
return ServerConnector.getProject().then(function (project) {
var map = helper.createCustomMap(project);
var searchDb = helper.createSearchDbOverlay(map);
var point = new google.maps.Point(316.05, 253.61);
var queryType = AbstractDbOverlay.QueryType.SEARCH_BY_COORDINATES;
var query = searchDb.encodeQuery(queryType, map.getModel().getId(), point, 2);
return searchDb.searchByEncodedQuery(query);
}).then(function (result) {
assert.ok(result.length > 0);
});
});
it("search by coordinates on map that doesn't exist", function () {
return ServerConnector.getProject().then(function (project) {
var map = helper.createCustomMap(project);
var searchDb = helper.createSearchDbOverlay(map);
var point = new google.maps.Point(316.05, 253.61);
var queryType = AbstractDbOverlay.QueryType.SEARCH_BY_COORDINATES;
var query = searchDb.encodeQuery(queryType, -1, point, 2);
return searchDb.searchByEncodedQuery(query);
}).then(function (result) {
assert.equal(logger.getWarnings().length, 1);
assert.equal(result.length, 0);
});
});
});
describe("searchByCoordinates", function() {
it("with too far reaction as result", function() {
return ServerConnector.getProject().then(function(project) {
describe("searchByCoordinates", function () {
it("with too far reaction as result", function () {
return ServerConnector.getProject().then(function (project) {
var map = helper.createCustomMap(project);
var searchDb = helper.createSearchDbOverlay(map);
var searchParams = {
modelId : map.getModel().getId(),
coordinates : new google.maps.Point(553.10, 479.18),
zoom : 4,
modelId: map.getModel().getId(),
coordinates: new google.maps.Point(553.10, 479.18),
zoom: 4,
};
return searchDb.searchByCoordinates(searchParams);
}).then(function(result) {
}).then(function (result) {
assert.equal(result.length, 0);
});
});
it("on empty map", function() {
it("on empty map", function () {
helper.setUrl("http://test/?id=empty");
return ServerConnector.getProject().then(function(project) {
return ServerConnector.getProject().then(function (project) {
var map = helper.createCustomMap(project);
var searchDb = helper.createSearchDbOverlay(map);
var searchParams = {
modelId : map.getModel().getId(),
coordinates : new google.maps.Point(553.10, 479.18),
zoom : 4,
modelId: map.getModel().getId(),
coordinates: new google.maps.Point(553.10, 479.18),
zoom: 4,
};
return searchDb.searchByCoordinates(searchParams);
}).then(function(result) {
}).then(function (result) {
assert.equal(result.length, 0);
});
});
it("on hidden nested object", function() {
return ServerConnector.getProject().then(function(project) {
it("on hidden nested object", function () {
return ServerConnector.getProject().then(function (project) {
var map = helper.createCustomMap(project);
var searchDb = helper.createSearchDbOverlay(map);
var searchParams = {
modelId : map.getModel().getId(),
coordinates : new google.maps.Point(316.05, 253.61),
zoom : 2,
modelId: map.getModel().getId(),
coordinates: new google.maps.Point(316.05, 253.61),
zoom: 2,
};
return searchDb.searchByCoordinates(searchParams);
}).then(function(result) {
}).then(function (result) {
// id of the parent
assert.equal(result[0].getId(), 329159);
});
});
it("on nested object", function() {
return ServerConnector.getProject().then(function(project) {
it("on nested object", function () {
return ServerConnector.getProject().then(function (project) {
var map = helper.createCustomMap(project);
var searchDb = helper.createSearchDbOverlay(map);
var searchParams = {
modelId : map.getModel().getId(),
coordinates : new google.maps.Point(316.05, 253.61),
zoom : 4,
modelId: map.getModel().getId(),
coordinates: new google.maps.Point(316.05, 253.61),
zoom: 4,
};
return searchDb.searchByCoordinates(searchParams);
}).then(function(result) {
}).then(function (result) {
assert.equal(result[0].getId(), 329159);
});
});
});
describe("getDetailDataByIdentifiedElement", function() {
it("get by alias", function() {
return ServerConnector.getProject().then(function(project) {
describe("getDetailDataByIdentifiedElement", function () {
it("get by alias", function () {
return ServerConnector.getProject().then(function (project) {
var map = helper.createCustomMap(project);
var searchDb = helper.createSearchDbOverlay(map);
var searchParams = new IdentifiedElement({
type : "ALIAS",
id : 329177,
modelId : project.getModel().getId(),
type: "ALIAS",
id: 329177,
modelId: project.getModel().getId(),
});
return searchDb.getDetailDataByIdentifiedElement(searchParams);
}).then(function(result) {
}).then(function (result) {
assert.equal(result.getId(), 329177);
});
});
it("get by point", function() {
return ServerConnector.getProject().then(function(project) {
it("get by point", function () {
return ServerConnector.getProject().then(function (project) {
var map = helper.createCustomMap(project);
var searchDb = helper.createSearchDbOverlay(map);
var searchParams = new IdentifiedElement({
type : "POINT",
id : "2,3",
modelId : project.getModel().getId(),
type: "POINT",
id: "2,3",
modelId: project.getModel().getId(),
});
return searchDb.getDetailDataByIdentifiedElement(searchParams);
}).then(function(result) {
}).then(function (result) {
assert.equal(result, null);
});
});
......
Supports Markdown
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