mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-10 10:59:35 -04:00
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.
This commit is contained in:
@@ -5,11 +5,12 @@ function getRadios (fields, name) {
|
||||
|
||||
return fields.map((field, idx) => {
|
||||
const count = idx + 1;
|
||||
const id = field.id || `${name}-${count}`;
|
||||
|
||||
return `
|
||||
<div class="govuk-radios__item">
|
||||
<input class="govuk-radios__input" id="${name}-1" name="${name}" type="radio" value="${field.value}" ${field.checked ? 'checked' : ''}>
|
||||
<label class="govuk-label govuk-radios__label" for="${name}-1">
|
||||
<input class="govuk-radios__input" id="${id}" name="${name}" type="radio" value="${field.value}" ${field.checked ? 'checked' : ''}>
|
||||
<label class="govuk-label govuk-radios__label" for="${id}">
|
||||
${field.label}
|
||||
</label>
|
||||
</div>`;
|
||||
@@ -20,10 +21,12 @@ function getRadioGroup (data) {
|
||||
let radioGroup = document.createElement('div');
|
||||
|
||||
radioGroup.classList.add('govuk-form-group');
|
||||
data.cssClasses.forEach(cssClass => radioGroup.classList.add(cssClass));
|
||||
if ('cssClasses' in data) {
|
||||
data.cssClasses.forEach(cssClass => radioGroup.classList.add(cssClass));
|
||||
}
|
||||
radioGroup.innerHTML = `
|
||||
<fieldset class="govuk-fieldset" id="${data.name}">
|
||||
<legend class="govuk-fieldset__legend">
|
||||
<legend class="govuk-fieldset__legend${data.hideLegend ? " govuk-visually-hidden" : ""}">
|
||||
${data.label}
|
||||
</legend>
|
||||
<div class="govuk-radios">
|
||||
|
||||
Reference in New Issue
Block a user