forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.7] [Index management] Fix regression on mappings editor for… (elas…
- Loading branch information
Showing
18 changed files
with
371 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
...components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.ts
This file was deleted.
Oops, something went wrong.
132 changes: 132 additions & 0 deletions
132
...omponents/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import React from 'react'; | ||
import { registerTestBed, TestBed, nextTick } from '../../../../../../../../../test_utils'; | ||
import { MappingsEditor } from '../../../mappings_editor'; | ||
|
||
jest.mock('@elastic/eui', () => ({ | ||
...jest.requireActual('@elastic/eui'), | ||
// Mocking EuiComboBox, as it utilizes "react-virtualized" for rendering search suggestions, | ||
// which does not produce a valid component wrapper | ||
EuiComboBox: (props: any) => ( | ||
<input | ||
data-test-subj={props['data-test-subj'] || 'mockComboBox'} | ||
onChange={async (syntheticEvent: any) => { | ||
props.onChange([syntheticEvent['0']]); | ||
}} | ||
/> | ||
), | ||
// Mocking EuiCodeEditor, which uses React Ace under the hood | ||
EuiCodeEditor: (props: any) => ( | ||
<input | ||
data-test-subj={props['data-test-subj'] || 'mockCodeEditor'} | ||
data-currentvalue={props.value} | ||
onChange={(e: any) => { | ||
props.onChange(e.jsonContent); | ||
}} | ||
/> | ||
), | ||
})); | ||
|
||
const createActions = (testBed: TestBed<TestSubjects>) => { | ||
const { find, waitFor, form, component } = testBed; | ||
|
||
const addField = async (name: string, type: string) => { | ||
const currentCount = find('fieldsListItem').length; | ||
|
||
form.setInputValue('nameParameterInput', name); | ||
find('createFieldForm.fieldType').simulate('change', [ | ||
{ | ||
label: type, | ||
value: type, | ||
}, | ||
]); | ||
|
||
await nextTick(); | ||
component.update(); | ||
|
||
find('createFieldForm.addButton').simulate('click'); | ||
|
||
// We wait until there is one more field in the DOM | ||
await waitFor('fieldsListItem', currentCount + 1); | ||
}; | ||
|
||
const selectTab = async (tab: 'fields' | 'templates' | 'advanced') => { | ||
const index = ['fields', 'templates', 'advanced'].indexOf(tab); | ||
const tabIdToContentMap: { [key: string]: TestSubjects } = { | ||
fields: 'documentFields', | ||
templates: 'dynamicTemplates', | ||
advanced: 'advancedConfiguration', | ||
}; | ||
|
||
const tabElement = find('formTab').at(index); | ||
if (tabElement.length === 0) { | ||
throw new Error(`Tab not found: "${tab}"`); | ||
} | ||
tabElement.simulate('click'); | ||
|
||
await waitFor(tabIdToContentMap[tab]); | ||
}; | ||
|
||
const updateJsonEditor = async (testSubject: TestSubjects, value: object) => { | ||
find(testSubject).simulate('change', { jsonContent: JSON.stringify(value) }); | ||
}; | ||
|
||
const getJsonEditorValue = (testSubject: TestSubjects) => { | ||
const value = find(testSubject).props()['data-currentvalue']; | ||
if (typeof value === 'string') { | ||
try { | ||
return JSON.parse(value); | ||
} catch { | ||
return { errorParsingJson: true, props: find(testSubject).props() }; | ||
} | ||
} | ||
return value; | ||
}; | ||
|
||
return { | ||
selectTab, | ||
addField, | ||
updateJsonEditor, | ||
getJsonEditorValue, | ||
}; | ||
}; | ||
|
||
export const setup = async (props: any = { onUpdate() {} }): Promise<MappingsEditorTestBed> => { | ||
const testBed = await registerTestBed<TestSubjects>(MappingsEditor, { | ||
memoryRouter: { | ||
wrapComponent: false, | ||
}, | ||
defaultProps: props, | ||
})(); | ||
|
||
return { | ||
...testBed, | ||
actions: createActions(testBed), | ||
}; | ||
}; | ||
|
||
export type MappingsEditorTestBed = TestBed<TestSubjects> & { | ||
actions: ReturnType<typeof createActions>; | ||
}; | ||
|
||
export type TestSubjects = | ||
| 'formTab' | ||
| 'mappingsEditor' | ||
| 'fieldsListItem' | ||
| 'fieldName' | ||
| 'mappingTypesDetectedCallout' | ||
| 'documentFields' | ||
| 'dynamicTemplates' | ||
| 'advancedConfiguration' | ||
| 'advancedConfiguration.numericDetection' | ||
| 'advancedConfiguration.numericDetection.input' | ||
| 'advancedConfiguration.dynamicMappingsToggle' | ||
| 'advancedConfiguration.dynamicMappingsToggle.input' | ||
| 'dynamicTemplatesEditor' | ||
| 'nameParameterInput' | ||
| 'createFieldForm.fieldType' | ||
| 'createFieldForm.addButton'; |
Oops, something went wrong.