Fixes indeterminism with the cy.intercept by moving it upwards above the clicks (#104501)

## Summary

Fixes indeterminism with cypress by moving the `cy.intercept('PATCH', '/api/timeline').as('updateTimeline');` above where the click is happening.

Backport to 7.14.0 to hopefully stabilize it better as well.

You can make the indeterminism deterministic by adding (for testing only), a `cy.wait(5000)` like so:

```ts
// Keep clicking on the disable all button until the first element of all the elements are no longer checked.
// In cases where the click handler is not present on the page just yet, this will cause the button to be clicked
// multiple times until it sees that the click took effect. You could go through the whole list but I just check
// for the first to be unchecked and then assume the click was successful
cy.root()
  .pipe(($el) => {
    $el.find(TIMELINE_ROW_RENDERERS_DISABLE_ALL_BTN).trigger('click');
    return $el.find(TIMELINE_ROW_RENDERERS_MODAL_ITEMS_CHECKBOX).first();
  })
  .should('not.be.checked');
 cy.wait(5000); // <--- Temp addition for testing to ensure our intercept works above this. If the intercept is below this then we see the same indetermism behavior but deterministically.
``` 

### Checklist

- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
This commit is contained in:
Frank Hassanabad 2021-07-06 12:47:55 -06:00 committed by GitHub
parent 194a8a87a8
commit dcd84ea81a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -63,8 +63,9 @@ describe('Row renderers', () => {
cy.get(TIMELINE_ROW_RENDERERS_SEARCHBOX).should('exist');
cy.get(TIMELINE_ROW_RENDERERS_SEARCHBOX).type('flow');
cy.get(TIMELINE_ROW_RENDERERS_MODAL_ITEMS_CHECKBOX).first().uncheck();
// Intercepts should be before click handlers that activate them rather than afterwards or you have race conditions
cy.intercept('PATCH', '/api/timeline').as('updateTimeline');
cy.get(TIMELINE_ROW_RENDERERS_MODAL_ITEMS_CHECKBOX).first().uncheck();
cy.wait('@updateTimeline').then((interception) => {
expect(interception.request.body.timeline.excludedRowRendererIds).to.contain('netflow');
@ -84,6 +85,9 @@ describe('Row renderers', () => {
cy.get(TIMELINE_ROW_RENDERERS_DISABLE_ALL_BTN).should('exist');
cy.get(TIMELINE_ROW_RENDERERS_MODAL_ITEMS_CHECKBOX).should('be.checked');
// Intercepts should be before click handlers that activate them rather than afterwards or you have race conditions
cy.intercept('PATCH', '/api/timeline').as('updateTimeline');
// Keep clicking on the disable all button until the first element of all the elements are no longer checked.
// In cases where the click handler is not present on the page just yet, this will cause the button to be clicked
// multiple times until it sees that the click took effect. You could go through the whole list but I just check
@ -95,7 +99,6 @@ describe('Row renderers', () => {
})
.should('not.be.checked');
cy.intercept('PATCH', '/api/timeline').as('updateTimeline');
cy.wait('@updateTimeline').its('response.statusCode').should('eq', 200);
cy.wait('@updateTimeline').then((interception) => {