diff options
| author | Thomas Haddad | 2017-01-11 15:28:08 +0100 |
|---|---|---|
| committer | Thomas Haddad | 2017-01-11 15:30:21 +0100 |
| commit | e19f37f690dd932f8f45b0c847e9fa5af197b7bd (patch) | |
| tree | f4d700ee63212b2d4af5b28fb8453dc37fa62a55 /spec/javascripts/journey_patterns | |
| parent | 19a6aedb8dfdb37b30c320fc17719f6e2ce89876 (diff) | |
| download | chouette-core-e19f37f690dd932f8f45b0c847e9fa5af197b7bd.tar.bz2 | |
Refactor Navigate container/component/specs
Signed-off-by: Thomas Shawarma Haddad <thomas.haddad@af83.com>
Diffstat (limited to 'spec/javascripts/journey_patterns')
| -rw-r--r-- | spec/javascripts/journey_patterns/actions_spec.js | 30 | ||||
| -rw-r--r-- | spec/javascripts/journey_patterns/reducers/pagination_spec.js | 28 |
2 files changed, 36 insertions, 22 deletions
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})) }) }) |
