diff options
author | tmashuang <thomas.b.huang@gmail.com> | 2018-05-21 20:59:26 +0800 |
---|---|---|
committer | tmashuang <thomas.b.huang@gmail.com> | 2018-05-21 20:59:26 +0800 |
commit | 13ebb0b455bc775a53b6bb30e675a39d02d8f6f5 (patch) | |
tree | 8e746281051ff1f75b948d89e1053c8da2ffc2cd /test/unit/app/controllers/notice-controller-test.js | |
parent | f279a8e61a3f50326fe9f26b0b860af47cd662fb (diff) | |
download | tangerine-wallet-browser-13ebb0b455bc775a53b6bb30e675a39d02d8f6f5.tar tangerine-wallet-browser-13ebb0b455bc775a53b6bb30e675a39d02d8f6f5.tar.gz tangerine-wallet-browser-13ebb0b455bc775a53b6bb30e675a39d02d8f6f5.tar.bz2 tangerine-wallet-browser-13ebb0b455bc775a53b6bb30e675a39d02d8f6f5.tar.lz tangerine-wallet-browser-13ebb0b455bc775a53b6bb30e675a39d02d8f6f5.tar.xz tangerine-wallet-browser-13ebb0b455bc775a53b6bb30e675a39d02d8f6f5.tar.zst tangerine-wallet-browser-13ebb0b455bc775a53b6bb30e675a39d02d8f6f5.zip |
Moved loose some loose test files to sub folders
Diffstat (limited to 'test/unit/app/controllers/notice-controller-test.js')
-rw-r--r-- | test/unit/app/controllers/notice-controller-test.js | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/test/unit/app/controllers/notice-controller-test.js b/test/unit/app/controllers/notice-controller-test.js new file mode 100644 index 000000000..e78b69623 --- /dev/null +++ b/test/unit/app/controllers/notice-controller-test.js @@ -0,0 +1,114 @@ +const assert = require('assert') +const configManagerGen = require('../../../lib/mock-config-manager') +const NoticeController = require('../../../../app/scripts/notice-controller') + +describe('notice-controller', function () { + var noticeController + + beforeEach(function () { + // simple localStorage polyfill + const configManager = configManagerGen() + noticeController = new NoticeController({ + configManager: configManager, + }) + }) + + 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', + // }] + var result = noticeController.getNoticesList() + assert.equal(result.length, 0) + done() + }) + }) + + 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('#updateNoticeslist', function () { + it('should integrate the latest changes from the source', function (done) { + var testList = [{ + id: 55, + read: false, + title: 'Futuristic Notice', + }] + noticeController.setNoticesList(testList) + noticeController.updateNoticesList().then(() => { + var newList = noticeController.getNoticesList() + assert.ok(newList[0].id === 55) + assert.ok(newList[1]) + done() + }) + }) + it('should not overwrite any existing fields', function (done) { + var testList = [{ + id: 0, + read: false, + title: 'Futuristic Notice', + }] + noticeController.setNoticesList(testList) + var newList = noticeController.getNoticesList() + assert.equal(newList[0].id, 0) + assert.equal(newList[0].title, 'Futuristic Notice') + assert.equal(newList.length, 1) + 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('#getLatestUnreadNotice', 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.getLatestUnreadNotice() + assert.equal(latestUnread.id, 2) + 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.getLatestUnreadNotice() + assert.ok(!latestUnread) + done() + }) + }) + }) +}) |