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