Skip to content

Commit

Permalink
Tidy up character count translation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
romaricpascal committed Oct 3, 2022
1 parent 04deadb commit c518e61
Showing 1 changed file with 19 additions and 32 deletions.
51 changes: 19 additions & 32 deletions src/govuk/components/character-count/character-count.unit.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,26 @@ describe('CharacterCount', () => {
component = new CharacterCount(createElement('div'))
})

it('formats singular remaining characters', () => {
expect(component.formatCountMessage(1, 'characters')).toEqual('You have 1 character remaining')
})
it('formats plural remaining characters', () => {
expect(component.formatCountMessage(10, 'characters')).toEqual('You have 10 characters remaining')
})
it('formats singular exceeding characters', () => {
expect(component.formatCountMessage(-1, 'characters')).toEqual('You have 1 character too many')
})
it('formats plural exceeding characters', () => {
expect(component.formatCountMessage(-10, 'characters')).toEqual('You have 10 characters too many')
})
it('formats character limit being met', () => {
expect(component.formatCountMessage(0, 'characters')).toEqual('You have no characters remaining')
})

it('formats singular remaining words', () => {
expect(component.formatCountMessage(1, 'words')).toEqual('You have 1 word remaining')
})
it('formats plural remaining words', () => {
expect(component.formatCountMessage(10, 'words')).toEqual('You have 10 words remaining')
})
it('formats singular exceeding words', () => {
expect(component.formatCountMessage(-1, 'words')).toEqual('You have 1 word too many')
})
it('formats plural exceeding words', () => {
expect(component.formatCountMessage(-10, 'words')).toEqual('You have 10 words too many')
})
it('formats word limit being met', () => {
expect(component.formatCountMessage(0, 'words')).toEqual('You have no words remaining')
})
const cases = [
{ number: 1, type: 'characters', expected: 'You have 1 character remaining' },
{ 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: 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' }
]
it.each(cases)(
'picks the relevant translation for $number $type',
function test ({ number, type, expected }) {
expect(component.formatCountMessage(number, type)).toEqual(expected)
}
)

it('formats the count', () => {
it('formats the number inserted in the message', () => {
expect(component.formatCountMessage(10000, 'words')).toEqual('You have 10,000 words remaining')
expect(component.formatCountMessage(-10000, 'words')).toEqual('You have 10,000 words too many')
})
Expand Down

0 comments on commit c518e61

Please sign in to comment.