-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
457 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
web/src/test/resources/assets/spec/config/TileLayersSpec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
describe('TileLayers', function() { | ||
var oldL; | ||
|
||
beforeEach(function () { | ||
oldL = global.L; | ||
global.L = { | ||
tileLayer: function () { | ||
return 'a tile layer'; | ||
}, | ||
Browser: { | ||
retina: false | ||
} | ||
}; | ||
global.L.tileLayer.wms = function () { | ||
return 'a tile layer'; | ||
}; | ||
}); | ||
|
||
it('gets the correct layer', function () { | ||
var tileLayers = requireFile('./config/tileLayers.js'); | ||
|
||
var layer = tileLayers.selectLayer('bla'); | ||
|
||
expect(layer).toBe('a tile layer'); | ||
}); | ||
|
||
afterEach(function () { | ||
global.L = oldL; | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
web/src/test/resources/assets/spec/graphhopper/GHInputSpec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var GHInput = requireFile('./graphhopper/GHInput.js'); | ||
|
||
describe("GHInput", function () { | ||
|
||
it("input should accept 0 and no addresses", function () { | ||
var input = new GHInput("12,0"); | ||
expect(input.toString()).toEqual("12,0"); | ||
var input = new GHInput("bluo,0"); | ||
expect(input.toString()).toEqual(undefined); | ||
expect(input.lat).toEqual(undefined); | ||
expect(input.lng).toEqual(undefined); | ||
var input = new GHInput("bluo"); | ||
expect(input.toString()).toEqual(undefined); | ||
var input = new GHInput(""); | ||
expect(input.toString()).toEqual(undefined); | ||
}); | ||
|
||
it("GHInput should set to unresolved if new input string", function () { | ||
var input = new GHInput("12.44, 68.44"); | ||
expect(input.isResolved()).toEqual(true); | ||
input.set("blup"); | ||
expect(input.isResolved()).toEqual(false); | ||
}); | ||
|
||
it("point should be parsable", function () { | ||
expect(new GHInput("12.44, 68.44").lat).toEqual(12.44); | ||
expect(new GHInput("12.44, 68.44").lng).toEqual(68.44); | ||
expect(new GHInput("12.44,68.44").lat).toEqual(12.44); | ||
expect(new GHInput("12.44,68.44").lng).toEqual(68.44); | ||
expect(new GHInput("london").lon).toEqual(undefined); | ||
}); | ||
}); |
89 changes: 89 additions & 0 deletions
89
web/src/test/resources/assets/spec/graphhopper/GHRequestSpec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
var GHRequest = requireFile('./graphhopper/GHRequest.js'); | ||
|
||
describe("GHRequest", function () { | ||
|
||
it("ghrequest should init correctly from params", function () { | ||
var ghRequest = new GHRequest("http://test.de"); | ||
var params = {}; | ||
params.do_zoom = true; | ||
ghRequest.init(params); | ||
expect(ghRequest.do_zoom).toEqual(params.do_zoom); | ||
|
||
params.do_zoom = false; | ||
ghRequest.init(params); | ||
expect(ghRequest.do_zoom).toEqual(params.do_zoom); | ||
}); | ||
|
||
it("features should work", function () { | ||
var ghRequest = new GHRequest("http://test.de?vehicle=car"); | ||
var params = {}; | ||
params.elevation = true; | ||
ghRequest.features = {"car": {}}; | ||
ghRequest.init(params); | ||
expect(ghRequest.hasElevation()).toEqual(false); | ||
|
||
// overwrite | ||
ghRequest.features = {"car": {elevation: true}}; | ||
ghRequest.init(params); | ||
expect(ghRequest.hasElevation()).toEqual(true); | ||
|
||
var params = {}; | ||
ghRequest.features = {"car": {elevation: true}}; | ||
ghRequest.init(params); | ||
expect(ghRequest.hasElevation()).toEqual(true); | ||
|
||
var params = {}; | ||
params.elevation = false; | ||
ghRequest.features = {"car": {elevation: true}}; | ||
ghRequest.init(params); | ||
expect(ghRequest.hasElevation()).toEqual(false); | ||
|
||
var params = {}; | ||
params.elevation = true; | ||
ghRequest.features = {"car": {elevation: false}}; | ||
ghRequest.init(params); | ||
expect(ghRequest.hasElevation()).toEqual(false); | ||
|
||
ghRequest = new GHRequest("http://test.de"); | ||
var params = {point: [[4, 3], [2, 3]], test: "x", test_array: [1, 2]}; | ||
ghRequest.init(params); | ||
|
||
// skip point, layer etc | ||
expect(ghRequest.api_params.point).toEqual(undefined); | ||
|
||
// include all other parameters | ||
expect(ghRequest.api_params.test).toEqual("x"); | ||
expect(ghRequest.api_params.test_array).toEqual([1, 2]); | ||
}); | ||
|
||
it("create URL from object 'dot' notation should work", function () { | ||
var ghRequest = new GHRequest("http://test.de?"); | ||
var params = { pt: { earliest_departure_time : 123}}; | ||
ghRequest.init(params); | ||
expect(ghRequest.api_params.pt).toBeDefined(); | ||
expect(ghRequest.api_params.pt.earliest_departure_time).toEqual(123); | ||
}); | ||
|
||
it("createPath should work", function () { | ||
var ghRequest = new GHRequest("http://test.de?"); | ||
ghRequest.init({ pt: { earliest_departure_time : 123 }, key: ""}); | ||
expect("&locale=en&vehicle=car&weighting=fastest&key=&pt.earliest_departure_time=123"). | ||
toEqual(ghRequest.createPath("")); | ||
|
||
ghRequest = new GHRequest("http://test.de?"); | ||
ghRequest.api_params.test = {ab: { xy: "12", z: "3"}}; | ||
expect("&locale=en&vehicle=car&weighting=fastest&test.ab.xy=12&test.ab.z=3"). | ||
toEqual(ghRequest.createPath("")); | ||
|
||
ghRequest = new GHRequest("http://test.de?"); | ||
ghRequest.api_params.heading = ["1", "2"]; | ||
expect("&locale=en&vehicle=car&weighting=fastest&heading=1&heading=2"). | ||
toEqual(ghRequest.createPath("")); | ||
|
||
ghRequest = new GHRequest("http://test.de?"); | ||
ghRequest.api_params.xy = { ab : ["1", "2"] }; | ||
expect("&locale=en&vehicle=car&weighting=fastest&xy.ab=1&xy.ab=2"). | ||
toEqual(ghRequest.createPath("")); | ||
}); | ||
}); | ||
|
20 changes: 20 additions & 0 deletions
20
web/src/test/resources/assets/spec/graphhopper/ToolsSpec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var graphhopperTools = requireFile('./graphhopper/tools.js'); | ||
|
||
describe('graphhopper tools', function () { | ||
it("should decode the polyline", function () { | ||
var list = graphhopperTools.decodePath("_p~iF~ps|U", false); | ||
expect(list).toEqual([[-120.2, 38.5]]); | ||
|
||
list = graphhopperTools.decodePath("_p~iF~ps|U_ulLnnqC_mqNvxq`@", false); | ||
expect(list).toEqual([[-120.2, 38.5], [-120.95, 40.7], [-126.45300000000002, 43.252]]); | ||
}); | ||
|
||
it("should decode the 3D polyline", function () { | ||
var list = graphhopperTools.decodePath("_p~iF~ps|Uo}@", true); | ||
expect(list).toEqual([[-120.2, 38.5, 10]]); | ||
|
||
list = graphhopperTools.decodePath("_p~iF~ps|Uo}@_ulLnnqC_anF_mqNvxq`@?", true); | ||
expect(list).toEqual([[-120.2, 38.5, 10], [-120.95, 40.7, 1234], [-126.45300000000002, 43.252, 1234]]); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
global.requireFile = function (name) { | ||
return require('../../../../../main/resources/assets/js/' + name); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"spec_dir": "src/test/resources/assets/spec", | ||
"spec_files": [ | ||
"**/*[sS]pec.js" | ||
], | ||
"helpers": [ | ||
"helpers/**/*.js" | ||
] | ||
} |
110 changes: 110 additions & 0 deletions
110
web/src/test/resources/assets/spec/routeManipulationSpec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Because leaflet-src.js requires window, document, and navigator we need to | ||
// provide these variables. | ||
global.window = { | ||
screen: {} | ||
}; | ||
global.document = { | ||
documentElement: { | ||
style: {} | ||
}, | ||
getElementsByTagName: function() { return []; }, | ||
createElement: function() { return {}; } | ||
}; | ||
global.navigator = { | ||
platform: 'nodejs', | ||
userAgent: 'nodejs' | ||
}; | ||
|
||
var L = require('leaflet'); | ||
var routeManipulation = requireFile('./routeManipulation.js'); | ||
|
||
/*some test data with url parameters: | ||
?point=52.550,13.352&point=52.547,13.358&point=52.541,13.368&point=52.542,13.376&point=52.542,13.383 | ||
&point=52.545,13.391&point=52.542,13.408&point=52.539,13.424&point=52.533,13.441&point=52.527,13.447 | ||
&point=52.533,13.476&point=52.561,13.457&point=52.581,13.397 */ | ||
var a = L.latLng(52.5500, 13.3520); | ||
var x1 = L.latLng(52.5470, 13.3580); | ||
var x2 = L.latLng(52.5410, 13.3680); | ||
var x3 = L.latLng(52.5420, 13.3760); | ||
var b = L.latLng(52.5420, 13.3830); | ||
var x4 = L.latLng(52.5450, 13.3910); | ||
var x5 = L.latLng(52.5420, 13.4080); | ||
var c = L.latLng(52.5390, 13.4240); | ||
var x6 = L.latLng(52.5330, 13.4410); | ||
var x7 = L.latLng(52.5270, 13.4470); | ||
var d = L.latLng(52.5330, 13.4760); | ||
var x8 = L.latLng(52.5610, 13.4570); | ||
var x9 = L.latLng(52.5810, 13.3970); | ||
|
||
var clickLocations = [ | ||
{ latlng: L.latLng(52.567,13.342), expectedIndex: 1}, | ||
{ latlng: L.latLng(52.540,13.378), expectedIndex: 1}, | ||
{ latlng: L.latLng(52.542,13.396), expectedIndex: 2}, | ||
{ latlng: L.latLng(52.526,13.463), expectedIndex: 3}, | ||
{ latlng: L.latLng(52.526,13.519), expectedIndex: 3} | ||
]; | ||
|
||
describe('getIntermediatePointIndex', function () { | ||
it('should work', function () { | ||
var routeSegments = [{ | ||
coordinates: [a, x1, x2, x3, b, x4, x5, c, x6, x7, d], | ||
wayPoints: [a, b, c, d] | ||
}]; | ||
|
||
for(var i=0; i < clickLocations.length; ++i) { | ||
expect(routeManipulation.getIntermediatePointIndex(routeSegments, clickLocations[i].latlng)) | ||
.toEqual(clickLocations[i].expectedIndex); | ||
} | ||
}); | ||
}); | ||
|
||
describe('getIntermediatePointIndex', function () { | ||
it('should work for round trips', function () { | ||
var routeSegments = [{ | ||
coordinates: [a, x1, x2, x3, b, x4, x5, c, x6, x7, d, x8, x9, a], | ||
wayPoints: [a, b, c, d, a] | ||
}]; | ||
|
||
var clickLocation = L.latLng(52.568,13.389); | ||
|
||
expect(routeManipulation.getIntermediatePointIndex(routeSegments, clickLocation)) | ||
.toEqual(4); | ||
}); | ||
}); | ||
|
||
describe('getIntermediaPointIndex', function() { | ||
it('should yield a nice order if some parts of the route are crossed twice', function() { | ||
// let 'a' be chosen as start and end point and 'b' as the first intermediate point. assume | ||
// that the route a->b is (partly) the same as b->a. if we add a second intermediate point | ||
// close to a road that is used on both ways we expect it to be inserted after 'b', | ||
// and not before 'b'. | ||
var routeSegments =[{ | ||
coordinates: [a, x1, x2, x3, b, x3, x2, x1, a], | ||
wayPoints: [a, b, a] | ||
}]; | ||
var clickLocation = L.latLng(52.540,13.376); | ||
expect(routeManipulation.getIntermediatePointIndex(routeSegments, clickLocation)) | ||
.toEqual(2); | ||
}); | ||
}); | ||
|
||
describe('getIntermediatePointIndex', function () { | ||
it('should work when using alternative routes', function () { | ||
var wayPoints = [a, b, c, d]; | ||
var routeSegments = [{ | ||
coordinates: [a, x1, x2, x3, b], | ||
wayPoints: wayPoints | ||
}, { | ||
coordinates: [b, x4, x5, c], | ||
wayPoints: wayPoints | ||
}, { | ||
coordinates: [c, x6, x7, d], | ||
wayPoints: wayPoints | ||
}]; | ||
|
||
for(var i=0; i < clickLocations.length; ++i) { | ||
expect(routeManipulation.getIntermediatePointIndex(routeSegments, clickLocations[i].latlng)) | ||
.toEqual(clickLocations[i].expectedIndex); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var formatTools = requireFile('./tools/format.js'); | ||
|
||
describe('formatTools', function () { | ||
it("should format location entry correctly", function () { | ||
var res = formatTools.formatLocationEntry({ | ||
"state": "Berlin", | ||
"country": "Deutschland", | ||
"country_code": "de", | ||
"continent": "Europäischen Union" | ||
}); | ||
expect(res).toEqual({country: "Deutschland", more: "Berlin, Europäischen Union"}); | ||
|
||
res = formatTools.formatLocationEntry({ | ||
"suburb": "Neukölln", | ||
"city_district": "Neukölln", | ||
"hamlet": "Rixdorf", | ||
"state": "Berlin", | ||
"country": "Deutschland", | ||
"country_code": "de", | ||
"continent": "Europäischen Union" | ||
}); | ||
expect(res).toEqual({city: "Rixdorf, Neukölln", country: "Deutschland", more: "Berlin, Europäischen Union"}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
var urlTools = requireFile('./tools/url.js'); | ||
|
||
describe('urlTools', function () { | ||
it("should parse URL correctly", function () { | ||
var params = urlTools.parseUrl("localhost:8989?test=pest&test2=true&test3=false&test4=2&test5=1.1&test5=2.7"); | ||
expect("pest").toEqual(params.test); | ||
expect(true).toEqual(params.test2); | ||
expect(false).toEqual(params.test3); | ||
expect("2").toEqual(params.test4); | ||
expect(["1.1", "2.7"]).toEqual(params.test5); | ||
|
||
// force array for point | ||
// URLs with one point only should work: https://graphhopper.com/maps/?point=50.413331%2C11.699066 | ||
params = urlTools.parseUrl("blup?point=49.946505%2C11.571232&point=&"); | ||
expect(params.point).toEqual(["49.946505,11.571232", ""]); | ||
|
||
params = urlTools.parseUrl("blup?point=&point=49.946505%2C11.571232"); | ||
expect(params.point).toEqual(["", "49.946505,11.571232"]); | ||
}); | ||
|
||
it("should create array out of point", function () { | ||
var params = urlTools.parseUrl("point=1&point=2"); | ||
expect(["1", "2"]).toEqual(params.point); | ||
|
||
params = urlTools.parseUrl("x=1&x=2"); | ||
expect(["1", "2"]).toEqual(params.x); | ||
}); | ||
|
||
it("should force array for point", function () { | ||
var params = urlTools.mergeParamIntoObject({}, "point", "1"); | ||
expect(["1"]).toEqual(params.point); | ||
|
||
params = urlTools.mergeParamIntoObject(params, "point", "2"); | ||
expect(["1", "2"]).toEqual(params.point); | ||
}) | ||
|
||
it("should create object from dotted URL parameter", function () { | ||
var someObject = urlTools.mergeParamIntoObject({}, "one.two", "12"); | ||
expect("12").toEqual(someObject.one.two); | ||
|
||
someObject = urlTools.mergeParamIntoObject({"one": {"xy": "34"}}, "one.two", "12"); | ||
expect("12").toEqual(someObject.one.two); | ||
expect("34").toEqual(someObject.one.xy); | ||
|
||
someObject = urlTools.mergeParamIntoObject({}, "one.two.three", "123"); | ||
expect("123").toEqual(someObject.one.two.three); | ||
|
||
var params = urlTools.parseUrl("localhost:8989?pt.test=now&pt.go.test=single&pt.go.further=far&pt.go.further=now"); | ||
expect("now").toEqual(params.pt.test); | ||
expect("single").toEqual(params.pt.go.test); | ||
expect(["far", "now"]).toEqual(params.pt.go.further); | ||
|
||
// does not work at the moment: the second parameter is skipped | ||
// params = urlTools.parseUrl("localhost:8989?pt.mix=now&pt.mix.test=now2"); | ||
// expect(["now", {"test" : "now2"}]).toEqual(params.pt.mix); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var vehicle = requireFile('./tools/vehicle.js'); | ||
|
||
describe('vehicle', function () { | ||
it("should sort vehicles and prefer car, foot, bike", function () { | ||
// car, foot and bike should come first. mc comes last | ||
var prefer = {"car": 1, "foot": 2, "bike": 3, "motorcycle": 10000}; | ||
var keys = vehicle.getSortedVehicleKeys({"motorcycle": "blup", "car": "blup", "mtb": "blup", "foot": "blup"}, prefer); | ||
expect(keys).toEqual(["car", "foot", "mtb", "motorcycle"]); | ||
}); | ||
}); |
Oops, something went wrong.