From 913d6935727ace3ac94c08adb4e1ec378741fb19 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 3 Jan 2018 16:31:33 +0100 Subject: Refs #5455 @6h; Add time and distance between stops in Journey Patterns - Adds a `JSON` attribute in the model - Adds the fields in the editor --- spec/javascript/journey_patterns/actions_spec.js | 16 +++++++++ .../reducers/journey_patterns_spec.js | 38 ++++++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) (limited to 'spec/javascript/journey_patterns') diff --git a/spec/javascript/journey_patterns/actions_spec.js b/spec/javascript/journey_patterns/actions_spec.js index 2542fa2f4..60d6d88bb 100644 --- a/spec/javascript/journey_patterns/actions_spec.js +++ b/spec/javascript/journey_patterns/actions_spec.js @@ -112,6 +112,22 @@ describe('when clicking on a journey pattern delete button', () => { expect(actions.deleteJourneyPattern(index)).toEqual(expectedAction) }) }) +describe('when changing on a journey pattern costs', () => { + it('should create an action to update journey pattern', () => { + const index = 1 + const costs = { + "1-2": { + distance: 1 + } + } + const expectedAction = { + type: 'UPDATE_JOURNEYPATTERN_COSTS', + index, + costs + } + expect(actions.updateJourneyPatternCosts(index, costs)).toEqual(expectedAction) + }) +}) describe('when clicking on validate button inside edit modal', () => { it('should create an action to save journey pattern modifications', () => { const index = 1 diff --git a/spec/javascript/journey_patterns/reducers/journey_patterns_spec.js b/spec/javascript/journey_patterns/reducers/journey_patterns_spec.js index 24780ab5a..bfa87d24a 100644 --- a/spec/javascript/journey_patterns/reducers/journey_patterns_spec.js +++ b/spec/javascript/journey_patterns/reducers/journey_patterns_spec.js @@ -47,7 +47,10 @@ describe('journeyPatterns reducer', () => { object_id : 'o1', published_name: 'M1', registration_number: '', - stop_points: fakeStopPoints + stop_points: fakeStopPoints, + costs: { + + } }, { deletable: false, @@ -55,7 +58,13 @@ describe('journeyPatterns reducer', () => { object_id : 'o2', published_name: 'M2', registration_number: '', - stop_points: fakeStopPoints + stop_points: fakeStopPoints, + costs: { + "1-2": { + distance: 0, + time: 10, + } + } } ] }) @@ -83,7 +92,8 @@ describe('journeyPatterns reducer', () => { published_name: 'M3', registration_number: '', deletable: false, - stop_points: stopPoints + stop_points: stopPoints, + costs: {} }, ...state]) }) @@ -100,6 +110,28 @@ describe('journeyPatterns reducer', () => { ).toEqual([newState, state[1]]) }) + it('should handle UPDATE_JOURNEYPATTERN_COSTS', () => { + const costs = { + "1-2": { + distance: 1 + } + } + const new_costs = { + "1-2": { + distance: 1, + time: 10, + } + } + const new_state = Object.assign({}, state[1], {costs: new_costs}) + expect( + jpReducer(state, { + type: 'UPDATE_JOURNEYPATTERN_COSTS', + index: 1, + costs + }) + ).toEqual([state[0], new_state]) + }) + it('should handle DELETE_JOURNEYPATTERN', () => { expect( jpReducer(state, { -- cgit v1.2.3 From d0e51ea2058163b76863797a4e337ba3f5d6611d Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 10 Jan 2018 10:08:34 +0100 Subject: Refs #5437 @0.5h; Propagate behaviour to the JourneyPatterns editor --- .../components/JourneyPatterns_spec.js | 77 ++++++++++ .../__snapshots__/JourneyPatterns_spec.js.snap | 169 +++++++++++++++++++++ 2 files changed, 246 insertions(+) create mode 100644 spec/javascript/journey_patterns/components/JourneyPatterns_spec.js create mode 100644 spec/javascript/journey_patterns/components/__snapshots__/JourneyPatterns_spec.js.snap (limited to 'spec/javascript/journey_patterns') diff --git a/spec/javascript/journey_patterns/components/JourneyPatterns_spec.js b/spec/javascript/journey_patterns/components/JourneyPatterns_spec.js new file mode 100644 index 000000000..0c852deff --- /dev/null +++ b/spec/javascript/journey_patterns/components/JourneyPatterns_spec.js @@ -0,0 +1,77 @@ +import React, { Component } from 'react' +import JourneyPatterns from '../../../../app/javascript/journey_patterns/components/JourneyPatterns' +import renderer from 'react-test-renderer' + +describe('stopPointHeader', () => { + set('features', () => { + return {} + }) + set('component', () => { + let props = { + status: { + features: features + }, + onCheckboxChange: ()=>{}, + onLoadFirstPage: ()=>{}, + onOpenEditModal: ()=>{}, + stopPointsList: [stop_point, same_city_stop_point, other_country_stop_point], + journeyPatterns: [] + } + let list = renderer.create( + + ).toJSON() + + return list + }) + + set('stop_point', () => { + return { + name: "Stop point", + city_name: "City Name", + zip_code: "12345", + country_code: "FR", + country_name: "france", + object_id: "sp-FR" + } + }) + + set('same_city_stop_point', () => { + return { + name: "Antother stop point", + city_name: stop_point.city_name, + zip_code: stop_point.zip_code, + country_code: stop_point.country_code, + country_name: stop_point.country_name, + object_id: stop_point.object_id + "-2" + } + }) + + set('other_country_stop_point', () => { + return { + name: "Antother stop point", + city_name: "New York", + zip_code: "232323", + country_code: "US", + country_name: "USA", + object_id: "sp-USA" + } + }) + it('should display the city name', () => { + expect(component).toMatchSnapshot() + }) + context('with the "long_distance_routes" feature', () => { + set('features', () => { + return { long_distance_routes: true } + }) + it('should display the country name', () => { + expect(component).toMatchSnapshot() + }) + }) +}) diff --git a/spec/javascript/journey_patterns/components/__snapshots__/JourneyPatterns_spec.js.snap b/spec/javascript/journey_patterns/components/__snapshots__/JourneyPatterns_spec.js.snap new file mode 100644 index 000000000..90b8cb656 --- /dev/null +++ b/spec/javascript/journey_patterns/components/__snapshots__/JourneyPatterns_spec.js.snap @@ -0,0 +1,169 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`stopPointHeader should display the city name 1`] = ` +
+
+
+
+
+
+ ID Mission +
+
+ Code mission +
+
+ Nb arrêts +
+
+
+
+ + + Stop point + + +
+
+
+
+ + + Antother stop point + + +
+
+
+
+ + + Antother stop point + + +
+
+
+
+
+
+
+
+
+`; + +exports[`stopPointHeader with the "long_distance_routes" feature should display the country name 1`] = ` +
+
+
+
+
+
+ ID Mission +
+
+ Code mission +
+
+ Nb arrêts +
+
+
+
+ + + Stop point + + +
+
+
+
+ + + Antother stop point + + +
+
+
+
+ + + Antother stop point + + +
+
+
+
+
+
+
+
+
+`; -- cgit v1.2.3 From aaa9ee2fabe87209df028bb225339108bf389f64 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 10 Jan 2018 10:47:23 +0100 Subject: Refs #5437 @1h; Refactor code --- .../components/__snapshots__/JourneyPatterns_spec.js.snap | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/javascript/journey_patterns') diff --git a/spec/javascript/journey_patterns/components/__snapshots__/JourneyPatterns_spec.js.snap b/spec/javascript/journey_patterns/components/__snapshots__/JourneyPatterns_spec.js.snap index 90b8cb656..a332e7d80 100644 --- a/spec/javascript/journey_patterns/components/__snapshots__/JourneyPatterns_spec.js.snap +++ b/spec/javascript/journey_patterns/components/__snapshots__/JourneyPatterns_spec.js.snap @@ -47,8 +47,8 @@ exports[`stopPointHeader should display the city name 1`] = ` className="td" >
@@ -63,7 +63,7 @@ exports[`stopPointHeader should display the city name 1`] = ` >
@@ -131,8 +131,8 @@ exports[`stopPointHeader with the "long_distance_routes" feature should display className="td" >
@@ -147,7 +147,7 @@ exports[`stopPointHeader with the "long_distance_routes" feature should display >
-- cgit v1.2.3 From bee0dd605e416833c680bdc9fafefbb5c1392ff6 Mon Sep 17 00:00:00 2001 From: Zog Date: Thu, 25 Jan 2018 12:43:56 +0100 Subject: Refs #5598 @1h; Add specs --- .../components/JourneyPattern_spec.js | 63 +++++++++ .../__snapshots__/JourneyPattern_spec.js.snap | 143 +++++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 spec/javascript/journey_patterns/components/JourneyPattern_spec.js create mode 100644 spec/javascript/journey_patterns/components/__snapshots__/JourneyPattern_spec.js.snap (limited to 'spec/javascript/journey_patterns') diff --git a/spec/javascript/journey_patterns/components/JourneyPattern_spec.js b/spec/javascript/journey_patterns/components/JourneyPattern_spec.js new file mode 100644 index 000000000..0da75ad47 --- /dev/null +++ b/spec/javascript/journey_patterns/components/JourneyPattern_spec.js @@ -0,0 +1,63 @@ +import React, { Component } from 'react' +import JourneyPattern from '../../../../app/javascript/journey_patterns/components/JourneyPattern' +import renderer from 'react-test-renderer' + +describe('the edit button', () => { + set('policy', () => { + return {} + }) + set('features', () => { + return [] + }) + set('editMode', () => { + return false + }) + set('component', () => { + let props = { + status: { + policy: policy, + features: features + }, + onCheckboxChange: ()=>{}, + onDeleteJourneyPattern: ()=>{}, + onOpenEditModal: ()=>{}, + journeyPatterns: {}, + value: { + stop_points: [] + }, + index: 0, + editMode: editMode + } + let list = renderer.create( + + ) + + return list + }) + + + it('should display the show link', () => { + expect(component.toJSON()).toMatchSnapshot() + expect(component.root.findByProps({"data-target": "#JourneyPatternModal"})._fiber.stateNode.children[0].text).toEqual("Consulter") + }) + + context('in edit mode', () => { + set('editMode', () => { + return true + }) + + it('should display the edit link', () => { + expect(component.toJSON()).toMatchSnapshot() + expect(component.root.findByProps({"data-target": "#JourneyPatternModal"})._fiber.stateNode.children[0].text).toEqual("Editer") + }) + }) +}) diff --git a/spec/javascript/journey_patterns/components/__snapshots__/JourneyPattern_spec.js.snap b/spec/javascript/journey_patterns/components/__snapshots__/JourneyPattern_spec.js.snap new file mode 100644 index 000000000..0bedd8d69 --- /dev/null +++ b/spec/javascript/journey_patterns/components/__snapshots__/JourneyPattern_spec.js.snap @@ -0,0 +1,143 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`the edit button in edit mode should display the edit link 1`] = ` +
+
+
+ - +
+
+
+ 0 + arrêt(s) +
+
+
+ +
+ +
+
+
+`; + +exports[`the edit button should display the show link 1`] = ` +
+
+
+ - +
+
+
+ 0 + arrêt(s) +
+
+
+ +
+ +
+
+
+`; -- cgit v1.2.3