Skip to content

Commit

Permalink
Revert translation string for when limit is met
Browse files Browse the repository at this point in the history
Updates the testing to use the JavaScript configuration
  • Loading branch information
romaricpascal committed Oct 3, 2022
1 parent 861eea9 commit 1ef30e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/govuk/components/character-count/character-count.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
13 changes: 11 additions & 2 deletions src/govuk/components/character-count/character-count.unit.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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', () => {
Expand Down

0 comments on commit 1ef30e0

Please sign in to comment.