mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
* Added CIT test for the fail processor. * Fixed linter issues. * Used new functions and helpers. * Added common test to ensure that a processor type was selected before saving. Fixed some titles and nits from the PR feedback. * Removed unused var. * Merged in master and updated tests to remove repeat code. Co-authored-by: John Dorlus <silne.dorlus@elastic.co>
This commit is contained in:
parent
dac56c149a
commit
677cb6dea3
4 changed files with 101 additions and 1 deletions
|
@ -37,6 +37,21 @@ describe('Processor: Common Fields For All Processors', () => {
|
|||
testBed.component.update();
|
||||
});
|
||||
|
||||
test('prevents form submission if required type field is not provided', async () => {
|
||||
const {
|
||||
actions: { addProcessor, saveNewProcessor },
|
||||
form,
|
||||
} = testBed;
|
||||
|
||||
// Open flyout to add new processor
|
||||
addProcessor();
|
||||
// Click submit button without entering any fields
|
||||
await saveNewProcessor();
|
||||
|
||||
// Expect form error as a processor type is required
|
||||
expect(form.getErrorsMessages()).toEqual(['A type is required.']);
|
||||
});
|
||||
|
||||
test('saves with common fields set', async () => {
|
||||
const {
|
||||
actions: { addProcessor, saveNewProcessor, addProcessorType },
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { setup, SetupResult, getProcessorValue } from './processor.helpers';
|
||||
|
||||
const FAIL_TYPE = 'fail';
|
||||
describe('Processor: Fail', () => {
|
||||
let onUpdate: jest.Mock;
|
||||
let testBed: SetupResult;
|
||||
|
||||
beforeAll(() => {
|
||||
jest.useFakeTimers();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
onUpdate = jest.fn();
|
||||
|
||||
await act(async () => {
|
||||
testBed = await setup({
|
||||
value: {
|
||||
processors: [],
|
||||
},
|
||||
onFlyoutOpen: jest.fn(),
|
||||
onUpdate,
|
||||
});
|
||||
});
|
||||
testBed.component.update();
|
||||
|
||||
const {
|
||||
actions: { addProcessor, addProcessorType },
|
||||
} = testBed;
|
||||
// Open the processor flyout
|
||||
addProcessor();
|
||||
|
||||
// Add type (the other fields are not visible until a type is selected)
|
||||
await addProcessorType(FAIL_TYPE);
|
||||
});
|
||||
|
||||
test('prevents form submission if required message field is not provided', async () => {
|
||||
const {
|
||||
actions: { saveNewProcessor },
|
||||
form,
|
||||
} = testBed;
|
||||
|
||||
// Click submit button with only the type defined
|
||||
await saveNewProcessor();
|
||||
|
||||
// Expect form error as "field" is required parameter
|
||||
expect(form.getErrorsMessages()).toEqual(['A message is required.']);
|
||||
});
|
||||
|
||||
test('saves with required parameter value', async () => {
|
||||
const {
|
||||
actions: { saveNewProcessor },
|
||||
form,
|
||||
} = testBed;
|
||||
|
||||
// Add "message" value (required)
|
||||
form.setInputValue('messageField.input', 'Test Error Message');
|
||||
// Save the field
|
||||
await saveNewProcessor();
|
||||
|
||||
const processors = getProcessorValue(onUpdate, FAIL_TYPE);
|
||||
expect(processors[0].fail).toEqual({
|
||||
message: 'Test Error Message',
|
||||
});
|
||||
});
|
||||
});
|
|
@ -140,6 +140,7 @@ type TestSubject =
|
|||
| 'appendValueField.input'
|
||||
| 'processorTypeSelector.input'
|
||||
| 'fieldNameField.input'
|
||||
| 'messageField.input'
|
||||
| 'mockCodeEditor'
|
||||
| 'tagField.input'
|
||||
| 'ignoreMissingSwitch.input'
|
||||
|
|
|
@ -37,5 +37,12 @@ const fieldsConfig: FieldsConfig = {
|
|||
};
|
||||
|
||||
export const Fail: FunctionComponent = () => {
|
||||
return <UseField component={Field} config={fieldsConfig.message} path="fields.message" />;
|
||||
return (
|
||||
<UseField
|
||||
data-test-subj="messageField"
|
||||
component={Field}
|
||||
config={fieldsConfig.message}
|
||||
path="fields.message"
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue