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