aboutsummaryrefslogtreecommitdiffstats
path: root/spec/javascripts
diff options
context:
space:
mode:
Diffstat (limited to 'spec/javascripts')
-rw-r--r--spec/javascripts/journey_patterns/actions_spec.js53
-rw-r--r--spec/javascripts/journey_patterns/reducers/modal_spec.js9
-rw-r--r--spec/javascripts/journey_patterns/reducers/pagination_spec.js38
-rw-r--r--spec/javascripts/journey_patterns/reducers/status_spec.js51
-rw-r--r--spec/javascripts/spec_helper.js2
5 files changed, 120 insertions, 33 deletions
diff --git a/spec/javascripts/journey_patterns/actions_spec.js b/spec/javascripts/journey_patterns/actions_spec.js
index ced053935..07f83ca1b 100644
--- a/spec/javascripts/journey_patterns/actions_spec.js
+++ b/spec/javascripts/journey_patterns/actions_spec.js
@@ -14,25 +14,38 @@ describe('when receiveJourneyPatterns is triggered', () => {
})
})
-describe('when landing on page', () => {
- it('should create an action to load the n first missions', () => {
+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: 'LOAD_FIRST_PAGE',
- dispatch
+ type: 'GO_TO_PREVIOUS_PAGE',
+ dispatch,
+ pagination,
+ nextPage
}
- expect(actions.loadFirstPage(dispatch)).toEqual(expectedAction)
+ 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,
- currentPage,
+ pagination,
nextPage
}
- expect(actions.goToNextPage(dispatch, currentPage)).toEqual(expectedAction)
+ expect(actions.goToNextPage(dispatch, pagination)).toEqual(expectedAction)
})
})
describe('when clicking on a journey pattern checkbox', () => {
@@ -53,13 +66,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', () => {
@@ -122,12 +134,21 @@ 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', () => {
+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: 'SAVE_PAGE',
- dispatch
+ type: 'FETCH_API',
}
- expect(actions.savePage(dispatch)).toEqual(expectedAction)
+ expect(actions.fetchingApi()).toEqual(expectedAction)
})
})
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..4800451e9 100644
--- a/spec/javascripts/journey_patterns/reducers/pagination_spec.js
+++ b/spec/javascripts/journey_patterns/reducers/pagination_spec.js
@@ -1,9 +1,13 @@
var reducer = require('es6_browserified/journey_patterns/reducers/pagination')
+
+const diff = 1
let state = {
page : 2,
- totalCount : 25
+ 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', () => {
@@ -19,10 +23,10 @@ describe('pagination reducer, given parameters allowing page change', () => {
reducer(state, {
type: 'GO_TO_NEXT_PAGE',
dispatch,
- currentPage,
+ pagination,
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', () => {
@@ -30,10 +34,10 @@ 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}))
+ ).toEqual(Object.assign({}, state, {page : state.page - 1, stateChanged: false}))
})
})
@@ -42,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', () => {
@@ -50,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)
@@ -61,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', () => {
@@ -69,9 +73,21 @@ describe('pagination reducer, given parameters not allowing to go to next page',
reducer(state, {
type: 'GO_TO_NEXT_PAGE',
dispatch,
- currentPage,
- nextPage : false
+ 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/javascripts/journey_patterns/reducers/status_spec.js b/spec/javascripts/journey_patterns/reducers/status_spec.js
new file mode 100644
index 000000000..91cbbb0b8
--- /dev/null
+++ b/spec/javascripts/journey_patterns/reducers/status_spec.js
@@ -0,0 +1,51 @@
+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 = {
+ 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}))
+ })
+
+})
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.