Prechádzať zdrojové kódy

Inject common constants of unit tests in init.js

Lennart Grahl 6 rokov pred
rodič
commit
44d8e490d6

+ 6 - 1
tests/bootstrap.ts

@@ -18,8 +18,13 @@
  */
 
 // tslint:disable:no-console
+import config from '../src/config';
 
 // A dependency graph that contains any wasm must all be imported asynchronously.
 import('../src/app')
-    .then(() => console.info('Bundle loaded'))
+    .then(() => {
+        // @ts-ignore
+        window.config = config;
+        console.info('Bundle loaded')
+    })
     .catch((e) => console.error('Could not load bundle', e));

+ 1 - 1
tests/filters.js

@@ -50,7 +50,7 @@ describe('Filters', function() {
         module('3ema.services');
         module('3ema.filters');
 
-        module(function($provide) {
+        module(($provide) => {
             $provide.value('WebClientService', webClientServiceMock);
             $provide.value('$translate', translationMock);
             $provide.constant('$state', null);

+ 12 - 0
tests/init.js

@@ -1,5 +1,17 @@
 // Wait for main application to be fully loaded
 beforeAll((done) => setTimeout(done, 1000));
 
+// Inject common constants
+beforeEach(function() {
+    module(($provide) => {
+        // Provide configuration
+        $provide.constant('CONFIG', window.config);
+
+        // Mock versions
+        $provide.constant('PROTOCOL_VERSION', 1337);
+        $provide.constant('VERSION', 42);
+    });
+});
+
 // Uninstall the mock clock after every test
 afterEach(() => jasmine.clock().uninstall());

+ 1 - 1
tests/service/browser.js

@@ -14,7 +14,7 @@ describe('BrowserService', function() {
     function testUserAgent(agent) {
         let $service;
         module('3ema.services');
-        module(function($provide) {
+        module(($provide) => {
             $provide.value('$window', {
                 navigator: { userAgent: agent }
             });

+ 0 - 9
tests/service/keystore.js

@@ -8,14 +8,6 @@ describe('TrustedKeyStoreService', function() {
     beforeAll(() => window.onbeforeunload = () => null);
 
     beforeEach(function() {
-
-        module(($provide) => {
-            $provide.constant('PROTOCOL_VERSION', 1337);
-            $provide.constant('CONFIG', {
-                'SELF_HOSTED': false,
-            });
-        });
-
         module('3ema.services');
 
         // Inject the service
@@ -24,7 +16,6 @@ describe('TrustedKeyStoreService', function() {
             foo = $service;
             $service.STORAGE_KEY = STORAGE_KEY;
         });
-
     });
 
     it('localstorage is not blocked', () => {

+ 0 - 9
tests/service/message.js

@@ -6,14 +6,6 @@ describe('MessageService', function() {
     beforeAll(() => window.onbeforeunload = () => null);
 
     beforeEach(function() {
-
-        // Inject constants
-        module(($provide) => {
-            $provide.constant('CONFIG', {
-                'DEBUG': true,
-            });
-        });
-
         // Load threema services
         module('3ema.services');
 
@@ -21,7 +13,6 @@ describe('MessageService', function() {
         inject(function(MessageService) {
             messageService = MessageService;
         });
-
     });
 
     describe ('getAccess', () => {

+ 0 - 2
tests/service/mime.js

@@ -6,7 +6,6 @@ describe('MimeService', function() {
     beforeAll(() => window.onbeforeunload = () => null);
 
     beforeEach(function() {
-
         module('pascalprecht.translate');
         module('3ema.services');
 
@@ -14,7 +13,6 @@ describe('MimeService', function() {
         inject(function(MimeService) {
             $service = MimeService;
         });
-
     });
 
     it('getLabel', () => {

+ 0 - 1
tests/service/notification.js

@@ -16,7 +16,6 @@ describe('NotificationService', function() {
         inject(function(NotificationService) {
             $service = NotificationService;
         });
-
     });
 
     describe('getAppNotificationSettings', function () {

+ 0 - 9
tests/service/qrcode.js

@@ -6,21 +6,12 @@ describe('QrCodeService', function() {
     beforeAll(() => window.onbeforeunload = () => null);
 
     beforeEach(function() {
-
-        module(($provide) => {
-            $provide.constant('PROTOCOL_VERSION', 1337);
-            $provide.constant('CONFIG', {
-                'SELF_HOSTED': false,
-            });
-        });
-
         module('3ema.services');
 
         // Inject the service
         inject(function(QrCodeService) {
             $service = QrCodeService;
         });
-
     });
 
     it('generates correct payload', () => {

+ 0 - 2
tests/service/receiver.js

@@ -6,14 +6,12 @@ describe('ReceiverService', function () {
     beforeAll(() => window.onbeforeunload = () => null);
 
     beforeEach(function () {
-
         module('3ema.services');
 
         // Inject the service
         inject(function (ReceiverService) {
             $service = ReceiverService;
         });
-
     });
 
     describe('Receiver', () => {

+ 0 - 2
tests/service/string.js

@@ -6,14 +6,12 @@ describe('StringService', function() {
     beforeAll(() => window.onbeforeunload = () => null);
 
     beforeEach(function() {
-
         module('3ema.services');
 
         // Inject the service
         inject(function(StringService) {
             $service = StringService;
         });
-
     });
 
     describe('byteChunkSplit', function() {

+ 0 - 2
tests/service/uri.js

@@ -6,14 +6,12 @@ describe('UriService', function() {
     beforeAll(() => window.onbeforeunload = () => null);
 
     beforeEach(function() {
-
         module('3ema.services');
 
         // Inject the service
         inject(function(UriService) {
             $service = UriService;
         });
-
     });
 
     it('parses query parameters', () => {