diff options
| author | cedricnjanga | 2017-10-10 11:05:53 +0200 |
|---|---|---|
| committer | cedricnjanga | 2017-10-10 11:05:53 +0200 |
| commit | 91e85a1b974eb0bfb42df8c896570e0a690d11f1 (patch) | |
| tree | fe36c73e7a6d13a90d274897b1ea9378458fd524 /spec/javascript/journey_patterns | |
| parent | 91af53dce7183146f79313df48f7e58b4d950598 (diff) | |
| download | chouette-core-91e85a1b974eb0bfb42df8c896570e0a690d11f1.tar.bz2 | |
Need to test webpack config and to configure teaspoon to run React Apps specs
Diffstat (limited to 'spec/javascript/journey_patterns')
5 files changed, 521 insertions, 0 deletions
diff --git a/spec/javascript/journey_patterns/actions_spec.js b/spec/javascript/journey_patterns/actions_spec.js new file mode 100644 index 000000000..75f2682b1 --- /dev/null +++ b/spec/javascript/journey_patterns/actions_spec.js @@ -0,0 +1,154 @@ +import actions from '../../app/javascript/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 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 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 callback = function(){} + const expectedAction = { + type: 'OPEN_CONFIRM_MODAL', + callback + } + expect(actions.openConfirmModal(callback)).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 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) + }) +}) +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/javascript/journey_patterns/reducers/journey_patterns_spec.js b/spec/javascript/journey_patterns/reducers/journey_patterns_spec.js new file mode 100644 index 000000000..13a88e477 --- /dev/null +++ b/spec/javascript/journey_patterns/reducers/journey_patterns_spec.js @@ -0,0 +1,125 @@ +import jpReducer from '../../../app/javascript/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", + position : 0, +},{ + area_type : "lda", + checked : false, + id : 40534, + name : "Thomas LemaƮtre", + object_id : "FR:92050:LDA:70915:STIF", + 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(()=>{ + 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: ''} + } + let stopPoints = stopPoints + expect( + jpReducer(state, { + type: 'ADD_JOURNEYPATTERN', + data: fakeData + }) + ).toEqual([{ + name : 'm3', + published_name: 'M3', + registration_number: '', + deletable: false, + stop_points: stopPoints + }, ...state]) + }) + + 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/javascript/journey_patterns/reducers/modal_spec.js b/spec/javascript/journey_patterns/reducers/modal_spec.js new file mode 100644 index 000000000..a5d215a9c --- /dev/null +++ b/spec/javascript/journey_patterns/reducers/modal_spec.js @@ -0,0 +1,98 @@ +import modalReducer from '../../../app/javascript/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 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 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/javascript/journey_patterns/reducers/pagination_spec.js b/spec/javascript/journey_patterns/reducers/pagination_spec.js new file mode 100644 index 000000000..78a09eace --- /dev/null +++ b/spec/javascript/journey_patterns/reducers/pagination_spec.js @@ -0,0 +1,93 @@ +import reducer from '../../../app/javascript/journey_patterns/reducers/pagination' + +const diff = 1 +let state = { + page : 2, + totalCount : 50, + stateChanged: false, + perPage: 20 +} +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) + }) +}) + +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: state.totalCount - diff})) + }) +}) diff --git a/spec/javascript/journey_patterns/reducers/status_spec.js b/spec/javascript/journey_patterns/reducers/status_spec.js new file mode 100644 index 000000000..bf27a3d05 --- /dev/null +++ b/spec/javascript/journey_patterns/reducers/status_spec.js @@ -0,0 +1,51 @@ +import statusReducer from '../../../app/javascript/journey_patterns/reducers/status' + +let state = {} + +let pagination = { + page : 2, + totalCount : 25, + stateChanged: false, + perPage: 12 +} +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_JOURNEY_PATTERNS', () => { + expect( + statusReducer(state, { + type: 'RECEIVE_JOURNEY_PATTERNS' + }) + ).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})) + }) + +}) |
