aboutsummaryrefslogtreecommitdiff
path: root/test/unit/specs/services/notification_utils/notification_utils.spec.js
blob: 60db7380c96d3abbf6d8819d8d8d3676335a779d (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import * as NotificationUtils from 'src/services/notification_utils/notification_utils.js'

describe('NotificationUtils', () => {
  describe('filteredNotificationsFromStore', () => {
    it('should return sorted notifications with configured types', () => {
      const store = {
        state: {
          notifications: {
            data: [
              {
                id: 1,
                action: { id: '1' },
                type: 'like'
              },
              {
                id: 2,
                action: { id: '2' },
                type: 'mention'
              },
              {
                id: 3,
                action: { id: '3' },
                type: 'repeat'
              }
            ]
          }
        },
        getters: {
          mergedConfig: {
            notificationVisibility: {
              likes: true,
              repeats: true,
              mentions: false
            }
          }
        }
      }
      const expected = [
        {
          action: { id: '3' },
          id: 3,
          type: 'repeat'
        },
        {
          action: { id: '1' },
          id: 1,
          type: 'like'
        }
      ]
      expect(NotificationUtils.filteredNotificationsFromStore(store)).to.eql(expected)
    })
  })

  describe('unseenNotificationsFromStore', () => {
    it('should return only notifications not marked as seen', () => {
      const store = {
        state: {
          notifications: {
            data: [
              {
                action: { id: '1' },
                type: 'like',
                seen: false
              },
              {
                action: { id: '2' },
                type: 'mention',
                seen: true
              }
            ]
          }
        },
        getters: {
          mergedConfig: {
            notificationVisibility: {
              likes: true,
              repeats: true,
              mentions: false
            }
          }
        }
      }
      const expected = [
        {
          action: { id: '1' },
          type: 'like',
          seen: false
        }
      ]
      expect(NotificationUtils.unseenNotificationsFromStore(store)).to.eql(expected)
    })
  })
})