From dcd84ea81a53de4f844c2ffaf98427989c7a2610 Mon Sep 17 00:00:00 2001 From: Frank Hassanabad Date: Tue, 6 Jul 2021 12:47:55 -0600 Subject: [PATCH] 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 --- .../cypress/integration/timelines/row_renderers.spec.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/security_solution/cypress/integration/timelines/row_renderers.spec.ts b/x-pack/plugins/security_solution/cypress/integration/timelines/row_renderers.spec.ts index c3e04aaaf6a1f..9986d9d2afbd9 100644 --- a/x-pack/plugins/security_solution/cypress/integration/timelines/row_renderers.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/timelines/row_renderers.spec.ts @@ -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) => {