From f7009121b1cbc421efd079bfb4cc43d91ab7ca28 Mon Sep 17 00:00:00 2001 From: jpl Date: Wed, 18 Jan 2017 09:40:47 +0100 Subject: Refs #2404: adding toggle_map tests, fixing also add_stop_point reducer --- spec/javascripts/itineraries/components_spec.js | 40 --- .../itineraries/reducers/stop_points_spec.js | 269 +++++++++++++++++++++ spec/javascripts/itineraries/reducers_spec.js | 179 -------------- 3 files changed, 269 insertions(+), 219 deletions(-) delete mode 100644 spec/javascripts/itineraries/components_spec.js create mode 100644 spec/javascripts/itineraries/reducers/stop_points_spec.js delete mode 100644 spec/javascripts/itineraries/reducers_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/itineraries/components_spec.js b/spec/javascripts/itineraries/components_spec.js deleted file mode 100644 index c9c57b5eb..000000000 --- a/spec/javascripts/itineraries/components_spec.js +++ /dev/null @@ -1,40 +0,0 @@ -// var React = require('react'); -// var Provider = require('react-redux').Provider; -// var actions = require('es6_browserified/itineraries/actions/index'); -// var App = require('es6_browserified/itineraries/components/TodoList'); -// var ConnectedApp = require('es6_browserified/itineraries/containers/VisibleTodoList'); -// var TestUtils = require('react-addons-test-utils'); - -// xdescribe('ConnectedApp', function() { -// var connectedApp, store, initialItems; -// var state; -// state = [ -// { -// text: 'first', -// index: 0, -// for_boarding: 'normal', -// for_alighting: 'normal' -// }, -// { -// text: 'second', -// index: 1, -// for_boarding: 'normal', -// for_alighting: 'normal' -// } -// ] - -// beforeEach(function() { -// store = state -// }); - -// describe('state provided by the store', function() { -// beforeEach(function() { -// connectedApp = TestUtils.renderIntoDocument(); -// }); - -// it('passes down items', function() { -// app = TestUtils.findRenderedComponentWithType(connectedApp, App); -// expect(app.props.items).toEqual(initialItems); -// }); -// }); -// }); diff --git a/spec/javascripts/itineraries/reducers/stop_points_spec.js b/spec/javascripts/itineraries/reducers/stop_points_spec.js new file mode 100644 index 000000000..b33feab28 --- /dev/null +++ b/spec/javascripts/itineraries/reducers/stop_points_spec.js @@ -0,0 +1,269 @@ +var stopPointsReducer = require('es6_browserified/itineraries/reducers/stopPoints') + +let state = [] + +describe('stops reducer', () => { + beforeEach(()=>{ + state = [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + }, + { + text: 'second', + index: 1, + 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, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + }, + { + text: '', + index: 2, + 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, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + }, + { + text: 'first', + index: 0, + 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, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + }, + { + text: 'first', + index: 0, + 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, + 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, + text: { + text: "new value", + stoparea_id: 1, + user_objectid: "1234" + } + }) + ).toEqual( + [ + { + text: 'new value', + index: 0, + stoppoint_id: '', + stoparea_id: 1, + for_boarding: 'normal', + for_alighting: 'normal', + user_objectid: "1234", + olMap: { + isOpened: false, + json: {} + } + }, + { + text: 'second', + index: 1, + 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, + for_boarding: 'prohibited', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + }, + { + text: 'second', + index: 1, + 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, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: true, + json: {} + } + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + } + ] + ) + }) +}) diff --git a/spec/javascripts/itineraries/reducers_spec.js b/spec/javascripts/itineraries/reducers_spec.js deleted file mode 100644 index 344cccab5..000000000 --- a/spec/javascripts/itineraries/reducers_spec.js +++ /dev/null @@ -1,179 +0,0 @@ -var reducer = require('es6_browserified/itineraries/reducers/stopPoints') -let state = [] -describe('stops reducer', () => { - beforeEach(()=>{ - state = [ - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - }) - - it('should return the initial state', () => { - expect( - reducer(undefined, {}) - ).toEqual([]) - }) - - it('should handle ADD_STOP', () => { - expect( - reducer(state, { - type: 'ADD_STOP' - }) - ).toEqual( - [ - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: '', - index: 2, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) - - it('should handle MOVE_UP_STOP', () => { - expect( - reducer(state, { - type: 'MOVE_STOP_UP', - index: 1 - }) - ).toEqual( - [ - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) - - it('should handle MOVE_DOWN_STOP', () => { - expect( - reducer(state, { - type: 'MOVE_STOP_DOWN', - index: 0 - }) - ).toEqual( - [ - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - }, - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) - - it('should handle DELETE_STOP', () => { - expect( - reducer(state, { - type: 'DELETE_STOP', - index: 1 - }) - ).toEqual( - [ - { - text: 'first', - index: 0, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) - - it('should handle UPDATE_INPUT_VALUE', () => { - expect( - reducer(state, { - type: 'UPDATE_INPUT_VALUE', - index: 0, - text: { - text: "new value", - stoparea_id: 1, - user_objectid: "1234" - } - }) - ).toEqual( - [ - { - text: 'new value', - index: 0, - stoppoint_id: '', - stoparea_id: 1, - for_boarding: 'normal', - for_alighting: 'normal', - user_objectid: "1234" - }, - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) - - it('should handle UPDATE_SELECT_VALUE', () => { - expect( - reducer(state, { - type :'UPDATE_SELECT_VALUE', - select_id: 'for_boarding', - select_value: 'prohibited', - index: 0 - }) - ).toEqual( - [ - { - text: 'first', - index: 0, - for_boarding: 'prohibited', - for_alighting: 'normal' - }, - { - text: 'second', - index: 1, - for_boarding: 'normal', - for_alighting: 'normal' - } - ] - ) - }) -}) -- cgit v1.2.3