Skip to content

Commit

Permalink
Merge pull request #402 from opentripplanner/dev
Browse files Browse the repository at this point in the history
Release (2021-07)
  • Loading branch information
binh-dam-ibigroup authored Jul 7, 2021
2 parents 3d4386f + fb581ac commit bbfec9f
Show file tree
Hide file tree
Showing 74 changed files with 2,750 additions and 568 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/node-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ jobs:
run: yarn lint
- name: Lint docs
run: yarn lint-docs
- name: Run tests with coverage
run: yarn cover
- name: Run tests
run: yarn jest
- name: Build example project
run: yarn build

# at this point, the build is successful
- name: Codecov
uses: codecov/[email protected]
continue-on-error: true
- name: Semantic Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
11 changes: 10 additions & 1 deletion __tests__/actions/__snapshots__/api.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

exports[`actions > api routingQuery should gracefully handle bad response 1`] = `
Array [
Array [
[Function],
],
Array [
Object {
"payload": Object {
Expand All @@ -16,6 +19,9 @@ Array [
Array [
[Function],
],
Array [
[Function],
],
Array [
Object {
"payload": Object {
Expand All @@ -35,6 +41,9 @@ Array [

exports[`actions > api routingQuery should make a query to OTP 1`] = `
Array [
Array [
[Function],
],
Array [
Object {
"payload": Object {
Expand All @@ -52,4 +61,4 @@ Array [
]
`;

exports[`actions > api routingQuery should make a query to OTP: OTP Query Path 1`] = `"/api/plan?fromPlace=Origin%20%2812%2C34%29%3A%3A12%2C34&toPlace=Destination%20%2834%2C12%29%3A%3A34%2C12&mode=WALK%2CTRANSIT"`;
exports[`actions > api routingQuery should make a query to OTP: OTP Query Path 1`] = `"/api/plan?fromPlace=Origin%20%2812%2C34%29%3A%3A12%2C34&toPlace=Destination%20%2834%2C12%29%3A%3A34%2C12&mode=WALK%2CTRANSIT&ignoreRealtimeUpdates=false"`;
77 changes: 73 additions & 4 deletions __tests__/util/itinerary.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/* globals describe, expect, it */

import { itineraryCanBeMonitored } from '../../lib/util/itinerary'
import {
getItineraryDefaultMonitoredDays,
itineraryCanBeMonitored
} from '../../lib/util/itinerary'
import { WEEKDAYS, WEEKEND_DAYS } from '../../lib/util/monitored-trip'

const walkLeg = {
mode: 'WALK'
}

describe('util > itinerary', () => {
describe('itineraryCanBeMonitored', () => {
Expand All @@ -20,9 +28,6 @@ describe('util > itinerary', () => {
mode: 'MICROMOBILITY_RENT',
rentedVehicle: true
}
const walkLeg = {
mode: 'WALK'
}
const rideHailLeg = {
mode: 'CAR_HAIL',
hailedCar: true
Expand Down Expand Up @@ -80,4 +85,68 @@ describe('util > itinerary', () => {
})
})
})
describe('getItineraryDefaultMonitoredDays', () => {
const transitLegWeekday = {
mode: 'BUS',
serviceDate: '20210609', // Wednesday
transitLeg: true
}
const transitLegSaturday = {
mode: 'BUS',
serviceDate: '20210612', // Saturday
transitLeg: true
}
const transitLegSunday = {
mode: 'BUS',
serviceDate: '20210613', // Sunday
transitLeg: true
}

const testCases = [{
expected: WEEKDAYS,
itinerary: {
legs: [walkLeg, transitLegWeekday]
},
title: 'should be [\'monday\' thru \'friday\'] for an itinerary starting on a weekday.'
}, {
expected: WEEKEND_DAYS,
itinerary: {
legs: [walkLeg, transitLegSaturday]
},
title: 'should be [\'saturday\', \'sunday\'] for an itinerary starting on a Saturday.'
}, {
expected: WEEKEND_DAYS,
itinerary: {
legs: [walkLeg, transitLegSunday]
},
title: 'should be [\'saturday\', \'sunday\'] for an itinerary starting on a Sunday.'
}, {
expected: WEEKDAYS,
itinerary: {
legs: [walkLeg],
startTime: 1623341891000 // Thursday 2021-06-10 12:18 pm EDT
},
title: 'should be [\'monday\' thru \'friday\'] for an itinerary without transit starting on a weekday (fallback case).'
}, {
expected: WEEKEND_DAYS,
itinerary: {
legs: [walkLeg],
startTime: 1623514691000 // Saturday 2021-06-12 12:18 pm EDT
},
title: 'should be [\'saturday\', \'sunday\'] for an itinerary without transit starting on a Saturday (fallback case).'
}, {
expected: WEEKEND_DAYS,
itinerary: {
legs: [walkLeg],
startTime: 1623601091000 // Sunday 2021-06-13 12:18 pm EDT
},
title: 'should be [\'saturday\', \'sunday\'] for an itinerary without transit starting on a Sunday (fallback case).'
}]

testCases.forEach(({ expected, itinerary, title }) => {
it(title, () => {
expect(getItineraryDefaultMonitoredDays(itinerary)).toBe(expected)
})
})
})
})
14 changes: 9 additions & 5 deletions __tests__/util/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ describe('util > state', () => {
const testCases = [{
expected: false,
input: {
currentQuery: {
from: fakeFromLocation
otp: {
currentQuery: {
from: fakeFromLocation
}
}
},
title: 'should not be valid with only from location'
}, {
expected: true,
input: {
currentQuery: {
from: fakeFromLocation,
to: fakeToLocation
otp: {
currentQuery: {
from: fakeFromLocation,
to: fakeToLocation
}
}
},
title: 'should be valid with from and to locations'
Expand Down
51 changes: 51 additions & 0 deletions example-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,31 @@ map:
- name: Stamen Toner Lite
url: http://tile.stamen.com/toner-lite/{z}/{x}/{y}.png
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.'
### Optional transitive.js (route rendering) properties:
### - labeledModes: an array of OTP modes for which the route label should be
### rendered on the map. Example of OTP modes: BUS, RAIL, ...
### The label is rendered under the condition that a route_short_name is provided
### in the GTFS feed for those routes, or that a getTransitiveRouteLabel function is defined
### in the ComponentContext (see example.js for more).
### - styles.labels,
### styles.segment_labels: styles attributes recognized by transitive.js.
### For examples of applicable style attributes, see
### https://github.com/conveyal/transitive.js/blob/master/stories/Transitive.stories.js#L47.
# transitive:
# labeledModes:
# - BUS
# - RAIL
# styles:
# labels:
# font-size: 14px
# font-family: Hind, sans-serif
# segment_labels:
# border-color: "#FFFFFF"
# border-radius: 6
# border-width: 2
# color: "#FFE0D0"
# font-family: Hind, sans-serif
# font-size: 18px

# it is possible to leave out a geocoder config entirely. In that case only
# GPS coordinates will be used when finding the origin/destination.
Expand Down Expand Up @@ -135,6 +160,29 @@ modes:
label: Own Bike
iconWidth: 18

# # The following modules require the datastoreUrl and trinetReDirect properties
# # to be set. Note: Most of these components are currently only configured for
# # TriMet.
# datastoreUrl: https://localhost:9000
# trinetReDirect: https://localhost:9001
# modules:
# # Provides UI elements for Call Takers to record calls/trip queries.
# - id: call
# # Provides UI elements for planning field trips on transit vehicles.
# - id: ft
# # Provides a form for constructing PDF documents for mailing to customers.
# - id: mailables
# items:
# - name: Rte 1 Schedule (1-Vermont)
# largePrint: true
# # The below settings allow for customizing the PDF letter.
# horizontalMargin: 108
# verticalMargin: 120
# introduction: 'Thank you for calling us to request information. We have enclosed for you the following item(s):'
# conclusion: Thank you for your patronage!
# footer: Transit Agency • 555-555-RIDE
# # NOTE: headerGraphic requires a valid URL to a png file.
# headerGraphic: 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/Trimet_logo.svg/1280px-Trimet_logo.svg.png'

routingTypes:
- key: ITINERARY
Expand All @@ -145,6 +193,9 @@ itinerary:
# Show fares for each transit leg (false if omitted).
# (Requires using LineItinerary.)
showRouteFares: false
# Whether the plan first/previous/next/last buttons should be shown along with
# plan trip itineraries.
showPlanFirstLastButtons: false

# The transitOperators key is a list of transit operators that can be used to
# order transit agencies when sorting by route. Also, this can optionally
Expand Down
20 changes: 17 additions & 3 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import {
BatchResultsScreen,
BatchRoutingPanel,
BatchSearchScreen,
CallHistoryWindow,
CallTakerControls,
CallTakerPanel,
CallTakerWindows,
DefaultItinerary,
DefaultMainPanel,
FieldTripWindows,
MailablesWindow,
MobileResultsScreen,
MobileSearchScreen,
ResponsiveWebapp,
Expand Down Expand Up @@ -72,6 +73,7 @@ const TermsOfStorage = () => (
// define some application-wide components that should be used in
// various places. The following components can be provided here:
// - defaultMobileTitle (required)
// - getTransitiveRouteLabel (optional, with signature itineraryLeg => string)
// - ItineraryBody (required)
// - ItineraryFooter (optional)
// - LegIcon (required)
Expand All @@ -84,7 +86,18 @@ const TermsOfStorage = () => (
// - TermsOfService (required if otpConfig.persistence.strategy === 'otp_middleware')
// - TermsOfStorage (required if otpConfig.persistence.strategy === 'otp_middleware')
const components = {

defaultMobileTitle: () => <div className='navbar-title'>OpenTripPlanner</div>,
/**
* Example of a custom route label provider to pass to @opentripplanner/core-utils/map#itineraryToTransitive.
* @param {*} itineraryLeg The OTP itinerary leg for which to obtain a custom route label.
* @returns A string with the custom label to display for the given leg, or null to render no label.
*/
getTransitiveRouteLabel: itineraryLeg => {
if (itineraryLeg.mode === 'RAIL') return 'Train'
if (itineraryLeg.mode === 'BUS') return itineraryLeg.routeShortName
return null // null or undefined or empty string will tell transitive-js to not render a route label.
},
ItineraryBody: DefaultItinerary,
LegIcon: MyLegIcon,
MainControls: isCallTakerModuleEnabled ? CallTakerControls : null,
Expand All @@ -95,8 +108,9 @@ const components = {
: DefaultMainPanel,
MapWindows: isCallTakerModuleEnabled
? () => <>
<CallTakerWindows />
<CallHistoryWindow />
<FieldTripWindows />
<MailablesWindow />
</>
: null,
MobileResultsScreen: isBatchRoutingEnabled
Expand Down Expand Up @@ -124,7 +138,7 @@ if (process.env.NODE_ENV === 'development') {
// set up the Redux store
const store = createStore(
combineReducers({
callTaker: createCallTakerReducer(),
callTaker: createCallTakerReducer(otpConfig),
otp: createOtpReducer(otpConfig),
user: createUserReducer(),
router: connectRouter(history)
Expand Down
Loading

0 comments on commit bbfec9f

Please sign in to comment.