summary refs log tree commit diff
path: root/syweb/webclient/test/unit
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2014-11-05 15:32:35 +0000
committerKegan Dougal <kegan@matrix.org>2014-11-05 15:32:35 +0000
commit6aba43f6cc2350f0fce3eb15c4bdd38d7a9c17f6 (patch)
tree41e8cfd2beabeddbd29125b503582b4497ddba4c /syweb/webclient/test/unit
parentFinish matrixService unit tests. Add missing encodeURIComponent to path args. (diff)
downloadsynapse-6aba43f6cc2350f0fce3eb15c4bdd38d7a9c17f6.tar.xz
Add a few eventHandlerService tests.
Diffstat (limited to 'syweb/webclient/test/unit')
-rw-r--r--syweb/webclient/test/unit/event-handler-service.spec.js105
1 files changed, 105 insertions, 0 deletions
diff --git a/syweb/webclient/test/unit/event-handler-service.spec.js b/syweb/webclient/test/unit/event-handler-service.spec.js
new file mode 100644
index 0000000000..023abec98b
--- /dev/null
+++ b/syweb/webclient/test/unit/event-handler-service.spec.js
@@ -0,0 +1,105 @@
+describe('EventHandlerService', function() {
+    var scope;
+    
+    var modelService = {};
+
+    // setup the service and mocked dependencies
+    beforeEach(function() {
+        // dependencies
+        module('matrixService');
+        module('notificationService');
+        module('mPresence');
+        
+        // cleanup mocked methods
+        modelService = {};
+        
+        // mocked dependencies
+        module(function ($provide) {
+          $provide.value('modelService', modelService);
+        });
+        
+        // tested service
+        module('eventHandlerService');
+    });
+    
+    beforeEach(inject(function($rootScope) {
+        scope = $rootScope;
+    }));
+
+    it('should be able to get the number of joined users in a room', inject(
+    function(eventHandlerService) {
+        var roomId = "!foo:matrix.org";
+        // set mocked data
+        modelService.getRoom = function(roomId) {
+            return {
+                room_id: roomId,
+                current_room_state: {
+                    members: {
+                        "@adam:matrix.org": {
+                            content: { membership: "join" },
+                            user_id: "@adam:matrix.org"
+                        },
+                        "@beth:matrix.org": {
+                            content: { membership: "invite" },
+                            user_id: "@beth:matrix.org"
+                        },
+                        "@charlie:matrix.org": {
+                            content: { membership: "join" },
+                            user_id: "@charlie:matrix.org"
+                        },
+                        "@danice:matrix.org": {
+                            content: { membership: "leave" },
+                            user_id: "@danice:matrix.org"
+                        }
+                    }
+                }
+            };
+        }
+        
+        var num = eventHandlerService.getUsersCountInRoom(roomId);
+        expect(num).toEqual(2);
+    }));
+    
+    it('should be able to get a users power level', inject(
+    function(eventHandlerService) {
+        var roomId = "!foo:matrix.org";
+        // set mocked data
+        modelService.getRoom = function(roomId) {
+            return {
+                room_id: roomId,
+                current_room_state: {
+                    members: {
+                        "@adam:matrix.org": {
+                            content: { membership: "join" },
+                            user_id: "@adam:matrix.org"
+                        },
+                        "@beth:matrix.org": {
+                            content: { membership: "join" },
+                            user_id: "@beth:matrix.org"
+                        }
+                    },
+                    s: {
+                        "m.room.power_levels": {
+                            content: {
+                                "@adam:matrix.org": 90,
+                                "default": 50
+                            }
+                        }
+                    },
+                    state: function(type, key) { 
+                        return key ? this.s[type+key] : this.s[type]
+                    }
+                }
+            };
+        };
+        
+        var num = eventHandlerService.getUserPowerLevel(roomId, "@beth:matrix.org");
+        expect(num).toEqual(50);
+        
+        num = eventHandlerService.getUserPowerLevel(roomId, "@adam:matrix.org");
+        expect(num).toEqual(90);
+        
+        num = eventHandlerService.getUserPowerLevel(roomId, "@unknown:matrix.org");
+        expect(num).toEqual(50);
+    }));
+});
\ No newline at end of file