aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/app/controllers/notice-controller-test.js
diff options
context:
space:
mode:
authorThomas Huang <tmashuang@users.noreply.github.com>2018-05-31 07:04:02 +0800
committerGitHub <noreply@github.com>2018-05-31 07:04:02 +0800
commitdc5477be3cc62dff912a9447c702edab66200f02 (patch)
tree4c4c4293bfbc2a80812d231af9c7e22877cebfbd /test/unit/app/controllers/notice-controller-test.js
parent5fc24930a7febd919ec6a8f6e9c14f2bac0ef2b2 (diff)
parente59f606adb65de85484b0fb258980543967ee5e1 (diff)
downloadtangerine-wallet-browser-dc5477be3cc62dff912a9447c702edab66200f02.tar
tangerine-wallet-browser-dc5477be3cc62dff912a9447c702edab66200f02.tar.gz
tangerine-wallet-browser-dc5477be3cc62dff912a9447c702edab66200f02.tar.bz2
tangerine-wallet-browser-dc5477be3cc62dff912a9447c702edab66200f02.tar.lz
tangerine-wallet-browser-dc5477be3cc62dff912a9447c702edab66200f02.tar.xz
tangerine-wallet-browser-dc5477be3cc62dff912a9447c702edab66200f02.tar.zst
tangerine-wallet-browser-dc5477be3cc62dff912a9447c702edab66200f02.zip
Merge pull request #4408 from MetaMask/v4.7.0rc2
Version 4.7.0 - rc2
Diffstat (limited to 'test/unit/app/controllers/notice-controller-test.js')
-rw-r--r--test/unit/app/controllers/notice-controller-test.js114
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()
+ })
+ })
+ })
+})