forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18n.test.js
99 lines (87 loc) · 3.01 KB
/
i18n.test.js
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {General} from 'mattermost-redux/constants';
import {getCurrentLocale, getTranslations} from 'selectors/i18n';
describe('selectors/i18n', () => {
describe('getCurrentLocale', () => {
test('not logged in', () => {
const state = {
entities: {
general: {
config: {
DefaultClientLocale: 'fr',
},
},
users: {
currentUserId: '',
profiles: {},
},
},
};
expect(getCurrentLocale(state)).toEqual('fr');
});
test('not logged in', () => {
const state = {
entities: {
general: {
config: {
DefaultClientLocale: 'fr',
},
},
users: {
currentUserId: 'abcd',
profiles: {
abcd: {
locale: 'de',
},
},
},
},
};
expect(getCurrentLocale(state)).toEqual('de');
});
test('returns default locale when invalid user locale specified', () => {
const state = {
entities: {
general: {
config: {
DefaultClientLocale: 'en',
},
},
users: {
currentUserId: 'abcd',
profiles: {
abcd: {
locale: 'not_valid',
},
},
},
},
};
expect(getCurrentLocale(state)).toEqual(General.DEFAULT_LOCALE);
});
});
describe('getTranslations', () => {
const state = {
views: {
i18n: {
translations: {
en: {
'test.hello_world': 'Hello, World!',
},
},
},
},
};
test('returns loaded translations', () => {
expect(getTranslations(state, 'en')).toBe(state.views.i18n.translations.en);
});
test('returns null for unloaded translations', () => {
expect(getTranslations(state, 'fr')).toEqual(undefined);
});
test('returns English translations for unsupported locale', () => {
// This test will have to be changed if we add support for Gaelic
expect(getTranslations(state, 'gd')).toBe(state.views.i18n.translations.en);
});
});
});