-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added tests for dot notation processors. #107340
Added tests for dot notation processors. #107340
Conversation
Pinging @elastic/kibana-stack-management (Team:Stack Management) |
@sebelga For the second test in this test case, when I fill out the field but omit the |
} = testBed; | ||
|
||
// Add "field" value (required) | ||
form.setInputValue('fieldNameField.input', 'missing'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you are testing a validation to run and then display a message you need to wait for the validation to have ran. The validation run after a 500ms debounce time after the form input value has change.
As you correctly use the fake timer from jest the 500ms never pass and the validation does not run.
This is what you need to do
// Wrap the `setInputValue` in an `act()` call as it modifies the internal value state of the field and mark it as "changed".
// This trigger the debounce which now waits...
await act(async () => {
form.setInputValue('fieldNameField.input', 'missing');
});
// Move ahead the debounce time which will then execute any validations
await act(async () => {
jest.runAllTimers();
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sebelga interestingly enough - we are not wrapping other instances of form.setInputValue()
in act()
(although I guess we probably should be?) or calling runAllTimers()
in these processor tests. Is there something different about this specific validation?
On another note - should the act()
be part of the actual setInputValue
method in the testbed utils? I see it does call component.update()
after the simulate change - related code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on what you are testing and if there is code reacts to the field value change. You might not need to wrap with an act
when changing the form input in certain cases. Here he is testing the result of the validation so he both needs the act()
and wait for the debounce.
If for example you are testing that the correct payload is sent, then you don't need to wait for useEffect
(that triggers the validate()
on field). You can set the value of all fields synchronously and simulate the click of the "Send" button. That will call the form.getData()
and all the values are there synchronously.
As you can see it in my latest test for preview, my helpers to modify field values all wrap with an act
call (https://github.com/elastic/kibana/pull/106410/files#diff-8733b59b04f21f21eb6bf66bd48aba1334abad4ec93d8bde99ac1386e000f131R32)
should the act() be part of the actual setInputValue method in the testbed utils?
It probably would have be good to do it there. Now it would require a lot of work to add it there and then remove it everywhere we have wrapped setInputValue
with an act
as it would be wrapped twice 😊
Note that this is all due to hooks and the way state updates and react in useEffect
. The await act( ... )
makes sure all the lifecycle has ran.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation @sebelga!
I was thinking there were other test cases where we were verifying the input validation, but I see now most of the processor tests are only testing empty fields on submit, e.g.,
test('prevents form submission if required fields are not provided', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;
// Click submit button with only the type defined
await saveNewProcessor();
// Expect form error as "field" and "target_field" are required parameters
expect(form.getErrorsMessages()).toEqual(['A field value is required.']);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and saveNewProcessor
is wrapped
async saveNewProcessor() {
await act(async () => {
find('addProcessorForm.submitButton').simulate('click');
});
component.update();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get it. I am not sure if this is spelled out explicitly in our CIT docs but I think it would be useful to do so. @sebelga @alisonelizabeth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @cuff-links! Left a few nits - looks like a some of the comments in the tests might have been copy-pasted and need to be updated.
...ines/public/application/components/pipeline_editor/__jest__/processors/dot_expander.test.tsx
Outdated
Show resolved
Hide resolved
...ines/public/application/components/pipeline_editor/__jest__/processors/dot_expander.test.tsx
Outdated
Show resolved
Hide resolved
...ines/public/application/components/pipeline_editor/__jest__/processors/dot_expander.test.tsx
Outdated
Show resolved
Hide resolved
} = testBed; | ||
|
||
// Add "field" value (required) | ||
form.setInputValue('fieldNameField.input', 'missing'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sebelga interestingly enough - we are not wrapping other instances of form.setInputValue()
in act()
(although I guess we probably should be?) or calling runAllTimers()
in these processor tests. Is there something different about this specific validation?
On another note - should the act()
be part of the actual setInputValue
method in the testbed utils? I see it does call component.update()
after the simulate change - related code.
...ines/public/application/components/pipeline_editor/__jest__/processors/dot_expander.test.tsx
Outdated
Show resolved
Hide resolved
@cuff-links We're in the 7.15 dev cycle now, so could you please update the version labels? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest LGTM. Ran tests locally. Thanks @cuff-links!
Looks like there are some linting issues that may need to be addressed before merging. The test failure reported looks unrelated to these changes.
Also, I noticed there is a new parameter for the dot expander processor. Opened #108895 as a follow-up issue to address.
💚 Build Succeeded
Metrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: |
* Added tests for dot notation processors. * Fixed nits in PR. * Fixed linting issues.
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
* Added tests for dot notation processors. * Fixed nits in PR. * Fixed linting issues. Co-authored-by: John Dorlus <[email protected]>
Summary
This PR is to add test coverage for the Ingest Pipelines Date Processor.
Test cases being covered
Prevents submission 0/1 required fields given.
Prevents submission when field does not contain
.
for the dot notation.Saves processor with default options
Saves processor with setting optional options.