diff --git a/src/client/assets/javascripts/application.js b/src/client/assets/javascripts/application.js index 32e4b77..b5e55d2 100644 --- a/src/client/assets/javascripts/application.js +++ b/src/client/assets/javascripts/application.js @@ -12,4 +12,57 @@ import './plant-search.js' import './pest-search.js' import './country-search.js' +function compareNames(a, b) { + if (a.text < b.text) { + return -1 + } + if (a.text > b.text) { + return 1 + } + return 0 +} + +export function timerFunction(query, finalArray, populateResults) { + return setTimeout(async () => { + try { + if (query.length > 2) { + return populateResults(finalArray.sort(compareNames)) + } + } catch (error) { + // TypeError: Failed to fetch + // console.log('Error fetching suggestions:', error) + } + }, 1000) +} + +export function inputValueTemplate(asd) { + return asd?.text +} + +export function suggestionTemplate(asd, regexValue) { + const inputElementCustom = + document.getElementsByClassName('custom-hint-class') + inputElementCustom[0]?.setAttribute('aria-label', 'autocomplete__hint') + inputElementCustom[0]?.setAttribute('id', 'autocomplete__hint') + let template + if (regexValue?.length > 0) { + template = + '
' + + asd?.text?.replace( + new RegExp(regexValue, 'gi'), + (match) => `${match}` + ) + + '
' + } else { + template = + '
' + + asd?.replace( + new RegExp(asd, 'gi'), + (match) => `${match}` + ) + + '
' + } + return template +} + initAll() diff --git a/src/client/assets/javascripts/country-search.js b/src/client/assets/javascripts/country-search.js index 40b90ff..b2242b6 100644 --- a/src/client/assets/javascripts/country-search.js +++ b/src/client/assets/javascripts/country-search.js @@ -1,4 +1,10 @@ import accessibleAutocomplete from './accessible-autocomplete.min.js' +import { + timerFunction, + inputValueTemplate, + suggestionTemplate +} from './application.js' + let finalArray = [] let timer @@ -10,28 +16,10 @@ async function fetchSuggestions(query, populateResults) { defaultcountryCode?.setAttribute('value', null) const apiUrl = '/search/countries?searchQuery=' + query await clearTimeout(timer) - timer = await setTimeout(async () => { - try { - if (query.length > 2) { - const response = await fetch(apiUrl) - const responseJSON = await response.json() - await renderSuggestions(responseJSON, query) - function compareNames(a, b) { - if (a.text < b.text) { - return -1 - } - if (a.text > b.text) { - return 1 - } - return 0 - } - populateResults(finalArray.sort(compareNames)) - } - } catch (error) { - // TypeError: Failed to fetch - // console.log('Error fetching suggestions:', error) - } - }, 1000) + const response = await fetch(apiUrl) + const responseJSON = await response.json() + await renderSuggestions(responseJSON, query) + timer = timerFunction(query, finalArray, populateResults) } let regexValue, suggestions async function renderSuggestions(json, query) { @@ -89,31 +77,15 @@ if (document.querySelector('#my-autocomplete-country-container')) { ?.childNodes[0]?.value, minLength: 3, autoselect: true, + hint: true, + hintClasses: 'custom-hint-class', showNoOptionsFound: false, templates: { inputValue: function (asd) { - return asd?.text + return inputValueTemplate(asd) }, suggestion: function (asd) { - if (regexValue?.length > 0) { - return ( - '
' + - asd?.text?.replace( - new RegExp(regexValue, 'gi'), - (match) => `${match}` - ) + - '
' - ) - } else { - return ( - '
' + - asd?.replace( - new RegExp(asd, 'gi'), - (match) => `${match}` - ) + - '
' - ) - } + return suggestionTemplate(asd, regexValue) } }, onConfirm diff --git a/src/client/assets/javascripts/pest-search.js b/src/client/assets/javascripts/pest-search.js index fb7ebaf..93ae44e 100644 --- a/src/client/assets/javascripts/pest-search.js +++ b/src/client/assets/javascripts/pest-search.js @@ -1,4 +1,9 @@ import accessibleAutocomplete from './accessible-autocomplete.min.js' +import { + timerFunction, + inputValueTemplate, + suggestionTemplate +} from './application.js' let finalArray = [] let timer @@ -10,28 +15,10 @@ async function fetchSuggestions(query, populateResults) { defaultcslref?.setAttribute('value', null) const apiUrl = '/search/pests?searchQuery=' + query await clearTimeout(timer) - timer = await setTimeout(async () => { - try { - if (query.length > 2) { - const response = await fetch(apiUrl) - const responseJSON = await response.json() - await renderSuggestions(responseJSON, query) - function compareNames(a, b) { - if (a.text.trim() < b.text.trim()) { - return -1 - } - if (a.text.trim() > b.text.trim()) { - return 1 - } - return 0 - } - populateResults(finalArray.sort(compareNames)) - } - } catch (error) { - // TypeError: Failed to fetch - // console.log('Error fetching suggestions:', error) - } - }, 1000) + const response = await fetch(apiUrl) + const responseJSON = await response.json() + await renderSuggestions(responseJSON, query) + timer = timerFunction(query, finalArray, populateResults) } let regexValue async function renderSuggestions(json, query) { @@ -308,7 +295,6 @@ const onConfirm = (e) => { .appendChild(inputCslref) } } -const cslRefElement = document.getElementById('#cslRef') if (document.querySelector('#my-autocomplete-pest-container')) { accessibleAutocomplete({ element: document.querySelector('#my-autocomplete-pest-container'), @@ -319,32 +305,15 @@ if (document.querySelector('#my-autocomplete-pest-container')) { ?.childNodes[0]?.value, minLength: 3, autoselect: true, + hint: true, + hintClasses: 'custom-hint-class', showNoOptionsFound: false, templates: { inputValue: function (asd) { - cslRefElement?.setAttribute('value', asd?.cslRef) - return asd?.text + return inputValueTemplate(asd) }, suggestion: function (asd) { - if (regexValue?.length > 0) { - return ( - '
' + - asd?.text?.replace( - new RegExp(regexValue, 'gi'), - (match) => `${match}` - ) + - '
' - ) - } else { - return ( - '
' + - asd?.replace( - new RegExp(asd, 'gi'), - (match) => `${match}` - ) + - '
' - ) - } + return suggestionTemplate(asd, regexValue) } }, onConfirm diff --git a/src/client/assets/javascripts/plant-search.js b/src/client/assets/javascripts/plant-search.js index 9de491c..5fa984d 100644 --- a/src/client/assets/javascripts/plant-search.js +++ b/src/client/assets/javascripts/plant-search.js @@ -1,4 +1,10 @@ import accessibleAutocomplete from './accessible-autocomplete.min.js' +import { + timerFunction, + inputValueTemplate, + suggestionTemplate +} from './application.js' + let finalArray = [] let timer @@ -9,28 +15,10 @@ async function fetchSuggestions(query, populateResults) { defaulthostref?.setAttribute('value', '') const apiUrl = '/search/plants?searchQuery=' + query await clearTimeout(timer) - timer = await setTimeout(async () => { - try { - if (query.length > 2) { - const response = await fetch(apiUrl) - const responseJSON = await response.json() - await renderSuggestions(responseJSON, query) - function compareNames(a, b) { - if (a.text < b.text) { - return -1 - } - if (a.text > b.text) { - return 1 - } - return 0 - } - populateResults(finalArray.sort(compareNames)) - } - } catch (error) { - // TypeError: Failed to fetch - // console.log('Error fetching suggestions:', error) - } - }, 1000) + const response = await fetch(apiUrl) + const responseJSON = await response.json() + await renderSuggestions(responseJSON, query) + timer = timerFunction(query, finalArray, populateResults) } let regexValue async function renderSuggestions(json, query) { @@ -313,8 +301,6 @@ const onConfirm = (e) => { document.querySelector('#my-autocomplete-container').appendChild(inputHref) } } -const hostRefElement = document.getElementById('#hostRef') - if (document.querySelector('#my-autocomplete-container')) { accessibleAutocomplete({ element: document.querySelector('#my-autocomplete-container'), @@ -325,32 +311,15 @@ if (document.querySelector('#my-autocomplete-container')) { ?.childNodes[0]?.value, minLength: 3, autoselect: true, + hint: true, + hintClasses: 'custom-hint-class', showNoOptionsFound: false, templates: { inputValue: function (asd) { - hostRefElement?.setAttribute('value', asd?.hostRef) - return asd?.text + return inputValueTemplate(asd) }, suggestion: function (asd) { - if (regexValue?.length > 0) { - return ( - '
' + - asd?.text?.replace( - new RegExp(regexValue, 'gi'), - (match) => `${match}` - ) + - '
' - ) - } else { - return ( - '
' + - asd?.replace( - new RegExp(asd, 'gi'), - (match) => `${match}` - ) + - '
' - ) - } + return suggestionTemplate(asd, regexValue) } }, onConfirm diff --git a/src/server/check-plant-health-information-and-import-rules/problem-with-service/controller.js b/src/server/check-plant-health-information-and-import-rules/problem-with-service/controller.js index 633cc9a..0dd7781 100644 --- a/src/server/check-plant-health-information-and-import-rules/problem-with-service/controller.js +++ b/src/server/check-plant-health-information-and-import-rules/problem-with-service/controller.js @@ -21,7 +21,7 @@ const problemWithServiceController = { const statusCode = parseInt(request.query.statusCode) const errorMessage = statusCodeMessage(statusCode) - let pageTitle = 'Error: ' + let pageTitle if ( statusCode === 500 || statusCode === 502 || @@ -29,16 +29,13 @@ const problemWithServiceController = { statusCode === 504 ) { pageTitle = - pageTitle + 'Sorry, there is a problem with the service — Check plant health information and import rules — GOV.UK' } else { if (statusCode === 404) { pageTitle = - pageTitle + 'Page not found — Check plant health information and import rules — GOV.UK' } else { - pageTitle = - pageTitle + 'Check plant health information and import rules — GOV.UK' + pageTitle = 'Check plant health information and import rules — GOV.UK' } } if (statusCode !== undefined) { diff --git a/src/server/check-plant-health-information-and-import-rules/problem-with-service/controller.test.js b/src/server/check-plant-health-information-and-import-rules/problem-with-service/controller.test.js index a43f5b3..957facb 100644 --- a/src/server/check-plant-health-information-and-import-rules/problem-with-service/controller.test.js +++ b/src/server/check-plant-health-information-and-import-rules/problem-with-service/controller.test.js @@ -2,6 +2,11 @@ import { problemWithServiceController } from '~/src/server/check-plant-health-in describe('problemWithServiceController', () => { let request, h + const technicalError = + 'Sorry, there is a problem with the service — Check plant health information and import rules — GOV.UK' + const pageNotFoundError = + 'Page not found — Check plant health information and import rules — GOV.UK' + const pageTitle = 'Check plant health information and import rules — GOV.UK' beforeEach(() => { request = { @@ -28,8 +33,7 @@ describe('problemWithServiceController', () => { expect.objectContaining({ heading: 404, message: 'Page not found', - pageTitle: - 'Error: Page not found — Check plant health information and import rules — GOV.UK', + pageTitle: pageNotFoundError, statusCode: 404 }) ) @@ -45,8 +49,7 @@ describe('problemWithServiceController', () => { expect.objectContaining({ heading: 403, message: 'Forbidden', - pageTitle: - 'Error: Check plant health information and import rules — GOV.UK', + pageTitle, statusCode: 403 }) ) @@ -62,8 +65,7 @@ describe('problemWithServiceController', () => { expect.objectContaining({ heading: 401, message: 'Unauthorized', - pageTitle: - 'Error: Check plant health information and import rules — GOV.UK', + pageTitle, statusCode: 401 }) ) @@ -79,8 +81,7 @@ describe('problemWithServiceController', () => { expect.objectContaining({ heading: 400, message: 'Bad Request', - pageTitle: - 'Error: Check plant health information and import rules — GOV.UK', + pageTitle, statusCode: 400 }) ) @@ -96,8 +97,7 @@ describe('problemWithServiceController', () => { expect.objectContaining({ heading: 500, message: 'Something went wrong', - pageTitle: - 'Error: Sorry, there is a problem with the service — Check plant health information and import rules — GOV.UK', + pageTitle: technicalError, statusCode: 500 }) ) @@ -113,8 +113,7 @@ describe('problemWithServiceController', () => { expect.objectContaining({ heading: 502, message: 'Something went wrong', - pageTitle: - 'Error: Sorry, there is a problem with the service — Check plant health information and import rules — GOV.UK', + pageTitle: technicalError, statusCode: 502 }) ) @@ -130,8 +129,7 @@ describe('problemWithServiceController', () => { expect.objectContaining({ heading: 503, message: 'Something went wrong', - pageTitle: - 'Error: Sorry, there is a problem with the service — Check plant health information and import rules — GOV.UK', + pageTitle: technicalError, statusCode: 503 }) ) @@ -147,8 +145,7 @@ describe('problemWithServiceController', () => { expect.objectContaining({ heading: 504, message: 'Something went wrong', - pageTitle: - 'Error: Sorry, there is a problem with the service — Check plant health information and import rules — GOV.UK', + pageTitle: technicalError, statusCode: 504 }) ) diff --git a/src/server/locales/plant-details/en_cy.json b/src/server/locales/plant-details/en_cy.json index 13e656b..505d89b 100644 --- a/src/server/locales/plant-details/en_cy.json +++ b/src/server/locales/plant-details/en_cy.json @@ -15,6 +15,7 @@ "prohibitedContentText3": "Er gwaethaf cyfyngiadau mewnforio, efallai y byddwch yn gallu", "prohibitedContentText4": "o unrhyw wlad, talaith neu diriogaeth", "prohibitedContentText5": "Rhaid i chi gymhwyso'r wybodaeth wahardd cyn dilyn y rheolau mewnforio", + "pestINNSContent": "Ystyrir bod y plâu a'r clefydau canlynol yn risg i amaethyddiaeth, garddwriaeth, bywyd gwyllt neu goedwigoedd Prydain Fawr. Gall llwythi gael eu dinistrio o'u herwydd. Hyd yn oed os oes gennych drwydded o dan Orchymyn Rhywogaethau Goresgynnol Estron 2019, mae'n bosibl y cânt eu dinistrio os oes angen oherwydd y risg o glefydau.", "pestNewContent1": "Ystyrir bod y plâu a'r clefydau canlynol yn risg i amaethyddiaeth, garddwriaeth, bywyd gwyllt neu goedwigoedd Prydain Fawr. Os canfyddir un o'r plâu neu'r clefydau hyn yn ystod arolygiadau iechyd planhigion, bydd camau'n cael eu cymryd. Gallai hyn arwain at oedi neu ddinistrio llwythi.", "pestNewContent2": "Ystyrir bod y plâu a'r clefydau canlynol yn risg i amaethyddiaeth, garddwriaeth, bywyd gwyllt neu goedwigoedd Prydain Fawr. Gall llwythi gael eu dinistrio o'u herwydd", "RNQPPestHeader": "Plâu a chlefydau eraill", diff --git a/src/server/locales/plant-details/en_gb.json b/src/server/locales/plant-details/en_gb.json index 7d8ceca..7287e96 100644 --- a/src/server/locales/plant-details/en_gb.json +++ b/src/server/locales/plant-details/en_gb.json @@ -27,6 +27,7 @@ "pestContentHundredPercentText41": "Consignments may be destroyed because of them.", "pestContentHundredPercentText42": "These pests and diseases are considered a risk to Great Britain's agriculture, horticulture, wildlife or forests. If one of these pests or diseases is found during plant health inspections, action will be taken. This could result in consignments being delayed or destroyed.", "pestContentHundredPercentText5": "You must", + "pestINNSContent": "The following pests and diseases are considered a risk to Great Britain's agriculture, horticulture, wildlife or forests. Consignments may be destroyed because of them. Even if you have a permit under the Invasive Alien Species Order 2019, they may be destroyed if needed due to disease risk.", "pestNewContent1": "The following pests and diseases are considered a risk to Great Britain's agriculture, horticulture, wildlife or forests. If one of these pests or diseases is found during plant health inspections, action will be taken. This could result in consignments being delayed or destroyed.", "pestNewContent2": "The following pests and diseases are considered a risk to Great Britain's agriculture, horticulture, wildlife or forests. Consignments may be destroyed because of them.", "RNQPPestHeader": "Other pests and diseases", diff --git a/src/server/plant-health/format/index.njk b/src/server/plant-health/format/index.njk index 53041d7..1c38f12 100644 --- a/src/server/plant-health/format/index.njk +++ b/src/server/plant-health/format/index.njk @@ -31,11 +31,11 @@ {% endif %}
- - - - - + + + + + {{ govukRadios({ name: "format", id: "format", diff --git a/src/server/plant-health/plant-details/index.njk b/src/server/plant-health/plant-details/index.njk index 86d87d7..bdb0e6a 100644 --- a/src/server/plant-health/plant-details/index.njk +++ b/src/server/plant-health/plant-details/index.njk @@ -115,8 +115,10 @@

{{mainContent.pestContentText1}} {{countrySearchQuery.value | capitalize}} {{mainContent.pestContentText2}}.

{% else %}

- {% if (annexSixRule) and (annexSixRule === 'INNS' or outcome.toLowerCase() === 'prohibited') %} + {% if (annexSixRule) and (outcome.toLowerCase() === 'prohibited') %} {{mainContent.pestNewContent2}} + {%elif (annexSixRule) and (annexSixRule === 'INNS') %} + {{mainContent.pestINNSContent}} {% else %} {{mainContent.pestNewContent1}} {% endif %}