Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmccar committed Oct 31, 2024
1 parent 0e0b85a commit 07ab732
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/components/address-input/autosuggest.address.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,8 @@ describe('script: address-input', () => {
describe('When the component initializes', () => {
it('checks api status by trying a request', async () => {
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', () => {
Expand Down Expand Up @@ -270,7 +269,7 @@ describe('script: address-input', () => {
});

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 () => {
Expand Down Expand Up @@ -314,7 +313,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);
Expand All @@ -336,7 +335,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 () => {
Expand All @@ -360,7 +359,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 () => {
Expand All @@ -380,7 +379,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);
Expand Down Expand Up @@ -611,7 +610,7 @@ 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);
expect(await apiFaker.getRequestCount('/addresses/eq?input=196%20colle&limit=10&favourwelsh=true')).toBe(1);
});
});

Expand All @@ -629,7 +628,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);
});
});

Expand Down Expand Up @@ -736,9 +735,7 @@ 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(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 () => {
Expand All @@ -747,9 +744,7 @@ describe('script: address-input', () => {
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);
});
});
});

0 comments on commit 07ab732

Please sign in to comment.