|
| 1 | +// @flow |
| 2 | + |
| 3 | +import clone from 'lodash/cloneDeep' |
| 4 | + |
| 5 | +import {sortAndFilterTrips} from '../' |
| 6 | +import {expectArrayToMatchContents} from '../../../../__tests__/test-utils' |
| 7 | +import {mockTripWithoutStopTimes} from '../../../mock-data' |
| 8 | + |
| 9 | +describe('editor > util > index', () => { |
| 10 | + describe('sortAndFilterTrips', () => { |
| 11 | + it('should sort trips where there are no stop times', () => { |
| 12 | + const mockTrips = [ |
| 13 | + clone(mockTripWithoutStopTimes), |
| 14 | + clone(mockTripWithoutStopTimes) |
| 15 | + ] |
| 16 | + mockTrips[0].id = 2 |
| 17 | + mockTrips[0].tripId = 'test-trip-id-2' |
| 18 | + expectArrayToMatchContents( |
| 19 | + sortAndFilterTrips(mockTrips, undefined) |
| 20 | + .map(trip => trip.tripId), |
| 21 | + ['test-trip-id-2', 'test-trip-id-1'] |
| 22 | + ) |
| 23 | + }) |
| 24 | + |
| 25 | + it('should sort trips where one of the trips has no stop times', () => { |
| 26 | + const mockTrips = [ |
| 27 | + clone(mockTripWithoutStopTimes), |
| 28 | + clone(mockTripWithoutStopTimes) |
| 29 | + ] |
| 30 | + mockTrips[0].id = 2 |
| 31 | + mockTrips[0].tripId = 'test-trip-id-2' |
| 32 | + mockTrips[0].stopTimes.push({ |
| 33 | + arrivalTime: 12345, |
| 34 | + departureTime: 12345, |
| 35 | + id: 1, |
| 36 | + shape_dist_traveled: 0, |
| 37 | + stopHeadsign: '', |
| 38 | + stopId: '1', |
| 39 | + stopSequence: 1 |
| 40 | + }) |
| 41 | + expectArrayToMatchContents( |
| 42 | + sortAndFilterTrips(mockTrips, undefined) |
| 43 | + .map(trip => trip.tripId), |
| 44 | + ['test-trip-id-1', 'test-trip-id-2'] |
| 45 | + ) |
| 46 | + }) |
| 47 | + |
| 48 | + it('should sort trips where both of the trips have stop times', () => { |
| 49 | + const mockTrips = [ |
| 50 | + clone(mockTripWithoutStopTimes), |
| 51 | + clone(mockTripWithoutStopTimes) |
| 52 | + ] |
| 53 | + mockTrips[0].id = 2 |
| 54 | + mockTrips[0].tripId = 'test-trip-id-2' |
| 55 | + mockTrips[0].stopTimes.push({ |
| 56 | + arrivalTime: 12345, |
| 57 | + departureTime: 12345, |
| 58 | + id: 1, |
| 59 | + shape_dist_traveled: 0, |
| 60 | + stopHeadsign: '', |
| 61 | + stopId: '1', |
| 62 | + stopSequence: 1 |
| 63 | + }) |
| 64 | + mockTrips[1].stopTimes.push({ |
| 65 | + arrivalTime: 45678, |
| 66 | + departureTime: 45678, |
| 67 | + id: 1, |
| 68 | + shape_dist_traveled: 0, |
| 69 | + stopHeadsign: '', |
| 70 | + stopId: '1', |
| 71 | + stopSequence: 1 |
| 72 | + }) |
| 73 | + expectArrayToMatchContents( |
| 74 | + sortAndFilterTrips(mockTrips, undefined) |
| 75 | + .map(trip => trip.tripId), |
| 76 | + ['test-trip-id-2', 'test-trip-id-1'] |
| 77 | + ) |
| 78 | + }) |
| 79 | + }) |
| 80 | +}) |
0 commit comments