Prechádzať zdrojové kódy

Add tests for MimeService

Danilo Bargen 8 rokov pred
rodič
commit
868f734f78
3 zmenil súbory, kde vykonal 37 pridanie a 0 odobranie
  1. 2 0
      karma.conf.js
  2. 33 0
      tests/service/mime.js
  3. 2 0
      tests/testsuite.html

+ 2 - 0
karma.conf.js

@@ -5,9 +5,11 @@ module.exports = function(config) {
         files: [
             'node_modules/angular/angular.js',
             'node_modules/angular-mocks/angular-mocks.js',
+            'node_modules/angular-translate/dist/angular-translate.min.js',
             'dist/app.js',
             'tests/filters.js',
             'tests/service/message.js',
+            'tests/service/mime.js',
             'tests/service/qrcode.js',
             'tests/service/uri.js',
             'tests/service/webclient.js',

+ 33 - 0
tests/service/mime.js

@@ -0,0 +1,33 @@
+describe('MimeService', function() {
+
+    let $service;
+
+    beforeAll(() => window.onbeforeunload = () => 'Ignoring page reload request');
+
+    beforeEach(function() {
+
+        module('pascalprecht.translate');
+        module('3ema.services');
+
+        // Inject the service
+        inject(function(MimeService) {
+            $service = MimeService;
+        });
+
+    });
+
+    it('getLabel', () => {
+        expect($service.getLabel('application/pdf')).toEqual('mimeTypes.pdf');
+        expect($service.getLabel('application/vnd.android.package-archive')).toEqual('mimeTypes.apk');
+        expect($service.getLabel('audio/mpeg3')).toEqual('mimeTypes.audio');
+        expect($service.getLabel('audio/x-mpeg-3')).toEqual('mimeTypes.audio');
+        expect($service.getLabel('audio/foobar')).toEqual('mimeTypes.audio');
+    });
+
+    it('getIcon', () => {
+        expect($service.getIconUrl('application/pdf')).toEqual('img/mime/ic_doc_pdf.png');
+        expect($service.getIconUrl('application/vnd.android.package-archive')).toEqual('img/mime/ic_doc_apk.png');
+        expect($service.getIconUrl('video/baz')).toEqual('img/mime/ic_doc_video.png');
+    });
+
+});

+ 2 - 0
tests/testsuite.html

@@ -13,11 +13,13 @@
 
         <script src="../node_modules/angular/angular.js"></script>
         <script src="../node_modules/angular-mocks/angular-mocks.js"></script>
+        <script src="../node_modules/angular-translate/dist/angular-translate.min.js"></script>
 
         <script src="../dist/app.js"></script>
 
         <script src="filters.js"></script>
         <script src="service/message.js"></script>
+        <script src="service/mime.js"></script>
         <script src="service/qrcode.js"></script>
         <script src="service/uri.js"></script>
         <script src="service/webclient.js"></script>