You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
3.6 KiB
115 lines
3.6 KiB
8 years ago
|
const assert = require('assert')
|
||
7 years ago
|
const configManagerGen = require('../../../lib/mock-config-manager')
|
||
|
const NoticeController = require('../../../../app/scripts/notice-controller')
|
||
8 years ago
|
|
||
8 years ago
|
describe('notice-controller', function () {
|
||
8 years ago
|
var noticeController
|
||
|
|
||
8 years ago
|
beforeEach(function () {
|
||
8 years ago
|
// simple localStorage polyfill
|
||
8 years ago
|
const configManager = configManagerGen()
|
||
8 years ago
|
noticeController = new NoticeController({
|
||
|
configManager: configManager,
|
||
|
})
|
||
|
})
|
||
|
|
||
8 years ago
|
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',
|
||
|
// }]
|
||
8 years ago
|
var result = noticeController.getNoticesList()
|
||
|
assert.equal(result.length, 0)
|
||
8 years ago
|
done()
|
||
8 years ago
|
})
|
||
|
})
|
||
|
|
||
8 years ago
|
describe('#setNoticesList', function () {
|
||
8 years ago
|
it('should set data appropriately', function (done) {
|
||
8 years ago
|
var testList = [{
|
||
8 years ago
|
id: 0,
|
||
|
read: false,
|
||
|
title: 'Futuristic Notice',
|
||
8 years ago
|
}]
|
||
|
noticeController.setNoticesList(testList)
|
||
|
var testListId = noticeController.getNoticesList()[0].id
|
||
|
assert.equal(testListId, 0)
|
||
8 years ago
|
done()
|
||
8 years ago
|
})
|
||
|
})
|
||
|
|
||
8 years ago
|
describe('#updateNoticeslist', function () {
|
||
|
it('should integrate the latest changes from the source', function (done) {
|
||
8 years ago
|
var testList = [{
|
||
8 years ago
|
id: 55,
|
||
|
read: false,
|
||
|
title: 'Futuristic Notice',
|
||
8 years ago
|
}]
|
||
|
noticeController.setNoticesList(testList)
|
||
|
noticeController.updateNoticesList().then(() => {
|
||
|
var newList = noticeController.getNoticesList()
|
||
|
assert.ok(newList[0].id === 55)
|
||
|
assert.ok(newList[1])
|
||
8 years ago
|
done()
|
||
8 years ago
|
})
|
||
|
})
|
||
8 years ago
|
it('should not overwrite any existing fields', function (done) {
|
||
8 years ago
|
var testList = [{
|
||
8 years ago
|
id: 0,
|
||
|
read: false,
|
||
|
title: 'Futuristic Notice',
|
||
8 years ago
|
}]
|
||
|
noticeController.setNoticesList(testList)
|
||
8 years ago
|
var newList = noticeController.getNoticesList()
|
||
|
assert.equal(newList[0].id, 0)
|
||
8 years ago
|
assert.equal(newList[0].title, 'Futuristic Notice')
|
||
8 years ago
|
assert.equal(newList.length, 1)
|
||
|
done()
|
||
8 years ago
|
})
|
||
|
})
|
||
|
|
||
|
describe('#markNoticeRead', function () {
|
||
8 years ago
|
it('should mark a notice as read', function (done) {
|
||
8 years ago
|
var testList = [{
|
||
8 years ago
|
id: 0,
|
||
|
read: false,
|
||
|
title: 'Futuristic Notice',
|
||
8 years ago
|
}]
|
||
|
noticeController.setNoticesList(testList)
|
||
|
noticeController.markNoticeRead(testList[0])
|
||
|
var newList = noticeController.getNoticesList()
|
||
|
assert.ok(newList[0].read)
|
||
8 years ago
|
done()
|
||
8 years ago
|
})
|
||
|
})
|
||
|
|
||
|
describe('#getLatestUnreadNotice', function () {
|
||
8 years ago
|
it('should retrieve the latest unread notice', function (done) {
|
||
8 years ago
|
var testList = [
|
||
8 years ago
|
{id: 0, read: true, title: 'Past Notice'},
|
||
|
{id: 1, read: false, title: 'Current Notice'},
|
||
|
{id: 2, read: false, title: 'Future Notice'},
|
||
8 years ago
|
]
|
||
|
noticeController.setNoticesList(testList)
|
||
|
var latestUnread = noticeController.getLatestUnreadNotice()
|
||
|
assert.equal(latestUnread.id, 2)
|
||
8 years ago
|
done()
|
||
8 years ago
|
})
|
||
8 years ago
|
it('should return undefined if no unread notices exist.', function (done) {
|
||
8 years ago
|
var testList = [
|
||
8 years ago
|
{id: 0, read: true, title: 'Past Notice'},
|
||
|
{id: 1, read: true, title: 'Current Notice'},
|
||
|
{id: 2, read: true, title: 'Future Notice'},
|
||
8 years ago
|
]
|
||
|
noticeController.setNoticesList(testList)
|
||
|
var latestUnread = noticeController.getLatestUnreadNotice()
|
||
|
assert.ok(!latestUnread)
|
||
8 years ago
|
done()
|
||
8 years ago
|
})
|
||
|
})
|
||
|
})
|
||
|
})
|