aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-12-17 04:44:47 +0800
committerkumavis <aaron@kumavis.me>2016-12-17 04:44:47 +0800
commit73998feeb2b6ba4ebb9a16c6ed54cce195c09013 (patch)
tree35c3b7572bfb16b9a2e0f0492d99448cc1fb714f /test
parentff13f40d1fae3781426b9fb1d22b723e50952dd9 (diff)
downloadtangerine-wallet-browser-73998feeb2b6ba4ebb9a16c6ed54cce195c09013.tar
tangerine-wallet-browser-73998feeb2b6ba4ebb9a16c6ed54cce195c09013.tar.gz
tangerine-wallet-browser-73998feeb2b6ba4ebb9a16c6ed54cce195c09013.tar.bz2
tangerine-wallet-browser-73998feeb2b6ba4ebb9a16c6ed54cce195c09013.tar.lz
tangerine-wallet-browser-73998feeb2b6ba4ebb9a16c6ed54cce195c09013.tar.xz
tangerine-wallet-browser-73998feeb2b6ba4ebb9a16c6ed54cce195c09013.tar.zst
tangerine-wallet-browser-73998feeb2b6ba4ebb9a16c6ed54cce195c09013.zip
move notice code from metamask-controller + config-manager, in to notice-controller
Diffstat (limited to 'test')
-rw-r--r--test/unit/config-manager-test.js94
-rw-r--r--test/unit/notice-controller-test.js115
2 files changed, 115 insertions, 94 deletions
diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js
index 409a7b3f7..26aa35a74 100644
--- a/test/unit/config-manager-test.js
+++ b/test/unit/config-manager-test.js
@@ -13,100 +13,6 @@ describe('config-manager', function() {
configManager = configManagerGen()
})
- describe('notices', function() {
- describe('#getNoticesList', function() {
- it('should return an empty array when new', function() {
- var testList = [{
- id:0,
- read:false,
- title:"Futuristic Notice"
- }]
- var result = configManager.getNoticesList()
- assert.equal(result.length, 0)
- })
- })
-
- describe('#setNoticesList', function() {
- it('should set data appropriately', function () {
- var testList = [{
- id:0,
- read:false,
- title:"Futuristic Notice"
- }]
- configManager.setNoticesList(testList)
- var testListId = configManager.getNoticesList()[0].id
- assert.equal(testListId, 0)
- })
- })
-
- describe('#updateNoticeslist', function() {
- it('should integrate the latest changes from the source', function() {
- var testList = [{
- id:55,
- read:false,
- title:"Futuristic Notice"
- }]
- configManager.setNoticesList(testList)
- configManager.updateNoticesList().then(() => {
- var newList = configManager.getNoticesList()
- assert.ok(newList[0].id === 55)
- assert.ok(newList[1])
- })
- })
- it('should not overwrite any existing fields', function () {
- var testList = [{
- id:0,
- read:false,
- title:"Futuristic Notice"
- }]
- configManager.setNoticesList(testList)
- configManager.updateNoticesList().then(() => {
- var newList = configManager.getNoticesList()
- assert.equal(newList[0].id, 0)
- assert.equal(newList[0].title, "Futuristic Notice")
- assert.equal(newList.length, 1)
- })
- })
- })
-
- describe('#markNoticeRead', function () {
- it('should mark a notice as read', function () {
- var testList = [{
- id:0,
- read:false,
- title:"Futuristic Notice"
- }]
- configManager.setNoticesList(testList)
- configManager.markNoticeRead(testList[0])
- var newList = configManager.getNoticesList()
- assert.ok(newList[0].read)
- })
- })
-
- describe('#getLatestUnreadNotice', function () {
- it('should retrieve the latest unread notice', function () {
- var testList = [
- {id:0,read:true,title:"Past Notice"},
- {id:1,read:false,title:"Current Notice"},
- {id:2,read:false,title:"Future Notice"},
- ]
- configManager.setNoticesList(testList)
- var latestUnread = configManager.getLatestUnreadNotice()
- assert.equal(latestUnread.id, 2)
- })
- it('should return undefined if no unread notices exist.', function () {
- var testList = [
- {id:0,read:true,title:"Past Notice"},
- {id:1,read:true,title:"Current Notice"},
- {id:2,read:true,title:"Future Notice"},
- ]
- configManager.setNoticesList(testList)
- var latestUnread = configManager.getLatestUnreadNotice()
- assert.ok(!latestUnread)
- })
- })
- })
-
describe('currency conversions', function() {
describe('#getCurrentFiat', function() {
diff --git a/test/unit/notice-controller-test.js b/test/unit/notice-controller-test.js
new file mode 100644
index 000000000..4aa4c8e7b
--- /dev/null
+++ b/test/unit/notice-controller-test.js
@@ -0,0 +1,115 @@
+const assert = require('assert')
+const extend = require('xtend')
+const rp = require('request-promise')
+const nock = require('nock')
+const configManagerGen = require('../lib/mock-config-manager')
+const NoticeController = require('../../app/scripts/notice-controller')
+const STORAGE_KEY = 'metamask-persistance-key'
+// Hacking localStorage support into JSDom
+window.localStorage = {}
+
+describe('notice-controller', function() {
+ var noticeController
+
+ beforeEach(function() {
+ let configManager = configManagerGen()
+ noticeController = new NoticeController({
+ configManager: configManager,
+ })
+ })
+
+ describe('notices', function() {
+ describe('#getNoticesList', function() {
+ it('should return an empty array when new', function() {
+ var testList = [{
+ id:0,
+ read:false,
+ title:"Futuristic Notice"
+ }]
+ var result = noticeController.getNoticesList()
+ assert.equal(result.length, 0)
+ })
+ })
+
+ describe('#setNoticesList', function() {
+ it('should set data appropriately', function () {
+ var testList = [{
+ id:0,
+ read:false,
+ title:"Futuristic Notice"
+ }]
+ noticeController.setNoticesList(testList)
+ var testListId = noticeController.getNoticesList()[0].id
+ assert.equal(testListId, 0)
+ })
+ })
+
+ describe('#updateNoticeslist', function() {
+ it('should integrate the latest changes from the source', function() {
+ 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])
+ })
+ })
+ it('should not overwrite any existing fields', function () {
+ var testList = [{
+ id:0,
+ read:false,
+ title:"Futuristic Notice"
+ }]
+ noticeController.setNoticesList(testList)
+ noticeController.updateNoticesList().then(() => {
+ var newList = noticeController.getNoticesList()
+ assert.equal(newList[0].id, 0)
+ assert.equal(newList[0].title, "Futuristic Notice")
+ assert.equal(newList.length, 1)
+ })
+ })
+ })
+
+ describe('#markNoticeRead', function () {
+ it('should mark a notice as read', function () {
+ 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)
+ })
+ })
+
+ describe('#getLatestUnreadNotice', function () {
+ it('should retrieve the latest unread notice', function () {
+ 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)
+ })
+ it('should return undefined if no unread notices exist.', function () {
+ 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)
+ })
+ })
+ })
+
+})