From 45ee688bd34f746a9852b54a2b8ee7d38c3a367a Mon Sep 17 00:00:00 2001 From: Xavier Metichecchia Date: Tue, 8 Oct 2024 11:57:56 -0400 Subject: [PATCH] Merge pull request #1859 from GSA/hotfix-cypress-datalayer-action PXBF-hotfix-cypress-datalayer-action: add wait to avoid race condition --- .../cypress/e2e/storybook/dataLayer.cy.js | 25 ++++++++++++++++--- usagov-2021 | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/benefit-finder/cypress/e2e/storybook/dataLayer.cy.js b/benefit-finder/cypress/e2e/storybook/dataLayer.cy.js index f3747d88d..fa0fa38fc 100644 --- a/benefit-finder/cypress/e2e/storybook/dataLayer.cy.js +++ b/benefit-finder/cypress/e2e/storybook/dataLayer.cy.js @@ -217,11 +217,28 @@ describe('Calls to Google Analytics Object', function () { .button() .contains(EN_LOCALE_DATA.intro.button) .then(() => { - // get the last pushed event - const ev = { ...window.dataLayer[window.dataLayer.length - 1] } - removeID(ev) + cy.wait(wait).then(() => { + assert.isDefined( + window.dataLayer.find(x => x.event === 'gtm.load'), + 'GTM is done loading' + ) + assert.isDefined( + window.dataLayer.find(x => x.event === 'bf_page_change'), + 'bf_page_change is loaded' + ) - expect(ev).to.deep.equal(dataLayerValueIntro) + cy.wait(500).then(() => { + console.log(window.dataLayer) + // get the last pushed event + const bfEventIndex = window.dataLayer.findIndex( + x => x.event === 'bf_page_change' + ) + const ev = { ...window.dataLayer[bfEventIndex] } + removeID(ev) + + expect(ev).to.deep.equal(dataLayerValueIntro) + }) + }) }) }) }) diff --git a/usagov-2021 b/usagov-2021 index eb418375f..0ca782595 160000 --- a/usagov-2021 +++ b/usagov-2021 @@ -1 +1 @@ -Subproject commit eb418375f783b0dc9f8ab330f2ba0507242bc053 +Subproject commit 0ca782595d9f266ed0064025a531d19cc070bc78