File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 1
1
/* globals describe, expect, it */
2
2
3
- import { getDefaultQuery } from '../../lib/util/state'
3
+ import { getDefaultQuery , queryIsValid } from '../../lib/util/state'
4
4
5
5
describe ( 'util > state' , ( ) => {
6
6
it ( 'getDefaultQuery should parse window hash if available' , ( ) => {
7
7
window . location . hash = '#plan?arriveBy=false&date=2017-02-03&fromPlace=12,34&toPlace=34,12&time=12:34'
8
8
expect ( getDefaultQuery ( ) ) . toMatchSnapshot ( )
9
9
} )
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
+ } )
10
45
} )
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ export { hasValidLocation }
56
56
57
57
function queryIsValid ( otpState ) {
58
58
return hasValidLocation ( otpState , 'from' ) &&
59
- hasValidLocation ( otpState , 'from ' )
59
+ hasValidLocation ( otpState , 'to ' )
60
60
// TODO: add mode validation
61
61
// TODO: add date/time validation
62
62
}
You can’t perform that action at this time.
0 commit comments