diff options
| author | Xinhui | 2017-01-09 12:12:02 +0100 |
|---|---|---|
| committer | Xinhui | 2017-01-09 12:12:02 +0100 |
| commit | cced737f5e806df59bd0008ae0c82aee712a7ce9 (patch) | |
| tree | 2d42c8e5b59a6031f3100fac098ed2ff3e679cc9 /spec/javascripts | |
| parent | 93ad8ee168b86ecc4ed6e918063c12030b96ac09 (diff) | |
| parent | 953fb3a48c43f5801bbc35dd02a2db26b21479b1 (diff) | |
| download | chouette-core-cced737f5e806df59bd0008ae0c82aee712a7ce9.tar.bz2 | |
Merge branch 'master' into staging
Diffstat (limited to 'spec/javascripts')
| -rw-r--r-- | spec/javascripts/itineraries/actions_spec.js (renamed from spec/javascripts/actions_spec.js) | 2 | ||||
| -rw-r--r-- | spec/javascripts/itineraries/components_spec.js | 40 | ||||
| -rw-r--r-- | spec/javascripts/itineraries/reducers_spec.js (renamed from spec/javascripts/reducers_spec.js) | 17 | ||||
| -rw-r--r-- | spec/javascripts/journey_patterns/actions_spec.js | 133 | ||||
| -rw-r--r-- | spec/javascripts/journey_patterns/reducers/journey_patterns_spec.js | 104 | ||||
| -rw-r--r-- | spec/javascripts/journey_patterns/reducers/modal_spec.js | 100 | ||||
| -rw-r--r-- | spec/javascripts/journey_patterns/reducers/pagination_spec.js | 77 | ||||
| -rw-r--r-- | spec/javascripts/spec_helper.js | 1 |
8 files changed, 465 insertions, 9 deletions
diff --git a/spec/javascripts/actions_spec.js b/spec/javascripts/itineraries/actions_spec.js index 55de1c31f..f86466375 100644 --- a/spec/javascripts/actions_spec.js +++ b/spec/javascripts/itineraries/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/itineraries/components_spec.js b/spec/javascripts/itineraries/components_spec.js new file mode 100644 index 000000000..c9c57b5eb --- /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(<Provider store={store}><ConnectedApp/></Provider>); +// }); + +// 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/itineraries/reducers_spec.js index a4880e73e..a8731af5f 100644 --- a/spec/javascripts/reducers_spec.js +++ b/spec/javascripts/itineraries/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(()=>{ @@ -119,15 +119,15 @@ 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', index: 0, text: { text: "new value", - stoparea_id: 1 + stoparea_id: 1, + user_objectid: "1234" } }) ).toEqual( @@ -135,9 +135,11 @@ describe('stops reducer', () => { { text: 'new value', index: 0, + stoppoint_id: '', stoparea_id: 1, for_boarding: 'normal', - for_alighting: 'normal' + for_alighting: 'normal', + user_objectid: "1234" }, { text: 'second', @@ -149,7 +151,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 +162,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/journey_patterns/actions_spec.js b/spec/javascripts/journey_patterns/actions_spec.js new file mode 100644 index 000000000..ced053935 --- /dev/null +++ b/spec/javascripts/journey_patterns/actions_spec.js @@ -0,0 +1,133 @@ +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 expectedAction = { + type: 'DELETE_JOURNEYPATTERN', + index + } + expect(actions.deleteJourneyPattern(index)).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) + }) +}) 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/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) + }) +}) 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/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. |
