/
setupI18n_test.ts
72 lines (66 loc) · 2.17 KB
/
setupI18n_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2017 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import type { LocalizerType } from '../../types/Util';
import { setupI18n } from '../../util/setupI18n';
import * as enMessages from '../../../_locales/en/messages.json';
describe('setupI18n', () => {
let i18n: LocalizerType;
beforeEach(() => {
i18n = setupI18n('en', enMessages);
});
describe('i18n', () => {
it('throws an error for unknown string', () => {
assert.throws(() => {
// eslint-disable-next-line local-rules/valid-i18n-keys
assert.strictEqual(i18n('icu:random'), '');
}, /missing translation/);
});
it('returns message for given string', () => {
assert.strictEqual(i18n('icu:reportIssue'), 'Contact Support');
});
it('returns message with single substitution', () => {
const actual = i18n('icu:migratingToSQLCipher', {
status: '45/200',
});
assert.equal(actual, 'Optimizing messages... 45/200 complete.');
});
it('returns message with multiple substitutions', () => {
const actual = i18n('icu:theyChangedTheTimer', {
name: 'Someone',
time: '5 minutes',
});
assert.equal(
actual,
'Someone set the disappearing message time to 5 minutes.'
);
});
it('returns a modern icu message formatted', () => {
const actual = i18n(
'icu:AddUserToAnotherGroupModal__toast--adding-user-to-group',
{ contact: 'CONTACT' }
);
assert.equal(actual, 'Adding CONTACT...');
});
});
describe('getLocale', () => {
it('returns a string with length two or greater', () => {
const locale = i18n.getLocale();
assert.isAtLeast(locale.trim().length, 2);
});
});
describe('getIntl', () => {
it('returns the intl object to call formatMessage()', () => {
const intl = i18n.getIntl();
assert.isObject(intl);
const result = intl.formatMessage(
{ id: 'icu:emptyInboxMessage' },
{ composeIcon: 'ICONIC' }
);
assert.equal(
result,
'Click the ICONIC above and search for your contacts or groups to message.'
);
});
});
});