Skip to content

Commit

Permalink
PLATUI-3359 remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyFothergill committed Dec 12, 2024
1 parent 0dab610 commit 55c3b10
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 64 deletions.
23 changes: 7 additions & 16 deletions lib/browser-tests/puppeteer-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export function withHmrcStylesAndScripts(body) {
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<link rel="stylesheet" href="/assets/hmrc-frontend-${version}.min.css">
<link rel="stylesheet" href="/assets/accessible-autocomplete-${version}.css">
${preloadGovukFonts}
</head>
<body class="govuk-template__body">
Expand All @@ -50,27 +49,19 @@ export function withHmrcStylesAndScripts(body) {
</script>
${body}
<script src="/assets/hmrc-frontend-${version}.min.js" type="module"></script>
<script src="/assets/accessible-autocomplete-${version}.js" type="module"></script>
</body>
</html>
`;
}

export async function render(page, body, options) {
await page.setRequestInterception(true);
const interceptPageRender = (req) => {
if (req.url() === 'http://localhost:3000/') {
return req.respond({ contentType: 'text/html', body });
}
return Promise.resolve().then(() => req.continue()).catch(() => {});
};
page.on('request', interceptPageRender);
try {
await page.goto('http://localhost:3000/', options); // if ever flaky, waitUntil networkidle0 (js loaded)
await page.bringToFront();
} finally {
page.off('request', interceptPageRender);
await page.setRequestInterception(false);
}
page.once('request', (req) => {
req.respond({ contentType: 'text/html', body });
page.setRequestInterception(false);
});
await page.goto('http://localhost:3000/', options); // if ever flaky, waitUntil networkidle0 (js loaded)
await page.evaluateHandle('document.fonts.ready');
await page.bringToFront();
return page;
}
89 changes: 41 additions & 48 deletions src/components/timeout-dialog/timeout-dialog.browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('/components/timeout-dialog', () => {
`);
await clockTickSeconds(page, 900);
await page.waitForNavigation({ timeout: 500 });
expect(page.url()).toMatch('/timeout-reached');
await expect(page.url()).toMatch('/timeout-reached');
});

it('should not sign you out when the countdown runs out if you chose to stay signed in', async () => {
Expand All @@ -91,7 +91,7 @@ describe('/components/timeout-dialog', () => {
await expect(page).toClick('button', { text: 'Stay signed in' });
await clockTickSeconds(page, 1);
await delay(500);
expect(page.url()).not.toMatch('/timeout-reached');
await expect(page.url()).not.toMatch('/timeout-reached');
await expect(page).not.toShowTimeoutDialog();
});

Expand Down Expand Up @@ -122,7 +122,7 @@ describe('/components/timeout-dialog', () => {
await expect(page).toClick('button', { text: 'Stay signed in' });
await clockTickSeconds(page, 900);
await page.waitForNavigation({ timeout: 500 });
expect(page.url()).toMatch('/timeout-reached');
await expect(page.url()).toMatch('/timeout-reached');
});

it('should let you extend your session repeatedly', async () => {
Expand All @@ -141,7 +141,7 @@ describe('/components/timeout-dialog', () => {
await expect(page.url()).not.toMatch('/timeout-reached');
await clockTickSeconds(page, 900);
await page.waitForNavigation({ timeout: 500 });
expect(page.url()).toMatch('/timeout-reached');
await expect(page.url()).toMatch('/timeout-reached');
});

it('should let you sign out early', async () => {
Expand All @@ -154,7 +154,7 @@ describe('/components/timeout-dialog', () => {
await clockTickSeconds(page, 800);
await expect(page).toClick('a', { text: 'Sign out' });
await page.waitForNavigation({ timeout: 500 });
expect(page.url()).toMatch('/timeout-reached');
await expect(page.url()).toMatch('/timeout-reached');
});

it('should let you specify a separate timeout url', async () => {
Expand All @@ -178,7 +178,7 @@ describe('/components/timeout-dialog', () => {
await clockTickSeconds(page, 800);
await expect(page).toClick('a', { text: 'Sign out' });
await page.waitForNavigation({ timeout: 500 });
expect(page.url()).toMatch('/signed-out-early');
await expect(page.url()).toMatch('/signed-out-early');
});

// TODO at the moment it doesn't, should we change test or implementation?
Expand All @@ -193,22 +193,19 @@ describe('/components/timeout-dialog', () => {
`);
await clockTickSeconds(page, 899);
await page.setRequestInterception(true);
try {
page.once('request', (req) => {
setTimeout(() => req.respond({
contentType: 'text/plain',
body: 'simulate slow response to signing out',
}), 2000);
});
await page.evaluate(() => {
document.getElementById('hmrc-timeout-sign-out-link').click();
window.clock.tick(1000); // to reach timeout while sign out page is still loading
});
await page.waitForNavigation({ timeout: 500 });
expect(page.url()).toMatch('/signed-out-early');
} finally {
await page.setRequestInterception(false);
}
await page.once('request', (req) => {
setTimeout(() => req.respond({
contentType: 'text/plain',
body: 'simulate slow response to signing out',
}), 2000);
page.setRequestInterception(false);
});
await page.evaluate(() => {
document.getElementById('hmrc-timeout-sign-out-link').click();
window.clock.tick(1000); // to reach timeout while sign out page is still loading
});
await page.waitForNavigation({ timeout: 500 });
await expect(page.url()).toMatch('/signed-out-early');
});

function takeTextContentEachSecondForAMinute(page, selector) {
Expand Down Expand Up @@ -258,7 +255,7 @@ describe('/components/timeout-dialog', () => {

await clockTickSeconds(page, 1);
await page.waitForNavigation({ timeout: 500 });
expect(page.url()).toMatch('/timeout-reached');
await expect(page.url()).toMatch('/timeout-reached');
});

function nineteenTimes(value) { return Array.from({ length: 19 }, () => value); }
Expand Down Expand Up @@ -295,7 +292,7 @@ describe('/components/timeout-dialog', () => {

await clockTickSeconds(page, 1);
await page.waitForNavigation({ timeout: 500 });
expect(page.url()).toMatch('/timeout-reached');
await expect(page.url()).toMatch('/timeout-reached');
});
});

Expand All @@ -309,31 +306,28 @@ describe('/components/timeout-dialog', () => {
let completeSlowTimeoutRequest;
const slowTimeout = new Promise((resolve) => { completeSlowTimeoutRequest = resolve; });
await page.setRequestInterception(true);
try {
page.once('request', (req) => {
slowTimeout.then(() => {
req.respond({
contentType: 'text/plain',
body: 'timeout page reached',
});
page.once('request', (req) => {
slowTimeout.then(() => {
req.respond({
contentType: 'text/plain',
body: 'timeout page reached',
});
page.setRequestInterception(false);
});
const [visibleMessage, audibleMessage] = await page.evaluate(() => {
window.clock.tick(10000); // bring up warning
window.clock.tick(30000); // overrun timeout by 20s, the redirect will hang until resolved
return [
document.querySelector('.hmrc-timeout-dialog__message').textContent,
document.querySelector('#hmrc-timeout-message').textContent,
];
});
expect(visibleMessage).toBe('For your security, we will sign you out in 0 seconds.');
expect(audibleMessage).toBe('For your security, we will sign you out in 20 seconds.');
completeSlowTimeoutRequest();
await page.waitForNavigation({ timeout: 500 });
await expect(page).toMatchTextContent('timeout page reached');
} finally {
await page.setRequestInterception(false);
}
});
const [visibleMessage, audibleMessage] = await page.evaluate(() => {
window.clock.tick(10000); // bring up warning
window.clock.tick(30000); // overrun timeout by 20s, the redirect will hang until resolved
return [
document.querySelector('.hmrc-timeout-dialog__message').textContent,
document.querySelector('#hmrc-timeout-message').textContent,
];
});
expect(visibleMessage).toBe('For your security, we will sign you out in 0 seconds.');
expect(audibleMessage).toBe('For your security, we will sign you out in 20 seconds.');
completeSlowTimeoutRequest();
await page.waitForNavigation({ timeout: 500 });
await expect(page).toMatchTextContent('timeout page reached');
});

it('should display the time remaining as a whole number of seconds', async () => {
Expand Down Expand Up @@ -410,6 +404,5 @@ describe('/components/timeout-dialog', () => {
await expect(background).toShowTimeoutDialog();
expect(await visualCountdownFrom(background))
.toBe('For your security, we will sign you out in 10 seconds.');
await session.close();
});
});

0 comments on commit 55c3b10

Please sign in to comment.