@opentripplanner/core-utils
Advanced tools
Comparing version 2.1.1 to 2.1.2
@@ -9,23 +9,2 @@ "use strict"; | ||
afterEach(_time.restoreDateNowBehavior); | ||
describe("planParamsToQuery", () => { | ||
it("should parse a depart at query", async () => { | ||
expect(await (0, _query.planParamsToQuery)({ | ||
arriveBy: "false", | ||
bannedRoutes: "897ABC", | ||
companies: "", | ||
date: "2019-10-31", | ||
fromPlace: "Guide Dogs for the Blind, Portland, OR, USA::45.517373,-122.675601", | ||
ignoreRealtimeUpdates: "true", | ||
maxWalkDistance: "1207", | ||
mode: "BUS,TRAM,RAIL,GONDOLA,WALK", | ||
optimize: "QUICK", | ||
showIntermediateStops: "true", | ||
time: "17:45", | ||
toPlace: "Weather Machine, Portland, OR, USA::45.519015,-122.679321", | ||
ui_activeItinerary: "0", | ||
ui_activeSearch: "irc7h4rb8", | ||
walkSpeed: "1.34" | ||
})).toMatchSnapshot(); | ||
}); | ||
}); | ||
describe("getDefaultQuery", () => { | ||
@@ -37,2 +16,52 @@ it("should return default query", () => { | ||
}); | ||
describe("getRoutingParams", () => { | ||
// the config isn't actually used except for some wheelchair check, so it is | ||
// ok to send an empty object for most tests | ||
const fakeConfig = {}; | ||
const makeBaseTestQuery = () => ({ ...(0, _query.getDefaultQuery)(), | ||
date: "2020-08-24", | ||
from: { | ||
lat: 36.95471026341096, | ||
lon: -122.0248185852425, | ||
name: "Steamer Lane, Santa Cruz, CA, 95060, USA" | ||
}, | ||
time: "21:53", | ||
to: { | ||
lat: 36.961843106786766, | ||
lon: -122.02402657342725, | ||
name: "Municipal Wharf St, Santa Cruz, CA, 95060, USA" | ||
} | ||
}); | ||
it("should create routing params for transit query", () => { | ||
expect((0, _query.getRoutingParams)(fakeConfig, makeBaseTestQuery())).toMatchSnapshot(); | ||
}); | ||
it("should create routing params for car rental query", () => { | ||
expect((0, _query.getRoutingParams)(fakeConfig, { ...makeBaseTestQuery(), | ||
companies: "FAKECOMPANY", | ||
mode: "CAR_RENT,BUS" | ||
})).toMatchSnapshot(); | ||
}); | ||
it("should create routing params for personal micromobility query", () => { | ||
expect((0, _query.getRoutingParams)(fakeConfig, { ...makeBaseTestQuery(), | ||
companies: "FAKECOMPANY", | ||
mode: "MICROMOBILITY,BUS", | ||
watts: 250 | ||
})).toMatchSnapshot(); | ||
}); | ||
it("should create routing params for intermediate places query", () => { | ||
expect((0, _query.getRoutingParams)(fakeConfig, { ...makeBaseTestQuery(), | ||
intermediatePlaces: [{ | ||
lat: 36.95145225211049, | ||
lon: -122.02672866668283, | ||
name: "Lighthouse Point Park, Santa Cruz, CA, USA" | ||
}, { | ||
lat: 36.95028619314903, | ||
lon: -122.05711810284686, | ||
name: "Natural Bridges State Beach, 2531 W Cliff Dr, Santa Cruz, CA, 95060, USA" | ||
}] | ||
})).toMatchSnapshot(); | ||
}); | ||
}); | ||
describe("parseLocationString", () => { | ||
@@ -49,2 +78,30 @@ it("should return null for null input", () => { | ||
}); | ||
describe("planParamsToQuery", () => { | ||
const makeBaseTestQuery = () => ({ | ||
arriveBy: "false", | ||
bannedRoutes: "897ABC", | ||
companies: "", | ||
date: "2019-10-31", | ||
fromPlace: "Guide Dogs for the Blind, Portland, OR, USA::45.517373,-122.675601", | ||
ignoreRealtimeUpdates: "true", | ||
maxWalkDistance: "1207", | ||
mode: "BUS,TRAM,RAIL,GONDOLA,WALK", | ||
optimize: "QUICK", | ||
showIntermediateStops: "true", | ||
time: "17:45", | ||
toPlace: "Weather Machine, Portland, OR, USA::45.519015,-122.679321", | ||
ui_activeItinerary: "0", | ||
ui_activeSearch: "irc7h4rb8", | ||
walkSpeed: "1.34" | ||
}); | ||
it("should parse a depart at query", () => { | ||
expect((0, _query.planParamsToQuery)(makeBaseTestQuery())).toMatchSnapshot(); | ||
}); | ||
it("should parse a query with intermediate places", () => { | ||
expect((0, _query.planParamsToQuery)({ ...makeBaseTestQuery(), | ||
intermediatePlaces: ["Mill Ends Park, Downtown - Portland::45.516202,-122.673247", "International Rose Test Garden, Portland::45.519094,-122.705692"] | ||
})).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
@@ -547,3 +547,3 @@ "use strict"; | ||
itineraryRewrite: places => Array.isArray(places) && places.length > 0 ? { | ||
intermediatePlaces: places.map(place => formatPlace(place)).join(",") | ||
intermediatePlaces: places.map(place => formatPlace(place)) | ||
} : undefined | ||
@@ -550,0 +550,0 @@ }, { |
@@ -263,3 +263,3 @@ "use strict"; | ||
// as locations. | ||
query.intermediatePlaces = params.intermediatePlaces ? params.intermediatePlaces.split(",").map(parseLocationString) : []; | ||
query.intermediatePlaces = params.intermediatePlaces ? params.intermediatePlaces.map(parseLocationString) : []; | ||
break; | ||
@@ -266,0 +266,0 @@ |
{ | ||
"name": "@opentripplanner/core-utils", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "Core functionality that is shared among numerous UI components", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -8,2 +8,3 @@ import { | ||
getDefaultQuery, | ||
getRoutingParams, | ||
parseLocationString, | ||
@@ -16,32 +17,75 @@ planParamsToQuery | ||
describe("planParamsToQuery", () => { | ||
it("should parse a depart at query", async () => { | ||
describe("getDefaultQuery", () => { | ||
it("should return default query", () => { | ||
setDefaultTestTime(); | ||
expect(getDefaultQuery()).toMatchSnapshot(); | ||
}); | ||
}); | ||
describe("getRoutingParams", () => { | ||
// the config isn't actually used except for some wheelchair check, so it is | ||
// ok to send an empty object for most tests | ||
const fakeConfig = {}; | ||
const makeBaseTestQuery = () => ({ | ||
...getDefaultQuery(), | ||
date: "2020-08-24", | ||
from: { | ||
lat: 36.95471026341096, | ||
lon: -122.0248185852425, | ||
name: "Steamer Lane, Santa Cruz, CA, 95060, USA" | ||
}, | ||
time: "21:53", | ||
to: { | ||
lat: 36.961843106786766, | ||
lon: -122.02402657342725, | ||
name: "Municipal Wharf St, Santa Cruz, CA, 95060, USA" | ||
} | ||
}); | ||
it("should create routing params for transit query", () => { | ||
expect( | ||
await planParamsToQuery({ | ||
arriveBy: "false", | ||
bannedRoutes: "897ABC", | ||
companies: "", | ||
date: "2019-10-31", | ||
fromPlace: | ||
"Guide Dogs for the Blind, Portland, OR, USA::45.517373,-122.675601", | ||
ignoreRealtimeUpdates: "true", | ||
maxWalkDistance: "1207", | ||
mode: "BUS,TRAM,RAIL,GONDOLA,WALK", | ||
optimize: "QUICK", | ||
showIntermediateStops: "true", | ||
time: "17:45", | ||
toPlace: "Weather Machine, Portland, OR, USA::45.519015,-122.679321", | ||
ui_activeItinerary: "0", | ||
ui_activeSearch: "irc7h4rb8", | ||
walkSpeed: "1.34" | ||
getRoutingParams(fakeConfig, makeBaseTestQuery()) | ||
).toMatchSnapshot(); | ||
}); | ||
it("should create routing params for car rental query", () => { | ||
expect( | ||
getRoutingParams(fakeConfig, { | ||
...makeBaseTestQuery(), | ||
companies: "FAKECOMPANY", | ||
mode: "CAR_RENT,BUS" | ||
}) | ||
).toMatchSnapshot(); | ||
}); | ||
}); | ||
describe("getDefaultQuery", () => { | ||
it("should return default query", () => { | ||
setDefaultTestTime(); | ||
expect(getDefaultQuery()).toMatchSnapshot(); | ||
it("should create routing params for personal micromobility query", () => { | ||
expect( | ||
getRoutingParams(fakeConfig, { | ||
...makeBaseTestQuery(), | ||
companies: "FAKECOMPANY", | ||
mode: "MICROMOBILITY,BUS", | ||
watts: 250 | ||
}) | ||
).toMatchSnapshot(); | ||
}); | ||
it("should create routing params for intermediate places query", () => { | ||
expect( | ||
getRoutingParams(fakeConfig, { | ||
...makeBaseTestQuery(), | ||
intermediatePlaces: [ | ||
{ | ||
lat: 36.95145225211049, | ||
lon: -122.02672866668283, | ||
name: "Lighthouse Point Park, Santa Cruz, CA, USA" | ||
}, | ||
{ | ||
lat: 36.95028619314903, | ||
lon: -122.05711810284686, | ||
name: | ||
"Natural Bridges State Beach, 2531 W Cliff Dr, Santa Cruz, CA, 95060, USA" | ||
} | ||
] | ||
}) | ||
).toMatchSnapshot(); | ||
}); | ||
}); | ||
@@ -66,2 +110,39 @@ | ||
}); | ||
describe("planParamsToQuery", () => { | ||
const makeBaseTestQuery = () => ({ | ||
arriveBy: "false", | ||
bannedRoutes: "897ABC", | ||
companies: "", | ||
date: "2019-10-31", | ||
fromPlace: | ||
"Guide Dogs for the Blind, Portland, OR, USA::45.517373,-122.675601", | ||
ignoreRealtimeUpdates: "true", | ||
maxWalkDistance: "1207", | ||
mode: "BUS,TRAM,RAIL,GONDOLA,WALK", | ||
optimize: "QUICK", | ||
showIntermediateStops: "true", | ||
time: "17:45", | ||
toPlace: "Weather Machine, Portland, OR, USA::45.519015,-122.679321", | ||
ui_activeItinerary: "0", | ||
ui_activeSearch: "irc7h4rb8", | ||
walkSpeed: "1.34" | ||
}); | ||
it("should parse a depart at query", () => { | ||
expect(planParamsToQuery(makeBaseTestQuery())).toMatchSnapshot(); | ||
}); | ||
it("should parse a query with intermediate places", () => { | ||
expect( | ||
planParamsToQuery({ | ||
...makeBaseTestQuery(), | ||
intermediatePlaces: [ | ||
"Mill Ends Park, Downtown - Portland::45.516202,-122.673247", | ||
"International Rose Test Garden, Portland::45.519094,-122.705692" | ||
] | ||
}) | ||
).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
@@ -642,5 +642,3 @@ import { | ||
? { | ||
intermediatePlaces: places | ||
.map(place => formatPlace(place)) | ||
.join(",") | ||
intermediatePlaces: places.map(place => formatPlace(place)) | ||
} | ||
@@ -647,0 +645,0 @@ : undefined |
@@ -274,3 +274,3 @@ import moment from "moment"; | ||
query.intermediatePlaces = params.intermediatePlaces | ||
? params.intermediatePlaces.split(",").map(parseLocationString) | ||
? params.intermediatePlaces.map(parseLocationString) | ||
: []; | ||
@@ -277,0 +277,0 @@ break; |
Sorry, the diff of this file is not supported yet
235742
6391