aboutsummaryrefslogtreecommitdiffstats
path: root/spec/javascript/routes
diff options
context:
space:
mode:
Diffstat (limited to 'spec/javascript/routes')
-rw-r--r--spec/javascript/routes/actions_spec.js101
-rw-r--r--spec/javascript/routes/reducers/stop_points_spec.js486
2 files changed, 587 insertions, 0 deletions
diff --git a/spec/javascript/routes/actions_spec.js b/spec/javascript/routes/actions_spec.js
new file mode 100644
index 000000000..507e1e0ed
--- /dev/null
+++ b/spec/javascript/routes/actions_spec.js
@@ -0,0 +1,101 @@
+import actions from '../../../app/javascript/routes/actions'
+
+describe('actions', () => {
+ it('should create an action to add a stop', () => {
+ const expectedAction = {
+ type: 'ADD_STOP',
+ }
+ expect(actions.addStop()).toEqual(expectedAction)
+ })
+})
+describe('actions', () => {
+ it('should create an action to move up a stop', () => {
+ const index = 1
+ const expectedAction = {
+ type: 'MOVE_STOP_UP',
+ index
+ }
+ expect(actions.moveStopUp(index)).toEqual(expectedAction)
+ })
+})
+describe('actions', () => {
+ it('should create an action to move down a stop', () => {
+ const index = 1
+ const expectedAction = {
+ type: 'MOVE_STOP_DOWN',
+ index
+ }
+ expect(actions.moveStopDown(index)).toEqual(expectedAction)
+ })
+})
+describe('actions', () => {
+ it('should create an action to delete a stop', () => {
+ const index = 1
+ const expectedAction = {
+ type: 'DELETE_STOP',
+ index
+ }
+ expect(actions.deleteStop(index)).toEqual(expectedAction)
+ })
+})
+describe('actions', () => {
+ it('should create an action to update the value of a stop', () => {
+ const text = 'updated text'
+ const index = 1
+ const expectedAction = {
+ type: 'UPDATE_INPUT_VALUE',
+ index,
+ text
+ }
+ expect(actions.updateInputValue(index, text)).toEqual(expectedAction)
+ })
+})
+
+describe('actions', () => {
+ it('should create an action to update the up select of a stop', () => {
+ const event = {
+ currentTarget: {
+ value: 'forbidden',
+ id: 'up'
+ }
+ }
+ const index = 1
+ const expectedAction = {
+ type :'UPDATE_SELECT_VALUE',
+ select_id: 'up',
+ select_value: 'forbidden',
+ index
+ }
+ expect(actions.updateSelectValue(event, index)).toEqual(expectedAction)
+ })
+})
+
+describe('actions', () => {
+ it('should create an action to toggle the map', () => {
+ const index = 1
+ const expectedAction = {
+ type: 'TOGGLE_MAP',
+ index
+ }
+ expect(actions.toggleMap(index)).toEqual(expectedAction)
+ })
+})
+
+describe('actions', () => {
+ it('should create an action to select a marker on the map', () => {
+ const index = 1
+ const data = {
+ geometry: undefined,
+ registration_number: 'rn_test',
+ stoparea_id: 'sid_test',
+ text: 't_test',
+ user_objectid: 'uoid_test'
+ }
+ const expectedAction = {
+ type: 'SELECT_MARKER',
+ index,
+ data
+ }
+ expect(actions.selectMarker(index, data)).toEqual(expectedAction)
+ })
+})
diff --git a/spec/javascript/routes/reducers/stop_points_spec.js b/spec/javascript/routes/reducers/stop_points_spec.js
new file mode 100644
index 000000000..b375cdc2c
--- /dev/null
+++ b/spec/javascript/routes/reducers/stop_points_spec.js
@@ -0,0 +1,486 @@
+import stopPointsReducer from '../../../../app/javascript/routes/reducers/stopPoints'
+
+let state = []
+
+let fakeData = {
+ geometry: undefined,
+ registration_number: 'rn_test',
+ stoparea_id: 'sid_test',
+ text: 't_test',
+ user_objectid: 'uoid_test'
+}
+
+describe('stops reducer', () => {
+ beforeEach(()=>{
+ state = [
+ {
+ text: 'first',
+ index: 0,
+ stoppoint_id: 72,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ },
+ {
+ text: 'second',
+ index: 1,
+ stoppoint_id: 73,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ }
+ ]
+ })
+
+ it('should return the initial state', () => {
+ expect(
+ stopPointsReducer(undefined, {})
+ ).toEqual([])
+ })
+
+ it('should handle ADD_STOP', () => {
+ expect(
+ stopPointsReducer(state, {
+ type: 'ADD_STOP'
+ })
+ ).toEqual(
+ [
+ {
+ text: 'first',
+ index: 0,
+ stoppoint_id: 72,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ },
+ {
+ text: 'second',
+ index: 1,
+ stoppoint_id: 73,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ },
+ {
+ text: '',
+ index: 2,
+ edit: true,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ }
+ ]
+ )
+ })
+
+ it('should handle MOVE_UP_STOP', () => {
+ expect(
+ stopPointsReducer(state, {
+ type: 'MOVE_STOP_UP',
+ index: 1
+ })
+ ).toEqual(
+ [
+ {
+ text: 'second',
+ index: 1,
+ stoppoint_id: 72,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ },
+ {
+ text: 'first',
+ index: 0,
+ stoppoint_id: 73,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ }
+ ]
+ )
+ })
+
+ it('should handle MOVE_DOWN_STOP', () => {
+ expect(
+ stopPointsReducer(state, {
+ type: 'MOVE_STOP_DOWN',
+ index: 0
+ })
+ ).toEqual(
+ [
+ {
+ text: 'second',
+ index: 1,
+ stoppoint_id: 72,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ },
+ {
+ text: 'first',
+ index: 0,
+ stoppoint_id: 73,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ }
+ ]
+ )
+ })
+
+ // it('should handle DELETE_STOP', () => {
+ // expect(
+ // stopPointsReducer(state, {
+ // type: 'DELETE_STOP',
+ // index: 1
+ // })
+ // ).toEqual(
+ // [
+ // {
+ // text: 'first',
+ // index: 0,
+ // stoppoint_id: 72,
+ // edit: false,
+ // for_boarding: 'normal',
+ // for_alighting: 'normal',
+ // olMap: {
+ // isOpened: false,
+ // json: {}
+ // }
+ // }
+ // ]
+ // )
+ // })
+
+ it('should handle UPDATE_INPUT_VALUE', () => {
+ expect(
+ stopPointsReducer(state, {
+ type: 'UPDATE_INPUT_VALUE',
+ index: 0,
+ edit: false,
+ text: {
+ text: "new value",
+ name: 'new',
+ stoparea_id: 1,
+ user_objectid: "1234",
+ longitude: 123,
+ latitude: 123,
+ registration_number: '0',
+ city_name: 'city',
+ area_type: 'area',
+ short_name: 'new',
+ comment: 'newcomment'
+ }
+ })
+ ).toEqual(
+ [
+ {
+ text: 'new value',
+ name: 'new',
+ index: 0,
+ stoppoint_id: 72,
+ edit: false,
+ stoparea_id: 1,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ user_objectid: "1234",
+ longitude: 123,
+ latitude: 123,
+ registration_number: '0',
+ city_name: 'city',
+ area_type: 'area',
+ short_name: 'new',
+ comment: 'newcomment',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ },
+ {
+ text: 'second',
+ index: 1,
+ stoppoint_id: 73,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ }
+ ]
+ )
+ })
+
+ it('should handle UPDATE_SELECT_VALUE', () => {
+ expect(
+ stopPointsReducer(state, {
+ type :'UPDATE_SELECT_VALUE',
+ select_id: 'for_boarding',
+ select_value: 'prohibited',
+ index: 0
+ })
+ ).toEqual(
+ [
+ {
+ text: 'first',
+ index: 0,
+ stoppoint_id: 72,
+ edit: false,
+ for_boarding: 'prohibited',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ },
+ {
+ text: 'second',
+ index: 1,
+ stoppoint_id: 73,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ }
+ ]
+ )
+ })
+
+ it('should handle TOGGLE_MAP', () => {
+ expect(
+ stopPointsReducer(state, {
+ type: 'TOGGLE_MAP',
+ index: 0
+ })
+ ).toEqual(
+ [
+ {
+ text: 'first',
+ index: 0,
+ stoppoint_id: 72,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: true,
+ json: {
+ text: 'first',
+ index: 0,
+ stoppoint_id: 72,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: undefined
+ }
+ }
+ },
+ {
+ text: 'second',
+ index: 1,
+ stoppoint_id: 73,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ }
+ ]
+ )
+ })
+
+ it('should handle TOGGLE_EDIT', () => {
+ expect(
+ stopPointsReducer(state, {
+ type: 'TOGGLE_EDIT',
+ index: 0
+ })
+ ).toEqual(
+ [
+ {
+ text: 'first',
+ index: 0,
+ stoppoint_id: 72,
+ edit: true,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ },
+ {
+ text: 'second',
+ index: 1,
+ stoppoint_id: 73,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ }
+ ]
+ )
+ })
+
+ it('should handle SELECT_MARKER', () => {
+ let openedMapState = [
+ {
+ text: 'first',
+ index: 0,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: true,
+ json: {}
+ }
+ },
+ {
+ text: 'second',
+ index: 1,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ }
+ ]
+ expect(
+ stopPointsReducer(openedMapState, {
+ type: 'SELECT_MARKER',
+ index: 0,
+ data: fakeData
+ })
+ ).toEqual(
+ [
+ {
+ text: 'first',
+ index: 0,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: true,
+ json: fakeData
+ }
+ },
+ {
+ text: 'second',
+ index: 1,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ }
+ ]
+ )
+ })
+
+ it('should handle UNSELECT_MARKER', () => {
+ let openedMapState = [
+ {
+ text: 'first',
+ index: 0,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: true,
+ json: {}
+ }
+ },
+ {
+ text: 'second',
+ index: 1,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ }
+ ]
+
+ expect(
+ stopPointsReducer(openedMapState, {
+ type: 'UNSELECT_MARKER',
+ index: 0
+ })
+ ).toEqual(
+ [
+ {
+ text: 'first',
+ index: 0,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: true,
+ json: {}
+ }
+ },
+ {
+ text: 'second',
+ index: 1,
+ edit: false,
+ for_boarding: 'normal',
+ for_alighting: 'normal',
+ olMap: {
+ isOpened: false,
+ json: {}
+ }
+ }
+ ]
+ )
+ })
+})