From c1ba6b6c218edcbcf53a8f15be62474a9b34c0a4 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 12 Jun 2017 12:57:37 +0200 Subject: [PATCH] [web] fix stopEdit --- .../__tests__/components/FlowView/ToggleEditSpec.js | 3 ++- web/src/js/__tests__/ducks/ui/flowSpec.js | 12 ++++++++---- web/src/js/ducks/ui/flow.js | 5 ++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/web/src/js/__tests__/components/FlowView/ToggleEditSpec.js b/web/src/js/__tests__/components/FlowView/ToggleEditSpec.js index 4578fdc8f..ec3a8462b 100644 --- a/web/src/js/__tests__/components/FlowView/ToggleEditSpec.js +++ b/web/src/js/__tests__/components/FlowView/ToggleEditSpec.js @@ -6,6 +6,7 @@ import { Provider } from 'react-redux' import { startEdit, stopEdit } from '../../../ducks/ui/flow' import { TFlow, TStore } from '../../ducks/tutils' +global.fetch = jest.fn() let tflow = new TFlow() describe('ToggleEdit Component', () => { @@ -24,7 +25,7 @@ describe('ToggleEdit Component', () => { it('should handle click on stopEdit', () => { tree.children[0].props.onClick() - expect(store.getActions()).toEqual([stopEdit(tflow, true)]) + expect(fetch).toBeCalled() }) it('should handle click on startEdit', () => { diff --git a/web/src/js/__tests__/ducks/ui/flowSpec.js b/web/src/js/__tests__/ducks/ui/flowSpec.js index cd6ffa2f3..11ca021e1 100644 --- a/web/src/js/__tests__/ducks/ui/flowSpec.js +++ b/web/src/js/__tests__/ducks/ui/flowSpec.js @@ -11,7 +11,7 @@ import reducer, { displayLarge } from '../../../ducks/ui/flow' -import { select, updateFlow } from '../../../ducks/flows' +import * as flowActions from '../../../ducks/flows' describe('flow reducer', () => { it('should return initial state', () => { @@ -61,11 +61,11 @@ describe('flow reducer', () => { }) it('should not change the contentview mode', () => { - expect(reducer({contentView: 'foo'}, select(1)).contentView).toEqual('foo') + expect(reducer({contentView: 'foo'}, flowActions.select(1)).contentView).toEqual('foo') }) it('should change the contentview mode to auto after editing when a new flow will be selected', () => { - expect(reducer({contentView: 'foo', modifiedFlow : 'test_flow'}, select(1)).contentView).toEqual('Auto') + expect(reducer({contentView: 'foo', modifiedFlow : 'test_flow'}, flowActions.select(1)).contentView).toEqual('Auto') }) it('should set update and merge the modifiedflow with the update values', () => { @@ -84,7 +84,11 @@ describe('flow reducer', () => { it('should stop editing when the selected flow is updated', () => { let modifiedFlow = {id: 1} let updatedFlow = {id: 1} - expect(reducer({modifiedFlow}, stopEdit(updatedFlow, modifiedFlow)).modifiedFlow).toBeFalsy() + expect(reducer( + { modifiedFlow }, + {type: flowActions.UPDATE, data: modifiedFlow} + ).modifiedFlow + ).toBeFalsy() }) it('should set content view', () => { diff --git a/web/src/js/ducks/ui/flow.js b/web/src/js/ducks/ui/flow.js index 51ad4184c..ea31db197 100644 --- a/web/src/js/ducks/ui/flow.js +++ b/web/src/js/ducks/ui/flow.js @@ -148,7 +148,6 @@ export function setContent(content){ return { type: SET_CONTENT, content } } -export function stopEdit(data, modifiedFlow) { - let diff = getDiff(data, modifiedFlow) - return {type: flowsActions.UPDATE, data, diff } +export function stopEdit(flow, modifiedFlow) { + return flowsActions.update(flow, getDiff(flow, modifiedFlow)) }