Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional qualitative (add the option to disable text responses) #42

Merged
merged 6 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import userFeedbackForm from '@nhsuk/user-feedback-form';
userFeedbackForm({
cssSelector: "#my-div-id",
formEndpoint: "https://example.com/my-api-endpoint/",
enableTextResponse: false,
});
```

Expand All @@ -37,12 +38,14 @@ The latest javascript file can be found in github releases https://github.com/nh
...

<!-- where you want the form to appear -->
<div id="nhsuk-user-feedback-form" data-form-endpoint="https://example.com/endpoint/"></div>
<div id="nhsuk-user-feedback-form" data-form-endpoint="https://example.com/endpoint/" data-enable-text-response="false"></div>
the-nathan-smith marked this conversation as resolved.
Show resolved Hide resolved
```

#### Attributes

`data-form-endpoint` - (required) An HTTP data store endpoint to POST data to. Include the trailing slash
`data-enable-text-response` - (optional) If "true", text responses will be enabled. If "false" or left out,
text responses will not be disabled.

## API

Expand Down
12 changes: 12 additions & 0 deletions local.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "node",
"AzureWebJobsStorage": "{AzureWebJobsStorage}",
"MONGO_CONNECTION_STRING": "mongodb://localhost"
},
"Host": {
"LocalHttpPort": 7071,
"CORS": "*"
}
}
the-nathan-smith marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 18 additions & 2 deletions src/confirmation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@ import Screen from '../screen';
import html from './template.html';

export default class ConfirmationScreen extends Screen {
getEnableTextResponse() {
return this.app.enableTextResponse;
}

render() {
this.updateHtml(html);
const textResponseLabel = '<p>We do not check feedback every day and cannot respond to comments.</p>';
the-nathan-smith marked this conversation as resolved.
Show resolved Hide resolved
const blankLabel = '';

let label;

/* If data-enable-text-response attribute is "false" show a blank label */
if (this.getEnableTextResponse() === false) {
label = blankLabel;
} else {
label = textResponseLabel;
}

const optionalHtml = html.replace('{{ label }}', label);

const node = this.updateHtml(html);
const node = this.updateHtml(optionalHtml);
const header = node.querySelector('.nhsuk-user-feedback-form-header');
header.setAttribute('tabIndex', '-1');
header.focus();
Expand Down
2 changes: 1 addition & 1 deletion src/confirmation/template.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="nhsuk-panel nhsuk-u-reading-width">
<h2 class="nhsuk-heading-s nhsuk-user-feedback-form-header">Thank you for your feedback.</h2>
<p>We do not check feedback every day and cannot respond to comments.</p>
{{ label }}
the-nathan-smith marked this conversation as resolved.
Show resolved Hide resolved
<p>Find out how to <a href="/contact-us/">contact the NHS</a> if you need to speak to someone.</p>
</div>
25 changes: 23 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ import PostData from './post-data';

import './nhsuk-feedback-form.css';

function getEnableTextResponse(container) {
if (container.getAttribute('data-enable-text-response') === 'true') {
the-nathan-smith marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
return false;
}

/**
* Get settings from data attributes on the container div
* @returns {Object} settings
*/
const getSettingsFromContainer = (container) => ({
enableTextResponse: getEnableTextResponse(container),
formEndpoint: container.getAttribute('data-form-endpoint'),
});

Expand All @@ -34,20 +42,32 @@ class App {

// The initial question's yes/no response. true=yes, false=no, null=unanswered.
this.isSatisfiedResponse = null;

this.enableTextResponse = this.settings.enableTextResponse;
}

onYes() {
this.isSatisfiedResponse = true;
this.postData.postYes();
new TextCommentsScreen(this).render();

if (this.enableTextResponse === false) {
new ConfirmationScreen(this).render();
} else {
new TextCommentsScreen(this).render();
}

onFeedbackEvent(this.container, true);
}

onNo() {
this.isSatisfiedResponse = false;
this.postData.postNo();
new TextCommentsScreen(this).render();

if (this.enableTextResponse === false) {
new ConfirmationScreen(this).render();
} else {
new TextCommentsScreen(this).render();
}

onFeedbackEvent(this.container, false);
}
Expand All @@ -67,6 +87,7 @@ class App {
* @param {Object} settings
* @param {string} settings.formEndpoint - API endpoint to post data to
* @param {string} settings.cssSelector - CSS selector to get the container div
* @param {boolean} settings.enableTextResponse - Disables text responses from the form
*/
export default function (settings = {}) {
const settingsWithDefaults = {
Expand Down
29 changes: 29 additions & 0 deletions tests/example/disabled-text-response.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">

<link rel="shortcut icon" href="">

<title>User feedback form test page</title>

<link rel="stylesheet" href="../../node_modules/nhsuk-frontend/dist/nhsuk.css">

<script src="../../dist/user-feedback-form.js" type="text/javascript" defer></script>
</head>
<body>
<div class="nhsuk-width-container">
<main class="nhsuk-main-wrapper">
<h1>User feedback form:</h1>
<div id="nhsuk-user-feedback-form" data-form-endpoint="http://localhost:8080/my-endpoint/" data-enable-text-response="false"></div>

<!--
If you have the user-feedback-store running locally and want to test it, the endpoint setting should probably be this:
<div id="nhsuk-user-feedback-form" data-form-endpoint="http://localhost:7071/"></div>
-->
</main>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion tests/example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="nhsuk-width-container">
<main class="nhsuk-main-wrapper">
<h1>User feedback form:</h1>
<div id="nhsuk-user-feedback-form" data-form-endpoint="http://localhost:8080/my-endpoint/"></div>
<div id="nhsuk-user-feedback-form" data-form-endpoint="http://localhost:8080/my-endpoint/" data-enable-text-response="true"></div>

<!--
If you have the user-feedback-store running locally and want to test it, the endpoint setting should probably be this:
Expand Down
25 changes: 25 additions & 0 deletions tests/integration/disable-text-response.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* global page expect */

beforeEach(async () => {
await page.goto('http://localhost:8080/tests/example/disabled-text-response.html');
await page.click('.nhsuk-user-feedback-form--yes');
});

describe('Form is added to page', () => {
it('should display on page', async () => {
const banner = await page.$('.nhsuk-user-feedback-form');
expect(banner).not.toBe(null);
});
});

describe('Skip text response', () => {
it('should load the confirmation page straight away', async () => {
const title = await page.$eval('h2', (element) => element.innerText);
expect(title).toBe('Thank you for your feedback.');
});

it('should not have feedback message', async () => {
const message = await page.$eval('p', (element) => element.innerText);
expect(message).not.toBe('We do not check feedback every day and cannot respond to comments.');
});
});