-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Ingest Pipelines] Add test coverage for ingest pipelines editor comp…
…onent (#69283) * first iteration of CIT tests * address pr feedback - use dot notation where we can - use string literals instead of + concatentation
- Loading branch information
1 parent
2544daf
commit e046029
Showing
14 changed files
with
334 additions
and
65 deletions.
There are no files selected for viewing
36 changes: 0 additions & 36 deletions
36
...tion/components/pipeline_processors_editor/__jest__/pipeline_processors_editor.helpers.ts
This file was deleted.
Oops, something went wrong.
158 changes: 158 additions & 0 deletions
158
...ion/components/pipeline_processors_editor/__jest__/pipeline_processors_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,158 @@ | ||
/* | ||
* 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 { act } from 'react-dom/test-utils'; | ||
import React from 'react'; | ||
import { registerTestBed, TestBed } from '../../../../../../../test_utils'; | ||
import { PipelineProcessorsEditor, Props } from '../pipeline_processors_editor.container'; | ||
|
||
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'} | ||
data-currentvalue={props.selectedOptions} | ||
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); | ||
}} | ||
/> | ||
), | ||
})); | ||
|
||
jest.mock('react-virtualized', () => ({ | ||
...jest.requireActual('react-virtualized'), | ||
AutoSizer: ({ children }: { children: any }) => ( | ||
<div>{children({ height: 500, width: 500 })}</div> | ||
), | ||
})); | ||
|
||
const testBedSetup = registerTestBed<TestSubject>(PipelineProcessorsEditor, { | ||
doMountAsync: false, | ||
}); | ||
|
||
export interface SetupResult extends TestBed<TestSubject> { | ||
actions: ReturnType<typeof createActions>; | ||
} | ||
|
||
/** | ||
* We make heavy use of "processorSelector" in these actions. They are a way to uniquely identify | ||
* a processor and are a stringified version of {@link ProcessorSelector}. | ||
* | ||
* @remark | ||
* See also {@link selectorToDataTestSubject}. | ||
*/ | ||
const createActions = (testBed: TestBed<TestSubject>) => { | ||
const { find, component } = testBed; | ||
|
||
return { | ||
async addProcessor(processorsSelector: string, type: string, options: Record<string, any>) { | ||
find(`${processorsSelector}.addProcessorButton`).simulate('click'); | ||
await act(async () => { | ||
find('processorTypeSelector').simulate('change', [{ value: type, label: type }]); | ||
}); | ||
component.update(); | ||
await act(async () => { | ||
find('processorOptionsEditor').simulate('change', { | ||
jsonContent: JSON.stringify(options), | ||
}); | ||
}); | ||
await act(async () => { | ||
find('processorSettingsForm.submitButton').simulate('click'); | ||
}); | ||
}, | ||
|
||
removeProcessor(processorSelector: string) { | ||
find(`${processorSelector}.moreMenu.button`).simulate('click'); | ||
find(`${processorSelector}.moreMenu.deleteButton`).simulate('click'); | ||
act(() => { | ||
find('removeProcessorConfirmationModal.confirmModalConfirmButton').simulate('click'); | ||
}); | ||
}, | ||
|
||
moveProcessor(processorSelector: string, dropZoneSelector: string) { | ||
act(() => { | ||
find(`${processorSelector}.moveItemButton`).simulate('click'); | ||
}); | ||
act(() => { | ||
find(dropZoneSelector).last().simulate('click'); | ||
}); | ||
component.update(); | ||
}, | ||
|
||
async addOnFailureProcessor( | ||
processorSelector: string, | ||
type: string, | ||
options: Record<string, any> | ||
) { | ||
find(`${processorSelector}.moreMenu.button`).simulate('click'); | ||
find(`${processorSelector}.moreMenu.addOnFailureButton`).simulate('click'); | ||
await act(async () => { | ||
find('processorTypeSelector').simulate('change', [{ value: type, label: type }]); | ||
}); | ||
component.update(); | ||
await act(async () => { | ||
find('processorOptionsEditor').simulate('change', { | ||
jsonContent: JSON.stringify(options), | ||
}); | ||
}); | ||
await act(async () => { | ||
find('processorSettingsForm.submitButton').simulate('click'); | ||
}); | ||
}, | ||
|
||
duplicateProcessor(processorSelector: string) { | ||
find(`${processorSelector}.moreMenu.button`).simulate('click'); | ||
act(() => { | ||
find(`${processorSelector}.moreMenu.duplicateButton`).simulate('click'); | ||
}); | ||
}, | ||
|
||
startAndCancelMove(processorSelector: string) { | ||
act(() => { | ||
find(`${processorSelector}.moveItemButton`).simulate('click'); | ||
}); | ||
component.update(); | ||
act(() => { | ||
find(`${processorSelector}.cancelMoveItemButton`).simulate('click'); | ||
}); | ||
}, | ||
|
||
toggleOnFailure() { | ||
find('pipelineEditorOnFailureToggle').simulate('click'); | ||
}, | ||
}; | ||
}; | ||
|
||
export const setup = async (props: Props): Promise<SetupResult> => { | ||
const testBed = await testBedSetup(props); | ||
return { | ||
...testBed, | ||
actions: createActions(testBed), | ||
}; | ||
}; | ||
|
||
type TestSubject = | ||
| 'pipelineEditorDoneButton' | ||
| 'pipelineEditorOnFailureToggle' | ||
| 'addProcessorsButtonLevel1' | ||
| 'processorSettingsForm' | ||
| 'processorSettingsForm.submitButton' | ||
| 'processorOptionsEditor' | ||
| 'processorSettingsFormFlyout' | ||
| 'processorTypeSelector' | ||
| 'pipelineEditorOnFailureTree' | ||
| string; |
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
Oops, something went wrong.