bv-ui-core 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/.eslintrc +40 -0
  2. package/.travis.yml +5 -0
  3. package/CONTRIBUTING.md +98 -0
  4. package/LICENSE.md +13 -0
  5. package/OWNERS +2 -0
  6. package/README.md +63 -0
  7. package/catalog-info.yaml +30 -0
  8. package/karma.conf.js +130 -0
  9. package/lib/README.md +61 -0
  10. package/lib/api/.babelrc +3 -0
  11. package/lib/api/.eslintrc +9 -0
  12. package/lib/api/README.md +134 -0
  13. package/lib/api/index.js +15 -0
  14. package/lib/api/statistics.js +148 -0
  15. package/lib/application/README.md +96 -0
  16. package/lib/application/index.js +171 -0
  17. package/lib/body/README.md +13 -0
  18. package/lib/body/index.js +19 -0
  19. package/lib/bvFetch/README.md +101 -0
  20. package/lib/bvFetch/index.js +383 -0
  21. package/lib/checkHighContrast/README.md +26 -0
  22. package/lib/checkHighContrast/index.js +36 -0
  23. package/lib/cookie/README.md +29 -0
  24. package/lib/cookie/index.js +111 -0
  25. package/lib/cookieConsent/README.md +41 -0
  26. package/lib/cookieConsent/index.js +227 -0
  27. package/lib/cssLoadChecker/README.md +19 -0
  28. package/lib/cssLoadChecker/index.js +72 -0
  29. package/lib/date.now/README.md +11 -0
  30. package/lib/date.now/index.js +40 -0
  31. package/lib/domainPolice/README.md +66 -0
  32. package/lib/domainPolice/index.js +95 -0
  33. package/lib/evented/README.md +42 -0
  34. package/lib/evented/index.js +135 -0
  35. package/lib/getOriginalConstructor/README.md +16 -0
  36. package/lib/getOriginalConstructor/index.js +52 -0
  37. package/lib/global/README.md +10 -0
  38. package/lib/global/index.js +48 -0
  39. package/lib/ie/README.md +13 -0
  40. package/lib/ie/index.js +25 -0
  41. package/lib/loader/README.md +73 -0
  42. package/lib/loader/index.js +358 -0
  43. package/lib/logger/README.md +82 -0
  44. package/lib/logger/index.js +180 -0
  45. package/lib/messageFormat/README.md +10 -0
  46. package/lib/messageFormat/index.js +42 -0
  47. package/lib/namespacer/README.md +57 -0
  48. package/lib/namespacer/index.js +98 -0
  49. package/lib/performance/README.md +35 -0
  50. package/lib/performance/entries.js +5 -0
  51. package/lib/performance/getEntries.js +42 -0
  52. package/lib/performance/getEntriesByName.js +61 -0
  53. package/lib/performance/getEntriesByType.js +55 -0
  54. package/lib/performance/index.js +11 -0
  55. package/lib/performance/mark.js +97 -0
  56. package/lib/performance/measure.js +106 -0
  57. package/lib/performance/now.js +63 -0
  58. package/lib/pixelsDisplayed/README.md +19 -0
  59. package/lib/pixelsDisplayed/index.js +113 -0
  60. package/lib/polyfills/README.md +39 -0
  61. package/lib/polyfills/fetch/Headers.js +3 -0
  62. package/lib/polyfills/fetch/Request.js +3 -0
  63. package/lib/polyfills/fetch/Response.js +3 -0
  64. package/lib/polyfills/fetch/fetch.js +3 -0
  65. package/lib/polyfills/fetch/index.js +57 -0
  66. package/lib/polyfills/promise.js +265 -0
  67. package/lib/queryShadowDom/README.md +50 -0
  68. package/lib/queryShadowDom/index.js +93 -0
  69. package/lib/region/README.md +64 -0
  70. package/lib/region/europe/index.js +94 -0
  71. package/lib/region/europe/territories.js +40 -0
  72. package/lib/region/index.js +123 -0
  73. package/lib/staticAssetLoader/README.md +116 -0
  74. package/lib/staticAssetLoader/index.js +248 -0
  75. package/lib/waitForBody/README.md +21 -0
  76. package/lib/waitForBody/index.js +36 -0
  77. package/mkdocs.yaml +5 -0
  78. package/package.json +55 -0
  79. package/test/.eslintrc +5 -0
  80. package/test/fixtures/lib.loader.document-is-wrong-in-ie8.js +5 -0
  81. package/test/fixtures/lib.loader.loadscript-attribute.js +3 -0
  82. package/test/fixtures/lib.loader.loadscript.js +3 -0
  83. package/test/fixtures/lib.loader.loadstylesheet.css +3 -0
  84. package/test/unit/api/.eslintrc +6 -0
  85. package/test/unit/api/index.spec.js +37 -0
  86. package/test/unit/api/response.json +67 -0
  87. package/test/unit/api/statistics.spec.js +218 -0
  88. package/test/unit/application/index.spec.js +313 -0
  89. package/test/unit/body/index.spec.js +15 -0
  90. package/test/unit/bvFetch/index.spec.js +246 -0
  91. package/test/unit/checkHighContrast/index.spec.js +16 -0
  92. package/test/unit/cookie/index.spec.js +191 -0
  93. package/test/unit/cookieConsent/index.spec.js +119 -0
  94. package/test/unit/cssLoadChecker/index.spec.js +75 -0
  95. package/test/unit/date.now/index.spec.js +21 -0
  96. package/test/unit/domainPolice/index.spec.js +141 -0
  97. package/test/unit/evented/index.spec.js +59 -0
  98. package/test/unit/getOriginalConstructor/index.spec.js +60 -0
  99. package/test/unit/global/index.spec.js +84 -0
  100. package/test/unit/ie/index.spec.js +14 -0
  101. package/test/unit/loader/index.spec.js +644 -0
  102. package/test/unit/logger/index.spec.js +141 -0
  103. package/test/unit/messageFormat/index.spec.js +31 -0
  104. package/test/unit/mochaInit.js +8 -0
  105. package/test/unit/namespacer/index.spec.js +100 -0
  106. package/test/unit/performance/getEntries.spec.js +30 -0
  107. package/test/unit/performance/getEntriesByName.spec.js +88 -0
  108. package/test/unit/performance/getEntriesByType.spec.js +48 -0
  109. package/test/unit/performance/index.spec.js +35 -0
  110. package/test/unit/performance/mark.spec.js +40 -0
  111. package/test/unit/performance/measure.spec.js +50 -0
  112. package/test/unit/performance/now.spec.js +21 -0
  113. package/test/unit/pixelsDisplayed/index.spec.js +271 -0
  114. package/test/unit/polyfills/fetch/Headers.js +12 -0
  115. package/test/unit/polyfills/fetch/Request.js +12 -0
  116. package/test/unit/polyfills/fetch/Response.js +12 -0
  117. package/test/unit/polyfills/fetch/fetch.js +12 -0
  118. package/test/unit/polyfills/fetch/index.js +61 -0
  119. package/test/unit/polyfills/promise.spec.js +48 -0
  120. package/test/unit/region/europe/index.spec.js +70 -0
  121. package/test/unit/region/index.spec.js +113 -0
  122. package/test/unit/staticAssetLoader/index.spec.js +215 -0
@@ -0,0 +1,271 @@
1
+ /**
2
+ * @fileOverview
3
+ * Unit tests for the Pixels Displayed module.
4
+ */
5
+
6
+ var module = require('../../../lib/pixelsDisplayed');
7
+
8
+ describe('lib/pixelsDisplayed', function () {
9
+ var pixelsDisplayedVertical;
10
+ var pixelsDisplayedHorizontal;
11
+ var sinonSandbox, stub;
12
+
13
+ var rect = {};
14
+
15
+ var el = {
16
+ getBoundingClientRect: function () {
17
+ return rect;
18
+ }
19
+ };
20
+
21
+ function stubAccessor () {
22
+ sinonSandbox = sinon.sandbox.create();
23
+ stub = sinonSandbox.stub(module, 'getDimensions').callsFake(function () {
24
+ return {
25
+ width: 500,
26
+ height: 500
27
+ }
28
+ });
29
+ }
30
+
31
+ before(function () {
32
+ pixelsDisplayedVertical = module.pixelsDisplayedVertical;
33
+ pixelsDisplayedHorizontal = module.pixelsDisplayedHorizontal;
34
+ });
35
+
36
+ beforeEach(function () {
37
+ stubAccessor();
38
+ rect = {
39
+ height: 200,
40
+ top: 100,
41
+ width: 200,
42
+ left: 100
43
+ };
44
+ });
45
+
46
+ afterEach(function () {
47
+ // we do expect stubbed method to have been called during each test
48
+ sinon.assert.called(stub);
49
+ sinonSandbox.restore();
50
+ });
51
+
52
+ describe('element is hidden vertically', function () {
53
+ describe('element is smaller than viewport', function () {
54
+ it('should be hidden when element is way above viewport', function () {
55
+ rect.top = -9999;
56
+
57
+ expect(pixelsDisplayedVertical(el)).to.eql(0);
58
+ });
59
+
60
+ it('should be hidden when element is right above viewport', function () {
61
+ rect.top = -200;
62
+
63
+ expect(pixelsDisplayedVertical(el)).to.eql(0);
64
+ });
65
+
66
+ it('should be hidden when element is way below viewport', function () {
67
+ rect.top = 9999;
68
+
69
+ expect(pixelsDisplayedVertical(el)).to.eql(0);
70
+ });
71
+
72
+ it('should be hidden when element is right below viewport', function () {
73
+ rect.top = 500;
74
+
75
+ expect(pixelsDisplayedVertical(el)).to.eql(0);
76
+ });
77
+ });
78
+
79
+ describe('element is bigger than viewport', function () {
80
+ beforeEach(function () {
81
+ rect.height = 1000;
82
+ });
83
+
84
+ it('should be hidden when element is way above viewport', function () {
85
+ rect.top = -9999;
86
+
87
+ expect(pixelsDisplayedVertical(el)).to.eql(0);
88
+ });
89
+
90
+ it('should be hidden when element is right above viewport', function () {
91
+ rect.top = -1000;
92
+
93
+ expect(pixelsDisplayedVertical(el)).to.eql(0);
94
+ });
95
+
96
+ it('should be hidden when element is way below viewport', function () {
97
+ rect.top = 9999;
98
+
99
+ expect(pixelsDisplayedVertical(el)).to.eql(0);
100
+ });
101
+
102
+ it('should be hidden when element is right below viewport', function () {
103
+ rect.top = 1000;
104
+
105
+ expect(pixelsDisplayedVertical(el)).to.eql(0);
106
+ });
107
+ });
108
+ });
109
+
110
+ describe('element is hidden horizontally', function () {
111
+ describe('element is smaller than viewport', function () {
112
+ it('should be hidden when element is way to the left of the viewport', function () {
113
+ rect.left = -9999;
114
+
115
+ expect(pixelsDisplayedHorizontal(el)).to.eql(0);
116
+ });
117
+
118
+ it('should be hidden when element is just to the left of the viewport', function () {
119
+ rect.left = -200;
120
+
121
+ expect(pixelsDisplayedHorizontal(el)).to.eql(0);
122
+ });
123
+
124
+ it('should be hidden when element is way to the right of the viewport', function () {
125
+ rect.left = 9999;
126
+
127
+ expect(pixelsDisplayedHorizontal(el)).to.eql(0);
128
+ });
129
+
130
+ it('should be hidden when element is just to the right of the viewport', function () {
131
+ rect.left = 500;
132
+
133
+ expect(pixelsDisplayedHorizontal(el)).to.eql(0);
134
+ });
135
+ });
136
+
137
+ describe('element is bigger than viewport', function () {
138
+ beforeEach(function () {
139
+ rect.width = 1000;
140
+ });
141
+
142
+ it('should be hidden when element is way to the left of the viewport', function () {
143
+ rect.left = -9999;
144
+
145
+ expect(pixelsDisplayedHorizontal(el)).to.eql(0);
146
+ });
147
+
148
+ it('should be hidden when element is just to the left of the viewport', function () {
149
+ rect.left = -1000;
150
+
151
+ expect(pixelsDisplayedHorizontal(el)).to.eql(0);
152
+ });
153
+
154
+ it('should be hidden when element is way to the right of the viewport', function () {
155
+ rect.left = 9999;
156
+
157
+ expect(pixelsDisplayedHorizontal(el)).to.eql(0);
158
+ });
159
+
160
+ it('should be hidden when element is just to the right of the viewport', function () {
161
+ rect.left = 1000;
162
+
163
+ expect(pixelsDisplayedHorizontal(el)).to.eql(0);
164
+ });
165
+ });
166
+ });
167
+
168
+ describe('element is visible vertically', function () {
169
+ describe('element is smaller than viewport', function () {
170
+ it('element should be visible when top position is 0', function () {
171
+ rect.top = 0;
172
+
173
+ expect(pixelsDisplayedVertical(el)).to.eql(200);
174
+ });
175
+
176
+ it('element should be visible when top position is greater than 0', function () {
177
+ rect.top = 499;
178
+
179
+ expect(pixelsDisplayedVertical(el)).to.eql(1);
180
+ });
181
+
182
+ it('element should be visible when top position is less than 0', function () {
183
+ rect.top = -199;
184
+
185
+ expect(pixelsDisplayedVertical(el)).to.eql(1);
186
+ });
187
+ });
188
+
189
+ describe('element is bigger than viewport', function () {
190
+ beforeEach(function () {
191
+ rect.height = 1000;
192
+ });
193
+
194
+ it('element should be visible when top position is 0', function () {
195
+ rect.top = 0;
196
+
197
+ expect(pixelsDisplayedVertical(el)).to.eql(500);
198
+ });
199
+
200
+ it('element should be visible when top position is greater than 0', function () {
201
+ rect.top = 100;
202
+
203
+ expect(pixelsDisplayedVertical(el)).to.eql(400);
204
+ });
205
+
206
+ it('element should be visible when top position is less than 0', function () {
207
+ rect.top = -600;
208
+
209
+ expect(pixelsDisplayedVertical(el)).to.eql(400);
210
+ });
211
+ });
212
+ });
213
+
214
+ describe('element is visible horizontally', function () {
215
+ describe('element is smaller than viewport', function () {
216
+ it('element should be visible when left position is 0', function () {
217
+ rect.left = 0;
218
+
219
+ expect(pixelsDisplayedHorizontal(el)).to.eql(200);
220
+ });
221
+
222
+ it('element should be visible when left position is greater than 0', function () {
223
+ rect.left = 499;
224
+
225
+ expect(pixelsDisplayedHorizontal(el)).to.eql(1);
226
+ });
227
+
228
+ it('element should be visible when left position is less than 0', function () {
229
+ rect.left = -199;
230
+
231
+ expect(pixelsDisplayedHorizontal(el)).to.eql(1);
232
+ });
233
+ });
234
+
235
+ describe('element is bigger than viewport', function () {
236
+ beforeEach(function () {
237
+ rect.width = 1000;
238
+ });
239
+
240
+ it('element should be visible when left position is 0', function () {
241
+ rect.left = 0;
242
+
243
+ expect(pixelsDisplayedHorizontal(el)).to.eql(500);
244
+ });
245
+
246
+ it('element should be visible when left position is greater than 0', function () {
247
+ rect.left = 100;
248
+
249
+ expect(pixelsDisplayedHorizontal(el)).to.eql(400);
250
+ });
251
+
252
+ it('element should be visible when left position is less than 0', function () {
253
+ rect.left = -600;
254
+
255
+ expect(pixelsDisplayedHorizontal(el)).to.eql(400);
256
+ });
257
+ });
258
+ });
259
+
260
+ it('Accessor function is working correctly', function () {
261
+ // Special case, we actually want to call the real function, so restore
262
+ // sandbox
263
+ sinonSandbox.restore();
264
+ var dimensions = module.getDimensions();
265
+ expect(dimensions.width).to.equal(window.innerWidth);
266
+ expect(dimensions.height).to.equal(window.innerHeight);
267
+ // And then re-set-it-up again and call method
268
+ stubAccessor();
269
+ dimensions = module.getDimensions();
270
+ })
271
+ });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @fileOverview
3
+ * Unit tests for the fetch Headers module.
4
+ */
5
+
6
+ var Headers = require('../../../../lib/polyfills/fetch/Headers');
7
+
8
+ describe('lib/polyfills/fetch/Headers', function () {
9
+ it('exports a function as its default export', function () {
10
+ expect(Headers).to.be.a('function');
11
+ });
12
+ })
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @fileOverview
3
+ * Unit tests for the fetch Request module.
4
+ */
5
+
6
+ var Request = require('../../../../lib/polyfills/fetch/Request');
7
+
8
+ describe('lib/polyfills/fetch/Request', function () {
9
+ it('exports a function as its default export', function () {
10
+ expect(Request).to.be.a('function');
11
+ });
12
+ })
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @fileOverview
3
+ * Unit tests for the fetch Response module.
4
+ */
5
+
6
+ var Response = require('../../../../lib/polyfills/fetch/Response');
7
+
8
+ describe('lib/polyfills/fetch/Response', function () {
9
+ it('exports a function as its default export', function () {
10
+ expect(Response).to.be.a('function');
11
+ });
12
+ })
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @fileOverview
3
+ * Unit tests for the fetch function module.
4
+ */
5
+
6
+ var fetch = require('../../../../lib/polyfills/fetch/fetch');
7
+
8
+ describe('lib/polyfills/fetch/fetch', function () {
9
+ it('exports a function as its default export', function () {
10
+ expect(fetch).to.be.a('function');
11
+ });
12
+ })
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @fileOverview
3
+ * Unit tests for the fetch polyfill module.
4
+ */
5
+
6
+ var global = require('../../../../lib/global');
7
+
8
+ describe('lib/polyfills/fetch', function () {
9
+ var nativeSupport = function () {
10
+ console.log('[native code]');
11
+ };
12
+
13
+ it('does not polyfill when natively supported', function () {
14
+ var fetch = global.fetch;
15
+
16
+ global.fetch = nativeSupport;
17
+
18
+ var fetchModule = require('../../../../lib/polyfills/fetch');
19
+
20
+ // Test named exports
21
+ expect(fetchModule.fetch).to.equal(nativeSupport);
22
+
23
+ // If we have native fetch support, we can also check these
24
+ if (fetch) {
25
+ expect(fetchModule.fetch).to.be.a('function');
26
+ expect(fetchModule.Headers).to.be.a('function');
27
+ expect(fetchModule.Request).to.be.a('function');
28
+ expect(fetchModule.Response).to.be.a('function');
29
+ }
30
+
31
+ global.fetch = fetch;
32
+
33
+ // Clear the require cache for the next time it's required
34
+ delete require.cache[require.resolve('../../../../lib/polyfills/fetch')];
35
+ });
36
+
37
+ it('polyfills when not natively supported', function () {
38
+ var fetch = global.fetch;
39
+
40
+ global.fetch = undefined;
41
+
42
+ var fetchModule = require('../../../../lib/polyfills/fetch');
43
+
44
+ // Test named exports
45
+ expect(fetchModule.fetch).not.to.equal(nativeSupport);
46
+
47
+ // Verify that we didn't pollute the global namespace
48
+ expect(global.fetch).to.equal(undefined);
49
+
50
+ // Now that we've polyfilled, we can check these
51
+ expect(fetchModule.fetch).to.be.a('function');
52
+ expect(fetchModule.Headers).to.be.a('function');
53
+ expect(fetchModule.Request).to.be.a('function');
54
+ expect(fetchModule.Response).to.be.a('function');
55
+
56
+ global.fetch = fetch;
57
+
58
+ // Clear the require cache for the next time it's required
59
+ delete require.cache[require.resolve('../../../../lib/polyfills/fetch')];
60
+ });
61
+ })
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @fileOverview
3
+ * Unit tests for the Promise polyfill module.
4
+ */
5
+
6
+ var global = require('../../../lib/global');
7
+
8
+ describe('lib/polyfills/promise', function () {
9
+ var nativeSupport = function () {
10
+ console.log('[native code]');
11
+ };
12
+
13
+ it('does not polyfill when natively supported', function () {
14
+ var Promise = global.Promise;
15
+
16
+ global.Promise = nativeSupport;
17
+
18
+ var PromiseModule = require('../../../lib/polyfills/promise');
19
+
20
+ expect(PromiseModule).to.equal(nativeSupport);
21
+
22
+ global.Promise = Promise;
23
+
24
+ // Clear the require cache for the next time it's required
25
+ delete require.cache[require.resolve('../../../lib/polyfills/promise')];
26
+ });
27
+
28
+ it('polyfills when not natively supported', function () {
29
+ var Promise = global.Promise;
30
+
31
+ global.Promise = undefined;
32
+
33
+ var PromiseModule = require('../../../lib/polyfills/promise');
34
+
35
+ expect(PromiseModule).not.to.equal(nativeSupport);
36
+
37
+ // Verify that we didn't pollute the global namespace
38
+ expect(global.Promise).to.equal(undefined);
39
+
40
+ // Now that we've polyfilled, we can check this
41
+ expect(PromiseModule).to.be.a('function');
42
+
43
+ global.Promise = Promise;
44
+
45
+ // Clear the require cache for the next time it's required
46
+ delete require.cache[require.resolve('../../../lib/polyfills/promise')];
47
+ });
48
+ })
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @file Unit tests for EU region module
3
+ */
4
+
5
+ var europe = require('../../../../lib/region/europe');
6
+
7
+ describe('lib/region/europe', function () {
8
+
9
+ describe('#hasTerritory', function () {
10
+
11
+ it('should throw an error for en_US', function () {
12
+ expect(function () {
13
+ europe.hasTerritory('en_US');
14
+ }).to.throw();
15
+ });
16
+
17
+ it('should throw an error for fr', function () {
18
+ expect(function () {
19
+ europe.hasTerritory('fr');
20
+ }).to.throw();
21
+ });
22
+
23
+ it('should return false for US', function () {
24
+ var result = europe.hasTerritory('US');
25
+ expect(result).to.equal(false);
26
+ });
27
+
28
+ it('should return true for GB', function () {
29
+ var result = europe.hasTerritory('GB');
30
+ expect(result).to.equal(true);
31
+ });
32
+ });
33
+
34
+ describe('#hasLocale', function () {
35
+
36
+ it('should throw an error for US', function () {
37
+ expect(function () {
38
+ europe.hasLocale('US');
39
+ }).to.throw();
40
+ });
41
+
42
+ it('should return false for en_US', function () {
43
+ var result = europe.hasLocale('en_US');
44
+ expect(result).to.equal(false);
45
+ });
46
+
47
+ it('should return false for en-US', function () {
48
+ var result = europe.hasLocale('en-US');
49
+ expect(result).to.equal(false);
50
+ });
51
+
52
+ it('should return true for en_GB', function () {
53
+ var result = europe.hasLocale('en_GB');
54
+ expect(result).to.equal(true);
55
+ });
56
+
57
+ it('should return true for en-GB', function () {
58
+ var result = europe.hasLocale('en-GB');
59
+ expect(result).to.equal(true);
60
+ });
61
+ });
62
+
63
+ describe('#listTerritories', function () {
64
+
65
+ it('should return an array', function () {
66
+ var result = europe.listTerritories();
67
+ expect(result).to.be.an('array');
68
+ });
69
+ });
70
+ });
@@ -0,0 +1,113 @@
1
+ /**
2
+ * @file Unit tests for region module
3
+ */
4
+
5
+ var region = require('../../../lib/region');
6
+
7
+
8
+ describe('lib/region', function () {
9
+
10
+ describe('#hasTerritory', function () {
11
+
12
+ it('should throw an error for en_US and europe', function () {
13
+ expect(function () {
14
+ region.hasTerritory('europe', 'en_US');
15
+ }).to.throw();
16
+ });
17
+
18
+ it('should throw an error for US and bananarama', function () {
19
+ expect(function () {
20
+ region.hasTerritory('bananarama', 'US');
21
+ }).to.throw();
22
+ });
23
+
24
+ it('should throw an error for fr and europe', function () {
25
+ expect(function () {
26
+ region.hasTerritory('europe', 'fr');
27
+ }).to.throw();
28
+ });
29
+
30
+ it('should return false for US and europe', function () {
31
+ var result = region.hasTerritory('europe', 'US');
32
+ expect(result).to.equal(false);
33
+ });
34
+
35
+ it('should return true for GB and europe', function () {
36
+ var result = region.hasTerritory('europe', 'GB');
37
+ expect(result).to.equal(true);
38
+ });
39
+ });
40
+
41
+ describe('#hasLocale', function () {
42
+
43
+ it('should throw an error for US and europe', function () {
44
+ expect(function () {
45
+ region.hasLocale('europe', 'US');
46
+ }).to.throw();
47
+ });
48
+
49
+ it('should throw an error for en_US and bananarama', function () {
50
+ expect(function () {
51
+ region.hasLocale('bananarama', 'en_US');
52
+ }).to.throw();
53
+ });
54
+
55
+ it('should return false for en_US and europe', function () {
56
+ var result = region.hasLocale('europe', 'en_US');
57
+ expect(result).to.equal(false);
58
+ });
59
+
60
+ it('should return false for en-US and europe', function () {
61
+ var result = region.hasLocale('europe', 'en-US');
62
+ expect(result).to.equal(false);
63
+ });
64
+
65
+ it('should return true for en_GB and europe', function () {
66
+ var result = region.hasLocale('europe', 'en_GB');
67
+ expect(result).to.equal(true);
68
+ });
69
+
70
+ it('should return true for en-GB and europe', function () {
71
+ var result = region.hasLocale('europe', 'en-GB');
72
+ expect(result).to.equal(true);
73
+ });
74
+ });
75
+
76
+ describe('#lookupTerritory', function () {
77
+
78
+ it('should throw an error for en_US', function () {
79
+ expect(function () {
80
+ region.lookupTerritory('en_US');
81
+ }).to.throw();
82
+ });
83
+
84
+ it('should return europe for GB', function () {
85
+ var result = region.lookupTerritory('GB');
86
+ expect(result).to.eql('europe');
87
+ });
88
+
89
+ it('should return "unsupported" for US', function () {
90
+ var result = region.lookupTerritory('US');
91
+ expect(result).to.eql('unsupported');
92
+ });
93
+ });
94
+
95
+ describe('#lookupLocale', function () {
96
+
97
+ it('should throw an error for US', function () {
98
+ expect(function () {
99
+ region.lookupLocale('US');
100
+ }).to.throw();
101
+ });
102
+
103
+ it('should return europe for en_GB', function () {
104
+ var result = region.lookupLocale('en_GB');
105
+ expect(result).to.eql('europe');
106
+ });
107
+
108
+ it('should return "unsupported" for en_US', function () {
109
+ var result = region.lookupLocale('en_US');
110
+ expect(result).to.eql('unsupported');
111
+ });
112
+ });
113
+ });