From 1c6f95e1d85119c741d1249c97fdacd91cc031e1 Mon Sep 17 00:00:00 2001 From: spalger Date: Mon, 5 Nov 2018 12:13:04 -0800 Subject: [PATCH 1/2] [input-control-vis/list-control-editor] add failing test to verify issue --- .../editor/list_control_editor.test.js | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/core_plugins/input_control_vis/public/components/editor/list_control_editor.test.js b/src/core_plugins/input_control_vis/public/components/editor/list_control_editor.test.js index 2cb418f9b7114..f4adcbf5cb7e3 100644 --- a/src/core_plugins/input_control_vis/public/components/editor/list_control_editor.test.js +++ b/src/core_plugins/input_control_vis/public/components/editor/list_control_editor.test.js @@ -20,7 +20,7 @@ import React from 'react'; import sinon from 'sinon'; import { shallow } from 'enzyme'; -import { mountWithIntl } from 'test_utils/enzyme_helpers'; +import { mountWithIntl, shallowWithIntl } from 'test_utils/enzyme_helpers'; import { findTestSubject } from '@elastic/eui/lib/test'; import { getIndexPatternMock } from './__tests__/get_index_pattern_mock'; @@ -287,3 +287,52 @@ test('handleNumberOptionChange - size', async () => { return false; }, 'unexpected input event')); }); + +test('field name change', async () => { + const component = shallowWithIntl( + {}} + parentCandidates={[]} + /> + ); + + const update = async () => { + // Ensure all promises resolve + await new Promise(resolve => process.nextTick(resolve)); + // Ensure the state changes are reflected + component.update(); + }; + + // ensure that after async loading is complete the DynamicOptionsSwitch is not disabled + expect(component.find('[data-test-subj="listControlDynamicOptionsSwitch"][disabled=false]')).toHaveLength(0); + await update(); + expect(component.find('[data-test-subj="listControlDynamicOptionsSwitch"][disabled=false]')).toHaveLength(1); + + component.setProps({ + controlParams: { + ...controlParams, + fieldName: 'numberField', + }, + }); + + // ensure that after async loading is complete the DynamicOptionsSwitch is disabled, because this is not a "string" field + expect(component.find('[data-test-subj="listControlDynamicOptionsSwitch"][disabled=true]')).toHaveLength(0); + await update(); + expect(component.find('[data-test-subj="listControlDynamicOptionsSwitch"][disabled=true]')).toHaveLength(1); + + component.setProps({ + controlParams + }); + + // ensure that after async loading is complete the DynamicOptionsSwitch is not disabled again, because we switched to original "string" field + expect(component.find('[data-test-subj="listControlDynamicOptionsSwitch"][disabled=false]')).toHaveLength(0); + await update(); + expect(component.find('[data-test-subj="listControlDynamicOptionsSwitch"][disabled=false]')).toHaveLength(1); +}); From 7d4f214cb24b35d7aa94b203f71176253cdc088c Mon Sep 17 00:00:00 2001 From: spalger Date: Mon, 5 Nov 2018 12:13:49 -0800 Subject: [PATCH 2/2] [input-control-vis/list-control-editor] update prevFieldName when fieldName changes --- .../public/components/editor/list_control_editor.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core_plugins/input_control_vis/public/components/editor/list_control_editor.js b/src/core_plugins/input_control_vis/public/components/editor/list_control_editor.js index cfb7bd1d3db91..560987cbd9c41 100644 --- a/src/core_plugins/input_control_vis/public/components/editor/list_control_editor.js +++ b/src/core_plugins/input_control_vis/public/components/editor/list_control_editor.js @@ -54,6 +54,7 @@ export class ListControlEditor extends Component { const isNewFieldName = prevState.prevFieldName !== nextProps.controlParams.fieldName; if (!prevState.isLoadingFieldType && isNewFieldName) { return { + prevFieldName: nextProps.controlParams.fieldName, isLoadingFieldType: true, }; }