aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/app/controllers/notice-controller-test.js
blob: 5e6ae9ac508040a513758271ed3084bff46c1dbc (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
const assert = require('assert')
const NoticeController = require('../../../../app/scripts/notice-controller')

describe('notice-controller', function () {
  var noticeController

  beforeEach(function () {
    noticeController = new NoticeController({})
  })

  describe('notices', function () {

    describe('#setNoticesList', function () {
      it('should set data appropriately', function (done) {
        var testList = [{
          id: 0,
          read: false,
          title: 'Futuristic Notice',
        }]
        noticeController.setNoticesList(testList)
        var testListId = noticeController.getNoticesList()[0].id
        assert.equal(testListId, 0)
        done()
      })
    })

    describe('#markNoticeRead', function () {
      it('should mark a notice as read', function (done) {
        var testList = [{
          id: 0,
          read: false,
          title: 'Futuristic Notice',
        }]
        noticeController.setNoticesList(testList)
        noticeController.markNoticeRead(testList[0])
        var newList = noticeController.getNoticesList()
        assert.ok(newList[0].read)
        done()
      })
    })

    describe('#getNextUnreadNotice', function () {
      it('should retrieve the latest unread notice', function (done) {
        var testList = [
          {id: 0, read: true, title: 'Past Notice'},
          {id: 1, read: false, title: 'Current Notice'},
          {id: 2, read: false, title: 'Future Notice'},
        ]
        noticeController.setNoticesList(testList)
        var latestUnread = noticeController.getNextUnreadNotice()
        assert.equal(latestUnread.id, 1)
        done()
      })
      it('should return undefined if no unread notices exist.', function (done) {
        var testList = [
          {id: 0, read: true, title: 'Past Notice'},
          {id: 1, read: true, title: 'Current Notice'},
          {id: 2, read: true, title: 'Future Notice'},
        ]
        noticeController.setNoticesList(testList)
        var latestUnread = noticeController.getNextUnreadNotice()
        assert.ok(!latestUnread)
        done()
      })
    })
  })
})