From c31346c9296625328a1f0df183e4f72c0bbe1bd0 Mon Sep 17 00:00:00 2001 From: rmccar <42928680+rmccar@users.noreply.github.com> Date: Fri, 8 Nov 2024 22:26:47 +0000 Subject: [PATCH] Fix flakey macro tests (#3414) --- .../address-input/autosuggest.address.spec.js | 30 ++++++++++--------- .../timeout-modal/timeout-modal.spec.js | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/components/address-input/autosuggest.address.spec.js b/src/components/address-input/autosuggest.address.spec.js index 9c2636d988..42f8e0c9d6 100644 --- a/src/components/address-input/autosuggest.address.spec.js +++ b/src/components/address-input/autosuggest.address.spec.js @@ -189,7 +189,7 @@ describe('script: address-input', () => { await setTestPage('/test', renderComponent('address-input', EXAMPLE_ADDRESS_INPUT_WITH_API)); await setTimeout(50); - expect(apiFaker.getRequestCount('/addresses/eq?input=cf142&limit=10')).toBe(1); + expect(await apiFaker.getRequestCount('/addresses/eq?input=cf142&limit=10')).toBe(1); }); describe('when api status is okay', () => { @@ -257,8 +257,9 @@ describe('script: address-input', () => { await page.$eval('.ons-js-autosuggest-input', (node) => (node.value = '196 coll')); await page.type('.ons-js-autosuggest-input', 'e'); + await setTimeout(50); - expect(apiFaker.getRequestCount('/addresses/eq?input=196%20colle&limit=10')).toBe(1); + expect(await apiFaker.getRequestCount('/addresses/eq?input=196%20colle&limit=10')).toBe(1); }); describe('when the value is a full postcode', () => { @@ -267,14 +268,15 @@ describe('script: address-input', () => { await page.$eval('.ons-js-autosuggest-input', (node) => (node.value = 'CF14 2N')); await page.type('.ons-js-autosuggest-input', 'T'); + + await setTimeout(100); }); it('provides expected parameters to the address API where `limit` is 100', async () => { - expect(apiFaker.getRequestCount('/addresses/eq?input=cf14%202nt&limit=100&groupfullpostcodes=combo')).toBe(1); + expect(await apiFaker.getRequestCount('/addresses/eq?input=cf14%202nt&limit=100&groupfullpostcodes=combo')).toBe(1); }); it('has expected suggestion entries', async () => { - await setTimeout(100); const suggestions = await page.$$eval('.ons-autosuggest__option', (nodes) => nodes.map((node) => node.textContent.trim())); expect(suggestions).toEqual(['196 College Road, Birmingham, B44 8HF', '196 College Road, Whitchurch, Cardiff, CF14 2NZ']); }); @@ -314,7 +316,7 @@ describe('script: address-input', () => { it('provides expected parameters to the address API', async () => { expect( - apiFaker.getRequestCount( + await apiFaker.getRequestCount( '/addresses/eq?input=penlline%20road%20whitchurch%20cardiff%20cf14%202nz&limit=100&groupfullpostcodes=combo', ), ).toBe(1); @@ -336,7 +338,7 @@ describe('script: address-input', () => { }); it('makes expected request when a suggestion is selected', async () => { - expect(apiFaker.getRequestCount('/addresses/eq/uprn/100070332099?addresstype=paf')).toBe(1); + expect(await apiFaker.getRequestCount('/addresses/eq/uprn/100070332099?addresstype=paf')).toBe(1); }); it('populates manual input fields with address from selection', async () => { @@ -360,7 +362,7 @@ describe('script: address-input', () => { }); it('provides expected parameters to the address API', async () => { - expect(apiFaker.getRequestCount('/addresses/eq?input=cf14%202&limit=10')).toBe(1); + expect(await apiFaker.getRequestCount('/addresses/eq?input=cf14%202&limit=10')).toBe(1); }); it('has expected suggestion entries', async () => { @@ -380,7 +382,7 @@ describe('script: address-input', () => { it('makes expected request', async () => { expect( - apiFaker.getRequestCount( + await apiFaker.getRequestCount( '/addresses/eq/bucket?postcode=CF14%202AA&streetname=Penlline%20Road&townname=Whitchurch&groupfullpostcodes=combo', ), ).toBe(1); @@ -611,7 +613,9 @@ describe('script: address-input', () => { await page.$eval('.ons-js-autosuggest-input', (node) => (node.value = '196 coll')); await page.type('.ons-js-autosuggest-input', 'e'); - expect(apiFaker.getRequestCount('/addresses/eq?input=196%20colle&limit=10&favourwelsh=true')).toBe(1); + await setTimeout(50); + + expect(await apiFaker.getRequestCount('/addresses/eq?input=196%20colle&limit=10&favourwelsh=true')).toBe(1); }); }); @@ -629,7 +633,7 @@ describe('script: address-input', () => { }); it('then the retrieveAddress function will be called', async () => { - expect(apiFaker.getRequestCount('/addresses/eq/uprn/100070332099?addresstype=paf')).toBe(1); + expect(await apiFaker.getRequestCount('/addresses/eq/uprn/100070332099?addresstype=paf')).toBe(1); }); }); @@ -735,10 +739,9 @@ describe('script: address-input', () => { it('provides expected parameters to the address API', async () => { await page.$eval('.ons-js-autosuggest-input', (node) => (node.value = '196 coll')); await page.type('.ons-js-autosuggest-input', 'e'); - await setTimeout(50); - expect(apiFaker.getRequestCount(searchEndpoint)).toBe(1); + expect(await apiFaker.getRequestCount(searchEndpoint)).toBe(1); }); it('requests further information for the selected address from the API with the expected parameters', async () => { @@ -746,10 +749,9 @@ describe('script: address-input', () => { await page.type('.ons-js-autosuggest-input', 'e', { delay: 20 }); await page.keyboard.press('ArrowDown'); await page.keyboard.press('Enter'); - await setTimeout(50); - expect(apiFaker.getRequestCount(uprnEndpoint)).toBe(1); + expect(await apiFaker.getRequestCount(uprnEndpoint)).toBe(1); }); }); }); diff --git a/src/components/timeout-modal/timeout-modal.spec.js b/src/components/timeout-modal/timeout-modal.spec.js index fa2538ff96..b5b59e070d 100644 --- a/src/components/timeout-modal/timeout-modal.spec.js +++ b/src/components/timeout-modal/timeout-modal.spec.js @@ -216,7 +216,7 @@ describe('script: timeout modal', () => { it('closes the modal', async () => { const modalIsVisible = await page.$eval('.ons-modal', (node) => node.classList.contains('ons-u-db')); - await setTimeout(50); + await setTimeout(100); expect(modalIsVisible).toBe(false); });