Skip to content

Commit 5f3382a

Browse files
committed
fix(util): fix queryIsValid check
also add test case for this function
1 parent dffd054 commit 5f3382a

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

__tests__/util/state.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,45 @@
11
/* globals describe, expect, it */
22

3-
import {getDefaultQuery} from '../../lib/util/state'
3+
import {getDefaultQuery, queryIsValid} from '../../lib/util/state'
44

55
describe('util > state', () => {
66
it('getDefaultQuery should parse window hash if available', () => {
77
window.location.hash = '#plan?arriveBy=false&date=2017-02-03&fromPlace=12,34&toPlace=34,12&time=12:34'
88
expect(getDefaultQuery()).toMatchSnapshot()
99
})
10+
11+
describe('queryIsValid', () => {
12+
const fakeFromLocation = {
13+
lat: 12,
14+
lon: 34
15+
}
16+
const fakeToLocation = {
17+
lat: 34,
18+
lon: 12
19+
}
20+
const testCases = [{
21+
expected: false,
22+
input: {
23+
currentQuery: {
24+
from: fakeFromLocation
25+
}
26+
},
27+
title: 'should not be valid with only from location'
28+
}, {
29+
expected: true,
30+
input: {
31+
currentQuery: {
32+
from: fakeFromLocation,
33+
to: fakeToLocation
34+
}
35+
},
36+
title: 'should be valid with from and to locations'
37+
}]
38+
39+
testCases.forEach((testCase) => {
40+
it(testCase.title, () => {
41+
expect(queryIsValid(testCase.input))[testCase.expected ? 'toBeTruthy' : 'toBeFalsy']()
42+
})
43+
})
44+
})
1045
})

lib/util/state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export { hasValidLocation }
5656

5757
function queryIsValid (otpState) {
5858
return hasValidLocation(otpState, 'from') &&
59-
hasValidLocation(otpState, 'from')
59+
hasValidLocation(otpState, 'to')
6060
// TODO: add mode validation
6161
// TODO: add date/time validation
6262
}

0 commit comments

Comments
 (0)