Debian Codegraph @

src/main.test.js

raw symbols SCIP
1 /* eslint-env jest */
2
3 import * as api from './main';
4
5 describe('main', function mainTestSuite() {
6
7 /* eslint-disable no-magic-numbers */
8
9 describe('getWeekStartByRegion(regionCode)', () => {
10 // eslint-disable-next-line require-jsdoc
11 function verify(code, expected) {
12 expect( api.getWeekStartByRegion(code) )
13 .toBe( expected );
14 }
15
16 it('should return correct result for ISO 3166 Alpha-2 code', () => {
17 verify('bs', 0);
18 verify('PE', 0);
19 verify('kw', 6);
20 verify('SD', 6);
21 verify('mv', 5);
22 verify('no', 1);
23 verify('RU', 1);
24 });
25
26 it('should return correct result for ISO 3166 Alpha-3 code', () => {
27 verify('can', 0);
28 verify('SLV', 0);
29 verify('dji', 6);
30 verify('QAT', 6);
31 verify('MDV', 5);
32 verify('esp', 1);
33 verify('MUS', 1);
34 });
35
36 it('should return correct result for ISO 3166 numeric code', () => {
37 verify(446, 0);
38 verify(710, 0);
39 verify(400, 6);
40 verify(729, 6);
41 verify(462, 5);
42 verify(246, 1);
43 verify(686, 1);
44 });
45
46 it('should return 1', () => {
47 verify(null, 1);
48 verify(0, 1);
49 verify('moon', 1);
50 });
51 });
52
53 describe('getWeekStartByLocale(locale)', () => {
54 // eslint-disable-next-line require-jsdoc
55 function verify(locale, expected) {
56 expect( api.getWeekStartByLocale(locale) )
57 .toBe( expected );
58 }
59
60 it('should return correct result for locale containing only language code', () => {
61 verify('HI', 0);
62 verify('jam', 0);
63 verify('FA', 6);
64 });
65
66 it('should return correct result for locale containing only language code and script', () => {
67 verify('Ms-arab', 0);
68 verify('PA_Arab', 0);
69 verify('az_arab', 6);
70 verify('Uz-latn', 1);
71 verify('Pa-Arab', 0);
72 verify('fa_DEVA', 6);
73 });
74
75 it('should return correct result for locale containing only script', () => {
76 verify('Arab', 6);
77 verify('deva', 0);
78 verify('cyrl', 1);
79 verify('Hans', 1);
80 verify('hant', 0);
81 verify('LATN', 1);
82 verify('Tfng', 1);
83 verify('THAA', 5);
84 });
85
86 it('should return correct result for locale containing only language and region code', () => {
87 verify('ar-sa', 0);
88 verify('en_NG', 1);
89 verify('FR-DZ', 6);
90 verify('es_mx', 0);
91 verify('BN-in', 0);
92 });
93
94 it('should return correct result for locale containing only script and region code', () => {
95 verify('ARAB_IN', 0);
96 verify('arab-IR', 6);
97 verify('Arab_MN', 1);
98 verify('Hant_MY', 1);
99 verify('latn_PY', 0);
100 });
101
102 it('should return correct result for locale containing language, script and region code', () => {
103 verify('az-arab-iq', 6);
104 verify('az_Arab-TR', 1);
105 verify('Az-Cyrl_Ru', 1);
106 verify('zh_Hant_tw', 0);
107 verify('ZH-HANT_VN', 1);
108 });
109
110 it('should return correct result for arbitrary locale', () => {
111 verify('xyz', 1);
112 verify('az_arab_IRA', 1);
113 verify('HI-Fij', 1);
114 verify('MS_SG_u-data', 0);
115 verify('en-mv-t-true-DE', 5);
116 });
117
118 it('should return 1 for non-found locale', () => {
119 verify('bej', 1);
120 verify('ccp', 1);
121 verify('HR', 1);
122 verify('vi', 1);
123 verify('Tfng', 1);
124 });
125
126 it('should return 1', () => {
127 verify(false, 1);
128 verify('', 1);
129 verify('some-strange-locale', 1);
130 verify('Summer moved on', 1);
131 });
132 });
133 });