aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuc Donnet2018-01-11 11:26:09 +0100
committerGitHub2018-01-11 11:26:09 +0100
commitdec9361ab612597c827e1618998965eb38f41b9b (patch)
tree1dc57b8c1875d77a04c59b13d4c3f06681ec5ed5 /spec
parentf7ed3ca6615bb4950b644d56136016c4482395a8 (diff)
parentc8a2e2ce194d3d051bb96522c40c4d34392bdf8e (diff)
downloadchouette-core-dec9361ab612597c827e1618998965eb38f41b9b.tar.bz2
Merge pull request #225 from af83/5535-compute-vehicle-journeys-times
5535 compute vehicle journeys times
Diffstat (limited to 'spec')
-rw-r--r--spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js112
-rw-r--r--spec/models/chouette/journey_pattern_spec.rb38
-rw-r--r--spec/support/journey_pattern_helper.rb19
3 files changed, 165 insertions, 4 deletions
diff --git a/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js b/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js
index 28de241ee..44e11aadf 100644
--- a/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js
+++ b/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js
@@ -76,12 +76,12 @@ describe('vehicleJourneys reducer', () => {
let pristineVjasList = [{
delta : 0,
arrival_time : {
- hour: '00',
- minute: '00'
+ hour: 0,
+ minute: 0
},
departure_time : {
- hour: '00',
- minute: '00'
+ hour: 0,
+ minute: 0
},
stop_point_objectid: 'test',
stop_area_cityname: 'city',
@@ -119,6 +119,110 @@ describe('vehicleJourneys reducer', () => {
}, ...state])
})
+ it('should handle ADD_VEHICLEJOURNEY with a start time and a fully timed JP', () => {
+ let pristineVjasList = [{
+ delta : 0,
+ arrival_time : {
+ hour: 22,
+ minute: 59
+ },
+ departure_time : {
+ hour: 22,
+ minute: 59
+ },
+ stop_point_objectid: 'test-1',
+ stop_area_cityname: 'city',
+ dummy: true
+ },
+ {
+ delta : 0,
+ arrival_time : {
+ hour: 0,
+ minute: 2
+ },
+ departure_time : {
+ hour: 0,
+ minute: 2
+ },
+ stop_point_objectid: 'test-2',
+ stop_area_cityname: 'city',
+ dummy: true
+ },
+ {
+ delta : 0,
+ arrival_time : {
+ hour: 0,
+ minute: 2
+ },
+ departure_time : {
+ hour: 0,
+ minute: 2
+ },
+ stop_point_objectid: 'test-3',
+ stop_area_cityname: 'city',
+ dummy: true
+ },
+ {
+ delta : 0,
+ arrival_time : {
+ hour: 0,
+ minute: 32
+ },
+ departure_time : {
+ hour: 0,
+ minute: 32
+ },
+ stop_point_objectid: 'test-4',
+ stop_area_cityname: 'city',
+ dummy: true
+ }]
+ let fakeData = {
+ published_journey_name: {value: 'test'},
+ published_journey_identifier: {value : ''},
+ "start_time.hour": {value : '22'},
+ "start_time.minute": {value : '59'}
+ }
+ let fakeSelectedJourneyPattern = {
+ id: "1",
+ full_schedule: true,
+ costs: {
+ "1-2": {
+ distance: 10,
+ time: 63
+ },
+ "2-4": {
+ distance: 10,
+ time: 30
+ }
+ }
+ }
+ let fakeSelectedCompany = {name: "ALBATRANS"}
+ expect(
+ vjReducer(state, {
+ type: 'ADD_VEHICLEJOURNEY',
+ data: fakeData,
+ selectedJourneyPattern: fakeSelectedJourneyPattern,
+ stopPointsList: [{object_id: 'test-1', city_name: 'city', stop_area_id: 1}, {object_id: 'test-2', city_name: 'city', stop_area_id: 2}, {object_id: 'test-3', city_name: 'city', stop_area_id: 3}, {object_id: 'test-4', city_name: 'city', stop_area_id: 4}],
+ selectedCompany: fakeSelectedCompany
+ })
+ ).toEqual([{
+ journey_pattern: fakeSelectedJourneyPattern,
+ company: fakeSelectedCompany,
+ published_journey_name: 'test',
+ published_journey_identifier: '',
+ short_id: '',
+ objectid: '',
+ footnotes: [],
+ time_tables: [],
+ purchase_windows: [],
+ vehicle_journey_at_stops: pristineVjasList,
+ selected: false,
+ deletable: false,
+ transport_mode: 'undefined',
+ transport_submode: 'undefined'
+ }, ...state])
+ })
+
it('should handle RECEIVE_VEHICLE_JOURNEYS', () => {
expect(
vjReducer(state, {
diff --git a/spec/models/chouette/journey_pattern_spec.rb b/spec/models/chouette/journey_pattern_spec.rb
index 077c85e85..b5eb9004c 100644
--- a/spec/models/chouette/journey_pattern_spec.rb
+++ b/spec/models/chouette/journey_pattern_spec.rb
@@ -32,6 +32,44 @@ describe Chouette::JourneyPattern, :type => :model do
# end
# end
+ describe "full_schedule?" do
+ let(:journey_pattern) { create :journey_pattern }
+ subject{ journey_pattern.full_schedule? }
+ context "when no time is set" do
+ it { should be_falsy }
+ end
+
+ context "when the costs are incomplete" do
+ context "with a missing distance" do
+ before(:each){
+ journey_pattern.costs = generate_journey_pattern_costs(->(i){i == 1 ? nil : 10}, 10)
+ }
+ it { should be_falsy }
+ end
+
+ context "with a missing time" do
+ before(:each){
+ journey_pattern.costs = generate_journey_pattern_costs(10, ->(i){i == 1 ? nil : 10})
+ }
+ it { should be_falsy }
+ end
+ end
+
+ context "with a zeroed cost" do
+ before(:each){
+ journey_pattern.costs = generate_journey_pattern_costs(->(i){i == 1 ? 0 : 10}, 10)
+ }
+ it { should be_falsy }
+ end
+
+ context "when all the times are set" do
+ before(:each){
+ journey_pattern.costs = generate_journey_pattern_costs(10, 10)
+ }
+ it { should be_truthy }
+ end
+ end
+
describe "state_update" do
def journey_pattern_to_state jp
jp.attributes.slice('name', 'published_name', 'registration_number').tap do |item|
diff --git a/spec/support/journey_pattern_helper.rb b/spec/support/journey_pattern_helper.rb
new file mode 100644
index 000000000..3ba1c501b
--- /dev/null
+++ b/spec/support/journey_pattern_helper.rb
@@ -0,0 +1,19 @@
+module Support
+ module JourneyPatternHelper
+ def generate_journey_pattern_costs distance, time
+ costs = {}
+ (journey_pattern.stop_points.size - 1).times do |i|
+ start, finish = journey_pattern.stop_points[i..i+1]
+ costs["#{start.stop_area_id}-#{finish.stop_area_id}"] = {
+ distance: (distance.respond_to?(:call) ? distance.call(i) : distance),
+ time: (time.respond_to?(:call) ? time.call(i) : time)
+ }
+ end
+ costs
+ end
+ end
+end
+
+RSpec.configure do | config |
+ config.include Support::JourneyPatternHelper, type: :model
+end