From 88e85ea01c16e9e31d0e508325d3d5202381a4e2 Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Tue, 15 Dec 2020 12:07:28 +0000 Subject: [PATCH] Update liveSearch JS tests and test helpers Includes a change to make these tests use the getRadioGroup helper to reduce duplication across the tests. This also makes a few changes to the helper so it can produce the HTML required. --- tests/javascripts/liveSearch.test.js | 87 +++++++++++------------ tests/javascripts/support/helpers/html.js | 11 +-- 2 files changed, 47 insertions(+), 51 deletions(-) diff --git a/tests/javascripts/liveSearch.test.js b/tests/javascripts/liveSearch.test.js index ba7422b92..59ff768bd 100644 --- a/tests/javascripts/liveSearch.test.js +++ b/tests/javascripts/liveSearch.test.js @@ -29,51 +29,42 @@ describe('Live search', () => { searchLabelText = "Search branding styles by name"; - function getRadiosHTML (departments) { - - let result = ''; - - departments.forEach((department, idx) => result += ` -
- - -
- `); - - return result; - - }; - beforeEach(() => { - const departments = [ - { - 'label': 'NHS', - 'id': 'nhs', - 'name': 'branding' - }, - { - 'label': 'Department for Work and Pensions', - 'id': 'dwp', - 'name': 'branding' - }, - { - 'label': 'Department for Education', - 'id': 'dfe', - 'name': 'branding' - }, - { - 'label': 'Home Office', - 'id': 'home-office', - 'name': 'branding' - } - ]; + const departmentData = { + name: 'departments', + hideLegend: true, + fields: [ + { + 'label': 'NHS', + 'id': 'nhs', + 'name': 'branding', + 'value': 'nhs' + }, + { + 'label': 'Department for Work and Pensions', + 'id': 'dwp', + 'name': 'branding', + 'value': 'dwp' + }, + { + 'label': 'Department for Education', + 'id': 'dfe', + 'name': 'branding', + 'value': 'dfe' + }, + { + 'label': 'Home Office', + 'id': 'home-office', + 'name': 'branding', + 'value': 'home-office' + } + ] + }; // set up DOM document.body.innerHTML = ` -