[6.x] [InputControlVis] React 16.4+ compatibility (#25164) (#25180)

Backports the following commits to 6.x:
 - [InputControlVis] React 16.4+ compatibility  (#25164)
This commit is contained in:
Spencer 2018-11-05 19:27:13 -08:00 committed by GitHub
parent 6228f6ce1b
commit 3ee118dffe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 1 deletions

View file

@ -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,
};
}

View file

@ -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(
<ListControlEditor
getIndexPattern={getIndexPatternMock}
controlIndex={0}
controlParams={controlParams}
handleFieldNameChange={handleFieldNameChange}
handleIndexPatternChange={handleIndexPatternChange}
handleCheckboxOptionChange={handleCheckboxOptionChange}
handleNumberOptionChange={handleNumberOptionChange}
handleParentChange={() => {}}
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);
});