From bf7e7b9db4261aed7eb317ffb28c1652eaba5a18 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Mon, 14 Nov 2016 14:49:53 +0100 Subject: Add Teaspoon / Phantomjs & action tests Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/actions_spec.js | 52 ++++++++++++++++++++++++++++++++++++++++ spec/javascripts/spec_helper.js | 32 +++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 spec/javascripts/actions_spec.js create mode 100644 spec/javascripts/spec_helper.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/actions_spec.js b/spec/javascripts/actions_spec.js new file mode 100644 index 000000000..43ebba77f --- /dev/null +++ b/spec/javascripts/actions_spec.js @@ -0,0 +1,52 @@ +var actions = require('es6_browserified/actions') + +describe('actions', () => { + it('should create an action to add a stop', () => { + const expectedAction = { + type: 'ADD_STOP', + } + expect(actions.addStop()).toEqual(expectedAction) + }) +}) +describe('actions', () => { + it('should create an action to move up a stop', () => { + const index = 1 + const expectedAction = { + type: 'MOVE_STOP_UP', + index + } + expect(actions.moveStopUp(index)).toEqual(expectedAction) + }) +}) +describe('actions', () => { + it('should create an action to add a stop', () => { + const index = 1 + const expectedAction = { + type: 'MOVE_STOP_DOWN', + index + } + expect(actions.moveStopDown(index)).toEqual(expectedAction) + }) +}) +describe('actions', () => { + it('should create an action to add a stop', () => { + const index = 1 + const expectedAction = { + type: 'DELETE_STOP', + index + } + expect(actions.deleteStop(index)).toEqual(expectedAction) + }) +}) +describe('actions', () => { + it('should create an action to add a stop', () => { + const text = 'updated text' + const index = 1 + const expectedAction = { + type: 'UPDATE_INPUT_VALUE', + index, + text + } + expect(actions.updateInputValue(index, text)).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/spec_helper.js b/spec/javascripts/spec_helper.js new file mode 100644 index 000000000..71d30ff8d --- /dev/null +++ b/spec/javascripts/spec_helper.js @@ -0,0 +1,32 @@ +// Teaspoon includes some support files, but you can use anything from your own support path too. +// require support/jasmine-jquery-1.7.0 +// require support/jasmine-jquery-2.0.0 +// require support/jasmine-jquery-2.1.0 +// require support/sinon +// require support/your-support-file +// +// PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion. +// Use this polyfill to avoid the confusion. +//= require support/phantomjs-shims +// +// You can require your own javascript files here. By default this will include everything in application, however you +// may get better load performance if you require the specific files that are being used in the spec that tests them. +//= require application +// +// Deferring execution +// If you're using CommonJS, RequireJS or some other asynchronous library you can defer execution. Call +// Teaspoon.execute() after everything has been loaded. Simple example of a timeout: +// +// Teaspoon.defer = true +// setTimeout(Teaspoon.execute, 1000) +// +// Matching files +// By default Teaspoon will look for files that match _spec.{js,js.coffee,.coffee}. Add a filename_spec.js file in your +// spec path and it'll be included in the default suite automatically. If you want to customize suites, check out the +// configuration in teaspoon_env.rb +// +// Manifest +// If you'd rather require your spec files manually (to control order for instance) you can disable the suite matcher in +// the configuration and use this file as a manifest. +// +// For more information: http://github.com/modeset/teaspoon -- cgit v1.2.3 From a98e911bb6f60b9414b9608e1fcd61561f033d0a Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 15 Nov 2016 17:53:46 +0100 Subject: Add for_boarding and for_alighting attributes for stop_points Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/actions_spec.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/actions_spec.js b/spec/javascripts/actions_spec.js index 43ebba77f..55de1c31f 100644 --- a/spec/javascripts/actions_spec.js +++ b/spec/javascripts/actions_spec.js @@ -19,7 +19,7 @@ describe('actions', () => { }) }) describe('actions', () => { - it('should create an action to add a stop', () => { + it('should create an action to move down a stop', () => { const index = 1 const expectedAction = { type: 'MOVE_STOP_DOWN', @@ -29,7 +29,7 @@ describe('actions', () => { }) }) describe('actions', () => { - it('should create an action to add a stop', () => { + it('should create an action to delete a stop', () => { const index = 1 const expectedAction = { type: 'DELETE_STOP', @@ -39,7 +39,7 @@ describe('actions', () => { }) }) describe('actions', () => { - it('should create an action to add a stop', () => { + it('should create an action to update the value of a stop', () => { const text = 'updated text' const index = 1 const expectedAction = { @@ -50,3 +50,22 @@ describe('actions', () => { expect(actions.updateInputValue(index, text)).toEqual(expectedAction) }) }) + +describe('actions', () => { + it('should create an action to update the up select of a stop', () => { + const event = { + currentTarget: { + value: 'forbidden', + id: 'up' + } + } + const index = 1 + const expectedAction = { + type :'UPDATE_SELECT_VALUE', + select_id: 'up', + select_value: 'forbidden', + index + } + expect(actions.updateSelectValue(event, index)).toEqual(expectedAction) + }) +}) -- cgit v1.2.3 From 3fb20fcc5ca5c39fae2c793e822eac1a2b2f6cb7 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Thu, 17 Nov 2016 17:42:29 +0100 Subject: Add reducers tests, some skipped until better es6 support while testing Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/reducers_spec.js | 178 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 spec/javascripts/reducers_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/reducers_spec.js b/spec/javascripts/reducers_spec.js new file mode 100644 index 000000000..a4880e73e --- /dev/null +++ b/spec/javascripts/reducers_spec.js @@ -0,0 +1,178 @@ +var reducer = require('es6_browserified/reducers/todos') +let state = [] +describe('stops reducer', () => { + beforeEach(()=>{ + state = [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + }) + + it('should return the initial state', () => { + expect( + reducer(undefined, {}) + ).toEqual([]) + }) + + it('should handle ADD_STOP', () => { + expect( + reducer(state, { + type: 'ADD_STOP' + }) + ).toEqual( + [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: '', + index: 2, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) + + it('should handle MOVE_UP_STOP', () => { + expect( + reducer(state, { + type: 'MOVE_STOP_UP', + index: 1 + }) + ).toEqual( + [ + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) + + it('should handle MOVE_DOWN_STOP', () => { + expect( + reducer(state, { + type: 'MOVE_STOP_DOWN', + index: 0 + }) + ).toEqual( + [ + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) + + it('should handle DELETE_STOP', () => { + expect( + reducer(state, { + type: 'DELETE_STOP', + index: 1 + }) + ).toEqual( + [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) + + //TODO unskip when es6 is properly functionnal + xit('should handle UPDATE_INPUT_VALUE', () => { + expect( + reducer(state, { + type: 'UPDATE_INPUT_VALUE', + index: 0, + text: { + text: "new value", + stoparea_id: 1 + } + }) + ).toEqual( + [ + { + text: 'new value', + index: 0, + stoparea_id: 1, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) + + xit('should handle UPDATE_SELECT_VALUE', () => { + expect( + reducer(state, { + type :'UPDATE_SELECT_VALUE', + select_id: 'for_boarding', + select_value: 'prohibited', + index: 0 + }) + ).toEqual( + [ + { + text: 'new value', + index: 0, + stoparea_id: 1, + for_boarding: 'prohibited', + for_alighting: 'normal' + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) +}) -- cgit v1.2.3 From 5376439a212f9e4a912c0d9520c4b3c9e7ef8f88 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 29 Nov 2016 12:06:43 +0100 Subject: Fix reducers specs with local dependency Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/components_spec.js | 40 +++++++++++++++++++++++++++++++++++++ spec/javascripts/reducers_spec.js | 7 +++---- spec/javascripts/spec_helper.js | 1 + 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 spec/javascripts/components_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/components_spec.js b/spec/javascripts/components_spec.js new file mode 100644 index 000000000..fc99a3335 --- /dev/null +++ b/spec/javascripts/components_spec.js @@ -0,0 +1,40 @@ +var React = require('react'); +var Provider = require('react-redux').Provider; +var actions = require('es6_browserified/actions/index'); +var App = require('es6_browserified/components/TodoList'); +var ConnectedApp = require('es6_browserified/containers/VisibleTodoList'); +var TestUtils = require('react-addons-test-utils'); + +xdescribe('ConnectedApp', function() { + var connectedApp, store, initialItems; + var state; + state = [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + + beforeEach(function() { + store = state + }); + + describe('state provided by the store', function() { + beforeEach(function() { + connectedApp = TestUtils.renderIntoDocument(); + }); + + it('passes down items', function() { + app = TestUtils.findRenderedComponentWithType(connectedApp, App); + expect(app.props.items).toEqual(initialItems); + }); + }); +}); diff --git a/spec/javascripts/reducers_spec.js b/spec/javascripts/reducers_spec.js index a4880e73e..985bdc220 100644 --- a/spec/javascripts/reducers_spec.js +++ b/spec/javascripts/reducers_spec.js @@ -120,7 +120,7 @@ describe('stops reducer', () => { }) //TODO unskip when es6 is properly functionnal - xit('should handle UPDATE_INPUT_VALUE', () => { + it('should handle UPDATE_INPUT_VALUE', () => { expect( reducer(state, { type: 'UPDATE_INPUT_VALUE', @@ -149,7 +149,7 @@ describe('stops reducer', () => { ) }) - xit('should handle UPDATE_SELECT_VALUE', () => { + it('should handle UPDATE_SELECT_VALUE', () => { expect( reducer(state, { type :'UPDATE_SELECT_VALUE', @@ -160,9 +160,8 @@ describe('stops reducer', () => { ).toEqual( [ { - text: 'new value', + text: 'first', index: 0, - stoparea_id: 1, for_boarding: 'prohibited', for_alighting: 'normal' }, diff --git a/spec/javascripts/spec_helper.js b/spec/javascripts/spec_helper.js index 71d30ff8d..a2fde3860 100644 --- a/spec/javascripts/spec_helper.js +++ b/spec/javascripts/spec_helper.js @@ -4,6 +4,7 @@ // require support/jasmine-jquery-2.1.0 // require support/sinon // require support/your-support-file +require('es6-object-assign').polyfill(); // // PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion. // Use this polyfill to avoid the confusion. -- cgit v1.2.3 From 724690ea7d1bf4c0f8fd2c57dd0636fee3c6574f Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 30 Nov 2016 16:56:11 +0100 Subject: Fix split itineraries and journey patterns for better understanding Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/actions_spec.js | 2 +- spec/javascripts/components_spec.js | 6 +++--- spec/javascripts/reducers_spec.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/actions_spec.js b/spec/javascripts/actions_spec.js index 55de1c31f..f86466375 100644 --- a/spec/javascripts/actions_spec.js +++ b/spec/javascripts/actions_spec.js @@ -1,4 +1,4 @@ -var actions = require('es6_browserified/actions') +var actions = require('es6_browserified/itineraries/actions') describe('actions', () => { it('should create an action to add a stop', () => { diff --git a/spec/javascripts/components_spec.js b/spec/javascripts/components_spec.js index fc99a3335..c7e541783 100644 --- a/spec/javascripts/components_spec.js +++ b/spec/javascripts/components_spec.js @@ -1,8 +1,8 @@ var React = require('react'); var Provider = require('react-redux').Provider; -var actions = require('es6_browserified/actions/index'); -var App = require('es6_browserified/components/TodoList'); -var ConnectedApp = require('es6_browserified/containers/VisibleTodoList'); +var actions = require('es6_browserified/itineraries/actions/index'); +var App = require('es6_browserified/itineraries/components/TodoList'); +var ConnectedApp = require('es6_browserified/itineraries/containers/VisibleTodoList'); var TestUtils = require('react-addons-test-utils'); xdescribe('ConnectedApp', function() { diff --git a/spec/javascripts/reducers_spec.js b/spec/javascripts/reducers_spec.js index 985bdc220..253229dda 100644 --- a/spec/javascripts/reducers_spec.js +++ b/spec/javascripts/reducers_spec.js @@ -1,4 +1,4 @@ -var reducer = require('es6_browserified/reducers/todos') +var reducer = require('es6_browserified/itineraries/reducers/todos') let state = [] describe('stops reducer', () => { beforeEach(()=>{ -- cgit v1.2.3 From c6f48a35ca41da95de0e3e10b893c297016ae8e7 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 6 Jan 2017 11:35:22 +0100 Subject: Move specs to separate directories Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/actions_spec.js | 71 -------- spec/javascripts/components_spec.js | 40 ----- spec/javascripts/itineraries/actions_spec.js | 71 ++++++++ spec/javascripts/itineraries/components_spec.js | 40 +++++ spec/javascripts/itineraries/reducers_spec.js | 178 +++++++++++++++++++++ spec/javascripts/journey_patterns/actions_spec.js | 0 spec/javascripts/journey_patterns/reducers_spec.js | 0 spec/javascripts/reducers_spec.js | 177 -------------------- 8 files changed, 289 insertions(+), 288 deletions(-) delete mode 100644 spec/javascripts/actions_spec.js delete mode 100644 spec/javascripts/components_spec.js create mode 100644 spec/javascripts/itineraries/actions_spec.js create mode 100644 spec/javascripts/itineraries/components_spec.js create mode 100644 spec/javascripts/itineraries/reducers_spec.js create mode 100644 spec/javascripts/journey_patterns/actions_spec.js create mode 100644 spec/javascripts/journey_patterns/reducers_spec.js delete mode 100644 spec/javascripts/reducers_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/actions_spec.js b/spec/javascripts/actions_spec.js deleted file mode 100644 index f86466375..000000000 --- a/spec/javascripts/actions_spec.js +++ /dev/null @@ -1,71 +0,0 @@ -var actions = require('es6_browserified/itineraries/actions') - -describe('actions', () => { - it('should create an action to add a stop', () => { - const expectedAction = { - type: 'ADD_STOP', - } - expect(actions.addStop()).toEqual(expectedAction) - }) -}) -describe('actions', () => { - it('should create an action to move up a stop', () => { - const index = 1 - const expectedAction = { - type: 'MOVE_STOP_UP', - index - } - expect(actions.moveStopUp(index)).toEqual(expectedAction) - }) -}) -describe('actions', () => { - it('should create an action to move down a stop', () => { - const index = 1 - const expectedAction = { - type: 'MOVE_STOP_DOWN', - index - } - expect(actions.moveStopDown(index)).toEqual(expectedAction) - }) -}) -describe('actions', () => { - it('should create an action to delete a stop', () => { - const index = 1 - const expectedAction = { - type: 'DELETE_STOP', - index - } - expect(actions.deleteStop(index)).toEqual(expectedAction) - }) -}) -describe('actions', () => { - it('should create an action to update the value of a stop', () => { - const text = 'updated text' - const index = 1 - const expectedAction = { - type: 'UPDATE_INPUT_VALUE', - index, - text - } - expect(actions.updateInputValue(index, text)).toEqual(expectedAction) - }) -}) - -describe('actions', () => { - it('should create an action to update the up select of a stop', () => { - const event = { - currentTarget: { - value: 'forbidden', - id: 'up' - } - } - const index = 1 - const expectedAction = { - type :'UPDATE_SELECT_VALUE', - select_id: 'up', - select_value: 'forbidden', - index - } - expect(actions.updateSelectValue(event, index)).toEqual(expectedAction) - }) -}) diff --git a/spec/javascripts/components_spec.js b/spec/javascripts/components_spec.js deleted file mode 100644 index c7e541783..000000000 --- a/spec/javascripts/components_spec.js +++ /dev/null @@ -1,40 +0,0 @@ -var React = require('react'); -var Provider = require('react-redux').Provider; -var actions = require('es6_browserified/itineraries/actions/index'); -var App = require('es6_browserified/itineraries/components/TodoList'); -var ConnectedApp = require('es6_browserified/itineraries/containers/VisibleTodoList'); -var TestUtils = require('react-addons-test-utils'); - -xdescribe('ConnectedApp', function() { - var connectedApp, store, initialItems; - var state; - state = [ - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - - beforeEach(function() { - store = state - }); - - describe('state provided by the store', function() { - beforeEach(function() { - connectedApp = TestUtils.renderIntoDocument(); - }); - - it('passes down items', function() { - app = TestUtils.findRenderedComponentWithType(connectedApp, App); - expect(app.props.items).toEqual(initialItems); - }); - }); -}); diff --git a/spec/javascripts/itineraries/actions_spec.js b/spec/javascripts/itineraries/actions_spec.js new file mode 100644 index 000000000..f86466375 --- /dev/null +++ b/spec/javascripts/itineraries/actions_spec.js @@ -0,0 +1,71 @@ +var actions = require('es6_browserified/itineraries/actions') + +describe('actions', () => { + it('should create an action to add a stop', () => { + const expectedAction = { + type: 'ADD_STOP', + } + expect(actions.addStop()).toEqual(expectedAction) + }) +}) +describe('actions', () => { + it('should create an action to move up a stop', () => { + const index = 1 + const expectedAction = { + type: 'MOVE_STOP_UP', + index + } + expect(actions.moveStopUp(index)).toEqual(expectedAction) + }) +}) +describe('actions', () => { + it('should create an action to move down a stop', () => { + const index = 1 + const expectedAction = { + type: 'MOVE_STOP_DOWN', + index + } + expect(actions.moveStopDown(index)).toEqual(expectedAction) + }) +}) +describe('actions', () => { + it('should create an action to delete a stop', () => { + const index = 1 + const expectedAction = { + type: 'DELETE_STOP', + index + } + expect(actions.deleteStop(index)).toEqual(expectedAction) + }) +}) +describe('actions', () => { + it('should create an action to update the value of a stop', () => { + const text = 'updated text' + const index = 1 + const expectedAction = { + type: 'UPDATE_INPUT_VALUE', + index, + text + } + expect(actions.updateInputValue(index, text)).toEqual(expectedAction) + }) +}) + +describe('actions', () => { + it('should create an action to update the up select of a stop', () => { + const event = { + currentTarget: { + value: 'forbidden', + id: 'up' + } + } + const index = 1 + const expectedAction = { + type :'UPDATE_SELECT_VALUE', + select_id: 'up', + select_value: 'forbidden', + index + } + expect(actions.updateSelectValue(event, index)).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/itineraries/components_spec.js b/spec/javascripts/itineraries/components_spec.js new file mode 100644 index 000000000..c7e541783 --- /dev/null +++ b/spec/javascripts/itineraries/components_spec.js @@ -0,0 +1,40 @@ +var React = require('react'); +var Provider = require('react-redux').Provider; +var actions = require('es6_browserified/itineraries/actions/index'); +var App = require('es6_browserified/itineraries/components/TodoList'); +var ConnectedApp = require('es6_browserified/itineraries/containers/VisibleTodoList'); +var TestUtils = require('react-addons-test-utils'); + +xdescribe('ConnectedApp', function() { + var connectedApp, store, initialItems; + var state; + state = [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + + beforeEach(function() { + store = state + }); + + describe('state provided by the store', function() { + beforeEach(function() { + connectedApp = TestUtils.renderIntoDocument(); + }); + + it('passes down items', function() { + app = TestUtils.findRenderedComponentWithType(connectedApp, App); + expect(app.props.items).toEqual(initialItems); + }); + }); +}); diff --git a/spec/javascripts/itineraries/reducers_spec.js b/spec/javascripts/itineraries/reducers_spec.js new file mode 100644 index 000000000..d77500d3e --- /dev/null +++ b/spec/javascripts/itineraries/reducers_spec.js @@ -0,0 +1,178 @@ +var reducer = require('es6_browserified/itineraries/reducers/todos') +let state = [] +describe('stops reducer', () => { + beforeEach(()=>{ + state = [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + }) + + it('should return the initial state', () => { + expect( + reducer(undefined, {}) + ).toEqual([]) + }) + + it('should handle ADD_STOP', () => { + expect( + reducer(state, { + type: 'ADD_STOP' + }) + ).toEqual( + [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: '', + index: 2, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) + + it('should handle MOVE_UP_STOP', () => { + expect( + reducer(state, { + type: 'MOVE_STOP_UP', + index: 1 + }) + ).toEqual( + [ + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) + + it('should handle MOVE_DOWN_STOP', () => { + expect( + reducer(state, { + type: 'MOVE_STOP_DOWN', + index: 0 + }) + ).toEqual( + [ + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) + + it('should handle DELETE_STOP', () => { + expect( + reducer(state, { + type: 'DELETE_STOP', + index: 1 + }) + ).toEqual( + [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) + + //TODO unskip when es6 is properly functionnal + it('should handle UPDATE_INPUT_VALUE', () => { + expect( + reducer(state, { + type: 'UPDATE_INPUT_VALUE', + index: 0, + text: { + text: "new value", + stoparea_id: 1 + } + }) + ).toEqual( + [ + { + text: 'new value', + index: 0, + stoppoint_id: '', + stoparea_id: 1, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) + + it('should handle UPDATE_SELECT_VALUE', () => { + expect( + reducer(state, { + type :'UPDATE_SELECT_VALUE', + select_id: 'for_boarding', + select_value: 'prohibited', + index: 0 + }) + ).toEqual( + [ + { + text: 'first', + index: 0, + for_boarding: 'prohibited', + for_alighting: 'normal' + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) +}) diff --git a/spec/javascripts/journey_patterns/actions_spec.js b/spec/javascripts/journey_patterns/actions_spec.js new file mode 100644 index 000000000..e69de29bb diff --git a/spec/javascripts/journey_patterns/reducers_spec.js b/spec/javascripts/journey_patterns/reducers_spec.js new file mode 100644 index 000000000..e69de29bb diff --git a/spec/javascripts/reducers_spec.js b/spec/javascripts/reducers_spec.js deleted file mode 100644 index 253229dda..000000000 --- a/spec/javascripts/reducers_spec.js +++ /dev/null @@ -1,177 +0,0 @@ -var reducer = require('es6_browserified/itineraries/reducers/todos') -let state = [] -describe('stops reducer', () => { - beforeEach(()=>{ - state = [ - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - }) - - it('should return the initial state', () => { - expect( - reducer(undefined, {}) - ).toEqual([]) - }) - - it('should handle ADD_STOP', () => { - expect( - reducer(state, { - type: 'ADD_STOP' - }) - ).toEqual( - [ - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: '', - index: 2, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) - - it('should handle MOVE_UP_STOP', () => { - expect( - reducer(state, { - type: 'MOVE_STOP_UP', - index: 1 - }) - ).toEqual( - [ - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) - - it('should handle MOVE_DOWN_STOP', () => { - expect( - reducer(state, { - type: 'MOVE_STOP_DOWN', - index: 0 - }) - ).toEqual( - [ - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) - - it('should handle DELETE_STOP', () => { - expect( - reducer(state, { - type: 'DELETE_STOP', - index: 1 - }) - ).toEqual( - [ - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) - - //TODO unskip when es6 is properly functionnal - it('should handle UPDATE_INPUT_VALUE', () => { - expect( - reducer(state, { - type: 'UPDATE_INPUT_VALUE', - index: 0, - text: { - text: "new value", - stoparea_id: 1 - } - }) - ).toEqual( - [ - { - text: 'new value', - index: 0, - stoparea_id: 1, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) - - it('should handle UPDATE_SELECT_VALUE', () => { - expect( - reducer(state, { - type :'UPDATE_SELECT_VALUE', - select_id: 'for_boarding', - select_value: 'prohibited', - index: 0 - }) - ).toEqual( - [ - { - text: 'first', - index: 0, - for_boarding: 'prohibited', - for_alighting: 'normal' - }, - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) -}) -- cgit v1.2.3 From 9a24c7534e9bf8236cf978a837b9051d4af1ee77 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 6 Jan 2017 11:40:03 +0100 Subject: Fix itineraries reducer spec now receiving proper user_objectid Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/itineraries/reducers_spec.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/itineraries/reducers_spec.js b/spec/javascripts/itineraries/reducers_spec.js index d77500d3e..a8731af5f 100644 --- a/spec/javascripts/itineraries/reducers_spec.js +++ b/spec/javascripts/itineraries/reducers_spec.js @@ -119,7 +119,6 @@ describe('stops reducer', () => { ) }) - //TODO unskip when es6 is properly functionnal it('should handle UPDATE_INPUT_VALUE', () => { expect( reducer(state, { @@ -127,7 +126,8 @@ describe('stops reducer', () => { index: 0, text: { text: "new value", - stoparea_id: 1 + stoparea_id: 1, + user_objectid: "1234" } }) ).toEqual( @@ -138,7 +138,8 @@ describe('stops reducer', () => { stoppoint_id: '', stoparea_id: 1, for_boarding: 'normal', - for_alighting: 'normal' + for_alighting: 'normal', + user_objectid: "1234" }, { text: 'second', -- cgit v1.2.3 From 7fe26f12de9a7d1d03e7f0fa4a6372eb987ba97f Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 6 Jan 2017 14:52:51 +0100 Subject: Add journeypatterns actions spec Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/journey_patterns/actions_spec.js | 135 ++++++++++++++++++++++ 1 file changed, 135 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/actions_spec.js b/spec/javascripts/journey_patterns/actions_spec.js index e69de29bb..6c23b722c 100644 --- a/spec/javascripts/journey_patterns/actions_spec.js +++ b/spec/javascripts/journey_patterns/actions_spec.js @@ -0,0 +1,135 @@ +var actions = require('es6_browserified/journey_patterns/actions') + +const dispatch = function(){} +const currentPage = 1 + +describe('when receiveJourneyPatterns is triggered', () => { + it('should create an action to pass json to reducer', () => { + const json = undefined + const expectedAction = { + type: 'RECEIVE_JOURNEY_PATTERNS', + json + } + expect(actions.receiveJourneyPatterns()).toEqual(expectedAction) + }) +}) + +describe('when landing on page', () => { + it('should create an action to load the n first missions', () => { + const expectedAction = { + type: 'LOAD_FIRST_PAGE', + dispatch + } + expect(actions.loadFirstPage(dispatch)).toEqual(expectedAction) + }) +}) +describe('when next navigation button is clicked', () => { + it('should create an action to go to next page', () => { + const nextPage = true + const expectedAction = { + type: 'GO_TO_NEXT_PAGE', + dispatch, + currentPage, + nextPage + } + expect(actions.goToNextPage(dispatch, currentPage)).toEqual(expectedAction) + }) +}) +describe('when clicking on a journey pattern checkbox', () => { + it('should create an action to update journey pattern stop points', () => { + const event = { + currentTarget: { + id: '1' + } + } + const index = 1 + const expectedAction = { + type: 'UPDATE_CHECKBOX_VALUE', + id: event.currentTarget.id, + index, + } + expect(actions.updateCheckboxValue(event, index)).toEqual(expectedAction) + }) +}) +describe('when clicking on next button', () => { + it('should create an action to open a confirm modal', () => { + const accept = {}, cancel = {} + const expectedAction = { + type: 'OPEN_CONFIRM_MODAL', + accept, + cancel, + } + expect(actions.openConfirmModal(accept, cancel)).toEqual(expectedAction) + }) +}) +describe('when clicking on edit button', () => { + it('should create an action to open a edit modal', () => { + const index = 1 + const journeyPattern = {} + const expectedAction = { + type: 'EDIT_JOURNEYPATTERN_MODAL', + index, + journeyPattern, + } + expect(actions.openEditModal(index, journeyPattern)).toEqual(expectedAction) + }) +}) +describe('when clicking on add button', () => { + it('should create an action to open a create modal', () => { + const expectedAction = { + type: 'CREATE_JOURNEYPATTERN_MODAL', + } + expect(actions.openCreateModal()).toEqual(expectedAction) + }) +}) +describe('when clicking on close button inside edit or add modal', () => { + it('should create an action to close modal', () => { + const expectedAction = { + type: 'CLOSE_MODAL', + } + expect(actions.closeModal()).toEqual(expectedAction) + }) +}) +describe('when clicking on a journey pattern delete button', () => { + it('should create an action to delete journey pattern', () => { + const index = 1 + const journeyPattern = {} + const expectedAction = { + type: 'DELETE_JOURNEYPATTERN', + index, + journeyPattern + } + expect(actions.deleteJourneyPattern(index, journeyPattern)).toEqual(expectedAction) + }) +}) +describe('when clicking on validate button inside edit modal', () => { + it('should create an action to save journey pattern modifications', () => { + const index = 1 + const data = {} + const expectedAction = { + type: 'SAVE_MODAL', + index, + data + } + expect(actions.saveModal(index, data)).toEqual(expectedAction) + }) +}) +describe('when clicking on validate button inside create modal', () => { + it('should create an action to create a new journey pattern', () => { + const data = {} + const expectedAction = { + type: 'ADD_JOURNEYPATTERN', + data + } + expect(actions.addJourneyPattern(data)).toEqual(expectedAction) + }) +}) +describe('when clicking on validate button at the bottom of the page', () => { + it('should create an action to post data and save it into db', () => { + const expectedAction = { + type: 'SAVE_PAGE', + dispatch + } + expect(actions.savePage(dispatch)).toEqual(expectedAction) + }) +}) -- cgit v1.2.3 From 41ad9d403a69bf36a01a7c61df1a08c0e41a6284 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 6 Jan 2017 16:13:55 +0100 Subject: Add first reducer spec and fix journeyPatterns initial state Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/journey_patterns/reducers_spec.js | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/reducers_spec.js b/spec/javascripts/journey_patterns/reducers_spec.js index e69de29bb..ba519dcf4 100644 --- a/spec/javascripts/journey_patterns/reducers_spec.js +++ b/spec/javascripts/journey_patterns/reducers_spec.js @@ -0,0 +1,63 @@ +var jpReducer = require('es6_browserified/journey_patterns/reducers/journeyPatterns') +let state = [] +describe('journeyPatterns reducer', () => { + beforeEach(()=>{ + state = [ + { + deletable: false, + name: 'm1', + object_id : 'o1', + published_name: 'M1', + registration_number: '', + stop_points: [{ + area_type : "lda", + checked : false, + id : 45289, + name : "Clichy Levallois", + object_id : "FR:92044:LDA:72073:STIF", + object_version : 1, + position : 0, + },{ + area_type : "lda", + checked : false, + id : 40534, + name : "Thomas Lemaître", + object_id : "FR:92050:LDA:70915:STIF", + object_version : 1, + position : 1, + }] + }, + { + deletable: false, + name: 'm2', + object_id : 'o2', + published_name: 'M2', + registration_number: '', + stop_points: [{ + area_type : "lda", + checked : false, + id : 45289, + name : "Clichy Levallois", + object_id : "FR:92044:LDA:72073:STIF", + object_version : 1, + position : 0, + },{ + area_type : "lda", + checked : false, + id : 40534, + name : "Thomas Lemaître", + object_id : "FR:92050:LDA:70915:STIF", + object_version : 1, + position : 1, + }] + }, + ] + }) + + it('should return the initial state', () => { + expect( + jpReducer(undefined, {}) + ).toEqual([]) + }) + +}) -- cgit v1.2.3 From b6cd50e722136033c0e579ebfadd855d5fe7de7d Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 6 Jan 2017 16:54:00 +0100 Subject: Remove unused argument in deleteJourneyPattern Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/journey_patterns/actions_spec.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/actions_spec.js b/spec/javascripts/journey_patterns/actions_spec.js index 6c23b722c..ced053935 100644 --- a/spec/javascripts/journey_patterns/actions_spec.js +++ b/spec/javascripts/journey_patterns/actions_spec.js @@ -93,13 +93,11 @@ describe('when clicking on close button inside edit or add modal', () => { describe('when clicking on a journey pattern delete button', () => { it('should create an action to delete journey pattern', () => { const index = 1 - const journeyPattern = {} const expectedAction = { type: 'DELETE_JOURNEYPATTERN', - index, - journeyPattern + index } - expect(actions.deleteJourneyPattern(index, journeyPattern)).toEqual(expectedAction) + expect(actions.deleteJourneyPattern(index)).toEqual(expectedAction) }) }) describe('when clicking on validate button inside edit modal', () => { -- cgit v1.2.3 From 1636f74a4cd87cacd8c95be22ec767da6bc5db3f Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 6 Jan 2017 18:07:02 +0100 Subject: Add journey patterns reducers specs and switch from toString to String method when updating checkbox value Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/journey_patterns/reducers_spec.js | 111 ++++++++++++++------- 1 file changed, 76 insertions(+), 35 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/reducers_spec.js b/spec/javascripts/journey_patterns/reducers_spec.js index ba519dcf4..422c97fee 100644 --- a/spec/javascripts/journey_patterns/reducers_spec.js +++ b/spec/javascripts/journey_patterns/reducers_spec.js @@ -1,5 +1,23 @@ var jpReducer = require('es6_browserified/journey_patterns/reducers/journeyPatterns') let state = [] +let fakeStopPoints = [{ + area_type : "lda", + checked : false, + id : 45289, + name : "Clichy Levallois", + object_id : "FR:92044:LDA:72073:STIF", + object_version : 1, + position : 0, +},{ + area_type : "lda", + checked : false, + id : 40534, + name : "Thomas Lemaître", + object_id : "FR:92050:LDA:70915:STIF", + object_version : 1, + position : 1, +}] + describe('journeyPatterns reducer', () => { beforeEach(()=>{ state = [ @@ -9,23 +27,7 @@ describe('journeyPatterns reducer', () => { object_id : 'o1', published_name: 'M1', registration_number: '', - stop_points: [{ - area_type : "lda", - checked : false, - id : 45289, - name : "Clichy Levallois", - object_id : "FR:92044:LDA:72073:STIF", - object_version : 1, - position : 0, - },{ - area_type : "lda", - checked : false, - id : 40534, - name : "Thomas Lemaître", - object_id : "FR:92050:LDA:70915:STIF", - object_version : 1, - position : 1, - }] + stop_points: fakeStopPoints }, { deletable: false, @@ -33,24 +35,8 @@ describe('journeyPatterns reducer', () => { object_id : 'o2', published_name: 'M2', registration_number: '', - stop_points: [{ - area_type : "lda", - checked : false, - id : 45289, - name : "Clichy Levallois", - object_id : "FR:92044:LDA:72073:STIF", - object_version : 1, - position : 0, - },{ - area_type : "lda", - checked : false, - id : 40534, - name : "Thomas Lemaître", - object_id : "FR:92050:LDA:70915:STIF", - object_version : 1, - position : 1, - }] - }, + stop_points: fakeStopPoints + } ] }) @@ -60,4 +46,59 @@ describe('journeyPatterns reducer', () => { ).toEqual([]) }) + it('should handle ADD_JOURNEYPATTERN', () => { + let fakeData = { + name: {value : 'm3'}, + published_name: {value: 'M3'}, + registration_number: {value: ''} + } + expect( + jpReducer(state, { + type: 'ADD_JOURNEYPATTERN', + data: fakeData + }) + ).toEqual([...state, { + name : 'm3', + published_name: 'M3', + registration_number: '', + deletable: false, + stop_points: fakeStopPoints + }]) + }) + + it('should handle UPDATE_CHECKBOX_VALUE', () => { + let newFirstStopPoint = Object.assign({}, fakeStopPoints[0], {checked: !fakeStopPoints[0].checked} ) + let newStopPoints = [newFirstStopPoint, fakeStopPoints[1]] + let newState = Object.assign({}, state[0], {stop_points: newStopPoints}) + expect( + jpReducer(state, { + type: 'UPDATE_CHECKBOX_VALUE', + id: 45289, + index: 0 + }) + ).toEqual([newState, state[1]]) + }) + + it('should handle DELETE_JOURNEYPATTERN', () => { + expect( + jpReducer(state, { + type: 'DELETE_JOURNEYPATTERN', + index: 1 + }) + ).toEqual([state[0], Object.assign({}, state[1], {deletable: true})]) + }) + it('should handle SAVE_MODAL', () => { + let newState = Object.assign({}, state[0], {name: 'p1', published_name: 'P1', registration_number: 'PP11'}) + expect( + jpReducer(state, { + type: 'SAVE_MODAL', + data: { + name: {value: 'p1'}, + published_name: {value: 'P1'}, + registration_number: {value: 'PP11'} + }, + index: 0 + }) + ).toEqual([newState, state[1]]) + }) }) -- cgit v1.2.3 From d594a4e6fffaaf163af3a27dc8e76f0b27eb7379 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Mon, 9 Jan 2017 10:46:30 +0100 Subject: Fix comment component spec for now Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/itineraries/components_spec.js | 72 ++++++++++++------------- 1 file changed, 36 insertions(+), 36 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/itineraries/components_spec.js b/spec/javascripts/itineraries/components_spec.js index c7e541783..c9c57b5eb 100644 --- a/spec/javascripts/itineraries/components_spec.js +++ b/spec/javascripts/itineraries/components_spec.js @@ -1,40 +1,40 @@ -var React = require('react'); -var Provider = require('react-redux').Provider; -var actions = require('es6_browserified/itineraries/actions/index'); -var App = require('es6_browserified/itineraries/components/TodoList'); -var ConnectedApp = require('es6_browserified/itineraries/containers/VisibleTodoList'); -var TestUtils = require('react-addons-test-utils'); +// var React = require('react'); +// var Provider = require('react-redux').Provider; +// var actions = require('es6_browserified/itineraries/actions/index'); +// var App = require('es6_browserified/itineraries/components/TodoList'); +// var ConnectedApp = require('es6_browserified/itineraries/containers/VisibleTodoList'); +// var TestUtils = require('react-addons-test-utils'); -xdescribe('ConnectedApp', function() { - var connectedApp, store, initialItems; - var state; - state = [ - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] +// xdescribe('ConnectedApp', function() { +// var connectedApp, store, initialItems; +// var state; +// state = [ +// { +// text: 'first', +// index: 0, +// for_boarding: 'normal', +// for_alighting: 'normal' +// }, +// { +// text: 'second', +// index: 1, +// for_boarding: 'normal', +// for_alighting: 'normal' +// } +// ] - beforeEach(function() { - store = state - }); +// beforeEach(function() { +// store = state +// }); - describe('state provided by the store', function() { - beforeEach(function() { - connectedApp = TestUtils.renderIntoDocument(); - }); +// describe('state provided by the store', function() { +// beforeEach(function() { +// connectedApp = TestUtils.renderIntoDocument(); +// }); - it('passes down items', function() { - app = TestUtils.findRenderedComponentWithType(connectedApp, App); - expect(app.props.items).toEqual(initialItems); - }); - }); -}); +// it('passes down items', function() { +// app = TestUtils.findRenderedComponentWithType(connectedApp, App); +// expect(app.props.items).toEqual(initialItems); +// }); +// }); +// }); -- cgit v1.2.3 From 7b57387a03a5f100320f91d7c8cb25e29d126815 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Mon, 9 Jan 2017 11:39:36 +0100 Subject: Add pagination spec and move totalCount into pagination for further and easier updates Signed-off-by: Thomas Shawarma Haddad --- .../reducers/journey_patterns_spec.js | 104 +++++++++++++++++++++ .../journey_patterns/reducers/pagination_spec.js | 77 +++++++++++++++ spec/javascripts/journey_patterns/reducers_spec.js | 104 --------------------- 3 files changed, 181 insertions(+), 104 deletions(-) create mode 100644 spec/javascripts/journey_patterns/reducers/journey_patterns_spec.js create mode 100644 spec/javascripts/journey_patterns/reducers/pagination_spec.js delete mode 100644 spec/javascripts/journey_patterns/reducers_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/reducers/journey_patterns_spec.js b/spec/javascripts/journey_patterns/reducers/journey_patterns_spec.js new file mode 100644 index 000000000..422c97fee --- /dev/null +++ b/spec/javascripts/journey_patterns/reducers/journey_patterns_spec.js @@ -0,0 +1,104 @@ +var jpReducer = require('es6_browserified/journey_patterns/reducers/journeyPatterns') +let state = [] +let fakeStopPoints = [{ + area_type : "lda", + checked : false, + id : 45289, + name : "Clichy Levallois", + object_id : "FR:92044:LDA:72073:STIF", + object_version : 1, + position : 0, +},{ + area_type : "lda", + checked : false, + id : 40534, + name : "Thomas Lemaître", + object_id : "FR:92050:LDA:70915:STIF", + object_version : 1, + position : 1, +}] + +describe('journeyPatterns reducer', () => { + beforeEach(()=>{ + state = [ + { + deletable: false, + name: 'm1', + object_id : 'o1', + published_name: 'M1', + registration_number: '', + stop_points: fakeStopPoints + }, + { + deletable: false, + name: 'm2', + object_id : 'o2', + published_name: 'M2', + registration_number: '', + stop_points: fakeStopPoints + } + ] + }) + + it('should return the initial state', () => { + expect( + jpReducer(undefined, {}) + ).toEqual([]) + }) + + it('should handle ADD_JOURNEYPATTERN', () => { + let fakeData = { + name: {value : 'm3'}, + published_name: {value: 'M3'}, + registration_number: {value: ''} + } + expect( + jpReducer(state, { + type: 'ADD_JOURNEYPATTERN', + data: fakeData + }) + ).toEqual([...state, { + name : 'm3', + published_name: 'M3', + registration_number: '', + deletable: false, + stop_points: fakeStopPoints + }]) + }) + + it('should handle UPDATE_CHECKBOX_VALUE', () => { + let newFirstStopPoint = Object.assign({}, fakeStopPoints[0], {checked: !fakeStopPoints[0].checked} ) + let newStopPoints = [newFirstStopPoint, fakeStopPoints[1]] + let newState = Object.assign({}, state[0], {stop_points: newStopPoints}) + expect( + jpReducer(state, { + type: 'UPDATE_CHECKBOX_VALUE', + id: 45289, + index: 0 + }) + ).toEqual([newState, state[1]]) + }) + + it('should handle DELETE_JOURNEYPATTERN', () => { + expect( + jpReducer(state, { + type: 'DELETE_JOURNEYPATTERN', + index: 1 + }) + ).toEqual([state[0], Object.assign({}, state[1], {deletable: true})]) + }) + it('should handle SAVE_MODAL', () => { + let newState = Object.assign({}, state[0], {name: 'p1', published_name: 'P1', registration_number: 'PP11'}) + expect( + jpReducer(state, { + type: 'SAVE_MODAL', + data: { + name: {value: 'p1'}, + published_name: {value: 'P1'}, + registration_number: {value: 'PP11'} + }, + index: 0 + }) + ).toEqual([newState, state[1]]) + }) +}) diff --git a/spec/javascripts/journey_patterns/reducers/pagination_spec.js b/spec/javascripts/journey_patterns/reducers/pagination_spec.js new file mode 100644 index 000000000..a99e8ff85 --- /dev/null +++ b/spec/javascripts/journey_patterns/reducers/pagination_spec.js @@ -0,0 +1,77 @@ +var reducer = require('es6_browserified/journey_patterns/reducers/pagination') +let state = { + page : 2, + totalCount : 25 +} +let currentPage = 2 +const dispatch = function(){} + +describe('pagination reducer, given parameters allowing page change', () => { + + it('should return the initial state', () => { + expect( + reducer(undefined, {}) + ).toEqual({}) + }) + + it('should handle GO_TO_NEXT_PAGE and change state', () => { + expect( + reducer(state, { + type: 'GO_TO_NEXT_PAGE', + dispatch, + currentPage, + nextPage : true + }) + ).toEqual(Object.assign({}, state, {page : state.page + 1})) + }) + + it('should return GO_TO_PREVIOUS_PAGE and change state', () => { + expect( + reducer(state, { + type: 'GO_TO_PREVIOUS_PAGE', + dispatch, + currentPage, + nextPage : false + }) + ).toEqual(Object.assign({}, state, {page : state.page - 1})) + }) +}) + + +describe('pagination reducer, given parameters not allowing to go to previous page', () => { + + beforeEach(()=>{ + state.page = 1 + currentPage = 1 + }) + + it('should return GO_TO_PREVIOUS_PAGE and not change state', () => { + expect( + reducer(state, { + type: 'GO_TO_PREVIOUS_PAGE', + dispatch, + currentPage, + nextPage : false + }) + ).toEqual(state) + }) +}) + +describe('pagination reducer, given parameters not allowing to go to next page', () => { + + beforeEach(()=>{ + state.page = 3 + currentPage = 3 + }) + + it('should return GO_TO_NEXT_PAGE and not change state', () => { + expect( + reducer(state, { + type: 'GO_TO_NEXT_PAGE', + dispatch, + currentPage, + nextPage : false + }) + ).toEqual(state) + }) +}) diff --git a/spec/javascripts/journey_patterns/reducers_spec.js b/spec/javascripts/journey_patterns/reducers_spec.js deleted file mode 100644 index 422c97fee..000000000 --- a/spec/javascripts/journey_patterns/reducers_spec.js +++ /dev/null @@ -1,104 +0,0 @@ -var jpReducer = require('es6_browserified/journey_patterns/reducers/journeyPatterns') -let state = [] -let fakeStopPoints = [{ - area_type : "lda", - checked : false, - id : 45289, - name : "Clichy Levallois", - object_id : "FR:92044:LDA:72073:STIF", - object_version : 1, - position : 0, -},{ - area_type : "lda", - checked : false, - id : 40534, - name : "Thomas Lemaître", - object_id : "FR:92050:LDA:70915:STIF", - object_version : 1, - position : 1, -}] - -describe('journeyPatterns reducer', () => { - beforeEach(()=>{ - state = [ - { - deletable: false, - name: 'm1', - object_id : 'o1', - published_name: 'M1', - registration_number: '', - stop_points: fakeStopPoints - }, - { - deletable: false, - name: 'm2', - object_id : 'o2', - published_name: 'M2', - registration_number: '', - stop_points: fakeStopPoints - } - ] - }) - - it('should return the initial state', () => { - expect( - jpReducer(undefined, {}) - ).toEqual([]) - }) - - it('should handle ADD_JOURNEYPATTERN', () => { - let fakeData = { - name: {value : 'm3'}, - published_name: {value: 'M3'}, - registration_number: {value: ''} - } - expect( - jpReducer(state, { - type: 'ADD_JOURNEYPATTERN', - data: fakeData - }) - ).toEqual([...state, { - name : 'm3', - published_name: 'M3', - registration_number: '', - deletable: false, - stop_points: fakeStopPoints - }]) - }) - - it('should handle UPDATE_CHECKBOX_VALUE', () => { - let newFirstStopPoint = Object.assign({}, fakeStopPoints[0], {checked: !fakeStopPoints[0].checked} ) - let newStopPoints = [newFirstStopPoint, fakeStopPoints[1]] - let newState = Object.assign({}, state[0], {stop_points: newStopPoints}) - expect( - jpReducer(state, { - type: 'UPDATE_CHECKBOX_VALUE', - id: 45289, - index: 0 - }) - ).toEqual([newState, state[1]]) - }) - - it('should handle DELETE_JOURNEYPATTERN', () => { - expect( - jpReducer(state, { - type: 'DELETE_JOURNEYPATTERN', - index: 1 - }) - ).toEqual([state[0], Object.assign({}, state[1], {deletable: true})]) - }) - it('should handle SAVE_MODAL', () => { - let newState = Object.assign({}, state[0], {name: 'p1', published_name: 'P1', registration_number: 'PP11'}) - expect( - jpReducer(state, { - type: 'SAVE_MODAL', - data: { - name: {value: 'p1'}, - published_name: {value: 'P1'}, - registration_number: {value: 'PP11'} - }, - index: 0 - }) - ).toEqual([newState, state[1]]) - }) -}) -- cgit v1.2.3 From 953fb3a48c43f5801bbc35dd02a2db26b21479b1 Mon Sep 17 00:00:00 2001 From: jpl Date: Mon, 9 Jan 2017 12:10:24 +0100 Subject: adding modal specs --- .../journey_patterns/reducers/modal_spec.js | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 spec/javascripts/journey_patterns/reducers/modal_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/reducers/modal_spec.js b/spec/javascripts/journey_patterns/reducers/modal_spec.js new file mode 100644 index 000000000..ee83cb251 --- /dev/null +++ b/spec/javascripts/journey_patterns/reducers/modal_spec.js @@ -0,0 +1,100 @@ +var modalReducer = require('es6_browserified/journey_patterns/reducers/modal') + +let state = {} + +let fakeJourneyPattern = { + name: 'jp_test 1', + object_id: 'jp_test:JourneyPattern:1', + published_name: 'jp_test publishedname 1', + registration_number: 'jp_test registrationnumber 1', + stop_points: [], + deletable: false +} + +const accept = cancel = function(){} + +describe('modal reducer', () => { + beforeEach(() => { + state = { + type: '', + modalProps: {}, + confirmModal: {} + } + }) + + it('should return the initial state', () => { + expect( + modalReducer(undefined, {}) + ).toEqual({}) + }) + + it('should handle OPEN_CONFIRM_MODAL', () => { + let newState = Object.assign({}, state, { + type: 'confirm', + confirmModal: { + accept: accept, + cancel: cancel + } + }) + expect( + modalReducer(state, { + type: 'OPEN_CONFIRM_MODAL', + accept, + cancel + }) + ).toEqual(newState) + }) + + it('should handle EDIT_JOURNEYPATTERN_MODAL', () => { + let newState = Object.assign({}, state, { + type: 'edit', + modalProps: { + index: 0, + journeyPattern: fakeJourneyPattern + }, + confirmModal: {} + }) + expect( + modalReducer(state, { + type: 'EDIT_JOURNEYPATTERN_MODAL', + index: 0, + journeyPattern : fakeJourneyPattern + }) + ).toEqual(newState) + }) + + it('should handle CREATE_JOURNEYPATTERN_MODAL', () => { + expect( + modalReducer(state, { + type: 'CREATE_JOURNEYPATTERN_MODAL' + }) + ).toEqual(Object.assign({}, state, { type: 'create' })) + }) + + it('should handle DELETE_JOURNEYPATTERN', () => { + expect( + modalReducer(state, { + type: 'DELETE_JOURNEYPATTERN', + index: 0 + }) + ).toEqual(state) + }) + + it('should handle SAVE_MODAL', () => { + expect( + modalReducer(state, { + type: 'SAVE_MODAL', + index: 0, + data: {} + }) + ).toEqual(state) + }) + + it('should handle CLOSE_MODAL', () => { + expect( + modalReducer(state, { + type: 'CLOSE_MODAL' + }) + ).toEqual(state) + }) +}) -- cgit v1.2.3 From 96fddd1b1c05cae286c045c019976ec1f522e71b Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Mon, 9 Jan 2017 17:25:33 +0100 Subject: Fix const declaration for strict mode in specs Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/journey_patterns/reducers/modal_spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/reducers/modal_spec.js b/spec/javascripts/journey_patterns/reducers/modal_spec.js index ee83cb251..46ab2d905 100644 --- a/spec/javascripts/journey_patterns/reducers/modal_spec.js +++ b/spec/javascripts/journey_patterns/reducers/modal_spec.js @@ -11,7 +11,8 @@ let fakeJourneyPattern = { deletable: false } -const accept = cancel = function(){} +const accept = function(){} +const cancel = function(){} describe('modal reducer', () => { beforeEach(() => { -- cgit v1.2.3 From 1ed5294c5227c2f8d24cb78c71a87f8f4d58f1b9 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 10 Jan 2017 17:23:58 +0100 Subject: Refs #2205: Fix confirm modal being opened only when journey patterns state changed Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/journey_patterns/actions_spec.js | 7 +++---- spec/javascripts/journey_patterns/reducers/modal_spec.js | 9 +++------ spec/javascripts/journey_patterns/reducers/pagination_spec.js | 4 ++-- spec/javascripts/spec_helper.js | 2 ++ 4 files changed, 10 insertions(+), 12 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/actions_spec.js b/spec/javascripts/journey_patterns/actions_spec.js index ced053935..03198c2c4 100644 --- a/spec/javascripts/journey_patterns/actions_spec.js +++ b/spec/javascripts/journey_patterns/actions_spec.js @@ -53,13 +53,12 @@ describe('when clicking on a journey pattern checkbox', () => { }) describe('when clicking on next button', () => { it('should create an action to open a confirm modal', () => { - const accept = {}, cancel = {} + const callback = function(){} const expectedAction = { type: 'OPEN_CONFIRM_MODAL', - accept, - cancel, + callback } - expect(actions.openConfirmModal(accept, cancel)).toEqual(expectedAction) + expect(actions.openConfirmModal(callback)).toEqual(expectedAction) }) }) describe('when clicking on edit button', () => { diff --git a/spec/javascripts/journey_patterns/reducers/modal_spec.js b/spec/javascripts/journey_patterns/reducers/modal_spec.js index 46ab2d905..0bc7c9240 100644 --- a/spec/javascripts/journey_patterns/reducers/modal_spec.js +++ b/spec/javascripts/journey_patterns/reducers/modal_spec.js @@ -11,8 +11,7 @@ let fakeJourneyPattern = { deletable: false } -const accept = function(){} -const cancel = function(){} +const cb = function(){} describe('modal reducer', () => { beforeEach(() => { @@ -33,15 +32,13 @@ describe('modal reducer', () => { let newState = Object.assign({}, state, { type: 'confirm', confirmModal: { - accept: accept, - cancel: cancel + callback: cb } }) expect( modalReducer(state, { type: 'OPEN_CONFIRM_MODAL', - accept, - cancel + callback: cb }) ).toEqual(newState) }) diff --git a/spec/javascripts/journey_patterns/reducers/pagination_spec.js b/spec/javascripts/journey_patterns/reducers/pagination_spec.js index a99e8ff85..1c8011fca 100644 --- a/spec/javascripts/journey_patterns/reducers/pagination_spec.js +++ b/spec/javascripts/journey_patterns/reducers/pagination_spec.js @@ -22,7 +22,7 @@ describe('pagination reducer, given parameters allowing page change', () => { currentPage, nextPage : true }) - ).toEqual(Object.assign({}, state, {page : state.page + 1})) + ).toEqual(Object.assign({}, state, {page : state.page + 1, stateChanged: false})) }) it('should return GO_TO_PREVIOUS_PAGE and change state', () => { @@ -33,7 +33,7 @@ describe('pagination reducer, given parameters allowing page change', () => { currentPage, nextPage : false }) - ).toEqual(Object.assign({}, state, {page : state.page - 1})) + ).toEqual(Object.assign({}, state, {page : state.page - 1, stateChanged: false})) }) }) diff --git a/spec/javascripts/spec_helper.js b/spec/javascripts/spec_helper.js index a2fde3860..a0285cccf 100644 --- a/spec/javascripts/spec_helper.js +++ b/spec/javascripts/spec_helper.js @@ -4,6 +4,8 @@ // require support/jasmine-jquery-2.1.0 // require support/sinon // require support/your-support-file +//= require jquery +//= require bootstrap-sass-official require('es6-object-assign').polyfill(); // // PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion. -- cgit v1.2.3 From 221300caac758edf7cdb34ec26f41952a2401728 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 11 Jan 2017 12:09:31 +0100 Subject: Add update journey patterns length after submitting correct values Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/journey_patterns/actions_spec.js | 6 +++++- spec/javascripts/journey_patterns/reducers/pagination_spec.js | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/actions_spec.js b/spec/javascripts/journey_patterns/actions_spec.js index 03198c2c4..736a4326a 100644 --- a/spec/javascripts/journey_patterns/actions_spec.js +++ b/spec/javascripts/journey_patterns/actions_spec.js @@ -26,13 +26,17 @@ describe('when landing on page', () => { describe('when next navigation button is clicked', () => { it('should create an action to go to next page', () => { const nextPage = true + const totalCount = 25 + const perPage = 12 const expectedAction = { type: 'GO_TO_NEXT_PAGE', dispatch, currentPage, + totalCount, + perPage, nextPage } - expect(actions.goToNextPage(dispatch, currentPage)).toEqual(expectedAction) + expect(actions.goToNextPage(dispatch, currentPage, totalCount, perPage)).toEqual(expectedAction) }) }) describe('when clicking on a journey pattern checkbox', () => { diff --git a/spec/javascripts/journey_patterns/reducers/pagination_spec.js b/spec/javascripts/journey_patterns/reducers/pagination_spec.js index 1c8011fca..430db4b64 100644 --- a/spec/javascripts/journey_patterns/reducers/pagination_spec.js +++ b/spec/javascripts/journey_patterns/reducers/pagination_spec.js @@ -1,7 +1,11 @@ var reducer = require('es6_browserified/journey_patterns/reducers/pagination') + +const totalCount = 25 +const perPage = 12 let state = { page : 2, - totalCount : 25 + totalCount : totalCount, + stateChanged: false } let currentPage = 2 const dispatch = function(){} @@ -20,6 +24,8 @@ describe('pagination reducer, given parameters allowing page change', () => { type: 'GO_TO_NEXT_PAGE', dispatch, currentPage, + totalCount, + perPage, nextPage : true }) ).toEqual(Object.assign({}, state, {page : state.page + 1, stateChanged: false})) @@ -70,6 +76,7 @@ describe('pagination reducer, given parameters not allowing to go to next page', type: 'GO_TO_NEXT_PAGE', dispatch, currentPage, + totalCount, nextPage : false }) ).toEqual(state) -- cgit v1.2.3 From 3717719e3487a0433c0d53d4494ac315bd966f89 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 11 Jan 2017 12:17:18 +0100 Subject: Add updateTotalCount specs Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/journey_patterns/actions_spec.js | 10 ++++++++++ .../journey_patterns/reducers/pagination_spec.js | 13 +++++++++++++ 2 files changed, 23 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/actions_spec.js b/spec/javascripts/journey_patterns/actions_spec.js index 736a4326a..4b7cb1f79 100644 --- a/spec/javascripts/journey_patterns/actions_spec.js +++ b/spec/javascripts/journey_patterns/actions_spec.js @@ -134,3 +134,13 @@ describe('when clicking on validate button at the bottom of the page', () => { expect(actions.savePage(dispatch)).toEqual(expectedAction) }) }) +describe('when submitting new journeyPatterns', () => { + it('should create an action to update pagination totalCount', () => { + const diff = 1 + const expectedAction = { + type: 'UPDATE_TOTAL_COUNT', + diff + } + expect(actions.updateTotalCount(diff)).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/journey_patterns/reducers/pagination_spec.js b/spec/javascripts/journey_patterns/reducers/pagination_spec.js index 430db4b64..8107794f6 100644 --- a/spec/javascripts/journey_patterns/reducers/pagination_spec.js +++ b/spec/javascripts/journey_patterns/reducers/pagination_spec.js @@ -1,6 +1,7 @@ var reducer = require('es6_browserified/journey_patterns/reducers/pagination') const totalCount = 25 +const diff = 1 const perPage = 12 let state = { page : 2, @@ -82,3 +83,15 @@ describe('pagination reducer, given parameters not allowing to go to next page', ).toEqual(state) }) }) + +describe('pagination reducer, given parameters changing totalCount', () => { + + it('should return UPDATE_TOTAL_COUNT and update totalCount', () => { + expect( + reducer(state, { + type: 'UPDATE_TOTAL_COUNT', + diff + }) + ).toEqual(Object.assign({}, state, {totalCount: totalCount - diff})) + }) +}) -- cgit v1.2.3 From e19f37f690dd932f8f45b0c847e9fa5af197b7bd Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 11 Jan 2017 15:28:08 +0100 Subject: Refactor Navigate container/component/specs Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/journey_patterns/actions_spec.js | 30 +++++++++++++++++----- .../journey_patterns/reducers/pagination_spec.js | 28 +++++++++----------- 2 files changed, 36 insertions(+), 22 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/actions_spec.js b/spec/javascripts/journey_patterns/actions_spec.js index 4b7cb1f79..b4e1a0845 100644 --- a/spec/javascripts/journey_patterns/actions_spec.js +++ b/spec/javascripts/journey_patterns/actions_spec.js @@ -23,20 +23,38 @@ describe('when landing on page', () => { expect(actions.loadFirstPage(dispatch)).toEqual(expectedAction) }) }) +describe('when previous navigation button is clicked', () => { + it('should create an action to go to previous page', () => { + const nextPage = false + const pagination = { + totalCount: 25, + perPage: 12, + page:1 + } + const expectedAction = { + type: 'GO_TO_PREVIOUS_PAGE', + dispatch, + pagination, + nextPage + } + expect(actions.goToPreviousPage(dispatch, pagination)).toEqual(expectedAction) + }) +}) describe('when next navigation button is clicked', () => { it('should create an action to go to next page', () => { const nextPage = true - const totalCount = 25 - const perPage = 12 + const pagination = { + totalCount: 25, + perPage: 12, + page:1 + } const expectedAction = { type: 'GO_TO_NEXT_PAGE', dispatch, - currentPage, - totalCount, - perPage, + pagination, nextPage } - expect(actions.goToNextPage(dispatch, currentPage, totalCount, perPage)).toEqual(expectedAction) + expect(actions.goToNextPage(dispatch, pagination)).toEqual(expectedAction) }) }) describe('when clicking on a journey pattern checkbox', () => { diff --git a/spec/javascripts/journey_patterns/reducers/pagination_spec.js b/spec/javascripts/journey_patterns/reducers/pagination_spec.js index 8107794f6..4800451e9 100644 --- a/spec/javascripts/journey_patterns/reducers/pagination_spec.js +++ b/spec/javascripts/journey_patterns/reducers/pagination_spec.js @@ -1,14 +1,13 @@ var reducer = require('es6_browserified/journey_patterns/reducers/pagination') -const totalCount = 25 const diff = 1 -const perPage = 12 let state = { page : 2, - totalCount : totalCount, - stateChanged: false + totalCount : 25, + stateChanged: false, + perPage: 12 } -let currentPage = 2 +let pagination = Object.assign({}, state) const dispatch = function(){} describe('pagination reducer, given parameters allowing page change', () => { @@ -24,9 +23,7 @@ describe('pagination reducer, given parameters allowing page change', () => { reducer(state, { type: 'GO_TO_NEXT_PAGE', dispatch, - currentPage, - totalCount, - perPage, + pagination, nextPage : true }) ).toEqual(Object.assign({}, state, {page : state.page + 1, stateChanged: false})) @@ -37,7 +34,7 @@ describe('pagination reducer, given parameters allowing page change', () => { reducer(state, { type: 'GO_TO_PREVIOUS_PAGE', dispatch, - currentPage, + pagination, nextPage : false }) ).toEqual(Object.assign({}, state, {page : state.page - 1, stateChanged: false})) @@ -49,7 +46,7 @@ describe('pagination reducer, given parameters not allowing to go to previous pa beforeEach(()=>{ state.page = 1 - currentPage = 1 + pagination.page = 1 }) it('should return GO_TO_PREVIOUS_PAGE and not change state', () => { @@ -57,7 +54,7 @@ describe('pagination reducer, given parameters not allowing to go to previous pa reducer(state, { type: 'GO_TO_PREVIOUS_PAGE', dispatch, - currentPage, + pagination, nextPage : false }) ).toEqual(state) @@ -68,7 +65,7 @@ describe('pagination reducer, given parameters not allowing to go to next page', beforeEach(()=>{ state.page = 3 - currentPage = 3 + pagination.page = 3 }) it('should return GO_TO_NEXT_PAGE and not change state', () => { @@ -76,9 +73,8 @@ describe('pagination reducer, given parameters not allowing to go to next page', reducer(state, { type: 'GO_TO_NEXT_PAGE', dispatch, - currentPage, - totalCount, - nextPage : false + pagination, + nextPage : true }) ).toEqual(state) }) @@ -92,6 +88,6 @@ describe('pagination reducer, given parameters changing totalCount', () => { type: 'UPDATE_TOTAL_COUNT', diff }) - ).toEqual(Object.assign({}, state, {totalCount: totalCount - diff})) + ).toEqual(Object.assign({}, state, {totalCount: state.totalCount - diff})) }) }) -- cgit v1.2.3 From c2c84618204791050e33d5e2ab13c8ac56399734 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 11 Jan 2017 16:18:21 +0100 Subject: Remove submitJourneyPattern action from reducer Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/journey_patterns/actions_spec.js | 9 --------- 1 file changed, 9 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/actions_spec.js b/spec/javascripts/journey_patterns/actions_spec.js index b4e1a0845..1140375d9 100644 --- a/spec/javascripts/journey_patterns/actions_spec.js +++ b/spec/javascripts/journey_patterns/actions_spec.js @@ -143,15 +143,6 @@ describe('when clicking on validate button inside create modal', () => { expect(actions.addJourneyPattern(data)).toEqual(expectedAction) }) }) -describe('when clicking on validate button at the bottom of the page', () => { - it('should create an action to post data and save it into db', () => { - const expectedAction = { - type: 'SAVE_PAGE', - dispatch - } - expect(actions.savePage(dispatch)).toEqual(expectedAction) - }) -}) describe('when submitting new journeyPatterns', () => { it('should create an action to update pagination totalCount', () => { const diff = 1 -- cgit v1.2.3 From d37324f9e80c485ed07623341489223a04e5096c Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 11 Jan 2017 16:53:56 +0100 Subject: Remove LOAD_FIRST_PAGE action from reducers Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/journey_patterns/actions_spec.js | 9 --------- 1 file changed, 9 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/actions_spec.js b/spec/javascripts/journey_patterns/actions_spec.js index 1140375d9..ef0470d2d 100644 --- a/spec/javascripts/journey_patterns/actions_spec.js +++ b/spec/javascripts/journey_patterns/actions_spec.js @@ -14,15 +14,6 @@ describe('when receiveJourneyPatterns is triggered', () => { }) }) -describe('when landing on page', () => { - it('should create an action to load the n first missions', () => { - const expectedAction = { - type: 'LOAD_FIRST_PAGE', - dispatch - } - expect(actions.loadFirstPage(dispatch)).toEqual(expectedAction) - }) -}) describe('when previous navigation button is clicked', () => { it('should create an action to go to previous page', () => { const nextPage = false -- cgit v1.2.3 From da1f31e0515dfe1e910ca0e2b2fb86572e0c7665 Mon Sep 17 00:00:00 2001 From: jpl Date: Thu, 12 Jan 2017 10:45:00 +0100 Subject: adding status spec --- .../journey_patterns/reducers/status_spec.js | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 spec/javascripts/journey_patterns/reducers/status_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/reducers/status_spec.js b/spec/javascripts/journey_patterns/reducers/status_spec.js new file mode 100644 index 000000000..9e4767f04 --- /dev/null +++ b/spec/javascripts/journey_patterns/reducers/status_spec.js @@ -0,0 +1,34 @@ +var statusReducer = require('es6_browserified/journey_patterns/reducers/status') + +let state = {} + +describe('status reducer', () => { + beforeEach(() => { + state = { + fetchSuccess: false, + isFetching: false + } + }) + + it('should return the initial state', () => { + expect( + statusReducer(undefined, {}) + ).toEqual({}) + }) + + it('should handle UNAVAILABLE_SERVER', () => { + expect( + statusReducer(state, { + type: 'UNAVAILABLE_SERVER' + }) + ).toEqual(Object.assign({}, state, {fetchSuccess: false})) + }) + + it('should handle RECEIVE_JOURNEY_PATTERNS', () => { + expect( + statusReducer(state, { + type: 'RECEIVE_JOURNEY_PATTERNS' + }) + ).toEqual(Object.assign({}, state, {fetchSuccess: true})) + }) +}) -- cgit v1.2.3 From 4564af7fa10eaf1ccd18aebe9dcc14fc41e61473 Mon Sep 17 00:00:00 2001 From: jpl Date: Thu, 12 Jan 2017 11:03:38 +0100 Subject: change default fetchSuccess status --- spec/javascripts/journey_patterns/reducers/status_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/reducers/status_spec.js b/spec/javascripts/journey_patterns/reducers/status_spec.js index 9e4767f04..4eeb5c442 100644 --- a/spec/javascripts/journey_patterns/reducers/status_spec.js +++ b/spec/javascripts/journey_patterns/reducers/status_spec.js @@ -5,7 +5,7 @@ let state = {} describe('status reducer', () => { beforeEach(() => { state = { - fetchSuccess: false, + fetchSuccess: true, isFetching: false } }) -- cgit v1.2.3 From baabdb94cd8f5778b8df8fbb85bc42e52f11223b Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Thu, 12 Jan 2017 11:32:34 +0100 Subject: Refs #2210: add isFetching in state for loader toggling Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/journey_patterns/actions_spec.js | 8 ++++++++ .../journey_patterns/reducers/status_spec.js | 19 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/actions_spec.js b/spec/javascripts/journey_patterns/actions_spec.js index ef0470d2d..07f83ca1b 100644 --- a/spec/javascripts/journey_patterns/actions_spec.js +++ b/spec/javascripts/journey_patterns/actions_spec.js @@ -144,3 +144,11 @@ describe('when submitting new journeyPatterns', () => { expect(actions.updateTotalCount(diff)).toEqual(expectedAction) }) }) +describe('when fetching api', () => { + it('should create an action to fetch api', () => { + const expectedAction = { + type: 'FETCH_API', + } + expect(actions.fetchingApi()).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/journey_patterns/reducers/status_spec.js b/spec/javascripts/journey_patterns/reducers/status_spec.js index 4eeb5c442..91cbbb0b8 100644 --- a/spec/javascripts/journey_patterns/reducers/status_spec.js +++ b/spec/javascripts/journey_patterns/reducers/status_spec.js @@ -2,6 +2,14 @@ var statusReducer = require('es6_browserified/journey_patterns/reducers/status') let state = {} +let pagination = { + page : 2, + totalCount : 25, + stateChanged: false, + perPage: 12 +} +const dispatch = function(){} + describe('status reducer', () => { beforeEach(() => { state = { @@ -29,6 +37,15 @@ describe('status reducer', () => { statusReducer(state, { type: 'RECEIVE_JOURNEY_PATTERNS' }) - ).toEqual(Object.assign({}, state, {fetchSuccess: true})) + ).toEqual(Object.assign({}, state, {fetchSuccess: true, isFetching: false})) }) + + it('should handle FETCH_API', () => { + expect( + statusReducer(state, { + type: 'FETCH_API' + }) + ).toEqual(Object.assign({}, state, {isFetching: true})) + }) + }) -- cgit v1.2.3 From ef1199167b7075a1911386dcbf09873bdb1dc606 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 17 Jan 2017 12:03:58 +0100 Subject: JS gardening for itineraries Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/itineraries/reducers_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/itineraries/reducers_spec.js b/spec/javascripts/itineraries/reducers_spec.js index a8731af5f..344cccab5 100644 --- a/spec/javascripts/itineraries/reducers_spec.js +++ b/spec/javascripts/itineraries/reducers_spec.js @@ -1,4 +1,4 @@ -var reducer = require('es6_browserified/itineraries/reducers/todos') +var reducer = require('es6_browserified/itineraries/reducers/stopPoints') let state = [] describe('stops reducer', () => { beforeEach(()=>{ -- cgit v1.2.3 From f7009121b1cbc421efd079bfb4cc43d91ab7ca28 Mon Sep 17 00:00:00 2001 From: jpl Date: Wed, 18 Jan 2017 09:40:47 +0100 Subject: Refs #2404: adding toggle_map tests, fixing also add_stop_point reducer --- spec/javascripts/itineraries/components_spec.js | 40 --- .../itineraries/reducers/stop_points_spec.js | 269 +++++++++++++++++++++ spec/javascripts/itineraries/reducers_spec.js | 179 -------------- 3 files changed, 269 insertions(+), 219 deletions(-) delete mode 100644 spec/javascripts/itineraries/components_spec.js create mode 100644 spec/javascripts/itineraries/reducers/stop_points_spec.js delete mode 100644 spec/javascripts/itineraries/reducers_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/itineraries/components_spec.js b/spec/javascripts/itineraries/components_spec.js deleted file mode 100644 index c9c57b5eb..000000000 --- a/spec/javascripts/itineraries/components_spec.js +++ /dev/null @@ -1,40 +0,0 @@ -// var React = require('react'); -// var Provider = require('react-redux').Provider; -// var actions = require('es6_browserified/itineraries/actions/index'); -// var App = require('es6_browserified/itineraries/components/TodoList'); -// var ConnectedApp = require('es6_browserified/itineraries/containers/VisibleTodoList'); -// var TestUtils = require('react-addons-test-utils'); - -// xdescribe('ConnectedApp', function() { -// var connectedApp, store, initialItems; -// var state; -// state = [ -// { -// text: 'first', -// index: 0, -// for_boarding: 'normal', -// for_alighting: 'normal' -// }, -// { -// text: 'second', -// index: 1, -// for_boarding: 'normal', -// for_alighting: 'normal' -// } -// ] - -// beforeEach(function() { -// store = state -// }); - -// describe('state provided by the store', function() { -// beforeEach(function() { -// connectedApp = TestUtils.renderIntoDocument(); -// }); - -// it('passes down items', function() { -// app = TestUtils.findRenderedComponentWithType(connectedApp, App); -// expect(app.props.items).toEqual(initialItems); -// }); -// }); -// }); diff --git a/spec/javascripts/itineraries/reducers/stop_points_spec.js b/spec/javascripts/itineraries/reducers/stop_points_spec.js new file mode 100644 index 000000000..b33feab28 --- /dev/null +++ b/spec/javascripts/itineraries/reducers/stop_points_spec.js @@ -0,0 +1,269 @@ +var stopPointsReducer = require('es6_browserified/itineraries/reducers/stopPoints') + +let state = [] + +describe('stops reducer', () => { + beforeEach(()=>{ + state = [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + } + ] + }) + + it('should return the initial state', () => { + expect( + stopPointsReducer(undefined, {}) + ).toEqual([]) + }) + + it('should handle ADD_STOP', () => { + expect( + stopPointsReducer(state, { + type: 'ADD_STOP' + }) + ).toEqual( + [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + }, + { + text: '', + index: 2, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + } + ] + ) + }) + + it('should handle MOVE_UP_STOP', () => { + expect( + stopPointsReducer(state, { + type: 'MOVE_STOP_UP', + index: 1 + }) + ).toEqual( + [ + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + }, + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + } + ] + ) + }) + + it('should handle MOVE_DOWN_STOP', () => { + expect( + stopPointsReducer(state, { + type: 'MOVE_STOP_DOWN', + index: 0 + }) + ).toEqual( + [ + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + }, + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + } + ] + ) + }) + + it('should handle DELETE_STOP', () => { + expect( + stopPointsReducer(state, { + type: 'DELETE_STOP', + index: 1 + }) + ).toEqual( + [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + } + ] + ) + }) + + it('should handle UPDATE_INPUT_VALUE', () => { + expect( + stopPointsReducer(state, { + type: 'UPDATE_INPUT_VALUE', + index: 0, + text: { + text: "new value", + stoparea_id: 1, + user_objectid: "1234" + } + }) + ).toEqual( + [ + { + text: 'new value', + index: 0, + stoppoint_id: '', + stoparea_id: 1, + for_boarding: 'normal', + for_alighting: 'normal', + user_objectid: "1234", + olMap: { + isOpened: false, + json: {} + } + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + } + ] + ) + }) + + it('should handle UPDATE_SELECT_VALUE', () => { + expect( + stopPointsReducer(state, { + type :'UPDATE_SELECT_VALUE', + select_id: 'for_boarding', + select_value: 'prohibited', + index: 0 + }) + ).toEqual( + [ + { + text: 'first', + index: 0, + for_boarding: 'prohibited', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + } + ] + ) + }) + + it('should handle TOGGLE_MAP', () => { + expect( + stopPointsReducer(state, { + type: 'TOGGLE_MAP', + index: 0 + }) + ).toEqual( + [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: true, + json: {} + } + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + } + ] + ) + }) +}) diff --git a/spec/javascripts/itineraries/reducers_spec.js b/spec/javascripts/itineraries/reducers_spec.js deleted file mode 100644 index 344cccab5..000000000 --- a/spec/javascripts/itineraries/reducers_spec.js +++ /dev/null @@ -1,179 +0,0 @@ -var reducer = require('es6_browserified/itineraries/reducers/stopPoints') -let state = [] -describe('stops reducer', () => { - beforeEach(()=>{ - state = [ - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - }) - - it('should return the initial state', () => { - expect( - reducer(undefined, {}) - ).toEqual([]) - }) - - it('should handle ADD_STOP', () => { - expect( - reducer(state, { - type: 'ADD_STOP' - }) - ).toEqual( - [ - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: '', - index: 2, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) - - it('should handle MOVE_UP_STOP', () => { - expect( - reducer(state, { - type: 'MOVE_STOP_UP', - index: 1 - }) - ).toEqual( - [ - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) - - it('should handle MOVE_DOWN_STOP', () => { - expect( - reducer(state, { - type: 'MOVE_STOP_DOWN', - index: 0 - }) - ).toEqual( - [ - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) - - it('should handle DELETE_STOP', () => { - expect( - reducer(state, { - type: 'DELETE_STOP', - index: 1 - }) - ).toEqual( - [ - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) - - it('should handle UPDATE_INPUT_VALUE', () => { - expect( - reducer(state, { - type: 'UPDATE_INPUT_VALUE', - index: 0, - text: { - text: "new value", - stoparea_id: 1, - user_objectid: "1234" - } - }) - ).toEqual( - [ - { - text: 'new value', - index: 0, - stoppoint_id: '', - stoparea_id: 1, - for_boarding: 'normal', - for_alighting: 'normal', - user_objectid: "1234" - }, - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) - - it('should handle UPDATE_SELECT_VALUE', () => { - expect( - reducer(state, { - type :'UPDATE_SELECT_VALUE', - select_id: 'for_boarding', - select_value: 'prohibited', - index: 0 - }) - ).toEqual( - [ - { - text: 'first', - index: 0, - for_boarding: 'prohibited', - for_alighting: 'normal' - }, - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) -}) -- cgit v1.2.3 From 0dc2401e06d28b7fa1d90c8f2f96776483c75c66 Mon Sep 17 00:00:00 2001 From: jpl Date: Wed, 25 Jan 2017 15:16:39 +0100 Subject: Refs #2405: adding specs to stop points (togglemap, selectmarker...) --- spec/javascripts/itineraries/actions_spec.js | 30 ++++++ .../itineraries/reducers/stop_points_spec.js | 118 +++++++++++++++++++++ 2 files changed, 148 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/itineraries/actions_spec.js b/spec/javascripts/itineraries/actions_spec.js index f86466375..2bae59987 100644 --- a/spec/javascripts/itineraries/actions_spec.js +++ b/spec/javascripts/itineraries/actions_spec.js @@ -69,3 +69,33 @@ describe('actions', () => { expect(actions.updateSelectValue(event, index)).toEqual(expectedAction) }) }) + +describe('actions', () => { + it('should create an action to toggle the map', () => { + const index = 1 + const expectedAction = { + type: 'TOGGLE_MAP', + index + } + expect(actions.toggleMap(index)).toEqual(expectedAction) + }) +}) + +describe('actions', () => { + it('should create an action to select a marker on the map', () => { + const index = 1 + const data = { + geometry: undefined, + registration_number: 'rn_test', + stoparea_id: 'sid_test', + text: 't_test', + user_objectid: 'uoid_test' + } + const expectedAction = { + type: 'SELECT_MARKER', + index, + data + } + expect(actions.selectMarker(index, data)).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/itineraries/reducers/stop_points_spec.js b/spec/javascripts/itineraries/reducers/stop_points_spec.js index b33feab28..fbd33af18 100644 --- a/spec/javascripts/itineraries/reducers/stop_points_spec.js +++ b/spec/javascripts/itineraries/reducers/stop_points_spec.js @@ -2,6 +2,14 @@ var stopPointsReducer = require('es6_browserified/itineraries/reducers/stopPoint let state = [] +let fakeData = { + geometry: undefined, + registration_number: 'rn_test', + stoparea_id: 'sid_test', + text: 't_test', + user_objectid: 'uoid_test' +} + describe('stops reducer', () => { beforeEach(()=>{ state = [ @@ -266,4 +274,114 @@ describe('stops reducer', () => { ] ) }) + + it('should handle SELECT_MARKER', () => { + let openedMapState = [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: true, + json: {} + } + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + } + ] + expect( + stopPointsReducer(openedMapState, { + type: 'SELECT_MARKER', + index: 0, + data: fakeData + }) + ).toEqual( + [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: true, + json: fakeData + } + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + } + ] + ) + }) + + it('should handle UNSELECT_MARKER', () => { + let openedMapState = [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: true, + json: {} + } + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + } + ] + + expect( + stopPointsReducer(openedMapState, { + type: 'UNSELECT_MARKER', + index: 0 + }) + ).toEqual( + [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: true, + json: {} + } + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + } + ] + ) + }) }) -- cgit v1.2.3 From 4684dfc6d3d442bc844c01d002c75abe11cc9fda Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 27 Jan 2017 18:18:02 +0100 Subject: Fix UPDATE_INPUT_VALUE spec in stop points Signed-off-by: Thomas Shawarma Haddad Signed-off-by: Jean-Paul Lescouzeres --- spec/javascripts/itineraries/reducers/stop_points_spec.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/itineraries/reducers/stop_points_spec.js b/spec/javascripts/itineraries/reducers/stop_points_spec.js index fbd33af18..72fbbeb6d 100644 --- a/spec/javascripts/itineraries/reducers/stop_points_spec.js +++ b/spec/javascripts/itineraries/reducers/stop_points_spec.js @@ -177,7 +177,9 @@ describe('stops reducer', () => { text: { text: "new value", stoparea_id: 1, - user_objectid: "1234" + user_objectid: "1234", + longitude: 123, + latitude: 123 } }) ).toEqual( @@ -190,6 +192,8 @@ describe('stops reducer', () => { for_boarding: 'normal', for_alighting: 'normal', user_objectid: "1234", + longitude: 123, + latitude: 123, olMap: { isOpened: false, json: {} -- cgit v1.2.3 From da1f748fcdfd15c5b873de3d05dc1a1803bca047 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Mon, 30 Jan 2017 15:32:51 +0100 Subject: Refs #2406: Automatically fill sidebar when toggling map, and disable confirm button when stoparea already selected Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/itineraries/reducers/stop_points_spec.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/itineraries/reducers/stop_points_spec.js b/spec/javascripts/itineraries/reducers/stop_points_spec.js index 72fbbeb6d..d6917f782 100644 --- a/spec/javascripts/itineraries/reducers/stop_points_spec.js +++ b/spec/javascripts/itineraries/reducers/stop_points_spec.js @@ -176,16 +176,19 @@ describe('stops reducer', () => { index: 0, text: { text: "new value", + name: 'new', stoparea_id: 1, user_objectid: "1234", longitude: 123, - latitude: 123 + latitude: 123, + registration_number: '0' } }) ).toEqual( [ { text: 'new value', + name: 'new', index: 0, stoppoint_id: '', stoparea_id: 1, @@ -194,6 +197,7 @@ describe('stops reducer', () => { user_objectid: "1234", longitude: 123, latitude: 123, + registration_number: '0', olMap: { isOpened: false, json: {} @@ -262,7 +266,13 @@ describe('stops reducer', () => { for_alighting: 'normal', olMap: { isOpened: true, - json: {} + json: { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: undefined + } } }, { -- cgit v1.2.3 From e723c5bc2f3c5f98e67e9e570dc50da0c48eacca Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Thu, 2 Feb 2017 15:30:17 +0100 Subject: Add first components spec, and set correct node version used in package.json Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/itineraries/components_spec.js | 53 +++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 spec/javascripts/itineraries/components_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/itineraries/components_spec.js b/spec/javascripts/itineraries/components_spec.js new file mode 100644 index 000000000..24ead7b5d --- /dev/null +++ b/spec/javascripts/itineraries/components_spec.js @@ -0,0 +1,53 @@ +var React = require('react'); +var shallow = require('enzyme').shallow; +var mount = require('enzyme').mount; +var StopPointList = require('es6_browserified/itineraries/components/StopPointList'); +var StopPoint = require('es6_browserified/itineraries/components/StopPoint'); +var sinon = require('sinon') + +describe('(Component) StopPointList', () => { + it('renders without exploding', () => { + const wrapper = shallow( {}} + onMoveDownClick={() => {}} + onMoveUpClick={() => {}} + onDeleteClick={() => {}} + onSelectChange={() => {}} + onSelectMarker={() => {}} + onUnselectMarker={() => {}} + />); + expect(wrapper.length).toEqual(1); + }); + + it('simulates click events', () => { + const state = { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal', + user_objectid: '', + olMap: { + isOpened: false, + json: {} + } + } + const onButtonClick = sinon.spy(); + const wrapper = mount( {}} + onMoveDownClick={() => {}} + onMoveUpClick={() => {}} + onDeleteClick={onButtonClick} + onSelectChange={() => {}} + onSelectMarker={() => {}} + onToggleMap={() => {}} + onUnselectMarker={() => {}} + first= {true} + last= {true} + index= {0} + />); + wrapper.find('.delete').simulate('click'); + expect(onButtonClick.calledOnce).toEqual(true); + }); +}); -- cgit v1.2.3 From b2a84ee1ff461dd9db3f338cfc1f262af9816a77 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Mon, 6 Feb 2017 15:56:09 +0100 Subject: Refs #2498: initializing react-redux for vehicle_journeys Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 spec/javascripts/vehicle_journeys/actions_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3 From b4631a366646303a2606120db99ff1d2297c3c91 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 8 Feb 2017 18:02:13 +0100 Subject: Refs #2501: Add fetchApi when landing on page, fetch status, wip display Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 31 ++++++++++++ .../vehicle_journeys/reducers/status_spec.js | 45 ++++++++++++++++++ .../reducers/vehicle_journeys_spec.js | 55 ++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 spec/javascripts/vehicle_journeys/reducers/status_spec.js create mode 100644 spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index e69de29bb..8999d4cb6 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -0,0 +1,31 @@ +var actions = require('es6_browserified/vehicle_journeys/actions') + +const dispatch = function(){} +const currentPage = 1 + +describe('when cannot fetch api', () => { + it('should create an action to toggle error', () => { + const expectedAction = { + type: 'UNAVAILABLE_SERVER', + } + expect(actions.unavailableServer()).toEqual(expectedAction) + }) +}) +describe('when fetching api', () => { + it('should create an action to fetch api', () => { + const expectedAction = { + type: 'FETCH_API', + } + expect(actions.fetchingApi()).toEqual(expectedAction) + }) +}) +describe('when receiveJourneyPatterns is triggered', () => { + it('should create an action to pass json to reducer', () => { + const json = undefined + const expectedAction = { + type: 'RECEIVE_VEHICLE_JOURNEYS', + json + } + expect(actions.receiveVehicleJourneys()).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/status_spec.js b/spec/javascripts/vehicle_journeys/reducers/status_spec.js new file mode 100644 index 000000000..d48d48f4a --- /dev/null +++ b/spec/javascripts/vehicle_journeys/reducers/status_spec.js @@ -0,0 +1,45 @@ +var statusReducer = require('es6_browserified/vehicle_journeys/reducers/status') + +let state = {} + +const dispatch = function(){} + +describe('status reducer', () => { + beforeEach(() => { + state = { + fetchSuccess: true, + isFetching: false + } + }) + + it('should return the initial state', () => { + expect( + statusReducer(undefined, {}) + ).toEqual({}) + }) + + it('should handle UNAVAILABLE_SERVER', () => { + expect( + statusReducer(state, { + type: 'UNAVAILABLE_SERVER' + }) + ).toEqual(Object.assign({}, state, {fetchSuccess: false})) + }) + + it('should handle RECEIVE_VEHICLE_JOURNEYS', () => { + expect( + statusReducer(state, { + type: 'RECEIVE_VEHICLE_JOURNEYS' + }) + ).toEqual(Object.assign({}, state, {fetchSuccess: true, isFetching: false})) + }) + + it('should handle FETCH_API', () => { + expect( + statusReducer(state, { + type: 'FETCH_API' + }) + ).toEqual(Object.assign({}, state, {isFetching: true})) + }) + +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js new file mode 100644 index 000000000..15baa75a5 --- /dev/null +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -0,0 +1,55 @@ +var vjReducer = require('es6_browserified/vehicle_journeys/reducers/vehicleJourneys') +let state = [] +let fakeFootnotes = [{ + id: 1, + code: 1, + label: "1" +},{ + id: 2, + code: 2, + label: "2" +}] + +let fakeTimeTables = [] +let fakeVJAS = [] + +describe('vehicleJourneys reducer', () => { + beforeEach(()=>{ + state = [ + { + journey_pattern_id: 1, + published_journey_name: "vj1", + objectid: 11, + deletable: false, + footnotes: fakeFootnotes, + time_tables: fakeTimeTables, + vehicle_journey_at_stops: fakeVJAS + }, + { + journey_pattern_id: 2, + published_journey_name: "vj2", + objectid: 22, + deletable: false, + footnotes: fakeFootnotes, + time_tables: fakeTimeTables, + vehicle_journey_at_stops: fakeVJAS + } + ] + }) + + it('should return the initial state', () => { + expect( + vjReducer(undefined, {}) + ).toEqual([]) + }) + + + it('should handle RECEIVE_VEHICLE_JOURNEYS', () => { + expect( + vjReducer(state, { + type: 'RECEIVE_VEHICLE_JOURNEYS', + json: state + }) + ).toEqual(state) + }) +}) -- cgit v1.2.3 From 9be58cefea65c8beea5273ad76d5d9b3a811983c Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Thu, 9 Feb 2017 18:11:24 +0100 Subject: Refs #2501: Add pagination for vehicle journeys Signed-off-by: Thomas Shawarma Haddad --- .../journey_patterns/reducers/pagination_spec.js | 4 +- .../vehicle_journeys/reducers/pagination_spec.js | 81 ++++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 spec/javascripts/vehicle_journeys/reducers/pagination_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/reducers/pagination_spec.js b/spec/javascripts/journey_patterns/reducers/pagination_spec.js index 4800451e9..d0f9fef47 100644 --- a/spec/javascripts/journey_patterns/reducers/pagination_spec.js +++ b/spec/javascripts/journey_patterns/reducers/pagination_spec.js @@ -3,9 +3,9 @@ var reducer = require('es6_browserified/journey_patterns/reducers/pagination') const diff = 1 let state = { page : 2, - totalCount : 25, + totalCount : 50, stateChanged: false, - perPage: 12 + perPage: 20 } let pagination = Object.assign({}, state) const dispatch = function(){} diff --git a/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js b/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js new file mode 100644 index 000000000..240d99c85 --- /dev/null +++ b/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js @@ -0,0 +1,81 @@ +var reducer = require('es6_browserified/vehicle_journeys/reducers/pagination') + +const diff = 1 +let state = { + page : 2, + totalCount : 25, + stateChanged: false, + perPage: 12 +} +let pagination = Object.assign({}, state) +const dispatch = function(){} + +describe('pagination reducer, given parameters allowing page change', () => { + + it('should return the initial state', () => { + expect( + reducer(undefined, {}) + ).toEqual({}) + }) + + it('should handle GO_TO_NEXT_PAGE and change state', () => { + expect( + reducer(state, { + type: 'GO_TO_NEXT_PAGE', + dispatch, + pagination, + nextPage : true + }) + ).toEqual(Object.assign({}, state, {page : state.page + 1, stateChanged: false})) + }) + + it('should return GO_TO_PREVIOUS_PAGE and change state', () => { + expect( + reducer(state, { + type: 'GO_TO_PREVIOUS_PAGE', + dispatch, + pagination, + nextPage : false + }) + ).toEqual(Object.assign({}, state, {page : state.page - 1, stateChanged: false})) + }) +}) + + +describe('pagination reducer, given parameters not allowing to go to previous page', () => { + + beforeEach(()=>{ + state.page = 1 + pagination.page = 1 + }) + + it('should return GO_TO_PREVIOUS_PAGE and not change state', () => { + expect( + reducer(state, { + type: 'GO_TO_PREVIOUS_PAGE', + dispatch, + pagination, + nextPage : false + }) + ).toEqual(state) + }) +}) + +describe('pagination reducer, given parameters not allowing to go to next page', () => { + + beforeEach(()=>{ + state.page = 3 + pagination.page = 3 + }) + + it('should return GO_TO_NEXT_PAGE and not change state', () => { + expect( + reducer(state, { + type: 'GO_TO_NEXT_PAGE', + dispatch, + pagination, + nextPage : true + }) + ).toEqual(state) + }) +}) -- cgit v1.2.3 From b97168aac7d42b1575e23e88fc104c22def86664 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Mon, 13 Feb 2017 15:49:28 +0100 Subject: Refs #2503: Add toggle for vehicle journeys arrival Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 8 +++++++ .../vehicle_journeys/reducers/filters_spec.js | 26 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 spec/javascripts/vehicle_journeys/reducers/filters_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 8999d4cb6..d09531564 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -29,3 +29,11 @@ describe('when receiveJourneyPatterns is triggered', () => { expect(actions.receiveVehicleJourneys()).toEqual(expectedAction) }) }) +describe('when toggling arrivals', () => { + it('should create an action to toggleArrivals', () => { + const expectedAction = { + type: 'TOGGLE_ARRIVALS', + } + expect(actions.toggleArrivals()).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js new file mode 100644 index 000000000..ecb80f3c3 --- /dev/null +++ b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js @@ -0,0 +1,26 @@ +var statusReducer = require('es6_browserified/vehicle_journeys/reducers/filters') + +let state = {} + +describe('filters reducer', () => { + beforeEach(() => { + state = { + toggleArrivals: false, + } + }) + + it('should return the initial state', () => { + expect( + statusReducer(undefined, {}) + ).toEqual({}) + }) + + it('should handle TOGGLE_ARRIVALS', () => { + expect( + statusReducer(state, { + type: 'TOGGLE_ARRIVALS' + }) + ).toEqual(Object.assign({}, state, {toggleArrivals: true})) + }) + +}) -- cgit v1.2.3 From 3c3bf04763105c5e4de8bdbf611fbb6a8dbeb03a Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 14 Feb 2017 18:23:09 +0100 Subject: Refs #2521: Add vjas time modification for vehicle journeys Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/spec_helper.js | 1 + spec/javascripts/vehicle_journeys/actions_spec.js | 14 +++++++++++ .../reducers/vehicle_journeys_spec.js | 28 +++++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/spec_helper.js b/spec/javascripts/spec_helper.js index a0285cccf..321ba3525 100644 --- a/spec/javascripts/spec_helper.js +++ b/spec/javascripts/spec_helper.js @@ -6,6 +6,7 @@ // require support/your-support-file //= require jquery //= require bootstrap-sass-official +//= require moment require('es6-object-assign').polyfill(); // // PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion. diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index d09531564..219fea96b 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -37,3 +37,17 @@ describe('when toggling arrivals', () => { expect(actions.toggleArrivals()).toEqual(expectedAction) }) }) +describe('when updating vjas time', () => { + it('should create an action to update time', () => { + const val = 33, subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true + const expectedAction = { + type: 'UPDATE_TIME', + val, + subIndex, + index, + timeUnit, + isDeparture + } + expect(actions.updateTime(val, subIndex, index, timeUnit, isDeparture)).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index 15baa75a5..d6ad1c8bd 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -1,4 +1,5 @@ var vjReducer = require('es6_browserified/vehicle_journeys/reducers/vehicleJourneys') + let state = [] let fakeFootnotes = [{ id: 1, @@ -11,7 +12,11 @@ let fakeFootnotes = [{ }] let fakeTimeTables = [] -let fakeVJAS = [] +let fakeVJAS = [{ + arrival_time : "2000-01-01T00:00:00+01:00", + departure_time : "2000-01-01T00:00:00+01:00", + stop_area_object_id : "FR:92024:ZDE:420553:STIF" +}] describe('vehicleJourneys reducer', () => { beforeEach(()=>{ @@ -52,4 +57,25 @@ describe('vehicleJourneys reducer', () => { }) ).toEqual(state) }) + + it('should handle UPDATE_TIME', () => { + const val = 33, subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true + let newVJAS = [{ + arrival_time : "2000-01-01T00:00:00+01:00", + departure_time : "2000-01-01T00:33:00+01:00", + stop_area_object_id : "FR:92024:ZDE:420553:STIF" + }] + let newVJ = Object.assign({}, state[0], {vehicle_journey_at_stops: newVJAS}) + expect( + vjReducer(state, { + type: 'UPDATE_TIME', + val, + subIndex, + index, + timeUnit, + isDeparture + }) + ).toEqual([newVJ, state[1]]) + }) + }) -- cgit v1.2.3 From b237c0947d65607b1fe03ead136dd952db1b8d63 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 15 Feb 2017 15:07:32 +0100 Subject: Refs #2521: Fix updateTime specs Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 7 ++++--- .../javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 219fea96b..5eb3abe45 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -39,15 +39,16 @@ describe('when toggling arrivals', () => { }) describe('when updating vjas time', () => { it('should create an action to update time', () => { - const val = 33, subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true + const val = 33, subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true, isArrivalsToggled = true const expectedAction = { type: 'UPDATE_TIME', val, subIndex, index, timeUnit, - isDeparture + isDeparture, + isArrivalsToggled } - expect(actions.updateTime(val, subIndex, index, timeUnit, isDeparture)).toEqual(expectedAction) + expect(actions.updateTime(val, subIndex, index, timeUnit, isDeparture, isArrivalsToggled)).toEqual(expectedAction) }) }) diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index d6ad1c8bd..ee075a203 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -59,7 +59,7 @@ describe('vehicleJourneys reducer', () => { }) it('should handle UPDATE_TIME', () => { - const val = 33, subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true + const val = 33, subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true, isArrivalsToggled = true let newVJAS = [{ arrival_time : "2000-01-01T00:00:00+01:00", departure_time : "2000-01-01T00:33:00+01:00", @@ -73,7 +73,8 @@ describe('vehicleJourneys reducer', () => { subIndex, index, timeUnit, - isDeparture + isDeparture, + isArrivalsToggled }) ).toEqual([newVJ, state[1]]) }) -- cgit v1.2.3 From 8db5541b1f01a2e1c9b7be8d5e40a7f9b62b801d Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 15 Feb 2017 18:08:27 +0100 Subject: Refs #2521: Fix vjas arrival and departure_time processed without moment Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/spec_helper.js | 1 - .../reducers/vehicle_journeys_spec.js | 22 +++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/spec_helper.js b/spec/javascripts/spec_helper.js index 321ba3525..a0285cccf 100644 --- a/spec/javascripts/spec_helper.js +++ b/spec/javascripts/spec_helper.js @@ -6,7 +6,6 @@ // require support/your-support-file //= require jquery //= require bootstrap-sass-official -//= require moment require('es6-object-assign').polyfill(); // // PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion. diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index ee075a203..5540caf02 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -13,8 +13,14 @@ let fakeFootnotes = [{ let fakeTimeTables = [] let fakeVJAS = [{ - arrival_time : "2000-01-01T00:00:00+01:00", - departure_time : "2000-01-01T00:00:00+01:00", + arrival_time : { + hour: '11', + minute: '11' + }, + departure_time : { + hour: '22', + minute: '22' + }, stop_area_object_id : "FR:92024:ZDE:420553:STIF" }] @@ -59,10 +65,16 @@ describe('vehicleJourneys reducer', () => { }) it('should handle UPDATE_TIME', () => { - const val = 33, subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true, isArrivalsToggled = true + const val = '33', subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true, isArrivalsToggled = true let newVJAS = [{ - arrival_time : "2000-01-01T00:00:00+01:00", - departure_time : "2000-01-01T00:33:00+01:00", + arrival_time : { + hour: '11', + minute: '11' + }, + departure_time : { + hour: '22', + minute: '33' + }, stop_area_object_id : "FR:92024:ZDE:420553:STIF" }] let newVJ = Object.assign({}, state[0], {vehicle_journey_at_stops: newVJAS}) -- cgit v1.2.3 From 69495e859893db0d3d75fbac23ac346a8bdc7eec Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Thu, 16 Feb 2017 11:56:46 +0100 Subject: Refs #2521: Add confirm modal when changing page if modifications were previously done Signed-off-by: Thomas Shawarma Haddad --- .../vehicle_journeys/reducers/modal_spec.js | 44 ++++++++++++++++++++++ .../vehicle_journeys/reducers/pagination_spec.js | 17 +++++++++ 2 files changed, 61 insertions(+) create mode 100644 spec/javascripts/vehicle_journeys/reducers/modal_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js new file mode 100644 index 000000000..8da8e6c65 --- /dev/null +++ b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js @@ -0,0 +1,44 @@ +var modalReducer = require('es6_browserified/vehicle_journeys/reducers/modal') + +let state = {} + +const cb = function(){} + +describe('modal reducer', () => { + beforeEach(() => { + state = { + type: '', + modalProps: {}, + confirmModal: {} + } + }) + + it('should return the initial state', () => { + expect( + modalReducer(undefined, {}) + ).toEqual({}) + }) + + it('should handle OPEN_CONFIRM_MODAL', () => { + let newState = Object.assign({}, state, { + type: 'confirm', + confirmModal: { + callback: cb + } + }) + expect( + modalReducer(state, { + type: 'OPEN_CONFIRM_MODAL', + callback: cb + }) + ).toEqual(newState) + }) + + it('should handle CLOSE_MODAL', () => { + expect( + modalReducer(state, { + type: 'CLOSE_MODAL' + }) + ).toEqual(state) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js b/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js index 240d99c85..2dd600436 100644 --- a/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js @@ -39,6 +39,23 @@ describe('pagination reducer, given parameters allowing page change', () => { }) ).toEqual(Object.assign({}, state, {page : state.page - 1, stateChanged: false})) }) + + it('should handle UPDATE_TIME', () => { + const val = '33', subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true, isArrivalsToggled = true + expect( + reducer(state, { + type: 'UPDATE_TIME', + val, + subIndex, + index, + timeUnit, + isDeparture, + isArrivalsToggled + }) + ).toEqual(Object.assign({}, state, {stateChanged: true}) +) + }) + }) -- cgit v1.2.3 From bb693070b8f06bc9cb4845d27d58dfed9ce3411e Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Thu, 16 Feb 2017 17:14:45 +0100 Subject: Refs #2522: Add vehicleJourney via modal, and put it first (not select2 yet for mission_id) Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 52 ++++++++++++++++++++++ .../vehicle_journeys/reducers/modal_spec.js | 8 ++++ .../reducers/vehicle_journeys_spec.js | 21 +++++++++ 3 files changed, 81 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 5eb3abe45..9f3f5e168 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -29,6 +29,58 @@ describe('when receiveJourneyPatterns is triggered', () => { expect(actions.receiveVehicleJourneys()).toEqual(expectedAction) }) }) +describe('when clicking on add button', () => { + it('should create an action to open a create modal', () => { + const expectedAction = { + type: 'CREATE_VEHICLEJOURNEY_MODAL', + } + expect(actions.openCreateModal()).toEqual(expectedAction) + }) +}) +describe('when clicking on validate button inside create modal', () => { + it('should create an action to create a new journey pattern', () => { + const data = {} + const expectedAction = { + type: 'ADD_VEHICLEJOURNEY', + data + } + expect(actions.addVehicleJourney(data)).toEqual(expectedAction) + }) +}) +describe('when previous navigation button is clicked', () => { + it('should create an action to go to previous page', () => { + const nextPage = false + const pagination = { + totalCount: 25, + perPage: 12, + page:1 + } + const expectedAction = { + type: 'GO_TO_PREVIOUS_PAGE', + dispatch, + pagination, + nextPage + } + expect(actions.goToPreviousPage(dispatch, pagination)).toEqual(expectedAction) + }) +}) +describe('when next navigation button is clicked', () => { + it('should create an action to go to next page', () => { + const nextPage = true + const pagination = { + totalCount: 25, + perPage: 12, + page:1 + } + const expectedAction = { + type: 'GO_TO_NEXT_PAGE', + dispatch, + pagination, + nextPage + } + expect(actions.goToNextPage(dispatch, pagination)).toEqual(expectedAction) + }) +}) describe('when toggling arrivals', () => { it('should create an action to toggleArrivals', () => { const expectedAction = { diff --git a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js index 8da8e6c65..8e854be40 100644 --- a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js @@ -34,6 +34,14 @@ describe('modal reducer', () => { ).toEqual(newState) }) + it('should handle CREATE_VEHICLEJOURNEY_MODAL', () => { + expect( + modalReducer(state, { + type: 'CREATE_VEHICLEJOURNEY_MODAL' + }) + ).toEqual(Object.assign({}, state, { type: 'create' })) + }) + it('should handle CLOSE_MODAL', () => { expect( modalReducer(state, { diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index 5540caf02..bb40add3a 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -55,6 +55,27 @@ describe('vehicleJourneys reducer', () => { }) + it('should handle ADD_VEHICLEJOURNEY', () => { + let fakeData = { + journey_pattern_id: {value : '1'}, + comment: {value: 'test'} + } + expect( + vjReducer(state, { + type: 'ADD_VEHICLEJOURNEY', + data: fakeData + }) + ).toEqual([{ + journey_pattern_id: 1, + comment: 'test', + objectid: '', + footnotes: [], + time_tables: [], + vehicle_journey_at_stops: [], + deletable: false + }, ...state]) + }) + it('should handle RECEIVE_VEHICLE_JOURNEYS', () => { expect( vjReducer(state, { -- cgit v1.2.3 From f0bf220b554dfea74e252e1d64f3dbda81055470 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 17 Feb 2017 11:52:39 +0100 Subject: Refs #2521: add selected attr to vehicle journey Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 10 ++++++++++ .../vehicle_journeys/reducers/vehicle_journeys_spec.js | 13 +++++++++++++ 2 files changed, 23 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 9f3f5e168..92783841a 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -81,6 +81,16 @@ describe('when next navigation button is clicked', () => { expect(actions.goToNextPage(dispatch, pagination)).toEqual(expectedAction) }) }) +describe('when checking a vehicleJourney', () => { + it('should create an action to select vj', () => { + const index = 1 + const expectedAction = { + type: 'SELECT_VEHICLEJOURNEY', + index + } + expect(actions.selectVehicleJourney(index)).toEqual(expectedAction) + }) +}) describe('when toggling arrivals', () => { it('should create an action to toggleArrivals', () => { const expectedAction = { diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index bb40add3a..0a7b2330b 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -32,6 +32,7 @@ describe('vehicleJourneys reducer', () => { published_journey_name: "vj1", objectid: 11, deletable: false, + selected: false, footnotes: fakeFootnotes, time_tables: fakeTimeTables, vehicle_journey_at_stops: fakeVJAS @@ -40,6 +41,7 @@ describe('vehicleJourneys reducer', () => { journey_pattern_id: 2, published_journey_name: "vj2", objectid: 22, + selected: false, deletable: false, footnotes: fakeFootnotes, time_tables: fakeTimeTables, @@ -112,4 +114,15 @@ describe('vehicleJourneys reducer', () => { ).toEqual([newVJ, state[1]]) }) + it('should handle SELECT_VEHICLEJOURNEY', () => { + const index = 0 + const newVJ = Object.assign({}, state[0], {selected: true}) + expect( + vjReducer(state, { + type: 'SELECT_VEHICLEJOURNEY', + index + }) + ).toEqual([newVJ, state[1]]) + }) + }) -- cgit v1.2.3 From 037308d9456132a8cc5cd3415c2bfe89f7e2b467 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 17 Feb 2017 17:28:54 +0100 Subject: Refs #2523: Add Delete vehicle journey (w/o modal) Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 8 ++++++++ .../vehicle_journeys/reducers/vehicle_journeys_spec.js | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 92783841a..d7e64b100 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -91,6 +91,14 @@ describe('when checking a vehicleJourney', () => { expect(actions.selectVehicleJourney(index)).toEqual(expectedAction) }) }) +describe('when clicking on delete button', () => { + it('should create an action to delete vj', () => { + const expectedAction = { + type: 'DELETE_VEHICLEJOURNEYS', + } + expect(actions.deleteVehicleJourneys()).toEqual(expectedAction) + }) +}) describe('when toggling arrivals', () => { it('should create an action to toggleArrivals', () => { const expectedAction = { diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index 0a7b2330b..6fd3d7a20 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -41,7 +41,7 @@ describe('vehicleJourneys reducer', () => { journey_pattern_id: 2, published_journey_name: "vj2", objectid: 22, - selected: false, + selected: true, deletable: false, footnotes: fakeFootnotes, time_tables: fakeTimeTables, @@ -125,4 +125,12 @@ describe('vehicleJourneys reducer', () => { ).toEqual([newVJ, state[1]]) }) + it('should handle DELETE_VEHICLEJOURNEYS', () => { + const newVJ = Object.assign({}, state[1], {deletable: true}) + expect( + vjReducer(state, { + type: 'DELETE_VEHICLEJOURNEYS' + }) + ).toEqual([state[0], newVJ]) + }) }) -- cgit v1.2.3 From 0f964a8cc0717d8f85b28887d26724a191e67d4a Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Mon, 20 Feb 2017 17:34:27 +0100 Subject: Refs #2505: Add delta between departure and arrival for vjas Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index 6fd3d7a20..27c2f2282 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -13,6 +13,7 @@ let fakeFootnotes = [{ let fakeTimeTables = [] let fakeVJAS = [{ + delta : '671', arrival_time : { hour: '11', minute: '11' @@ -90,6 +91,7 @@ describe('vehicleJourneys reducer', () => { it('should handle UPDATE_TIME', () => { const val = '33', subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true, isArrivalsToggled = true let newVJAS = [{ + delta: 682, arrival_time : { hour: '11', minute: '11' -- cgit v1.2.3 From dd8487d6771ac76ebc60eff7e50730b2314a0ec2 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 21 Feb 2017 16:56:41 +0100 Subject: Refs #2521: Add shift vj schedules, no implementation of day offset yet Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 12 ++++++- .../reducers/vehicle_journeys_spec.js | 38 ++++++++++++++++++---- 2 files changed, 43 insertions(+), 7 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index d7e64b100..b3a0fe810 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -38,7 +38,7 @@ describe('when clicking on add button', () => { }) }) describe('when clicking on validate button inside create modal', () => { - it('should create an action to create a new journey pattern', () => { + it('should create an action to create a new vehicle journey', () => { const data = {} const expectedAction = { type: 'ADD_VEHICLEJOURNEY', @@ -122,3 +122,13 @@ describe('when updating vjas time', () => { expect(actions.updateTime(val, subIndex, index, timeUnit, isDeparture, isArrivalsToggled)).toEqual(expectedAction) }) }) +describe('when clicking on validate button inside shifting modal', () => { + it('should create an action to shift a vehiclejourney schedule', () => { + const data = {} + const expectedAction = { + type: 'SHIFT_VEHICLEJOURNEY', + data + } + expect(actions.shiftVehicleJourney(data)).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index 27c2f2282..1e1c16796 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -13,10 +13,10 @@ let fakeFootnotes = [{ let fakeTimeTables = [] let fakeVJAS = [{ - delta : '671', + delta : 627, arrival_time : { hour: '11', - minute: '11' + minute: '55' }, departure_time : { hour: '22', @@ -31,7 +31,7 @@ describe('vehicleJourneys reducer', () => { { journey_pattern_id: 1, published_journey_name: "vj1", - objectid: 11, + objectid: '11', deletable: false, selected: false, footnotes: fakeFootnotes, @@ -41,7 +41,7 @@ describe('vehicleJourneys reducer', () => { { journey_pattern_id: 2, published_journey_name: "vj2", - objectid: 22, + objectid: '22', selected: true, deletable: false, footnotes: fakeFootnotes, @@ -91,10 +91,10 @@ describe('vehicleJourneys reducer', () => { it('should handle UPDATE_TIME', () => { const val = '33', subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true, isArrivalsToggled = true let newVJAS = [{ - delta: 682, + delta: 638, arrival_time : { hour: '11', - minute: '11' + minute: '55' }, departure_time : { hour: '22', @@ -135,4 +135,30 @@ describe('vehicleJourneys reducer', () => { }) ).toEqual([state[0], newVJ]) }) + + it('should handle SHIFT_VEHICLEJOURNEY', () => { + let newVJAS = [{ + delta: 627, + arrival_time : { + hour: '12', + minute: '00' + }, + departure_time : { + hour: '22', + minute: '27' + }, + stop_area_object_id : "FR:92024:ZDE:420553:STIF" + }] + let fakeData = { + objectid: {value : '11'}, + additional_time: {value: '5'} + } + let newVJ = Object.assign({}, state[0], {vehicle_journey_at_stops: newVJAS}) + expect( + vjReducer(state, { + type: 'SHIFT_VEHICLEJOURNEY', + data: fakeData + }) + ).toEqual([newVJ, state[1]]) + }) }) -- cgit v1.2.3 From 530109322e61cbc7c0127a243ab467d468c50ebe Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 22 Feb 2017 12:29:10 +0100 Subject: Fix Shift feature with preselected vehicle journey Signed-off-by: Thomas Shawarma Haddad --- .../vehicle_journeys/reducers/vehicle_journeys_spec.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index 1e1c16796..93f557e03 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -33,7 +33,7 @@ describe('vehicleJourneys reducer', () => { published_journey_name: "vj1", objectid: '11', deletable: false, - selected: false, + selected: true, footnotes: fakeFootnotes, time_tables: fakeTimeTables, vehicle_journey_at_stops: fakeVJAS @@ -42,7 +42,7 @@ describe('vehicleJourneys reducer', () => { journey_pattern_id: 2, published_journey_name: "vj2", objectid: '22', - selected: true, + selected: false, deletable: false, footnotes: fakeFootnotes, time_tables: fakeTimeTables, @@ -117,23 +117,23 @@ describe('vehicleJourneys reducer', () => { }) it('should handle SELECT_VEHICLEJOURNEY', () => { - const index = 0 - const newVJ = Object.assign({}, state[0], {selected: true}) + const index = 1 + const newVJ = Object.assign({}, state[1], {selected: true}) expect( vjReducer(state, { type: 'SELECT_VEHICLEJOURNEY', index }) - ).toEqual([newVJ, state[1]]) + ).toEqual([state[0], newVJ]) }) it('should handle DELETE_VEHICLEJOURNEYS', () => { - const newVJ = Object.assign({}, state[1], {deletable: true}) + const newVJ = Object.assign({}, state[0], {deletable: true}) expect( vjReducer(state, { type: 'DELETE_VEHICLEJOURNEYS' }) - ).toEqual([state[0], newVJ]) + ).toEqual([newVJ, state[1]]) }) it('should handle SHIFT_VEHICLEJOURNEY', () => { -- cgit v1.2.3 From b88cd552930099714000393584355c314f045cb6 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 22 Feb 2017 14:30:06 +0100 Subject: Remove components spec as browserify-rails externals don't work Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/itineraries/components_spec.js | 53 ------------------------- 1 file changed, 53 deletions(-) delete mode 100644 spec/javascripts/itineraries/components_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/itineraries/components_spec.js b/spec/javascripts/itineraries/components_spec.js deleted file mode 100644 index 24ead7b5d..000000000 --- a/spec/javascripts/itineraries/components_spec.js +++ /dev/null @@ -1,53 +0,0 @@ -var React = require('react'); -var shallow = require('enzyme').shallow; -var mount = require('enzyme').mount; -var StopPointList = require('es6_browserified/itineraries/components/StopPointList'); -var StopPoint = require('es6_browserified/itineraries/components/StopPoint'); -var sinon = require('sinon') - -describe('(Component) StopPointList', () => { - it('renders without exploding', () => { - const wrapper = shallow( {}} - onMoveDownClick={() => {}} - onMoveUpClick={() => {}} - onDeleteClick={() => {}} - onSelectChange={() => {}} - onSelectMarker={() => {}} - onUnselectMarker={() => {}} - />); - expect(wrapper.length).toEqual(1); - }); - - it('simulates click events', () => { - const state = { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal', - user_objectid: '', - olMap: { - isOpened: false, - json: {} - } - } - const onButtonClick = sinon.spy(); - const wrapper = mount( {}} - onMoveDownClick={() => {}} - onMoveUpClick={() => {}} - onDeleteClick={onButtonClick} - onSelectChange={() => {}} - onSelectMarker={() => {}} - onToggleMap={() => {}} - onUnselectMarker={() => {}} - first= {true} - last= {true} - index= {0} - />); - wrapper.find('.delete').simulate('click'); - expect(onButtonClick.calledOnce).toEqual(true); - }); -}); -- cgit v1.2.3 From dd1f5d9e9e984e6d704d23dd90a3c0757460cc68 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 22 Feb 2017 14:30:06 +0100 Subject: Remove components spec as browserify-rails externals don't work Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/itineraries/components_spec.js | 53 ------------------------- 1 file changed, 53 deletions(-) delete mode 100644 spec/javascripts/itineraries/components_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/itineraries/components_spec.js b/spec/javascripts/itineraries/components_spec.js deleted file mode 100644 index 24ead7b5d..000000000 --- a/spec/javascripts/itineraries/components_spec.js +++ /dev/null @@ -1,53 +0,0 @@ -var React = require('react'); -var shallow = require('enzyme').shallow; -var mount = require('enzyme').mount; -var StopPointList = require('es6_browserified/itineraries/components/StopPointList'); -var StopPoint = require('es6_browserified/itineraries/components/StopPoint'); -var sinon = require('sinon') - -describe('(Component) StopPointList', () => { - it('renders without exploding', () => { - const wrapper = shallow( {}} - onMoveDownClick={() => {}} - onMoveUpClick={() => {}} - onDeleteClick={() => {}} - onSelectChange={() => {}} - onSelectMarker={() => {}} - onUnselectMarker={() => {}} - />); - expect(wrapper.length).toEqual(1); - }); - - it('simulates click events', () => { - const state = { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal', - user_objectid: '', - olMap: { - isOpened: false, - json: {} - } - } - const onButtonClick = sinon.spy(); - const wrapper = mount( {}} - onMoveDownClick={() => {}} - onMoveUpClick={() => {}} - onDeleteClick={onButtonClick} - onSelectChange={() => {}} - onSelectMarker={() => {}} - onToggleMap={() => {}} - onUnselectMarker={() => {}} - first= {true} - last= {true} - index= {0} - />); - wrapper.find('.delete').simulate('click'); - expect(onButtonClick.calledOnce).toEqual(true); - }); -}); -- cgit v1.2.3 From 46ed7a797e1243e133e45be15cf8d6452997460f Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 22 Feb 2017 15:06:51 +0100 Subject: Fix Add specs and improve pad method Signed-off-by: Thomas Shawarma Haddad --- .../vehicle_journeys/reducers/vehicle_journeys_spec.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index 93f557e03..01a66bc01 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -59,6 +59,17 @@ describe('vehicleJourneys reducer', () => { it('should handle ADD_VEHICLEJOURNEY', () => { + let resultVJ = [{ + delta : 0, + arrival_time : { + hour: '00', + minute: '00' + }, + departure_time : { + hour: '00', + minute: '00' + } + }] let fakeData = { journey_pattern_id: {value : '1'}, comment: {value: 'test'} @@ -74,7 +85,8 @@ describe('vehicleJourneys reducer', () => { objectid: '', footnotes: [], time_tables: [], - vehicle_journey_at_stops: [], + vehicle_journey_at_stops: resultVJ, + selected: false, deletable: false }, ...state]) }) -- cgit v1.2.3 From 4da287ebaab5df1247c325754a1c10c71243c978 Mon Sep 17 00:00:00 2001 From: jpl Date: Wed, 22 Feb 2017 16:36:04 +0100 Subject: Refs #2629: updating route subform, olmap (second pass) --- .../itineraries/reducers/stop_points_spec.js | 68 ++++++++++++++++++++-- 1 file changed, 64 insertions(+), 4 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/itineraries/reducers/stop_points_spec.js b/spec/javascripts/itineraries/reducers/stop_points_spec.js index d6917f782..adbf77aa1 100644 --- a/spec/javascripts/itineraries/reducers/stop_points_spec.js +++ b/spec/javascripts/itineraries/reducers/stop_points_spec.js @@ -16,6 +16,7 @@ describe('stops reducer', () => { { text: 'first', index: 0, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -26,6 +27,7 @@ describe('stops reducer', () => { { text: 'second', index: 1, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -52,6 +54,7 @@ describe('stops reducer', () => { { text: 'first', index: 0, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -62,6 +65,7 @@ describe('stops reducer', () => { { text: 'second', index: 1, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -72,6 +76,7 @@ describe('stops reducer', () => { { text: '', index: 2, + edit: true, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -94,6 +99,7 @@ describe('stops reducer', () => { { text: 'second', index: 1, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -104,6 +110,7 @@ describe('stops reducer', () => { { text: 'first', index: 0, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -126,6 +133,7 @@ describe('stops reducer', () => { { text: 'second', index: 1, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -136,6 +144,7 @@ describe('stops reducer', () => { { text: 'first', index: 0, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -158,6 +167,7 @@ describe('stops reducer', () => { { text: 'first', index: 0, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -174,6 +184,7 @@ describe('stops reducer', () => { stopPointsReducer(state, { type: 'UPDATE_INPUT_VALUE', index: 0, + edit: false, text: { text: "new value", name: 'new', @@ -190,6 +201,7 @@ describe('stops reducer', () => { text: 'new value', name: 'new', index: 0, + edit: false, stoppoint_id: '', stoparea_id: 1, for_boarding: 'normal', @@ -206,6 +218,7 @@ describe('stops reducer', () => { { text: 'second', index: 1, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -220,16 +233,17 @@ describe('stops reducer', () => { it('should handle UPDATE_SELECT_VALUE', () => { expect( stopPointsReducer(state, { - type :'UPDATE_SELECT_VALUE', - select_id: 'for_boarding', - select_value: 'prohibited', - index: 0 + type :'UPDATE_SELECT_VALUE', + select_id: 'for_boarding', + select_value: 'prohibited', + index: 0 }) ).toEqual( [ { text: 'first', index: 0, + edit: false, for_boarding: 'prohibited', for_alighting: 'normal', olMap: { @@ -240,6 +254,7 @@ describe('stops reducer', () => { { text: 'second', index: 1, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -262,6 +277,7 @@ describe('stops reducer', () => { { text: 'first', index: 0, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -269,6 +285,7 @@ describe('stops reducer', () => { json: { text: 'first', index: 0, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: undefined @@ -278,6 +295,41 @@ describe('stops reducer', () => { { text: 'second', index: 1, + edit: false, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + } + ] + ) + }) + + it('should handle TOGGLE_EDIT', () => { + expect( + stopPointsReducer(state, { + type: 'TOGGLE_EDIT', + index: 0 + }) + ).toEqual( + [ + { + text: 'first', + index: 0, + edit: true, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + }, + { + text: 'second', + index: 1, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -294,6 +346,7 @@ describe('stops reducer', () => { { text: 'first', index: 0, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -304,6 +357,7 @@ describe('stops reducer', () => { { text: 'second', index: 1, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -323,6 +377,7 @@ describe('stops reducer', () => { { text: 'first', index: 0, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -333,6 +388,7 @@ describe('stops reducer', () => { { text: 'second', index: 1, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -349,6 +405,7 @@ describe('stops reducer', () => { { text: 'first', index: 0, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -359,6 +416,7 @@ describe('stops reducer', () => { { text: 'second', index: 1, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -378,6 +436,7 @@ describe('stops reducer', () => { { text: 'first', index: 0, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { @@ -388,6 +447,7 @@ describe('stops reducer', () => { { text: 'second', index: 1, + edit: false, for_boarding: 'normal', for_alighting: 'normal', olMap: { -- cgit v1.2.3 From 3b30c4a02db84c9c605b93da25d36e5f57fca9ca Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 22 Feb 2017 18:44:04 +0100 Subject: Refs #2524: Add Duplicate Vehicle journey feature Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 10 ++++++++ .../reducers/vehicle_journeys_spec.js | 28 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index b3a0fe810..952c80312 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -132,3 +132,13 @@ describe('when clicking on validate button inside shifting modal', () => { expect(actions.shiftVehicleJourney(data)).toEqual(expectedAction) }) }) +describe('when clicking on validate button inside duplicating modal', () => { + it('should create an action to duplicate a vehiclejourney schedule', () => { + const data = {} + const expectedAction = { + type: 'DUPLICATE_VEHICLEJOURNEY', + data + } + expect(actions.duplicateVehicleJourney(data)).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index 01a66bc01..dc04d5bf7 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -173,4 +173,32 @@ describe('vehicleJourneys reducer', () => { }) ).toEqual([newVJ, state[1]]) }) + + it('should handle DUPLICATE_VEHICLEJOURNEY', () => { + let newVJAS = [{ + delta: 627, + arrival_time : { + hour: '12', + minute: '00' + }, + departure_time : { + hour: '22', + minute: '27' + }, + stop_area_object_id : "FR:92024:ZDE:420553:STIF" + }] + let fakeData = { + duplicate_number: {value : 1}, + additional_time: {value: '5'} + } + let newVJ = Object.assign({}, state[0], {vehicle_journey_at_stops: newVJAS, selected: false}) + newVJ.comment = state[0].comment + '-0' + delete newVJ['objectid'] + expect( + vjReducer(state, { + type: 'DUPLICATE_VEHICLEJOURNEY', + data: fakeData + }) + ).toEqual([state[0], newVJ, state[1]]) + }) }) -- cgit v1.2.3 From ec224c3a86678c6765a8f5a4ba6700e66b747cc7 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Thu, 23 Feb 2017 14:46:05 +0100 Subject: Refs #2521: Add edit modal for vj medatatas (only comment editable) Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 10 ++++++++++ .../vehicle_journeys/reducers/vehicle_journeys_spec.js | 13 +++++++++++++ 2 files changed, 23 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 952c80312..5d01ac284 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -132,6 +132,16 @@ describe('when clicking on validate button inside shifting modal', () => { expect(actions.shiftVehicleJourney(data)).toEqual(expectedAction) }) }) +describe('when clicking on validate button inside editing modal', () => { + it('should create an action to update a vehiclejourney', () => { + const data = {} + const expectedAction = { + type: 'EDIT_VEHICLEJOURNEY', + data + } + expect(actions.editVehicleJourney(data)).toEqual(expectedAction) + }) +}) describe('when clicking on validate button inside duplicating modal', () => { it('should create an action to duplicate a vehiclejourney schedule', () => { const data = {} diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index dc04d5bf7..35d53a1fd 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -201,4 +201,17 @@ describe('vehicleJourneys reducer', () => { }) ).toEqual([state[0], newVJ, state[1]]) }) + + it('should handle EDIT_VEHICLEJOURNEY', () => { + let fakeData = { + comment: {value : 'toto'}, + } + let newVJ = Object.assign({}, state[0], {comment: fakeData.comment.value}) + expect( + vjReducer(state, { + type: 'EDIT_VEHICLEJOURNEY', + data: fakeData + }) + ).toEqual([newVJ, state[1]]) + }) }) -- cgit v1.2.3 From 72c004af1cc964433019aa0fea54e81cc9d0918d Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 24 Feb 2017 14:59:30 +0100 Subject: Refs #2521: Add footnote edition for one vj Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 31 ++++++++++++++++++++++ .../vehicle_journeys/reducers/modal_spec.js | 31 ++++++++++++++++++++++ .../reducers/vehicle_journeys_spec.js | 23 ++++++++++++++++ 3 files changed, 85 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 5d01ac284..d2c95d4a1 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -152,3 +152,34 @@ describe('when clicking on validate button inside duplicating modal', () => { expect(actions.duplicateVehicleJourney(data)).toEqual(expectedAction) }) }) +describe('when clicking on edit notes modal', () => { + it('should create an action to open footnotes modal', () => { + const vehicleJourney = {} + const expectedAction = { + type: 'EDIT_NOTES_VEHICLEJOURNEY_MODAL', + vehicleJourney + } + expect(actions.openNotesEditModal(vehicleJourney)).toEqual(expectedAction) + }) +}) +describe('when clicking on a footnote button inside footnote modal', () => { + it('should create an action to toggle this footnote', () => { + const footnote = {}, isShown = true + const expectedAction = { + type: 'TOGGLE_FOOTNOTE_MODAL', + footnote, + isShown + } + expect(actions.toggleFootnoteModal(footnote, isShown)).toEqual(expectedAction) + }) +}) +describe('when clicking on validate button inside footnote modal', () => { + it('should create an action to update vj footnotes', () => { + const footnotes = [] + const expectedAction = { + type: 'EDIT_VEHICLEJOURNEY_NOTES', + footnotes + } + expect(actions.editVehicleJourneyNotes(footnotes)).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js index 8e854be40..b41f0818f 100644 --- a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js @@ -49,4 +49,35 @@ describe('modal reducer', () => { }) ).toEqual(state) }) + + it('should handle EDIT_NOTES_VEHICLEJOURNEY_MODAL', () => { + let vehicleJourney = {} + let modalPropsResult = { + vehicleJourney: {} + } + expect( + modalReducer(state, { + type: 'EDIT_NOTES_VEHICLEJOURNEY_MODAL', + vehicleJourney + }) + ).toEqual(Object.assign({}, state, {type: 'notes_edit', modalProps: modalPropsResult})) + }) + + it('should handle TOGGLE_FOOTNOTE_MODAL', () => { + state.modalProps = {vehicleJourney : {footnotes: [{}, {}]}} + let footnote = {} + let newState = { + // for the sake of the test, no need to specify the type + type: '', + modalProps:{vehicleJourney: {footnotes: [{},{},{}]}}, + confirmModal: {} + } + expect( + modalReducer(state, { + type: 'TOGGLE_FOOTNOTE_MODAL', + footnote, + isShown: true + }) + ).toEqual(newState) + }) }) diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index 35d53a1fd..f0665a023 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -1,6 +1,11 @@ var vjReducer = require('es6_browserified/vehicle_journeys/reducers/vehicleJourneys') let state = [] +let stateModal = { + type: '', + modalProps: {}, + confirmModal: {} +} let fakeFootnotes = [{ id: 1, code: 1, @@ -214,4 +219,22 @@ describe('vehicleJourneys reducer', () => { }) ).toEqual([newVJ, state[1]]) }) + + + it('should handle EDIT_VEHICLEJOURNEY_NOTES', () => { + let fakeFootnote = { + id: 3, + code: 3, + label: "3" + } + fakeFootnotes.push(fakeFootnote) + let fakeFootnotesResult = fakeFootnotes.slice(0) + let newVJ = Object.assign({}, state[0], {footnotes: fakeFootnotesResult}) + expect( + vjReducer(state, { + type: 'EDIT_VEHICLEJOURNEY_NOTES', + footnotes: fakeFootnotesResult + }) + ).toEqual([newVJ, state[1]]) + }) }) -- cgit v1.2.3 From 17ed10b09295bfc7657010583d4aab16314a88c3 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 24 Feb 2017 15:01:56 +0100 Subject: Fix spec gardening Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index f0665a023..2eff8a559 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -222,13 +222,11 @@ describe('vehicleJourneys reducer', () => { it('should handle EDIT_VEHICLEJOURNEY_NOTES', () => { - let fakeFootnote = { + let fakeFootnotesResult = fakeFootnotes.push({ id: 3, code: 3, label: "3" - } - fakeFootnotes.push(fakeFootnote) - let fakeFootnotesResult = fakeFootnotes.slice(0) + }) let newVJ = Object.assign({}, state[0], {footnotes: fakeFootnotesResult}) expect( vjReducer(state, { -- cgit v1.2.3 From 30413955f5b28d747ce48c186c3421e389599972 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Mon, 27 Feb 2017 18:02:08 +0100 Subject: Refs #2521: Add edit calendar modal (no add yet) Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 30 ++++++++++++++++++++ .../vehicle_journeys/reducers/modal_spec.js | 33 ++++++++++++++++++++++ .../reducers/vehicle_journeys_spec.js | 27 +++++++++++------- 3 files changed, 80 insertions(+), 10 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index d2c95d4a1..f602a8c89 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -183,3 +183,33 @@ describe('when clicking on validate button inside footnote modal', () => { expect(actions.editVehicleJourneyNotes(footnotes)).toEqual(expectedAction) }) }) +describe('when clicking on calendar button in toolbox', () => { + it('should create an action to open calendar modal', () => { + const vehicleJourneys = [] + const expectedAction = { + type: 'EDIT_CALENDARS_VEHICLEJOURNEY_MODAL', + vehicleJourneys + } + expect(actions.openCalendarsEditModal(vehicleJourneys)).toEqual(expectedAction) + }) +}) +describe('when clicking on delete button next to a timetable inside modal', () => { + it('should create an action to delete timetable from selected vehicle journeys', () => { + const timetable = {} + const expectedAction = { + type: 'DELETE_CALENDAR_MODAL', + timetable + } + expect(actions.deleteCalendarModal(timetable)).toEqual(expectedAction) + }) +}) +describe('when clicking on validate button inside calendars modal', () => { + it('should create an action to update vj calendars', () => { + const vehicleJourneys = [] + const expectedAction = { + type: 'EDIT_VEHICLEJOURNEYS_CALENDARS', + vehicleJourneys + } + expect(actions.editVehicleJourneyCalendars(vehicleJourneys)).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js index b41f0818f..fecb7bb0d 100644 --- a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js @@ -80,4 +80,37 @@ describe('modal reducer', () => { }) ).toEqual(newState) }) + + it('should handle EDIT_CALENDARS_VEHICLEJOURNEY_MODAL', () => { + let vehicleJourneys = [] + let modalPropsResult = { + vehicleJourneys: [], + timetables: [] + } + expect( + modalReducer(state, { + type: 'EDIT_CALENDARS_VEHICLEJOURNEY_MODAL', + vehicleJourneys + }) + ).toEqual(Object.assign({}, state, {type: 'calendars_edit', modalProps: modalPropsResult})) + }) + + it('should handle DELETE_CALENDAR_MODAL', () => { + // TODO spec more for vehiclejourneys + let deletableTimetable = {'delete': 'delete'} + state.modalProps = {vehicleJourneys : [], timetables: [{'test': 'test'}, {'test 2': 'test 2'}, deletableTimetable] } + let footnote = {} + let newState = { + // for the sake of the test, no need to specify the type + type: '', + modalProps:{vehicleJourneys: [], timetables: [{'test': 'test'},{'test 2': 'test 2'}]}, + confirmModal: {} + } + expect( + modalReducer(state, { + type: 'DELETE_CALENDAR_MODAL', + timetable: deletableTimetable + }) + ).toEqual(newState) + }) }) diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index 2eff8a559..0e1daa360 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -16,7 +16,16 @@ let fakeFootnotes = [{ label: "2" }] -let fakeTimeTables = [] +let fakeTimeTables = [{ + comment: 'test 1', + objectid: '1' +},{ + comment: 'test 2', + objectid: '2' +},{ + comment: 'test 3', + objectid: '3' +}] let fakeVJAS = [{ delta : 627, arrival_time : { @@ -221,18 +230,16 @@ describe('vehicleJourneys reducer', () => { }) - it('should handle EDIT_VEHICLEJOURNEY_NOTES', () => { - let fakeFootnotesResult = fakeFootnotes.push({ - id: 3, - code: 3, - label: "3" + it('should handle EDIT_VEHICLEJOURNEYS_CALENDARS', () => { + let newState = JSON.parse(JSON.stringify(state)) + newState.map((vj, i) =>{ + return Object.assign({}, vj, {time_tables : vj.time_tables[0]}) }) - let newVJ = Object.assign({}, state[0], {footnotes: fakeFootnotesResult}) expect( vjReducer(state, { - type: 'EDIT_VEHICLEJOURNEY_NOTES', - footnotes: fakeFootnotesResult + type: 'EDIT_VEHICLEJOURNEYS_CALENDARS', + vehicleJourneys: newState }) - ).toEqual([newVJ, state[1]]) + ).toEqual(newState) }) }) -- cgit v1.2.3 From 3377eea59a660f0817c29a6ed7fa9a466c66a070 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 28 Feb 2017 13:51:27 +0100 Subject: Fix vj specs and modal specs Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/reducers/modal_spec.js | 7 +++++-- .../javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js index fecb7bb0d..576656c88 100644 --- a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js @@ -98,12 +98,15 @@ describe('modal reducer', () => { it('should handle DELETE_CALENDAR_MODAL', () => { // TODO spec more for vehiclejourneys let deletableTimetable = {'delete': 'delete'} - state.modalProps = {vehicleJourneys : [], timetables: [{'test': 'test'}, {'test 2': 'test 2'}, deletableTimetable] } + let fakeTimetables = [{'test': 'test'}, {'test 2': 'test 2'}, deletableTimetable] + let newTimeTables = [{'test': 'test'}, {'test 2': 'test 2'}] + let fakeVehicleJourneys= [{time_tables: fakeTimetables}, {time_tables: fakeTimetables}] + state.modalProps = {vehicleJourneys : fakeVehicleJourneys, timetables: fakeTimetables } let footnote = {} let newState = { // for the sake of the test, no need to specify the type type: '', - modalProps:{vehicleJourneys: [], timetables: [{'test': 'test'},{'test 2': 'test 2'}]}, + modalProps:{vehicleJourneys: [{time_tables: newTimeTables},{time_tables: newTimeTables}], timetables: [{'test': 'test'},{'test 2': 'test 2'}]}, confirmModal: {} } expect( diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index 0e1daa360..ac4c299c9 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -85,7 +85,7 @@ describe('vehicleJourneys reducer', () => { } }] let fakeData = { - journey_pattern_id: {value : '1'}, + journey_pattern_objectid: {value : '1'}, comment: {value: 'test'} } expect( @@ -94,7 +94,7 @@ describe('vehicleJourneys reducer', () => { data: fakeData }) ).toEqual([{ - journey_pattern_id: 1, + journey_pattern: {objectid: '1'}, comment: 'test', objectid: '', footnotes: [], -- cgit v1.2.3 From 072e4f76f1c98dca9b4a85efa87052842d880d07 Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 28 Feb 2017 15:03:30 +0100 Subject: Refs #2648: updating jp_collection layout --- spec/javascripts/journey_patterns/reducers/journey_patterns_spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/reducers/journey_patterns_spec.js b/spec/javascripts/journey_patterns/reducers/journey_patterns_spec.js index 422c97fee..9fcabf439 100644 --- a/spec/javascripts/journey_patterns/reducers/journey_patterns_spec.js +++ b/spec/javascripts/journey_patterns/reducers/journey_patterns_spec.js @@ -57,13 +57,13 @@ describe('journeyPatterns reducer', () => { type: 'ADD_JOURNEYPATTERN', data: fakeData }) - ).toEqual([...state, { + ).toEqual([{ name : 'm3', published_name: 'M3', registration_number: '', deletable: false, stop_points: fakeStopPoints - }]) + }, ...state]) }) it('should handle UPDATE_CHECKBOX_VALUE', () => { -- cgit v1.2.3 From 496cb95c40d2108a89ec6c3aef534ab496066861 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 28 Feb 2017 15:36:13 +0100 Subject: Refs #2521: Add Tools Wrapper and CANCEL_SELECTION action Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 9 +++++++++ .../vehicle_journeys/reducers/vehicle_journeys_spec.js | 11 +++++++++++ 2 files changed, 20 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index f602a8c89..593e1b092 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -91,6 +91,15 @@ describe('when checking a vehicleJourney', () => { expect(actions.selectVehicleJourney(index)).toEqual(expectedAction) }) }) +describe('when clicking on cancel selection button', () => { + it('should create an action to cancel whole selection', () => { + const index = 1 + const expectedAction = { + type: 'CANCEL_SELECTION' + } + expect(actions.cancelSelection()).toEqual(expectedAction) + }) +}) describe('when clicking on delete button', () => { it('should create an action to delete vj', () => { const expectedAction = { diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index ac4c299c9..422cd1461 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -153,6 +153,17 @@ describe('vehicleJourneys reducer', () => { ).toEqual([state[0], newVJ]) }) + it('should handle CANCEL_SELECTION', () => { + const index = 1 + const newVJ = Object.assign({}, state[0], {selected: false}) + expect( + vjReducer(state, { + type: 'CANCEL_SELECTION', + index + }) + ).toEqual([newVJ, state[1]]) + }) + it('should handle DELETE_VEHICLEJOURNEYS', () => { const newVJ = Object.assign({}, state[0], {deletable: true}) expect( -- cgit v1.2.3 From 599addc323b0b08ddcea7871748760c0bec83585 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 28 Feb 2017 18:30:51 +0100 Subject: Refs #2521: Fix use correct vj properties (published journey name / id & company) Signed-off-by: Thomas Shawarma Haddad --- .../vehicle_journeys/reducers/vehicle_journeys_spec.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index 422cd1461..02e9deffc 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -17,13 +17,13 @@ let fakeFootnotes = [{ }] let fakeTimeTables = [{ - comment: 'test 1', + published_journey_name: 'test 1', objectid: '1' },{ - comment: 'test 2', + published_journey_name: 'test 2', objectid: '2' },{ - comment: 'test 3', + published_journey_name: 'test 3', objectid: '3' }] let fakeVJAS = [{ @@ -86,7 +86,7 @@ describe('vehicleJourneys reducer', () => { }] let fakeData = { journey_pattern_objectid: {value : '1'}, - comment: {value: 'test'} + published_journey_name: {value: 'test'} } expect( vjReducer(state, { @@ -95,7 +95,7 @@ describe('vehicleJourneys reducer', () => { }) ).toEqual([{ journey_pattern: {objectid: '1'}, - comment: 'test', + published_journey_name: 'test', objectid: '', footnotes: [], time_tables: [], @@ -217,7 +217,7 @@ describe('vehicleJourneys reducer', () => { additional_time: {value: '5'} } let newVJ = Object.assign({}, state[0], {vehicle_journey_at_stops: newVJAS, selected: false}) - newVJ.comment = state[0].comment + '-0' + newVJ.published_journey_name = state[0].published_journey_name + '-0' delete newVJ['objectid'] expect( vjReducer(state, { @@ -229,9 +229,10 @@ describe('vehicleJourneys reducer', () => { it('should handle EDIT_VEHICLEJOURNEY', () => { let fakeData = { - comment: {value : 'toto'}, + published_journey_name: {value : 'test'}, + published_journey_identifier: {value: 'test'} } - let newVJ = Object.assign({}, state[0], {comment: fakeData.comment.value}) + let newVJ = Object.assign({}, state[0], {published_journey_name: fakeData.published_journey_name.value, published_journey_identifier: fakeData.published_journey_identifier.value}) expect( vjReducer(state, { type: 'EDIT_VEHICLEJOURNEY', -- cgit v1.2.3 From 886088ed4944865689debc8d821ce04753650e81 Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 28 Feb 2017 19:20:03 +0100 Subject: Refs #2648: jp_collection refacto, to allow adding a jp from scratch --- .../reducers/journey_patterns_spec.js | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/reducers/journey_patterns_spec.js b/spec/javascripts/journey_patterns/reducers/journey_patterns_spec.js index 9fcabf439..df288e530 100644 --- a/spec/javascripts/journey_patterns/reducers/journey_patterns_spec.js +++ b/spec/javascripts/journey_patterns/reducers/journey_patterns_spec.js @@ -6,7 +6,6 @@ let fakeStopPoints = [{ id : 45289, name : "Clichy Levallois", object_id : "FR:92044:LDA:72073:STIF", - object_version : 1, position : 0, },{ area_type : "lda", @@ -14,9 +13,29 @@ let fakeStopPoints = [{ id : 40534, name : "Thomas Lemaître", object_id : "FR:92050:LDA:70915:STIF", - object_version : 1, position : 1, }] +let stopPoints = [{ + area_type : 'zdep', + city_name : 'Plaisir', + for_alighting : 'normal', + for_boarding : 'normal', + id : 14892, + name : 'test1', + object_id : 'test:StopPoint:1', + position : 0, + zip_code : '78490' +},{ + area_type : 'zdep', + city_name : 'Plaisir', + for_alighting : 'normal', + for_boarding : 'normal', + id : 14893, + name : 'test2', + object_id : 'test:StopPoint:2', + position : 1, + zip_code : '78490' +}] describe('journeyPatterns reducer', () => { beforeEach(()=>{ @@ -52,6 +71,7 @@ describe('journeyPatterns reducer', () => { published_name: {value: 'M3'}, registration_number: {value: ''} } + let stopPoints = stopPoints expect( jpReducer(state, { type: 'ADD_JOURNEYPATTERN', @@ -62,7 +82,7 @@ describe('journeyPatterns reducer', () => { published_name: 'M3', registration_number: '', deletable: false, - stop_points: fakeStopPoints + stop_points: stopPoints }, ...state]) }) -- cgit v1.2.3 From 030d07718bde5fb9bbb165e06e7d2269c9217190 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Thu, 2 Mar 2017 17:04:09 +0100 Subject: Refs #2522: use Bselect2 to link a jp to a vj Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 26 ++++++++++++++++++++-- .../vehicle_journeys/reducers/modal_spec.js | 10 +++++++++ .../reducers/vehicle_journeys_spec.js | 7 +++--- 3 files changed, 38 insertions(+), 5 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 593e1b092..3824893e4 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -37,14 +37,36 @@ describe('when clicking on add button', () => { expect(actions.openCreateModal()).toEqual(expectedAction) }) }) +describe('when using select2 to pick a journey pattern', () => { + it('should create an action to select a journey pattern inside modal', () => { + let selectedJP = { + id: 1, + object_id: 2, + name: 'test', + published_name: 'test' + } + const expectedAction = { + type: 'SELECT_JP_CREATE_MODAL', + selectedItem:{ + id: selectedJP.id, + objectid: selectedJP.object_id, + name: selectedJP.name, + published_name: selectedJP.published_name + } + } + expect(actions.selectJPCreateModal(selectedJP)).toEqual(expectedAction) + }) +}) describe('when clicking on validate button inside create modal', () => { it('should create an action to create a new vehicle journey', () => { const data = {} + const selectedJourneyPattern = {} const expectedAction = { type: 'ADD_VEHICLEJOURNEY', - data + data, + selectedJourneyPattern } - expect(actions.addVehicleJourney(data)).toEqual(expectedAction) + expect(actions.addVehicleJourney(data, selectedJourneyPattern)).toEqual(expectedAction) }) }) describe('when previous navigation button is clicked', () => { diff --git a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js index 576656c88..edf55ca65 100644 --- a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js @@ -42,6 +42,16 @@ describe('modal reducer', () => { ).toEqual(Object.assign({}, state, { type: 'create' })) }) + it('should handle SELECT_JP_CREATE_MODAL', () => { + let newModalProps = {selectedJPModal : {id: 1}} + expect( + modalReducer(state, { + type: 'SELECT_JP_CREATE_MODAL', + selectedItem: {id: 1} + }) + ).toEqual(Object.assign({}, state, {modalProps: newModalProps})) + }) + it('should handle CLOSE_MODAL', () => { expect( modalReducer(state, { diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index 02e9deffc..60e78047e 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -85,16 +85,17 @@ describe('vehicleJourneys reducer', () => { } }] let fakeData = { - journey_pattern_objectid: {value : '1'}, published_journey_name: {value: 'test'} } + let fakeSelectedJourneyPattern = { id: "1"} expect( vjReducer(state, { type: 'ADD_VEHICLEJOURNEY', - data: fakeData + data: fakeData, + selectedJourneyPattern: fakeSelectedJourneyPattern }) ).toEqual([{ - journey_pattern: {objectid: '1'}, + journey_pattern: fakeSelectedJourneyPattern, published_journey_name: 'test', objectid: '', footnotes: [], -- cgit v1.2.3 From 284d590435ab85b86d3722eb50ce4e1c3b3abf2c Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 3 Mar 2017 18:08:20 +0100 Subject: Refs #2521: Add timetable to one or more vj Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 26 +++++++++++++++ .../vehicle_journeys/reducers/modal_spec.js | 37 ++++++++++++++++++++-- 2 files changed, 60 insertions(+), 3 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 3824893e4..56a2e8511 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -244,3 +244,29 @@ describe('when clicking on validate button inside calendars modal', () => { expect(actions.editVehicleJourneyCalendars(vehicleJourneys)).toEqual(expectedAction) }) }) +describe('when clicking on add button inside calendars modal', () => { + it('should create an action to add the selected timetable to preselected vjs', () => { + const expectedAction = { + type: 'ADD_SELECTED_TIMETABLE', + } + expect(actions.addSelectedTimetable()).toEqual(expectedAction) + }) +}) +describe('when using select2 to pick a timetable', () => { + it('should create an action to select a timetable inside modal', () => { + let selectedTT = { + id: 1, + objectid: 2, + comment: 'test', + } + const expectedAction = { + type: 'SELECT_TT_CALENDAR_MODAL', + selectedItem:{ + id: selectedTT.id, + objectid: selectedTT.objectid, + comment: selectedTT.comment, + } + } + expect(actions.selectTTCalendarsModal(selectedTT)).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js index edf55ca65..7c81d729b 100644 --- a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js @@ -105,14 +105,45 @@ describe('modal reducer', () => { ).toEqual(Object.assign({}, state, {type: 'calendars_edit', modalProps: modalPropsResult})) }) + it('should handle SELECT_TT_CALENDAR_MODAL', () => { + let newModalProps = {selectedTimetable : {id: 1}} + expect( + modalReducer(state, { + type: 'SELECT_TT_CALENDAR_MODAL', + selectedItem: {id: 1} + }) + ).toEqual(Object.assign({}, state, {modalProps: newModalProps})) + }) + + it('should handle ADD_SELECTED_TIMETABLE', () => { + let fakeTimetables = [{'test': 'test'}, {'test 2': 'test 2'}, {'add': 'add'}] + let newTimeTables = [{'test': 'test'}, {'test 2': 'test 2'}, {'add': 'add'}] + let fakeVehicleJourneys= [{time_tables: fakeTimetables}, {time_tables: newTimeTables}] + state.modalProps.vehicleJourneys = fakeVehicleJourneys + state.modalProps.timetables = fakeTimetables + state.modalProps.selectedTimetable = {'add': 'add'} + let newState = { + type: '', + modalProps:{ + vehicleJourneys: [{time_tables: newTimeTables},{time_tables: newTimeTables}], + timetables: [{'test': 'test'},{'test 2': 'test 2'},{'add': 'add'}], + selectedTimetable: {'add': 'add'} + }, + confirmModal: {} + } + expect( + modalReducer(state, { + type: 'ADD_SELECTED_TIMETABLE', + }) + ).toEqual(newState) + }) + it('should handle DELETE_CALENDAR_MODAL', () => { - // TODO spec more for vehiclejourneys let deletableTimetable = {'delete': 'delete'} let fakeTimetables = [{'test': 'test'}, {'test 2': 'test 2'}, deletableTimetable] let newTimeTables = [{'test': 'test'}, {'test 2': 'test 2'}] let fakeVehicleJourneys= [{time_tables: fakeTimetables}, {time_tables: fakeTimetables}] - state.modalProps = {vehicleJourneys : fakeVehicleJourneys, timetables: fakeTimetables } - let footnote = {} + state.modalProps = Object.assign({}, state.modalProps,{vehicleJourneys : fakeVehicleJourneys, timetables: fakeTimetables }) let newState = { // for the sake of the test, no need to specify the type type: '', -- cgit v1.2.3 From e9554edf1a988e9e0a6928742ddbbe914002e8cb Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Mon, 6 Mar 2017 10:46:52 +0100 Subject: Refs #2521: Fix deletable/selected correlation when reduced Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index 60e78047e..cf80dc01f 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -166,7 +166,7 @@ describe('vehicleJourneys reducer', () => { }) it('should handle DELETE_VEHICLEJOURNEYS', () => { - const newVJ = Object.assign({}, state[0], {deletable: true}) + const newVJ = Object.assign({}, state[0], {deletable: true, selected: false}) expect( vjReducer(state, { type: 'DELETE_VEHICLEJOURNEYS' -- cgit v1.2.3 From 6e9a27ad1681a0fc8a12ea2f478856468f6cbfc4 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Mon, 6 Mar 2017 16:58:15 +0100 Subject: Refs #2507: Add reset, interval and toggle vj w/o schedules Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 36 ++++++++ .../vehicle_journeys/reducers/filters_spec.js | 99 +++++++++++++++++++++- 2 files changed, 134 insertions(+), 1 deletion(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 56a2e8511..301f5d8ba 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -270,3 +270,39 @@ describe('when using select2 to pick a timetable', () => { expect(actions.selectTTCalendarsModal(selectedTT)).toEqual(expectedAction) }) }) +describe('when clicking on reset button inside query filters', () => { + it('should create an action to reset the query filters', () => { + const expectedAction = { + type: 'RESET_FILTERS', + } + expect(actions.resetFilters()).toEqual(expectedAction) + }) +}) +describe('when clicking on checkbox to show vj without schedule', () => { + it('should create an action to toggle this filter', () => { + const expectedAction = { + type: 'TOGGLE_WITHOUT_SCHEDULE', + } + expect(actions.toggleWithoutSchedule()).toEqual(expectedAction) + }) +}) +describe('when setting new interval', () => { + const val = 1 + const unit = 'hour' + it('should create actions to update intervals in state', () => { + let expectedAction = { + type: 'UPDATE_START_TIME_FILTER', + val, + unit + } + expect(actions.updateStartTimeFilter(val, unit)).toEqual(expectedAction) + }) + it('should create actions to update intervals in state', () => { + let expectedAction = { + type: 'UPDATE_END_TIME_FILTER', + val, + unit + } + expect(actions.updateEndTimeFilter(val, unit)).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js index ecb80f3c3..53ac5d75b 100644 --- a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js @@ -3,9 +3,34 @@ var statusReducer = require('es6_browserified/vehicle_journeys/reducers/filters' let state = {} describe('filters reducer', () => { + const cleanInterval = { + start:{ + hour: '00', + minute: '00' + }, + end:{ + hour: '23', + minute: '59' + } + } beforeEach(() => { state = { - toggleArrivals: false, + toggleArrivals: false, + query: { + interval: { + start:{ + hour: '11', + minute: '11' + }, + end:{ + hour: '22', + minute: '22' + } + }, + journeyPattern: {}, + timetable: {}, + withoutSchedule: false + } } }) @@ -23,4 +48,76 @@ describe('filters reducer', () => { ).toEqual(Object.assign({}, state, {toggleArrivals: true})) }) + it('should handle RESET_FILTERS', () => { + let cleanQuery = JSON.parse(JSON.stringify(state.query)) + cleanQuery.interval = cleanInterval + expect( + statusReducer(state, { + type: 'RESET_FILTERS' + }) + ).toEqual(Object.assign({}, state, {query: cleanQuery})) + }) + + it('should handle TOGGLE_WITHOUT_SCHEDULE', () => { + let rslt = JSON.parse(JSON.stringify(state.query)) + rslt.withoutSchedule = true + expect( + statusReducer(state, { + type: 'TOGGLE_WITHOUT_SCHEDULE' + }) + ).toEqual(Object.assign({}, state, {query: rslt})) + }) + + it('should handle UPDATE_START_TIME_FILTER', () => { + let val = 12 + let unit = 'minute' + let rslt = JSON.parse(JSON.stringify(state.query)) + rslt.interval.start.minute = String(val) + expect( + statusReducer(state, { + type: 'UPDATE_START_TIME_FILTER', + val, + unit + }) + ).toEqual(Object.assign({}, state, {query: rslt})) + }) + + it('should handle UPDATE_START_TIME_FILTER and not make any update', () => { + let val = 23 + let unit = 'hour' + expect( + statusReducer(state, { + type: 'UPDATE_START_TIME_FILTER', + val, + unit + }) + ).toEqual(state) + }) + + it('should handle UPDATE_END_TIME_FILTER', () => { + let val = 12 + let unit = 'minute' + let rslt = JSON.parse(JSON.stringify(state.query)) + rslt.interval.end.minute = String(val) + expect( + statusReducer(state, { + type: 'UPDATE_END_TIME_FILTER', + val, + unit + }) + ).toEqual(Object.assign({}, state, {query: rslt})) + }) + + it('should handle UPDATE_END_TIME_FILTER and not make any update', () => { + let val = 1 + let unit = 'hour' + expect( + statusReducer(state, { + type: 'UPDATE_END_TIME_FILTER', + val, + unit + }) + ).toEqual(state) + }) + }) -- cgit v1.2.3 From b472d23f30462027910dfc7260fd09e3f350d1ea Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 7 Mar 2017 12:21:55 +0100 Subject: Refs #2507: add timetable to filters Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 18 ++++++++++++++++++ .../vehicle_journeys/reducers/filters_spec.js | 10 ++++++++++ 2 files changed, 28 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 301f5d8ba..6a868baf9 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -306,3 +306,21 @@ describe('when setting new interval', () => { expect(actions.updateEndTimeFilter(val, unit)).toEqual(expectedAction) }) }) +describe('when using select2 to pick a timetable in the filters', () => { + it('should create an action to select a timetable as a filter', () => { + let selectedTT = { + id: 1, + objectid: 2, + comment: 'test', + } + const expectedAction = { + type: 'SELECT_TT_FILTER', + selectedItem:{ + id: selectedTT.id, + objectid: selectedTT.objectid, + comment: selectedTT.comment, + } + } + expect(actions.filterSelect2Timetable(selectedTT)).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js index 53ac5d75b..7d62e01f2 100644 --- a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js @@ -120,4 +120,14 @@ describe('filters reducer', () => { ).toEqual(state) }) + it('should handle SELECT_TT_FILTER', () => { + let newTimetable = {timetable : {id: 1}} + let newQuery = Object.assign({}, state.query, newTimetable) + expect( + statusReducer(state, { + type: 'SELECT_TT_FILTER', + selectedItem: {id: 1} + }) + ).toEqual(Object.assign({}, state, {query: newQuery})) + }) }) -- cgit v1.2.3 From 77c80710df7f54f424634ce49e11108ef48240c4 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 7 Mar 2017 15:00:51 +0100 Subject: Refs #2507: Add JourneyPattern in filters Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 20 ++++++++++++++++++++ .../vehicle_journeys/reducers/filters_spec.js | 11 +++++++++++ 2 files changed, 31 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 6a868baf9..45e43ab9f 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -324,3 +324,23 @@ describe('when using select2 to pick a timetable in the filters', () => { expect(actions.filterSelect2Timetable(selectedTT)).toEqual(expectedAction) }) }) +describe('when using select2 to pick a journeypattern in the filters', () => { + it('should create an action to select a journey pattern as a filter', () => { + let selectedJP = { + id: 1, + object_id: 2, + name: 'test', + published_name: 'test' + } + const expectedAction = { + type: 'SELECT_JP_FILTER', + selectedItem:{ + id: selectedJP.id, + objectid: selectedJP.object_id, + name: selectedJP.name, + published_name: selectedJP.published_name + } + } + expect(actions.filterSelect2JourneyPattern(selectedJP)).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js index 7d62e01f2..02072192f 100644 --- a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js @@ -130,4 +130,15 @@ describe('filters reducer', () => { }) ).toEqual(Object.assign({}, state, {query: newQuery})) }) + + it('should handle SELECT_JP_FILTER', () => { + let newJourneyPattern = {journeyPattern : {id: 1}} + let newQuery = Object.assign({}, state.query, newJourneyPattern) + expect( + statusReducer(state, { + type: 'SELECT_JP_FILTER', + selectedItem: {id: 1} + }) + ).toEqual(Object.assign({}, state, {query: newQuery})) + }) }) -- cgit v1.2.3 From bb10391face1fb10689e2210d192a918a2078aa0 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 8 Mar 2017 15:01:37 +0100 Subject: Refs #2507: fix whole query system with batchActions and queryString Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 19 ++++++++++++++----- .../vehicle_journeys/reducers/filters_spec.js | 5 +++-- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 45e43ab9f..ac73462e0 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -72,6 +72,7 @@ describe('when clicking on validate button inside create modal', () => { describe('when previous navigation button is clicked', () => { it('should create an action to go to previous page', () => { const nextPage = false + const queryString = '' const pagination = { totalCount: 25, perPage: 12, @@ -81,13 +82,15 @@ describe('when previous navigation button is clicked', () => { type: 'GO_TO_PREVIOUS_PAGE', dispatch, pagination, - nextPage + nextPage, + queryString } - expect(actions.goToPreviousPage(dispatch, pagination)).toEqual(expectedAction) + expect(actions.goToPreviousPage(dispatch, pagination, queryString)).toEqual(expectedAction) }) }) describe('when next navigation button is clicked', () => { it('should create an action to go to next page', () => { + const queryString = '' const nextPage = true const pagination = { totalCount: 25, @@ -98,9 +101,10 @@ describe('when next navigation button is clicked', () => { type: 'GO_TO_NEXT_PAGE', dispatch, pagination, - nextPage + nextPage, + queryString } - expect(actions.goToNextPage(dispatch, pagination)).toEqual(expectedAction) + expect(actions.goToNextPage(dispatch, pagination, queryString)).toEqual(expectedAction) }) }) describe('when checking a vehicleJourney', () => { @@ -273,7 +277,12 @@ describe('when using select2 to pick a timetable', () => { describe('when clicking on reset button inside query filters', () => { it('should create an action to reset the query filters', () => { const expectedAction = { - type: 'RESET_FILTERS', + type: 'BATCH', + payload: [ + {type: 'RESET_FILTERS'}, + {type: 'RESET_PAGINATION'}, + {type: 'QUERY_FILTER_VEHICLEJOURNEYS', dispatch: undefined}, + ] } expect(actions.resetFilters()).toEqual(expectedAction) }) diff --git a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js index 02072192f..c985733c8 100644 --- a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js @@ -29,8 +29,9 @@ describe('filters reducer', () => { }, journeyPattern: {}, timetable: {}, - withoutSchedule: false - } + withoutSchedule: false, + }, + queryString: '' } }) -- cgit v1.2.3 From 62c1e3e5a8e27e9ddc8c8c538251db6dc3610109 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 8 Mar 2017 15:18:46 +0100 Subject: Refs #2507: add some specs for latest actions/reducers w/filters Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 21 +++++++++++++++++++++ .../vehicle_journeys/reducers/pagination_spec.js | 11 +++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index ac73462e0..4851d6081 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -287,6 +287,19 @@ describe('when clicking on reset button inside query filters', () => { expect(actions.resetFilters()).toEqual(expectedAction) }) }) +describe('when clicking on filter button inside query filters', () => { + it('should create an action to filter', () => { + const expectedAction = { + type: 'BATCH', + payload: [ + {type: 'CREATE_QUERY_STRING'}, + {type: 'RESET_PAGINATION'}, + {type: 'QUERY_FILTER_VEHICLEJOURNEYS', dispatch: undefined}, + ] + } + expect(actions.filterQuery()).toEqual(expectedAction) + }) +}) describe('when clicking on checkbox to show vj without schedule', () => { it('should create an action to toggle this filter', () => { const expectedAction = { @@ -353,3 +366,11 @@ describe('when using select2 to pick a journeypattern in the filters', () => { expect(actions.filterSelect2JourneyPattern(selectedJP)).toEqual(expectedAction) }) }) +describe('when user clicked either on filter or reset button in filters', () => { + it('should create an action to reset pagination', () => { + const expectedAction = { + type: 'RESET_PAGINATION', + } + expect(actions.resetPagination()).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js b/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js index 2dd600436..55e48dfd6 100644 --- a/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js @@ -18,6 +18,14 @@ describe('pagination reducer, given parameters allowing page change', () => { ).toEqual({}) }) + it('should handle RESET_PAGINATION', () => { + expect( + reducer(state, { + type: 'RESET_PAGINATION', + }) + ).toEqual(Object.assign({}, state, {page: 1})) + }) + it('should handle GO_TO_NEXT_PAGE and change state', () => { expect( reducer(state, { @@ -52,8 +60,7 @@ describe('pagination reducer, given parameters allowing page change', () => { isDeparture, isArrivalsToggled }) - ).toEqual(Object.assign({}, state, {stateChanged: true}) -) + ).toEqual(Object.assign({}, state, {stateChanged: true})) }) }) -- cgit v1.2.3 From ba066d534d0b6c4dd27930de15c9fd85a9c51147 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 8 Mar 2017 15:49:03 +0100 Subject: Refs #2507: create queryString w/ state query params Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 8 ++++++++ spec/javascripts/vehicle_journeys/reducers/filters_spec.js | 9 +++++++++ 2 files changed, 17 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 4851d6081..8817bc34c 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -374,3 +374,11 @@ describe('when user clicked either on filter or reset button in filters', () => expect(actions.resetPagination()).toEqual(expectedAction) }) }) +describe('when user clicked either on filter or reset button in filters', () => { + it('should create an action to create a queryString with params filters', () => { + const expectedAction = { + type: 'CREATE_QUERY_STRING', + } + expect(actions.createQueryString()).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js index c985733c8..8d75044f7 100644 --- a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js @@ -142,4 +142,13 @@ describe('filters reducer', () => { }) ).toEqual(Object.assign({}, state, {query: newQuery})) }) + + it('should handle SELECT_JP_FILTER', () => { + let strResult = "journey_pattern_id=undefined&timetable_id=undefined&range_start=1111&range_end=2222" + expect( + statusReducer(state, { + type: 'CREATE_QUERY_STRING', + }) + ).toEqual(Object.assign({}, state, {queryString: strResult})) + }) }) -- cgit v1.2.3 From a1196f73977e1a350fbba9f622f5f2191c0a93ce Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 8 Mar 2017 16:51:36 +0100 Subject: Refs #2750: Disable inputs for dummy vjas Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index cf80dc01f..dbdb253c7 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -95,6 +95,7 @@ describe('vehicleJourneys reducer', () => { selectedJourneyPattern: fakeSelectedJourneyPattern }) ).toEqual([{ + dummy: false, journey_pattern: fakeSelectedJourneyPattern, published_journey_name: 'test', objectid: '', -- cgit v1.2.3 From 113ab0e2ed4bb7564ee25427d1ad2721f41aa639 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 8 Mar 2017 18:06:30 +0100 Subject: Refs #2751: Add UPDATE_TOTAL_COUNT for vj Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 10 ++++++++++ spec/javascripts/vehicle_journeys/reducers/pagination_spec.js | 9 +++++++++ 2 files changed, 19 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 8817bc34c..ec52036d6 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -382,3 +382,13 @@ describe('when user clicked either on filter or reset button in filters', () => expect(actions.createQueryString()).toEqual(expectedAction) }) }) +describe('when submitting new vj', () => { + it('should create an action to update pagination totalCount', () => { + const diff = 1 + const expectedAction = { + type: 'UPDATE_TOTAL_COUNT', + diff + } + expect(actions.updateTotalCount(diff)).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js b/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js index 55e48dfd6..ff74e1a0d 100644 --- a/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js @@ -26,6 +26,15 @@ describe('pagination reducer, given parameters allowing page change', () => { ).toEqual(Object.assign({}, state, {page: 1})) }) + it('should handle UPDATE_TOTAL_COUNT', () => { + expect( + reducer(state, { + type: 'UPDATE_TOTAL_COUNT', + diff: 1 + }) + ).toEqual(Object.assign({}, state, {totalCount: 24})) + }) + it('should handle GO_TO_NEXT_PAGE and change state', () => { expect( reducer(state, { -- cgit v1.2.3 From 3ec5c7bf65b267ce96431906feb6025cfbff347a Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Thu, 9 Mar 2017 17:38:25 +0100 Subject: Fix Filter query spec Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/reducers/filters_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js index 8d75044f7..84608243b 100644 --- a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js @@ -144,7 +144,7 @@ describe('filters reducer', () => { }) it('should handle SELECT_JP_FILTER', () => { - let strResult = "journey_pattern_id=undefined&timetable_id=undefined&range_start=1111&range_end=2222" + let strResult = "q%5Bjourney_pattern_id_eq%5D=undefined&q%5Btime_tables_id_eq%5D=undefined&q%5Bvehicle_journey_at_stops_departure_time_gteq%5D=11%3A11&q%5Bvehicle_journey_at_stops_departure_time_lteq%5D=22%3A22" expect( statusReducer(state, { type: 'CREATE_QUERY_STRING', -- cgit v1.2.3 From 54254d44578a8d5057a3dc7738ae570f55720833 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 10 Mar 2017 16:25:23 +0100 Subject: Fix add vj when no vj fetched before Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 12 ++++++++---- .../vehicle_journeys/reducers/vehicle_journeys_spec.js | 14 ++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index ec52036d6..6916f463f 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -43,7 +43,8 @@ describe('when using select2 to pick a journey pattern', () => { id: 1, object_id: 2, name: 'test', - published_name: 'test' + published_name: 'test', + stop_area_short_descriptions: ['test'] } const expectedAction = { type: 'SELECT_JP_CREATE_MODAL', @@ -51,7 +52,8 @@ describe('when using select2 to pick a journey pattern', () => { id: selectedJP.id, objectid: selectedJP.object_id, name: selectedJP.name, - published_name: selectedJP.published_name + published_name: selectedJP.published_name, + stop_areas: selectedJP.stop_area_short_descriptions } } expect(actions.selectJPCreateModal(selectedJP)).toEqual(expectedAction) @@ -61,12 +63,14 @@ describe('when clicking on validate button inside create modal', () => { it('should create an action to create a new vehicle journey', () => { const data = {} const selectedJourneyPattern = {} + const stopPointsList = [] const expectedAction = { type: 'ADD_VEHICLEJOURNEY', data, - selectedJourneyPattern + selectedJourneyPattern, + stopPointsList } - expect(actions.addVehicleJourney(data, selectedJourneyPattern)).toEqual(expectedAction) + expect(actions.addVehicleJourney(data, selectedJourneyPattern, stopPointsList)).toEqual(expectedAction) }) }) describe('when previous navigation button is clicked', () => { diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index dbdb253c7..f1c9798af 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -73,7 +73,7 @@ describe('vehicleJourneys reducer', () => { it('should handle ADD_VEHICLEJOURNEY', () => { - let resultVJ = [{ + let pristineVjasList = [{ delta : 0, arrival_time : { hour: '00', @@ -82,26 +82,28 @@ describe('vehicleJourneys reducer', () => { departure_time : { hour: '00', minute: '00' - } + }, + stop_point_objectid: 'test', + dummy: true }] let fakeData = { published_journey_name: {value: 'test'} } - let fakeSelectedJourneyPattern = { id: "1"} + let fakeSelectedJourneyPattern = {id: "1"} expect( vjReducer(state, { type: 'ADD_VEHICLEJOURNEY', data: fakeData, - selectedJourneyPattern: fakeSelectedJourneyPattern + selectedJourneyPattern: fakeSelectedJourneyPattern, + stopPointsList: [{object_id: 'test'}] }) ).toEqual([{ - dummy: false, journey_pattern: fakeSelectedJourneyPattern, published_journey_name: 'test', objectid: '', footnotes: [], time_tables: [], - vehicle_journey_at_stops: resultVJ, + vehicle_journey_at_stops: pristineVjasList, selected: false, deletable: false }, ...state]) -- cgit v1.2.3 From b7961e9d2bf0862ff3ec08db6f64c7fa323f9123 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 10 Mar 2017 17:38:40 +0100 Subject: Fix lost vjas attribute when fixing 0 vj case Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index f1c9798af..6bc592bd1 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -84,6 +84,7 @@ describe('vehicleJourneys reducer', () => { minute: '00' }, stop_point_objectid: 'test', + stop_area_cityname: 'city', dummy: true }] let fakeData = { @@ -95,7 +96,7 @@ describe('vehicleJourneys reducer', () => { type: 'ADD_VEHICLEJOURNEY', data: fakeData, selectedJourneyPattern: fakeSelectedJourneyPattern, - stopPointsList: [{object_id: 'test'}] + stopPointsList: [{object_id: 'test', city_name: 'city'}] }) ).toEqual([{ journey_pattern: fakeSelectedJourneyPattern, -- cgit v1.2.3 From a473fe3aa7a73df1a85a89eb678097bfe8bfe931 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Mon, 13 Mar 2017 16:58:45 +0100 Subject: Refs #2776: Fix TotalCount with new json, and check when no vj Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 10 ++++++++++ spec/javascripts/vehicle_journeys/reducers/pagination_spec.js | 9 +++++++++ 2 files changed, 19 insertions(+) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 6916f463f..b9876b331 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -396,3 +396,13 @@ describe('when submitting new vj', () => { expect(actions.updateTotalCount(diff)).toEqual(expectedAction) }) }) +describe('when receiving vj', () => { + it('should create an action to show pagination totalCount', () => { + const total = 1 + const expectedAction = { + type: 'RECEIVE_TOTAL_COUNT', + total + } + expect(actions.receiveTotalCount(total)).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js b/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js index ff74e1a0d..57417a3b9 100644 --- a/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js @@ -18,6 +18,15 @@ describe('pagination reducer, given parameters allowing page change', () => { ).toEqual({}) }) + it('should handle RECEIVE_TOTAL_COUNT', () => { + expect( + reducer(state, { + type: 'RECEIVE_TOTAL_COUNT', + total: 1 + }) + ).toEqual(Object.assign({}, state, {totalCount: 1})) + }) + it('should handle RESET_PAGINATION', () => { expect( reducer(state, { -- cgit v1.2.3 From d72889430339b0666e992849d781c07886540a54 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 14 Mar 2017 12:48:38 +0100 Subject: Refs #2791: Add company select2 in add / edit modal Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/vehicle_journeys/actions_spec.js | 30 +++++++++++++++++++--- .../vehicle_journeys/reducers/modal_spec.js | 10 ++++++++ .../reducers/vehicle_journeys_spec.js | 8 ++++-- 3 files changed, 42 insertions(+), 6 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index b9876b331..351b8038b 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -63,14 +63,16 @@ describe('when clicking on validate button inside create modal', () => { it('should create an action to create a new vehicle journey', () => { const data = {} const selectedJourneyPattern = {} + const selectedCompany = {} const stopPointsList = [] const expectedAction = { type: 'ADD_VEHICLEJOURNEY', data, selectedJourneyPattern, - stopPointsList + stopPointsList, + selectedCompany } - expect(actions.addVehicleJourney(data, selectedJourneyPattern, stopPointsList)).toEqual(expectedAction) + expect(actions.addVehicleJourney(data, selectedJourneyPattern, stopPointsList, selectedCompany)).toEqual(expectedAction) }) }) describe('when previous navigation button is clicked', () => { @@ -174,11 +176,13 @@ describe('when clicking on validate button inside shifting modal', () => { describe('when clicking on validate button inside editing modal', () => { it('should create an action to update a vehiclejourney', () => { const data = {} + const selectedCompany = {} const expectedAction = { type: 'EDIT_VEHICLEJOURNEY', - data + data, + selectedCompany } - expect(actions.editVehicleJourney(data)).toEqual(expectedAction) + expect(actions.editVehicleJourney(data, selectedCompany)).toEqual(expectedAction) }) }) describe('when clicking on validate button inside duplicating modal', () => { @@ -406,3 +410,21 @@ describe('when receiving vj', () => { expect(actions.receiveTotalCount(total)).toEqual(expectedAction) }) }) +describe('when using select2 to pick a company', () => { + it('should create an action to select a company inside modal', () => { + let selectedCompany = { + id: 1, + objectid: 2, + name: 'test', + } + const expectedAction = { + type: 'SELECT_CP_EDIT_MODAL', + selectedItem:{ + id: selectedCompany.id, + objectid: selectedCompany.objectid, + name: selectedCompany.name, + } + } + expect(actions.select2Company(selectedCompany)).toEqual(expectedAction) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js index 7c81d729b..c016812da 100644 --- a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js @@ -157,4 +157,14 @@ describe('modal reducer', () => { }) ).toEqual(newState) }) + + it('should handle SELECT_CP_EDIT_MODAL', () => { + let newModalProps = {selectedCompany : {name: 'ALBATRANS'}} + expect( + modalReducer(state, { + type: 'SELECT_CP_EDIT_MODAL', + selectedItem: {name: 'ALBATRANS'} + }) + ).toEqual(Object.assign({}, state, {modalProps: newModalProps})) + }) }) diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js index 6bc592bd1..6dc07e9bd 100644 --- a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -91,15 +91,18 @@ describe('vehicleJourneys reducer', () => { published_journey_name: {value: 'test'} } let fakeSelectedJourneyPattern = {id: "1"} + let fakeSelectedCompany = {name: "ALBATRANS"} expect( vjReducer(state, { type: 'ADD_VEHICLEJOURNEY', data: fakeData, selectedJourneyPattern: fakeSelectedJourneyPattern, - stopPointsList: [{object_id: 'test', city_name: 'city'}] + stopPointsList: [{object_id: 'test', city_name: 'city'}], + selectedCompany: fakeSelectedCompany }) ).toEqual([{ journey_pattern: fakeSelectedJourneyPattern, + company: fakeSelectedCompany, published_journey_name: 'test', objectid: '', footnotes: [], @@ -237,7 +240,8 @@ describe('vehicleJourneys reducer', () => { published_journey_name: {value : 'test'}, published_journey_identifier: {value: 'test'} } - let newVJ = Object.assign({}, state[0], {published_journey_name: fakeData.published_journey_name.value, published_journey_identifier: fakeData.published_journey_identifier.value}) + let fakeSelectedCompany : {name : 'ALBATRANS'} + let newVJ = Object.assign({}, state[0], {company: fakeSelectedCompany, published_journey_name: fakeData.published_journey_name.value, published_journey_identifier: fakeData.published_journey_identifier.value}) expect( vjReducer(state, { type: 'EDIT_VEHICLEJOURNEY', -- cgit v1.2.3 From 531f4eb80fca4cd1902f34c79222dab7de5554c9 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Mon, 20 Mar 2017 12:28:14 +0100 Subject: Refs #2876: Add data in sidebar when olmap is toggled Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/itineraries/reducers/stop_points_spec.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/itineraries/reducers/stop_points_spec.js b/spec/javascripts/itineraries/reducers/stop_points_spec.js index adbf77aa1..6065fa4ed 100644 --- a/spec/javascripts/itineraries/reducers/stop_points_spec.js +++ b/spec/javascripts/itineraries/reducers/stop_points_spec.js @@ -192,7 +192,10 @@ describe('stops reducer', () => { user_objectid: "1234", longitude: 123, latitude: 123, - registration_number: '0' + registration_number: '0', + city_name: 'city', + area_type: 'area', + short_name: 'new' } }) ).toEqual( @@ -210,6 +213,9 @@ describe('stops reducer', () => { longitude: 123, latitude: 123, registration_number: '0', + city_name: 'city', + area_type: 'area', + short_name: 'new', olMap: { isOpened: false, json: {} -- cgit v1.2.3