Skip to content

Commit f162be7

Browse files
authored
Merge pull request #11 from opentripplanner/dev
0.2.0
2 parents 30ed0a7 + dffd054 commit f162be7

30 files changed

+2342
-1191
lines changed

Diff for: .gitignore

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
# macOS
12
.DS_Store
2-
tmp
3+
4+
# node stuff
35
node_modules
4-
config.yml
56
*.log
7+
8+
# transpiled files
9+
build/*
10+
11+
# testing stuff
12+
tmp
13+
coverage
14+
15+
# secrets
16+
config.yml

Diff for: .travis.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ node_js:
77
- '6'
88
after_success:
99
- npm run semantic-release
10+
before_script:
11+
- yarn global add codecov
1012
script:
11-
- yarn test
13+
- yarn run lint
14+
- yarn run lint-docs
15+
- yarn run cover
16+
- codecov
1217
branches:
1318
except:
1419
- /^v\d+\.\d+\.\d+$/

Diff for: __tests__/actions/__snapshots__/api.js.snap

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`actions > api should make a query to OTP 1`] = `"/api/plan?arriveBy=false&fromPlace=12%2C34&showIntermediateStops=true&toPlace=34%2C12"`;
4+
5+
exports[`actions > api should make a query to OTP 2`] = `
6+
Array [
7+
Array [
8+
Object {
9+
"type": "PLAN_REQUEST",
10+
},
11+
],
12+
Array [
13+
Object {
14+
"payload": Object {
15+
"fake": "response",
16+
},
17+
"type": "PLAN_RESPONSE",
18+
},
19+
],
20+
]
21+
`;

Diff for: __tests__/actions/api.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* globals describe, expect, it, jest */
2+
3+
import nock from 'nock'
4+
5+
import {planTrip} from '../../lib/actions/api'
6+
7+
function timeoutPromise (ms) {
8+
return new Promise((resolve, reject) => {
9+
setTimeout(resolve, ms)
10+
})
11+
}
12+
13+
const planTripAction = planTrip()
14+
15+
describe('actions > api', () => {
16+
it('should make a query to OTP', async () => {
17+
nock('http://mock-host.com')
18+
.get(/api\/plan/)
19+
.reply(200, {
20+
fake: 'response'
21+
})
22+
.on('request', (req, interceptor) => {
23+
expect(req.path).toMatchSnapshot()
24+
})
25+
26+
const mockDispatch = jest.fn()
27+
planTripAction(mockDispatch, () => {
28+
return {
29+
otp: {
30+
config: {
31+
api: {
32+
host: 'http://mock-host.com',
33+
path: '/api',
34+
port: 80
35+
}
36+
},
37+
currentQuery: {
38+
from: {
39+
lat: 12,
40+
lon: 34
41+
},
42+
to: {
43+
lat: 34,
44+
lon: 12
45+
}
46+
},
47+
searches: []
48+
}
49+
}
50+
})
51+
52+
// wait for request to complete
53+
await timeoutPromise(100)
54+
55+
expect(mockDispatch.mock.calls).toMatchSnapshot()
56+
})
57+
})

Diff for: __tests__/util/__snapshots__/state.js.snap

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`util > state getDefaultQuery should parse window hash if available 1`] = `
4+
Object {
5+
"date": "2017-02-03",
6+
"departArrive": "DEPART",
7+
"from": Object {
8+
"lat": "12",
9+
"lon": "34",
10+
"name": "12.00000, 34.00000",
11+
},
12+
"mode": undefined,
13+
"time": "12:34",
14+
"to": Object {
15+
"lat": "34",
16+
"lon": "12",
17+
"name": "34.00000, 12.00000",
18+
},
19+
"type": "ITINERARY",
20+
}
21+
`;

Diff for: __tests__/util/itinerary.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {isTransit} from '../../lib/util/itinerary'
2+
3+
describe('util > itinerary', () => {
4+
it('isTransit should work', () => {
5+
expect(isTransit('CAR')).toBeFalsy()
6+
})
7+
})

Diff for: __tests__/util/state.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* globals describe, expect, it */
2+
3+
import {getDefaultQuery} from '../../lib/util/state'
4+
5+
describe('util > state', () => {
6+
it('getDefaultQuery should parse window hash if available', () => {
7+
window.location.hash = '#plan?arriveBy=false&date=2017-02-03&fromPlace=12,34&toPlace=34,12&time=12:34'
8+
expect(getDefaultQuery()).toMatchSnapshot()
9+
})
10+
})

Diff for: dist/index.css

+58-48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/index.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: example.css

+9
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@
1818
margin: 0px;
1919
padding: 0px;
2020
}
21+
22+
button.header, button.step, .intermediate-stops button {
23+
background: inherit;
24+
color: inherit;
25+
border: 0;
26+
text-align: inherit;
27+
text-decoration: none;
28+
width: 100%;
29+
}

Diff for: lib/actions/api.js

+13-18
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
/* globals fetch */
2+
13
import deepEqual from 'deep-equal'
24
import { createAction } from 'redux-actions'
3-
import fetch from 'isomorphic-fetch'
45
import qs from 'qs'
56

7+
if (typeof (fetch) === 'undefined') {
8+
require('isomorphic-fetch')
9+
}
10+
611
import { hasValidLocation } from '../util/state'
712

813
export const receivedPlanResponse = createAction('PLAN_RESPONSE')
914
export const requestPlanResponse = createAction('PLAN_REQUEST')
1015

11-
export function planTrip () {
16+
export function planTrip (customOtpQueryBuilder) {
1217
return function (dispatch, getState) {
1318
const otpState = getState().otp
1419
const latest = otpState.searches.length && otpState.searches[otpState.searches.length - 1]
@@ -19,7 +24,8 @@ export function planTrip () {
1924
}
2025
if (!hasValidLocation(otpState, 'from') || !hasValidLocation(otpState, 'to')) return // TODO: replace with isQueryValid?
2126
dispatch(requestPlanResponse())
22-
const url = constructPlanQuery(getState().otp.config.api, getState().otp.currentQuery)
27+
const queryBuilderFn = customOtpQueryBuilder || constructPlanQuery
28+
const url = queryBuilderFn(otpState.config.api, otpState.currentQuery)
2329
// setURLSearch(url)
2430
fetch(url)
2531
.then(response => {
@@ -41,24 +47,13 @@ function constructPlanQuery (api, query) {
4147
const planEndpoint = `${api.host}:${api.port}${api.path}/plan`
4248
const { mode, time, date } = query
4349
const params = {
50+
arriveBy: query.departArrive === 'ARRIVE',
51+
date,
4452
fromPlace: `${query.from.lat},${query.from.lon}`,
4553
showIntermediateStops: true,
4654
toPlace: `${query.to.lat},${query.to.lon}`,
47-
mode
48-
}
49-
switch (query.departArrive) {
50-
case 'ARRIVE':
51-
params.arriveBy = true
52-
params.date = date
53-
params.time = time
54-
break
55-
case 'DEPART':
56-
params.arriveBy = false
57-
params.date = date
58-
params.time = time
59-
break
60-
default:
61-
break
55+
mode,
56+
time
6257
}
6358
const stringParams = qs.stringify(params)
6459
// TODO: set url hash based on params

Diff for: lib/components/form/date-time-selector.js

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { connect } from 'react-redux'
77
import { setDepart, setDate, setTime } from '../../actions/form'
88

99
class DateTimeSelector extends Component {
10-
1110
static propTypes = {
1211
location: PropTypes.object,
1312
label: PropTypes.string,

Diff for: lib/components/form/error-message.js

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { connect } from 'react-redux'
44
import { getActiveSearch } from '../../util/state'
55

66
class ErrorMessage extends Component {
7-
87
static propTypes = {
98
itineraries: PropTypes.array
109
}

0 commit comments

Comments
 (0)