mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[InputControlVis] React 16.4+ compatibility (#25164)
* [input-control-vis/list-control-editor] add failing test to verify issue * [input-control-vis/list-control-editor] update prevFieldName when fieldName changes
This commit is contained in:
parent
0709293aac
commit
c9d8bdc82d
2 changed files with 51 additions and 1 deletions
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue