2016-12-16 21:44:47 +01:00
|
|
|
const assert = require('assert')
|
|
|
|
const configManagerGen = require('../lib/mock-config-manager')
|
|
|
|
const NoticeController = require('../../app/scripts/notice-controller')
|
|
|
|
|
2017-05-04 23:35:10 +02:00
|
|
|
describe('notice-controller', function () {
|
2016-12-16 21:44:47 +01:00
|
|
|
var noticeController
|
|
|
|
|
2017-05-04 23:35:10 +02:00
|
|
|
beforeEach(function () {
|
2017-01-15 07:35:26 +01:00
|
|
|
// simple localStorage polyfill
|
2017-05-04 23:35:10 +02:00
|
|
|
const configManager = configManagerGen()
|
2016-12-16 21:44:47 +01:00
|
|
|
noticeController = new NoticeController({
|
|
|
|
configManager: configManager,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-05-04 23:35:10 +02:00
|
|
|
describe('notices', function () {
|
|
|
|
describe('#getNoticesList', function () {
|
|
|
|
it('should return an empty array when new', function (done) {
|
|
|
|
// const testList = [{
|
|
|
|
// id: 0,
|
|
|
|
// read: false,
|
|
|
|
// title: 'Futuristic Notice',
|
|
|
|
// }]
|
2016-12-16 21:44:47 +01:00
|
|
|
var result = noticeController.getNoticesList()
|
|
|
|
assert.equal(result.length, 0)
|
2017-03-31 04:26:01 +02:00
|
|
|
done()
|
2016-12-16 21:44:47 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
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) {
|
2016-12-16 21:44:47 +01:00
|
|
|
var testList = [{
|
2017-05-04 23:35:10 +02:00
|
|
|
id: 0,
|
|
|
|
read: false,
|
|
|
|
title: 'Futuristic Notice',
|
2016-12-16 21:44:47 +01:00
|
|
|
}]
|
|
|
|
noticeController.setNoticesList(testList)
|
|
|
|
var testListId = noticeController.getNoticesList()[0].id
|
|
|
|
assert.equal(testListId, 0)
|
2017-03-31 04:26:01 +02:00
|
|
|
done()
|
2016-12-16 21:44:47 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-05-04 23:35:10 +02:00
|
|
|
describe('#updateNoticeslist', function () {
|
|
|
|
it('should integrate the latest changes from the source', function (done) {
|
2016-12-16 21:44:47 +01:00
|
|
|
var testList = [{
|
2017-05-04 23:35:10 +02:00
|
|
|
id: 55,
|
|
|
|
read: false,
|
|
|
|
title: 'Futuristic Notice',
|
2016-12-16 21:44:47 +01:00
|
|
|
}]
|
|
|
|
noticeController.setNoticesList(testList)
|
|
|
|
noticeController.updateNoticesList().then(() => {
|
|
|
|
var newList = noticeController.getNoticesList()
|
|
|
|
assert.ok(newList[0].id === 55)
|
|
|
|
assert.ok(newList[1])
|
2017-03-31 04:26:01 +02:00
|
|
|
done()
|
2016-12-16 21:44:47 +01:00
|
|
|
})
|
|
|
|
})
|
2017-03-31 04:26:01 +02:00
|
|
|
it('should not overwrite any existing fields', function (done) {
|
2016-12-16 21:44:47 +01:00
|
|
|
var testList = [{
|
2017-05-04 23:35:10 +02:00
|
|
|
id: 0,
|
|
|
|
read: false,
|
|
|
|
title: 'Futuristic Notice',
|
2016-12-16 21:44:47 +01:00
|
|
|
}]
|
|
|
|
noticeController.setNoticesList(testList)
|
2017-03-31 04:26:01 +02:00
|
|
|
var newList = noticeController.getNoticesList()
|
|
|
|
assert.equal(newList[0].id, 0)
|
2017-05-04 23:35:10 +02:00
|
|
|
assert.equal(newList[0].title, 'Futuristic Notice')
|
2017-03-31 04:26:01 +02:00
|
|
|
assert.equal(newList.length, 1)
|
|
|
|
done()
|
2016-12-16 21:44:47 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('#markNoticeRead', function () {
|
2017-03-31 04:26:01 +02:00
|
|
|
it('should mark a notice as read', function (done) {
|
2016-12-16 21:44:47 +01:00
|
|
|
var testList = [{
|
2017-05-04 23:35:10 +02:00
|
|
|
id: 0,
|
|
|
|
read: false,
|
|
|
|
title: 'Futuristic Notice',
|
2016-12-16 21:44:47 +01:00
|
|
|
}]
|
|
|
|
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()
|
2016-12-16 21:44:47 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('#getLatestUnreadNotice', function () {
|
2017-03-31 04:26:01 +02:00
|
|
|
it('should retrieve the latest unread notice', function (done) {
|
2016-12-16 21:44:47 +01:00
|
|
|
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'},
|
2016-12-16 21:44:47 +01:00
|
|
|
]
|
|
|
|
noticeController.setNoticesList(testList)
|
|
|
|
var latestUnread = noticeController.getLatestUnreadNotice()
|
|
|
|
assert.equal(latestUnread.id, 2)
|
2017-03-31 04:26:01 +02:00
|
|
|
done()
|
2016-12-16 21:44:47 +01:00
|
|
|
})
|
2017-03-31 04:26:01 +02:00
|
|
|
it('should return undefined if no unread notices exist.', function (done) {
|
2016-12-16 21:44:47 +01:00
|
|
|
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'},
|
2016-12-16 21:44:47 +01:00
|
|
|
]
|
|
|
|
noticeController.setNoticesList(testList)
|
|
|
|
var latestUnread = noticeController.getLatestUnreadNotice()
|
|
|
|
assert.ok(!latestUnread)
|
2017-03-31 04:26:01 +02:00
|
|
|
done()
|
2016-12-16 21:44:47 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|