Преглед изворни кода

Move getDndModeSimplified function to NotificationService

Danilo Bargen пре 7 година
родитељ
комит
a177e9bfe2
4 измењених фајлова са 102 додато и 94 уклоњено
  1. 1 5
      src/partials/messenger.ts
  2. 14 0
      src/services/notification.ts
  3. 0 89
      tests/filters.js
  4. 87 0
      tests/service/notification.js

+ 1 - 5
src/partials/messenger.ts

@@ -1079,11 +1079,7 @@ class NavigationController {
      * The 'until' mode will be processed depending on the expiration timestamp.
      */
     public dndModeSimplified(conversation: threema.Conversation): 'on' | 'mention' | 'off' {
-        const simplified = this.notificationService.getAppNotificationSettings(conversation);
-        if (simplified.dnd.enabled) {
-            return simplified.dnd.mentionOnly ? 'mention' : 'on';
-        }
-        return 'off';
+        return this.notificationService.getDndModeSimplified(conversation);
     }
 
 }

+ 14 - 0
src/services/notification.ts

@@ -298,6 +298,20 @@ export class NotificationService {
         };
     }
 
+    /**
+     * Return a simplified DND mode.
+     *
+     * This will return either 'on', 'off' or 'mention'.
+     * The 'until' mode will be processed depending on the expiration timestamp.
+     */
+    public getDndModeSimplified(conversation: threema.Conversation): 'on' | 'mention' | 'off' {
+        const simplified = this.getAppNotificationSettings(conversation);
+        if (simplified.dnd.enabled) {
+            return simplified.dnd.mentionOnly ? 'mention' : 'on';
+        }
+        return 'off';
+    }
+
     /**
      * Notify the user via Desktop Notification API.
      *

+ 0 - 89
tests/filters.js

@@ -291,95 +291,6 @@ describe('Filters', function() {
         });
     });
 
-    describe('dndModeSimplified', function() {
-        let process = (dnd, sound) => {
-            return $filter('dndModeSimplified')({
-                notifications: {
-                    dnd: dnd,
-                    sound: sound,
-                },
-            })
-        };
-
-        it('dnd enabled', () => {
-            expect(process(
-                {mode: 'on'},
-                {mode: 'default'}
-            )).toEqual('on');
-        });
-
-        it('dnd enabled (no sound)', () => {
-            expect(process(
-                {mode: 'on'},
-                {mode: 'muted'}
-            )).toEqual('on');
-        });
-
-        it('dnd disabled', () => {
-            expect(process(
-                {mode: 'off'},
-                {mode: 'default'}
-            )).toEqual('off');
-        });
-
-        it('dnd disabled (no sound)', () => {
-            expect(process(
-                {mode: 'off'},
-                {mode: 'muted'}
-            )).toEqual('off');
-        });
-
-        it('mention only', () => {
-            expect(process(
-                {mode: 'on', mentionOnly: true},
-                {mode: 'default'}
-            )).toEqual('mention');
-        });
-
-        it('mention only (no sound)', () => {
-            expect(process(
-                {mode: 'on', mentionOnly: true},
-                {mode: 'muted'}
-            )).toEqual('mention');
-        });
-
-        it('until (not expired)', () => {
-            jasmine.clock().install();
-            jasmine.clock().mockDate(new Date(2018, 9, 9, 20, 42));
-            expect(process(
-                {mode: 'until', until: +(new Date(2018, 9, 9, 20, 50))},
-                {mode: 'default'}
-            )).toEqual('on');
-        });
-
-        it('until (expired)', () => {
-            jasmine.clock().install();
-            jasmine.clock().mockDate(new Date(2018, 9, 9, 20, 42));
-            expect(process(
-                {mode: 'until', until: +(new Date(2018, 9, 9, 19, 50))},
-                {mode: 'default'}
-            )).toEqual('off');
-        });
-
-        it('until (mention only, not expired)', () => {
-            jasmine.clock().install();
-            jasmine.clock().mockDate(new Date(2018, 9, 9, 20, 42));
-            expect(process(
-                {mode: 'until', until: +(new Date(2018, 9, 9, 20, 50)), mentionOnly: true},
-                {mode: 'default'}
-            )).toEqual('mention');
-        });
-
-        it('until (mention only, expired)', () => {
-            jasmine.clock().install();
-            jasmine.clock().mockDate(new Date(2018, 9, 9, 20, 42));
-            expect(process(
-                {mode: 'until', until: +(new Date(2018, 9, 9, 19, 50)), mentionOnly: true},
-                {mode: 'default'}
-            )).toEqual('off');
-        });
-    });
-
     describe('enlargeSingleEmoji', function() {
         let process = (text) => {
             return $filter('enlargeSingleEmoji')(text, true)

+ 87 - 0
tests/service/notification.js

@@ -125,4 +125,91 @@ describe('NotificationService', function() {
         });
     });
 
+    describe('getDndModeSimplified', function() {
+        let process = (dnd, sound) => {
+            return $service.getDndModeSimplified({
+                notifications: {dnd: dnd, sound: sound},
+            })
+        };
+
+        it('dnd enabled', () => {
+            expect(process(
+                {mode: 'on'},
+                {mode: 'default'}
+            )).toEqual('on');
+        });
+
+        it('dnd enabled (no sound)', () => {
+            expect(process(
+                {mode: 'on'},
+                {mode: 'muted'}
+            )).toEqual('on');
+        });
+
+        it('dnd disabled', () => {
+            expect(process(
+                {mode: 'off'},
+                {mode: 'default'}
+            )).toEqual('off');
+        });
+
+        it('dnd disabled (no sound)', () => {
+            expect(process(
+                {mode: 'off'},
+                {mode: 'muted'}
+            )).toEqual('off');
+        });
+
+        it('mention only', () => {
+            expect(process(
+                {mode: 'on', mentionOnly: true},
+                {mode: 'default'}
+            )).toEqual('mention');
+        });
+
+        it('mention only (no sound)', () => {
+            expect(process(
+                {mode: 'on', mentionOnly: true},
+                {mode: 'muted'}
+            )).toEqual('mention');
+        });
+
+        it('until (not expired)', () => {
+            jasmine.clock().install();
+            jasmine.clock().mockDate(new Date(2018, 9, 9, 20, 42));
+            expect(process(
+                {mode: 'until', until: +(new Date(2018, 9, 9, 20, 50))},
+                {mode: 'default'}
+            )).toEqual('on');
+        });
+
+        it('until (expired)', () => {
+            jasmine.clock().install();
+            jasmine.clock().mockDate(new Date(2018, 9, 9, 20, 42));
+            expect(process(
+                {mode: 'until', until: +(new Date(2018, 9, 9, 19, 50))},
+                {mode: 'default'}
+            )).toEqual('off');
+        });
+
+        it('until (mention only, not expired)', () => {
+            jasmine.clock().install();
+            jasmine.clock().mockDate(new Date(2018, 9, 9, 20, 42));
+            expect(process(
+                {mode: 'until', until: +(new Date(2018, 9, 9, 20, 50)), mentionOnly: true},
+                {mode: 'default'}
+            )).toEqual('mention');
+        });
+
+        it('until (mention only, expired)', () => {
+            jasmine.clock().install();
+            jasmine.clock().mockDate(new Date(2018, 9, 9, 20, 42));
+            expect(process(
+                {mode: 'until', until: +(new Date(2018, 9, 9, 19, 50)), mentionOnly: true},
+                {mode: 'default'}
+            )).toEqual('off');
+        });
+    });
+
+
 });