aboutsummaryrefslogtreecommitdiffstats
path: root/spec/javascripts
diff options
context:
space:
mode:
authorThomas Haddad2017-02-09 18:11:24 +0100
committerThomas Haddad2017-02-09 18:11:24 +0100
commit9be58cefea65c8beea5273ad76d5d9b3a811983c (patch)
tree44d8306cc3145c19ca312057608570483f0e7fbb /spec/javascripts
parentb4631a366646303a2606120db99ff1d2297c3c91 (diff)
downloadchouette-core-9be58cefea65c8beea5273ad76d5d9b3a811983c.tar.bz2
Refs #2501: Add pagination for vehicle journeys
Signed-off-by: Thomas Shawarma Haddad <thomas.haddad@af83.com>
Diffstat (limited to 'spec/javascripts')
-rw-r--r--spec/javascripts/journey_patterns/reducers/pagination_spec.js4
-rw-r--r--spec/javascripts/vehicle_journeys/reducers/pagination_spec.js81
2 files changed, 83 insertions, 2 deletions
diff --git a/spec/javascripts/journey_patterns/reducers/pagination_spec.js b/spec/javascripts/journey_patterns/reducers/pagination_spec.js
index 4800451e9..d0f9fef47 100644
--- a/spec/javascripts/journey_patterns/reducers/pagination_spec.js
+++ b/spec/javascripts/journey_patterns/reducers/pagination_spec.js
@@ -3,9 +3,9 @@ var reducer = require('es6_browserified/journey_patterns/reducers/pagination')
const diff = 1
let state = {
page : 2,
- totalCount : 25,
+ totalCount : 50,
stateChanged: false,
- perPage: 12
+ perPage: 20
}
let pagination = Object.assign({}, state)
const dispatch = function(){}
diff --git a/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js b/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js
new file mode 100644
index 000000000..240d99c85
--- /dev/null
+++ b/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js
@@ -0,0 +1,81 @@
+var reducer = require('es6_browserified/vehicle_journeys/reducers/pagination')
+
+const diff = 1
+let state = {
+ page : 2,
+ totalCount : 25,
+ stateChanged: false,
+ perPage: 12
+}
+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)
+ })
+})