diff options
| author | Alban Peignier | 2017-02-15 18:05:05 +0100 |
|---|---|---|
| committer | Alban Peignier | 2017-02-15 18:05:05 +0100 |
| commit | ec0100578753b8f9d5b415f699749c7abfb91f7b (patch) | |
| tree | 9d462c55cd2467401ec2cfa6c6b66baa777dd76c /spec/javascripts | |
| parent | b1a5743598ec96ecda0c6638d575de87c3ad6642 (diff) | |
| parent | 4d41a1cc6adbf64d16a9293f883be15d3ee6c03f (diff) | |
| download | chouette-core-ec0100578753b8f9d5b415f699749c7abfb91f7b.tar.bz2 | |
Merge branch 'master' into staging
Diffstat (limited to 'spec/javascripts')
| -rw-r--r-- | spec/javascripts/itineraries/actions_spec.js | 30 | ||||
| -rw-r--r-- | spec/javascripts/itineraries/components_spec.js | 89 | ||||
| -rw-r--r-- | spec/javascripts/itineraries/reducers/stop_points_spec.js | 401 | ||||
| -rw-r--r-- | spec/javascripts/itineraries/reducers_spec.js | 179 |
4 files changed, 482 insertions, 217 deletions
diff --git a/spec/javascripts/itineraries/actions_spec.js b/spec/javascripts/itineraries/actions_spec.js index f86466375..2bae59987 100644 --- a/spec/javascripts/itineraries/actions_spec.js +++ b/spec/javascripts/itineraries/actions_spec.js @@ -69,3 +69,33 @@ describe('actions', () => { 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/javascripts/itineraries/components_spec.js b/spec/javascripts/itineraries/components_spec.js index c9c57b5eb..24ead7b5d 100644 --- a/spec/javascripts/itineraries/components_spec.js +++ b/spec/javascripts/itineraries/components_spec.js @@ -1,40 +1,53 @@ -// 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'); +var React = require('react'); +var shallow = require('enzyme').shallow; +var mount = require('enzyme').mount; +var StopPointList = require('es6_browserified/itineraries/components/StopPointList'); +var StopPoint = require('es6_browserified/itineraries/components/StopPoint'); +var sinon = require('sinon') -// 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' -// } -// ] +describe('(Component) StopPointList', () => { + it('renders without exploding', () => { + const wrapper = shallow(<StopPointList + stopPoints = {[]} + onChange = {() => {}} + onMoveDownClick={() => {}} + onMoveUpClick={() => {}} + onDeleteClick={() => {}} + onSelectChange={() => {}} + onSelectMarker={() => {}} + onUnselectMarker={() => {}} + />); + expect(wrapper.length).toEqual(1); + }); -// beforeEach(function() { -// store = state -// }); - -// describe('state provided by the store', function() { -// beforeEach(function() { -// connectedApp = TestUtils.renderIntoDocument(<Provider store={store}><ConnectedApp/></Provider>); -// }); - -// it('passes down items', function() { -// app = TestUtils.findRenderedComponentWithType(connectedApp, App); -// expect(app.props.items).toEqual(initialItems); -// }); -// }); -// }); + it('simulates click events', () => { + const state = { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal', + user_objectid: '', + olMap: { + isOpened: false, + json: {} + } + } + const onButtonClick = sinon.spy(); + const wrapper = mount(<StopPoint + value = {state} + onChange = {() => {}} + onMoveDownClick={() => {}} + onMoveUpClick={() => {}} + onDeleteClick={onButtonClick} + onSelectChange={() => {}} + onSelectMarker={() => {}} + onToggleMap={() => {}} + onUnselectMarker={() => {}} + first= {true} + last= {true} + index= {0} + />); + wrapper.find('.delete').simulate('click'); + expect(onButtonClick.calledOnce).toEqual(true); + }); +}); 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..d6917f782 --- /dev/null +++ b/spec/javascripts/itineraries/reducers/stop_points_spec.js @@ -0,0 +1,401 @@ +var stopPointsReducer = require('es6_browserified/itineraries/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, + 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", + name: 'new', + stoparea_id: 1, + user_objectid: "1234", + longitude: 123, + latitude: 123, + registration_number: '0' + } + }) + ).toEqual( + [ + { + text: 'new value', + name: 'new', + index: 0, + stoppoint_id: '', + stoparea_id: 1, + for_boarding: 'normal', + for_alighting: 'normal', + user_objectid: "1234", + longitude: 123, + latitude: 123, + registration_number: '0', + 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: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: undefined + } + } + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + } + ] + ) + }) + + it('should handle SELECT_MARKER', () => { + let openedMapState = [ + { + 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: {} + } + } + ] + expect( + stopPointsReducer(openedMapState, { + type: 'SELECT_MARKER', + index: 0, + data: fakeData + }) + ).toEqual( + [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: true, + json: fakeData + } + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { + isOpened: false, + json: {} + } + } + ] + ) + }) + + it('should handle UNSELECT_MARKER', () => { + let openedMapState = [ + { + 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: {} + } + } + ] + + expect( + stopPointsReducer(openedMapState, { + type: 'UNSELECT_MARKER', + 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 a8731af5f..000000000 --- a/spec/javascripts/itineraries/reducers_spec.js +++ /dev/null @@ -1,179 +0,0 @@ -var reducer = require('es6_browserified/itineraries/reducers/todos') -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' - } - ] - ) - }) -}) |
