Skip to content

Commit

Permalink
Fixes indeterminism with the cy.intercept by moving it upwards above …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
FrankHassanabad authored Jul 6, 2021
1 parent 194a8a8 commit dcd84ea
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand All @@ -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) => {
Expand Down

0 comments on commit dcd84ea

Please sign in to comment.