From 20d75343244154eccf2a98bbeb1e97d16cc4af5f Mon Sep 17 00:00:00 2001 From: Ryan Miller Date: Fri, 23 Aug 2024 13:17:13 +1000 Subject: [PATCH] chore: fix i18n test names --- .../utils/i18n/formatMessageWithArgs_test.ts | 39 +++++++++++++++++++ .../unit/utils/i18n/getMessage_test.ts | 12 +++--- .../session/unit/utils/i18n/stripped_test.ts | 12 +++--- 3 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 ts/test/session/unit/utils/i18n/formatMessageWithArgs_test.ts diff --git a/ts/test/session/unit/utils/i18n/formatMessageWithArgs_test.ts b/ts/test/session/unit/utils/i18n/formatMessageWithArgs_test.ts new file mode 100644 index 000000000..0ebaea506 --- /dev/null +++ b/ts/test/session/unit/utils/i18n/formatMessageWithArgs_test.ts @@ -0,0 +1,39 @@ +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-nocheck - TODO: add generic type to setupI18n to fix this + +import { expect } from 'chai'; +import { initI18n, testDictionary } from './util'; + +describe('formatMessageWithArgs', () => { + const i18n = initI18n(testDictionary); + + it('returns the message with args for a message', () => { + const message = i18n('Hello, {name}!', { name: 'Alice' }); + expect(message).to.equal('Hello, Alice!'); + }); + + it('returns the message with args for a multi-arg message', () => { + const message = i18n('{found_count} of {count} match', { count: 1, found_count: 2 }); + expect(message).to.equal('2 of 1 match'); + }); + + it("returns the message with args for plural message' with no args", () => { + const message = i18n('No args'); + expect(message).to.equal('No args'); + }); + + it('returns the message with args for a token with args', () => { + const message = i18n('Hello, {name}!', { name: 'Alice' }); + expect(message).to.equal('Hello, Alice!'); + }); + + it('returns the message with args for a token with a tag', () => { + const message = i18n('Hello, {name}! Welcome!', { name: 'Alice' }); + expect(message).to.equal('Hello, Alice! Welcome!'); + }); + + it('returns the message with args for a token with a tag and args', () => { + const message = i18n('Hello, {name}! Welcome, {arg}!', { name: 'Alice', arg: 'Bob' }); + expect(message).to.equal('Hello, Alice! Welcome, Bob!'); + }); +}); diff --git a/ts/test/session/unit/utils/i18n/getMessage_test.ts b/ts/test/session/unit/utils/i18n/getMessage_test.ts index 9eca8d16d..b40b33fe6 100644 --- a/ts/test/session/unit/utils/i18n/getMessage_test.ts +++ b/ts/test/session/unit/utils/i18n/getMessage_test.ts @@ -7,32 +7,32 @@ import { initI18n, testDictionary } from './util'; describe('getMessage', () => { const i18n = initI18n(testDictionary); - it('returns the raw message for a token', () => { + it('returns the message for a token', () => { const message = i18n('greeting', { name: 'Alice' }); expect(message).to.equal('Hello, Alice!'); }); - it('returns the raw message for a plural token', () => { + it('returns the message for a plural token', () => { const message = i18n('search', { count: 1, found_count: 2 }); expect(message).to.equal('2 of 1 match'); }); - it('returns the raw message for a token with no args', () => { + it('returns the message for a token with no args', () => { const message = i18n('noArgs'); expect(message).to.equal('No args'); }); - it('returns the raw message for a token with args', () => { + it('returns the message for a token with args', () => { const message = i18n('args', { name: 'Alice' }); expect(message).to.equal('Hello, Alice!'); }); - it('returns the raw message for a token with a tag', () => { + it('returns the message for a token with a tag', () => { const message = i18n('tag', { name: 'Alice' }); expect(message).to.equal('Hello, Alice! Welcome!'); }); - it('returns the raw message for a token with a tag and args', () => { + it('returns the message for a token with a tag and args', () => { const message = i18n('argInTag', { name: 'Alice', arg: 'Bob' }); expect(message).to.equal('Hello, Alice! Welcome, Bob!'); }); diff --git a/ts/test/session/unit/utils/i18n/stripped_test.ts b/ts/test/session/unit/utils/i18n/stripped_test.ts index 655a1cd63..514405ea9 100644 --- a/ts/test/session/unit/utils/i18n/stripped_test.ts +++ b/ts/test/session/unit/utils/i18n/stripped_test.ts @@ -7,32 +7,32 @@ import { initI18n, testDictionary } from './util'; describe('stripped', () => { const i18n = initI18n(testDictionary); - it('returns the raw message for a token', () => { + it('returns the stripped message for a token', () => { const message = i18n.stripped('greeting', { name: 'Alice' }); expect(message).to.equal('Hello, Alice!'); }); - it('returns the raw message for a plural token', () => { + it('returns the stripped message for a plural token', () => { const message = i18n.stripped('search', { count: 1, found_count: 2 }); expect(message).to.equal('2 of 1 match'); }); - it('returns the raw message for a token with no args', () => { + it('returns the stripped message for a token with no args', () => { const message = i18n.stripped('noArgs'); expect(message).to.equal('No args'); }); - it('returns the raw message for a token with args', () => { + it('returns the stripped message for a token with args', () => { const message = i18n.stripped('args', { name: 'Alice' }); expect(message).to.equal('Hello, Alice!'); }); - it('returns the raw message for a token with the tags stripped', () => { + it('returns the stripped message for a token with the tags stripped', () => { const message = i18n.stripped('tag', { name: 'Alice' }); expect(message).to.equal('Hello, Alice! Welcome!'); }); - it('returns the raw message for a token with the tags stripped', () => { + it('returns the stripped message for a token with the tags stripped', () => { const message = i18n.stripped('argInTag', { name: 'Alice', arg: 'Bob' }); expect(message).to.equal('Hello, Alice! Welcome, Bob!'); });