From 953fb3a48c43f5801bbc35dd02a2db26b21479b1 Mon Sep 17 00:00:00 2001 From: jpl Date: Mon, 9 Jan 2017 12:10:24 +0100 Subject: adding modal specs --- .../journey_patterns/reducers/modal_spec.js | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 spec/javascripts/journey_patterns/reducers/modal_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/reducers/modal_spec.js b/spec/javascripts/journey_patterns/reducers/modal_spec.js new file mode 100644 index 000000000..ee83cb251 --- /dev/null +++ b/spec/javascripts/journey_patterns/reducers/modal_spec.js @@ -0,0 +1,100 @@ +var modalReducer = require('es6_browserified/journey_patterns/reducers/modal') + +let state = {} + +let fakeJourneyPattern = { + name: 'jp_test 1', + object_id: 'jp_test:JourneyPattern:1', + published_name: 'jp_test publishedname 1', + registration_number: 'jp_test registrationnumber 1', + stop_points: [], + deletable: false +} + +const accept = cancel = function(){} + +describe('modal reducer', () => { + beforeEach(() => { + state = { + type: '', + modalProps: {}, + confirmModal: {} + } + }) + + it('should return the initial state', () => { + expect( + modalReducer(undefined, {}) + ).toEqual({}) + }) + + it('should handle OPEN_CONFIRM_MODAL', () => { + let newState = Object.assign({}, state, { + type: 'confirm', + confirmModal: { + accept: accept, + cancel: cancel + } + }) + expect( + modalReducer(state, { + type: 'OPEN_CONFIRM_MODAL', + accept, + cancel + }) + ).toEqual(newState) + }) + + it('should handle EDIT_JOURNEYPATTERN_MODAL', () => { + let newState = Object.assign({}, state, { + type: 'edit', + modalProps: { + index: 0, + journeyPattern: fakeJourneyPattern + }, + confirmModal: {} + }) + expect( + modalReducer(state, { + type: 'EDIT_JOURNEYPATTERN_MODAL', + index: 0, + journeyPattern : fakeJourneyPattern + }) + ).toEqual(newState) + }) + + it('should handle CREATE_JOURNEYPATTERN_MODAL', () => { + expect( + modalReducer(state, { + type: 'CREATE_JOURNEYPATTERN_MODAL' + }) + ).toEqual(Object.assign({}, state, { type: 'create' })) + }) + + it('should handle DELETE_JOURNEYPATTERN', () => { + expect( + modalReducer(state, { + type: 'DELETE_JOURNEYPATTERN', + index: 0 + }) + ).toEqual(state) + }) + + it('should handle SAVE_MODAL', () => { + expect( + modalReducer(state, { + type: 'SAVE_MODAL', + index: 0, + data: {} + }) + ).toEqual(state) + }) + + it('should handle CLOSE_MODAL', () => { + expect( + modalReducer(state, { + type: 'CLOSE_MODAL' + }) + ).toEqual(state) + }) +}) -- cgit v1.2.3