Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ describe('EastingNorthingField', () => {
northing: 315469
}

const mockT = jest.fn().mockReturnValue('translated country error')
const mockT = jest.fn().mockReturnValue('translated country')
const mockTranslator = { ...stubTranslator, t: mockT }

const result = collection.validate(getFormData(invalidSingleState))
Expand All @@ -905,12 +905,12 @@ describe('EastingNorthingField', () => {

expect(mockT).toHaveBeenCalledWith(
'components.eastingNorthingField.wrongCountry',
{ country: 'Scotland' }
{ country: 'translated country' }
)
expect(viewErrors).toEqual([
expect.objectContaining({
href: '#myComponent',
text: 'translated country error'
text: 'translated country'
})
])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class EastingNorthingField extends FormComponent {
if (err.context?.country) {
err.text = translator.t(
'components.eastingNorthingField.wrongCountry',
{ country: err.context.country }
{ country: translator.t(`common.${err.context.country}`) }
)
}
})
Expand Down
4 changes: 1 addition & 3 deletions src/server/plugins/engine/components/GeospatialField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ export class GeospatialField extends FormComponent {
'components.geospatialField.validation.wrongCountry',
{
count: Number(err.path[1]) + 1,
country: translator.t(
`common.${(err.context.country as string).toLowerCase()}`
)
country: translator.t(`common.${err.context.country}`)
}
)
}
Expand Down
12 changes: 2 additions & 10 deletions src/server/plugins/engine/components/helpers/geospatial.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
GeospatialFieldOptionsCountryEnum,
type GeospatialFieldComponent,
type GeospatialFieldOptionsCountry
} from '@defra/forms-model'
Expand All @@ -20,13 +19,6 @@ import {
} from '~/src/server/plugins/engine/types.js'
import { countries } from '~/src/server/plugins/map/routes/index.js'

const countriesDesc: Record<GeospatialFieldOptionsCountryEnum, string> = {
[GeospatialFieldOptionsCountryEnum.England]: 'England',
[GeospatialFieldOptionsCountryEnum.NorthernIreland]: 'Northern Ireland',
[GeospatialFieldOptionsCountryEnum.Scotland]: 'Scotland',
[GeospatialFieldOptionsCountryEnum.Wales]: 'Wales'
}

const Joi = JoiBase.extend({
type: 'array',
base: JoiBase.array(),
Expand Down Expand Up @@ -161,7 +153,7 @@ export function getGeospatialSchema(

if (!result) {
return helpers.error('any.custom', {
country: countriesDesc[country as GeospatialFieldOptionsCountryEnum]
country
})
}

Expand Down Expand Up @@ -212,7 +204,7 @@ export function getEastingNorthingCountryValidator(
return helpers.error(
'any.custom',
{
country: countriesDesc[country as GeospatialFieldOptionsCountryEnum]
country
},
{ path: [field.name] }
)
Expand Down
2 changes: 1 addition & 1 deletion src/server/plugins/engine/i18n/translations/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"and": "a",
"england": "Lloegr",
"wales": "Cymru",
"northernIreland": "Gogledd Iwerddon",
"northern-ireland": "Gogledd Iwerddon",
"scotland": "Yr Alban",
"sendFeedback": "Anfon adborth"
},
Expand Down
2 changes: 1 addition & 1 deletion src/server/plugins/engine/i18n/translations/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"and": "and",
"england": "England",
"wales": "Wales",
"northernIreland": "Northern Ireland",
"northern-ireland": "Northern Ireland",
"scotland": "Scotland",
"sendFeedback": "Send feedback"
},
Expand Down
Loading