Skip to content

Commit

Permalink
PLATUI-2588: Adding in hideSignOutButton functionality (#324)
Browse files Browse the repository at this point in the history
PLATUI-2588: Adding in hideSignOutButton functionality for non-HMRC services
  • Loading branch information
JoPintoPaul committed Nov 1, 2023
1 parent 7263780 commit f90f58d
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [5.52.0] - 2023-11-01

### Changed

- Modify the timeout dialog to take in an optional parameter to not display a sign out link. This feature was proposed by
DWP Access to Work as cross-Government request: https://github.com/hmrc/hmrc-frontend/issues/316

## [5.51.0] - 2023-10-24

### Changed
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "hmrc-frontend",
"version": "5.51.0",
"version": "5.52.0",
"description": "Design patterns for HMRC frontends",
"scripts": {
"start": "gulp dev",
Expand Down
3 changes: 2 additions & 1 deletion src/components/timeout-dialog/template.njk
Expand Up @@ -12,4 +12,5 @@
data-message-suffix="{{ params.messageSuffix }}"
data-keep-alive-button-text="{{ params.keepAliveButtonText }}"
data-sign-out-button-text="{{ params.signOutButtonText }}"
data-synchronise-tabs="{{ params.synchroniseTabs }}"/>
data-synchronise-tabs="{{ params.synchroniseTabs }}"
data-hide-sign-out-button="{{ params.hideSignOutButton }}"/>
24 changes: 15 additions & 9 deletions src/components/timeout-dialog/timeout-dialog.js
Expand Up @@ -66,6 +66,9 @@ function TimeoutDialog($module, $sessionActivityService) {
synchroniseTabs: validate.boolean(
lookupData('data-synchronise-tabs') || false,
),
hideSignOutButton: validate.boolean(
lookupData('data-hide-sign-out-button') || false,
),
};

// Default timeoutUrl to signOutUrl if not set
Expand Down Expand Up @@ -182,20 +185,23 @@ function TimeoutDialog($module, $sessionActivityService) {
'<button id="hmrc-timeout-keep-signin-btn" class="govuk-button">',
settings.keepAliveButtonText,
);
const $signOutButton = utils.generateDomElementFromStringAndAppendText(
'<a id="hmrc-timeout-sign-out-link" class="govuk-link hmrc-timeout-dialog__link">',
settings.signOutButtonText,
);

$staySignedInButton.addEventListener('click', keepAliveAndClose);
$signOutButton.addEventListener('click', signOut);
$signOutButton.setAttribute('href', settings.signOutUrl);

$element.appendChild($visualMessge);
$element.appendChild($audibleMessage);
$element.appendChild($staySignedInButton);
$staySignedInButton.addEventListener('click', keepAliveAndClose);
$element.appendChild(document.createTextNode(' '));
$element.appendChild(wrapLink($signOutButton));

if (!settings.hideSignOutButton) {
const $signOutButton = utils.generateDomElementFromStringAndAppendText(
'<a id="hmrc-timeout-sign-out-link" class="govuk-link hmrc-timeout-dialog__link">',
settings.signOutButtonText,
);
$signOutButton.addEventListener('click', signOut);
$signOutButton.setAttribute('href', settings.signOutUrl);

$element.appendChild(wrapLink($signOutButton));
}

const dialogControl = dialog.displayDialog($element);

Expand Down
35 changes: 32 additions & 3 deletions src/components/timeout-dialog/timeout-dialog.test.js
Expand Up @@ -191,14 +191,14 @@ describe('/components/timeout-dialog', () => {
expect(testScope.latestDialog$element.querySelector('button#hmrc-timeout-keep-signin-btn.govuk-button').parentNode).not.toBe(testScope.latestDialog$element.querySelector('#hmrc-timeout-sign-out-link').parentNode);
});

it('should redirect to signout url when signout is clicked', () => {
it('should redirect to sign out url when sign out is clicked', () => {
assume(redirectHelper.redirectToUrl).not.toHaveBeenCalled();

clickElem(testScope.latestDialog$element.querySelector('#hmrc-timeout-sign-out-link'));
expect(redirectHelper.redirectToUrl).toHaveBeenCalledWith('/sign-out');
});

it('should use the signout url on the signout link', () => {
it('should use the sign out url on the sign out link', () => {
const $signoutLink = testScope.latestDialog$element.querySelector('a#hmrc-timeout-sign-out-link');
expect($signoutLink.attributes.getNamedItem('href').value).toEqual('/sign-out');
});
Expand Down Expand Up @@ -326,7 +326,7 @@ describe('/components/timeout-dialog', () => {
expect(getElemText(testScope.latestDialog$element.querySelector('a#hmrc-timeout-sign-out-link'))).toEqual('sign OUT');
});

it('should redirect to default signout url when signout is clicked', () => {
it('should redirect to default sign out url when sign out is clicked', () => {
assume(redirectHelper.redirectToUrl).not.toHaveBeenCalled();

expect(testScope.latestDialog$element.querySelector('#hmrc-timeout-sign-out-link')).not.toBeNull();
Expand All @@ -336,6 +336,35 @@ describe('/components/timeout-dialog', () => {
});
});

describe('display the sign out button', () => {
it('should not show sign out button when data-hide-sign-out-button parameter is set', () => {
setupDialog({
'data-title': 'my custom TITLE',
'data-message': 'MY custom message',
'data-message-suffix': 'My message suffix.',
'data-keep-alive-button-text': 'KEEP alive',
'data-hide-sign-out-button': true,
});

pretendSecondsHavePassed(780);

expect(testScope.latestDialog$element.querySelector('a#hmrc-timeout-sign-out-link')).toBeNull();
});

it('should show sign out button by default', () => {
setupDialog({
'data-title': 'my custom TITLE',
'data-message': 'MY custom message',
'data-message-suffix': 'My message suffix.',
'data-keep-alive-button-text': 'KEEP alive',
});

pretendSecondsHavePassed(780);

expect(testScope.latestDialog$element.querySelector('a#hmrc-timeout-sign-out-link')).not.toBeNull();
});
});

describe('Restarting countdown on close', () => {
it('should restart with default settings', () => {
setupDialog({ 'data-message': 'time:' });
Expand Down
9 changes: 9 additions & 0 deletions src/components/timeout-dialog/timeout-dialog.yaml
Expand Up @@ -48,6 +48,8 @@ examples:
keepAliveButtonText: "keepAliveButtonText"
signOutButtonText: "signOutButtonText"
synchroniseTabs: false
hideSignOutButton: false
# hideSignOutButton is experimental, please don't use in HMRC services without testing with your users. See Github issues/316
visualRegressionTests:
backstopScenarioOptions:
delay: 10000
Expand All @@ -58,6 +60,13 @@ examples:
keepAliveUrl: "?abc=def"
signOutUrl: "?ghi=jkl"
synchroniseTabs: true
- name: hide-sign-out-button
data:
timeout: 75
countdown: 74
keepAliveUrl: "?abc=def"
signOutUrl: "?ghi=jkl"
hideSignOutButton: true

visualRegressionTests:
backstopScenarioOptions:
Expand Down

0 comments on commit f90f58d

Please sign in to comment.