1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 02:58:09 +01:00
metamask-extension/test/unit/app/controllers/notice-controller-test.js

68 lines
2.1 KiB
JavaScript
Raw Normal View History

const assert = require('assert')
const NoticeController = require('../../../../app/scripts/notice-controller')
2017-05-04 23:35:10 +02:00
describe('notice-controller', function () {
var noticeController
2017-05-04 23:35:10 +02:00
beforeEach(function () {
noticeController = new NoticeController({})
})
2017-05-04 23:35:10 +02:00
describe('notices', function () {
2017-05-04 23:35:10 +02:00
describe('#setNoticesList', function () {
2017-03-31 04:26:01 +02:00
it('should set data appropriately', function (done) {
var testList = [{
2017-05-04 23:35:10 +02:00
id: 0,
read: false,
title: 'Futuristic Notice',
}]
noticeController.setNoticesList(testList)
var testListId = noticeController.getNoticesList()[0].id
assert.equal(testListId, 0)
2017-03-31 04:26:01 +02:00
done()
})
})
describe('#markNoticeRead', function () {
2017-03-31 04:26:01 +02:00
it('should mark a notice as read', function (done) {
var testList = [{
2017-05-04 23:35:10 +02:00
id: 0,
read: false,
title: 'Futuristic Notice',
}]
noticeController.setNoticesList(testList)
noticeController.markNoticeRead(testList[0])
var newList = noticeController.getNoticesList()
assert.ok(newList[0].read)
2017-03-31 04:26:01 +02:00
done()
})
})
describe('#getNextUnreadNotice', function () {
2017-03-31 04:26:01 +02:00
it('should retrieve the latest unread notice', function (done) {
var testList = [
2017-05-04 23:35:10 +02:00
{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)
2017-03-31 04:26:01 +02:00
done()
})
2017-03-31 04:26:01 +02:00
it('should return undefined if no unread notices exist.', function (done) {
var testList = [
2017-05-04 23:35:10 +02:00
{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)
2017-03-31 04:26:01 +02:00
done()
})
})
})
})