summary refs log tree commit diff
path: root/syweb/webclient/test/unit/notification-service.spec.js
blob: 4205ca09692cf476d83aa52d6338a4722d36f4c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
describe('NotificationService', function() {

    var userId = "@ali:matrix.org";
    var displayName = "Alice M";
    var bingWords = ["coffee","foo(.*)bar"]; // literal and wildcard

    beforeEach(function() {
        module('notificationService');
    });
    
    // User IDs
    
    it('should bing on a user ID.', inject(
    function(notificationService) {
        expect(notificationService.containsBingWord(userId, displayName, 
        bingWords, "Hello @ali:matrix.org, how are you?")).toEqual(true);
    }));
    
    it('should bing on a partial user ID.', inject(
    function(notificationService) {
        expect(notificationService.containsBingWord(userId, displayName, 
        bingWords, "Hello @ali, how are you?")).toEqual(true);
    }));
    
    it('should bing on a case-insensitive user ID.', inject(
    function(notificationService) {
        expect(notificationService.containsBingWord(userId, displayName, 
        bingWords, "Hello @AlI:matrix.org, how are you?")).toEqual(true);
    }));
    
    // Display names
    
    it('should bing on a display name.', inject(
    function(notificationService) {
        expect(notificationService.containsBingWord(userId, displayName, 
        bingWords, "Hello Alice M, how are you?")).toEqual(true);
    }));
    
    it('should bing on a case-insensitive display name.', inject(
    function(notificationService) {
        expect(notificationService.containsBingWord(userId, displayName, 
        bingWords, "Hello ALICE M, how are you?")).toEqual(true);
    }));
    
    // Bing words
    
    it('should bing on a bing word.', inject(
    function(notificationService) {
        expect(notificationService.containsBingWord(userId, displayName, 
        bingWords, "I really like coffee")).toEqual(true);
    }));
    
    it('should bing on case-insensitive bing words.', inject(
    function(notificationService) {
        expect(notificationService.containsBingWord(userId, displayName, 
        bingWords, "Coffee is great")).toEqual(true);
    }));
    
    it('should bing on wildcard (.*) bing words.', inject(
    function(notificationService) {
        expect(notificationService.containsBingWord(userId, displayName, 
        bingWords, "It was foomahbar I think.")).toEqual(true);
    }));
    
    // invalid
    
    it('should gracefully handle bad input.', inject(
    function(notificationService) {
        expect(notificationService.containsBingWord(userId, displayName, 
        bingWords, { "foo": "bar" })).toEqual(false);
    }));
    
    it('should gracefully handle just a user ID.', inject(
    function(notificationService) {
        expect(notificationService.containsBingWord(userId, undefined, 
        undefined, "Hello @ali:matrix.org, how are you?")).toEqual(true);
    }));
});