diff --git a/web/client/reducers/__tests__/widgets-test.js b/web/client/reducers/__tests__/widgets-test.js index 0162c6d0e3..2a0c6558c7 100644 --- a/web/client/reducers/__tests__/widgets-test.js +++ b/web/client/reducers/__tests__/widgets-test.js @@ -218,6 +218,34 @@ describe('Test the widgets reducer', () => { expect(uWidgets[0].dependenciesMap).toBeFalsy(); expect(uWidgets[0].id).toBe("2"); }); + it('test deleteWidget if the some other widgets [not deleted] has dependenciesMap = {}', () => { + const state = { + containers: { + [DEFAULT_TARGET]: { + widgets: [{ + id: "1", + maps: [{mapId: 1, layers: [1, 2]}] + }, { + id: "2", + mapSync: true, + dependenciesMap: { + layers: "widgets[1].maps[1].layers" + } + }, { + id: "3", + mapSync: true, + dependenciesMap: {} + }] + } + } + }; + const newState = widgets(state, deleteWidget({id: "1"})); + const uWidgets = newState.containers[DEFAULT_TARGET].widgets; + expect(uWidgets.length).toBe(2); + expect(uWidgets[0].mapSync).toBeFalsy(); + expect(uWidgets[0].dependenciesMap).toBeFalsy(); + expect(uWidgets[0].id).toBe("2"); + }); it('init', () => { const defaults = {initialSize: { w: 4, diff --git a/web/client/reducers/widgets.js b/web/client/reducers/widgets.js index 96f1fb0406..22ea887048 100644 --- a/web/client/reducers/widgets.js +++ b/web/client/reducers/widgets.js @@ -182,7 +182,7 @@ function widgetsReducer(state = emptyState, action) { const allWidgets = get(updatedState, path, []); return set(path, allWidgets.map(m => { if (m.dependenciesMap) { - const [, dependentWidgetId] = WIDGETS_REGEX.exec((Object.values(m.dependenciesMap) || [])[0]); + const [, dependentWidgetId] = WIDGETS_REGEX.exec((Object.values(m.dependenciesMap) || [])[0]) || []; if (dependentWidgetId) { if (action.widget.id === dependentWidgetId) { return {...omit(m, "dependenciesMap"), mapSync: false};