aboutsummaryrefslogtreecommitdiffstats
path: root/spec/javascripts
diff options
context:
space:
mode:
authorThomas Haddad2017-02-08 18:02:13 +0100
committerThomas Haddad2017-02-08 18:02:13 +0100
commitb4631a366646303a2606120db99ff1d2297c3c91 (patch)
tree8ceee2cdebb1d8660c301797ee2a4491bad60e12 /spec/javascripts
parent3e17d660064632335064b6784d1586a8d19af505 (diff)
downloadchouette-core-b4631a366646303a2606120db99ff1d2297c3c91.tar.bz2
Refs #2501: Add fetchApi when landing on page, fetch status, wip display
Signed-off-by: Thomas Shawarma Haddad <thomas.haddad@af83.com>
Diffstat (limited to 'spec/javascripts')
-rw-r--r--spec/javascripts/vehicle_journeys/actions_spec.js31
-rw-r--r--spec/javascripts/vehicle_journeys/reducers/status_spec.js45
-rw-r--r--spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js55
3 files changed, 131 insertions, 0 deletions
diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js
index e69de29bb..8999d4cb6 100644
--- a/spec/javascripts/vehicle_journeys/actions_spec.js
+++ b/spec/javascripts/vehicle_journeys/actions_spec.js
@@ -0,0 +1,31 @@
+var actions = require('es6_browserified/vehicle_journeys/actions')
+
+const dispatch = function(){}
+const currentPage = 1
+
+describe('when cannot fetch api', () => {
+ it('should create an action to toggle error', () => {
+ const expectedAction = {
+ type: 'UNAVAILABLE_SERVER',
+ }
+ expect(actions.unavailableServer()).toEqual(expectedAction)
+ })
+})
+describe('when fetching api', () => {
+ it('should create an action to fetch api', () => {
+ const expectedAction = {
+ type: 'FETCH_API',
+ }
+ expect(actions.fetchingApi()).toEqual(expectedAction)
+ })
+})
+describe('when receiveJourneyPatterns is triggered', () => {
+ it('should create an action to pass json to reducer', () => {
+ const json = undefined
+ const expectedAction = {
+ type: 'RECEIVE_VEHICLE_JOURNEYS',
+ json
+ }
+ expect(actions.receiveVehicleJourneys()).toEqual(expectedAction)
+ })
+})
diff --git a/spec/javascripts/vehicle_journeys/reducers/status_spec.js b/spec/javascripts/vehicle_journeys/reducers/status_spec.js
new file mode 100644
index 000000000..d48d48f4a
--- /dev/null
+++ b/spec/javascripts/vehicle_journeys/reducers/status_spec.js
@@ -0,0 +1,45 @@
+var statusReducer = require('es6_browserified/vehicle_journeys/reducers/status')
+
+let state = {}
+
+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_VEHICLE_JOURNEYS', () => {
+ expect(
+ statusReducer(state, {
+ type: 'RECEIVE_VEHICLE_JOURNEYS'
+ })
+ ).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/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js
new file mode 100644
index 000000000..15baa75a5
--- /dev/null
+++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js
@@ -0,0 +1,55 @@
+var vjReducer = require('es6_browserified/vehicle_journeys/reducers/vehicleJourneys')
+let state = []
+let fakeFootnotes = [{
+ id: 1,
+ code: 1,
+ label: "1"
+},{
+ id: 2,
+ code: 2,
+ label: "2"
+}]
+
+let fakeTimeTables = []
+let fakeVJAS = []
+
+describe('vehicleJourneys reducer', () => {
+ beforeEach(()=>{
+ state = [
+ {
+ journey_pattern_id: 1,
+ published_journey_name: "vj1",
+ objectid: 11,
+ deletable: false,
+ footnotes: fakeFootnotes,
+ time_tables: fakeTimeTables,
+ vehicle_journey_at_stops: fakeVJAS
+ },
+ {
+ journey_pattern_id: 2,
+ published_journey_name: "vj2",
+ objectid: 22,
+ deletable: false,
+ footnotes: fakeFootnotes,
+ time_tables: fakeTimeTables,
+ vehicle_journey_at_stops: fakeVJAS
+ }
+ ]
+ })
+
+ it('should return the initial state', () => {
+ expect(
+ vjReducer(undefined, {})
+ ).toEqual([])
+ })
+
+
+ it('should handle RECEIVE_VEHICLE_JOURNEYS', () => {
+ expect(
+ vjReducer(state, {
+ type: 'RECEIVE_VEHICLE_JOURNEYS',
+ json: state
+ })
+ ).toEqual(state)
+ })
+})