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