aboutsummaryrefslogtreecommitdiff
path: root/test/unit/specs/services/notification_utils/notification_utils.spec.js
blob: c44b8c9e0da916735451f3d04e4abec4d79fd5be (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
import * as NotificationUtils from 'src/services/notification_utils/notification_utils.js'

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

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