From 1ef30e054ee3bc99fb4e30e1ebeff408a4fb7ab5 Mon Sep 17 00:00:00 2001 From: Romaric Date: Mon, 3 Oct 2022 16:21:07 +0100 Subject: [PATCH] Revert translation string for when limit is met Updates the testing to use the JavaScript configuration --- .../components/character-count/character-count.mjs | 4 ++-- .../character-count/character-count.unit.test.mjs | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/govuk/components/character-count/character-count.mjs b/src/govuk/components/character-count/character-count.mjs index cb22c1e7a9..92a5ed44ff 100644 --- a/src/govuk/components/character-count/character-count.mjs +++ b/src/govuk/components/character-count/character-count.mjs @@ -57,13 +57,13 @@ function CharacterCount ($module, config) { // Characters charactersUnderLimitOne: 'You have %{count} character remaining', charactersUnderLimitOther: 'You have %{count} characters remaining', - charactersAtLimit: 'You have no characters remaining', + charactersAtLimit: 'You have 0 characters remaining', charactersOverLimitOne: 'You have %{count} character too many', charactersOverLimitOther: 'You have %{count} characters too many', // Words wordsUnderLimitOne: 'You have %{count} word remaining', wordsUnderLimitOther: 'You have %{count} words remaining', - wordsAtLimit: 'You have no words remaining', + wordsAtLimit: 'You have 0 words remaining', wordsOverLimitOne: 'You have %{count} word too many', wordsOverLimitOther: 'You have %{count} words too many' } diff --git a/src/govuk/components/character-count/character-count.unit.test.mjs b/src/govuk/components/character-count/character-count.unit.test.mjs index ebef39a2d2..371b83249f 100644 --- a/src/govuk/components/character-count/character-count.unit.test.mjs +++ b/src/govuk/components/character-count/character-count.unit.test.mjs @@ -19,12 +19,12 @@ describe('CharacterCount', () => { { number: 10, type: 'characters', expected: 'You have 10 characters remaining' }, { number: -1, type: 'characters', expected: 'You have 1 character too many' }, { number: -10, type: 'characters', expected: 'You have 10 characters too many' }, - { number: 0, type: 'characters', expected: 'You have no characters remaining' }, + { number: 0, type: 'characters', expected: 'You have 0 characters remaining' }, { number: 1, type: 'words', expected: 'You have 1 word remaining' }, { number: 10, type: 'words', expected: 'You have 10 words remaining' }, { number: -1, type: 'words', expected: 'You have 1 word too many' }, { number: -10, type: 'words', expected: 'You have 10 words too many' }, - { number: 0, type: 'words', expected: 'You have no words remaining' } + { number: 0, type: 'words', expected: 'You have 0 words remaining' } ] it.each(cases)( 'picks the relevant translation for $number $type', @@ -51,6 +51,15 @@ describe('CharacterCount', () => { // Other keys remain untouched expect(component.formatCountMessage(10, 'characters')).toEqual('You have 10 characters remaining') }) + + it('uses specific keys for when limit is reached', () => { + const component = new CharacterCount(createElement('div'), { + i18n: { charactersAtLimit: 'Custom text.' }, + 'i18n.wordsAtLimit': 'Different custom text.' + }) + expect(component.formatCountMessage(0, 'characters')).toEqual('Custom text.') + expect(component.formatCountMessage(0, 'words')).toEqual('Different custom text.') + }) }) describe('lang attribute configuration', () => {