diff options
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/app/controllers/notice-controller-test.js | 67 | ||||
-rw-r--r-- | test/unit/app/nodeify-test.js | 49 | ||||
-rw-r--r-- | test/unit/migrations/033-test.js | 40 | ||||
-rw-r--r-- | test/unit/ui/app/actions.spec.js | 65 | ||||
-rw-r--r-- | test/unit/ui/app/reducers/app.spec.js | 9 | ||||
-rw-r--r-- | test/unit/ui/app/reducers/metamask.spec.js | 43 |
6 files changed, 104 insertions, 169 deletions
diff --git a/test/unit/app/controllers/notice-controller-test.js b/test/unit/app/controllers/notice-controller-test.js deleted file mode 100644 index 834c88f7b..000000000 --- a/test/unit/app/controllers/notice-controller-test.js +++ /dev/null @@ -1,67 +0,0 @@ -const assert = require('assert') -const NoticeController = require('../../../../app/scripts/notice-controller') - -describe('notice-controller', function () { - var noticeController - - beforeEach(function () { - noticeController = new NoticeController() - }) - - describe('notices', function () { - - 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('#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('#getNextUnreadNotice', 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.getNextUnreadNotice() - assert.equal(latestUnread.id, 1) - 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.getNextUnreadNotice() - assert.ok(!latestUnread) - done() - }) - }) - }) -}) diff --git a/test/unit/app/nodeify-test.js b/test/unit/app/nodeify-test.js index 938b76c68..fa5e49fb2 100644 --- a/test/unit/app/nodeify-test.js +++ b/test/unit/app/nodeify-test.js @@ -2,16 +2,16 @@ const assert = require('assert') const nodeify = require('../../../app/scripts/lib/nodeify') describe('nodeify', function () { - var obj = { + const obj = { foo: 'bar', promiseFunc: function (a) { - var solution = this.foo + a + const solution = this.foo + a return Promise.resolve(solution) }, } it('should retain original context', function (done) { - var nodified = nodeify(obj.promiseFunc, obj) + const nodified = nodeify(obj.promiseFunc, obj) nodified('baz', function (err, res) { if (!err) { assert.equal(res, 'barbaz') @@ -22,7 +22,7 @@ describe('nodeify', function () { }) }) - it('should allow the last argument to not be a function', function (done) { + it('no callback - should allow the last argument to not be a function', function (done) { const nodified = nodeify(obj.promiseFunc, obj) try { nodified('baz') @@ -31,4 +31,45 @@ describe('nodeify', function () { done(new Error('should not have thrown if the last argument is not a function')) } }) + + it('no callback - should asyncly throw an error if underlying function does', function (done) { + const nodified = nodeify(async () => { throw new Error('boom!') }, obj) + process.prependOnceListener('uncaughtException', function (err) { + assert.ok(err, 'got expected error') + assert.ok(err.message.includes('boom!'), 'got expected error message') + done() + }) + try { + nodified('baz') + } catch (err) { + done(new Error('should not have thrown an error synchronously')) + } + }) + + it('sync functions - returns value', function (done) { + const nodified = nodeify(() => 42) + try { + nodified((err, result) => { + if (err) return done(new Error(`should not have thrown any error: ${err.message}`)) + assert.equal(42, result, 'got expected result') + }) + done() + } catch (err) { + done(new Error(`should not have thrown any error: ${err.message}`)) + } + }) + + it('sync functions - handles errors', function (done) { + const nodified = nodeify(() => { throw new Error('boom!') }) + try { + nodified((err, result) => { + if (result) return done(new Error('should not have returned any result')) + assert.ok(err, 'got expected error') + assert.ok(err.message.includes('boom!'), 'got expected error message') + }) + done() + } catch (err) { + done(new Error(`should not have thrown any error: ${err.message}`)) + } + }) }) diff --git a/test/unit/migrations/033-test.js b/test/unit/migrations/033-test.js new file mode 100644 index 000000000..b111198fd --- /dev/null +++ b/test/unit/migrations/033-test.js @@ -0,0 +1,40 @@ +const assert = require('assert') +const migration33 = require('../../../app/scripts/migrations/033') + +describe('Migration to delete notice controller', () => { + const oldStorage = { + 'meta': {}, + 'data': { + 'NoticeController': { + 'noticesList': [ + { + id: 0, + read: false, + date: 'Thu Feb 09 2017', + title: 'Terms of Use', + body: 'notice body', + }, + { + id: 2, + read: false, + title: 'Privacy Notice', + body: 'notice body', + }, + { + id: 4, + read: false, + title: 'Phishing Warning', + body: 'notice body', + }, + ], + }, + }, + } + + it('removes notice controller from state', () => { + migration33.migrate(oldStorage) + .then(newStorage => { + assert.equal(newStorage.data.NoticeController, undefined) + }) + }) +}) diff --git a/test/unit/ui/app/actions.spec.js b/test/unit/ui/app/actions.spec.js index 46e94bb32..86c3f8aff 100644 --- a/test/unit/ui/app/actions.spec.js +++ b/test/unit/ui/app/actions.spec.js @@ -1031,52 +1031,6 @@ describe('Actions', () => { }) }) - describe('#markNoticeRead', () => { - let markNoticeReadSpy - const notice = { - id: 0, - read: false, - date: 'test date', - title: 'test title', - body: 'test body', - } - - beforeEach(() => { - markNoticeReadSpy = sinon.stub(background, 'markNoticeRead') - }) - - afterEach(() => { - markNoticeReadSpy.restore() - }) - - it('calls markNoticeRead in background', () => { - const store = mockStore() - - store.dispatch(actions.markNoticeRead(notice)) - .then(() => { - assert(markNoticeReadSpy.calledOnce) - }) - - }) - - it('errors when markNoticeRead in background throws', () => { - const store = mockStore() - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'HIDE_LOADING_INDICATION' }, - { type: 'DISPLAY_WARNING', value: 'error' }, - ] - markNoticeReadSpy.callsFake((notice, callback) => { - callback(new Error('error')) - }) - - store.dispatch(actions.markNoticeRead()) - .catch(() => { - assert.deepEqual(store.getActions(), expectedActions) - }) - }) - }) - describe('#setProviderType', () => { let setProviderTypeSpy let store @@ -1308,6 +1262,25 @@ describe('Actions', () => { }) }) + describe('#setCompletedOnboarding', () => { + let completeOnboardingSpy + + beforeEach(() => { + completeOnboardingSpy = sinon.stub(background, 'completeOnboarding') + completeOnboardingSpy.callsFake(cb => cb()) + }) + + after(() => { + completeOnboardingSpy.restore() + }) + + it('completes onboarding', async () => { + const store = mockStore() + await store.dispatch(actions.setCompletedOnboarding()) + assert.equal(completeOnboardingSpy.callCount, 1) + }) + }) + describe('#updateNetworkNonce', () => { let getTransactionCountSpy diff --git a/test/unit/ui/app/reducers/app.spec.js b/test/unit/ui/app/reducers/app.spec.js index 6c77e0ef9..09cf3dbf0 100644 --- a/test/unit/ui/app/reducers/app.spec.js +++ b/test/unit/ui/app/reducers/app.spec.js @@ -445,15 +445,6 @@ describe('App State', () => { assert.equal(state.forgottenPassword, false) }) - it('shows notice', () => { - const state = reduceApp(metamaskState, { - type: actions.SHOW_NOTICE, - }) - - assert.equal(state.transForward, true) - assert.equal(state.isLoading, false) - }) - it('reveals account', () => { const state = reduceApp(metamaskState, { type: actions.REVEAL_ACCOUNT, diff --git a/test/unit/ui/app/reducers/metamask.spec.js b/test/unit/ui/app/reducers/metamask.spec.js index 388c67c76..d7876bf39 100644 --- a/test/unit/ui/app/reducers/metamask.spec.js +++ b/test/unit/ui/app/reducers/metamask.spec.js @@ -35,49 +35,6 @@ describe('MetaMask Reducers', () => { assert.equal(state.isRevealingSeedWords, false) }) - it('shows notice', () => { - const notice = { - id: 0, - read: false, - date: 'Date', - title: 'Title', - body: 'Body', - } - - const state = reduceMetamask({}, { - type: actions.SHOW_NOTICE, - value: notice, - }) - - assert.equal(state.noActiveNotices, false) - assert.equal(state.nextUnreadNotice, notice) - }) - - it('clears notice', () => { - - const notice = { - id: 0, - read: false, - date: 'Date', - title: 'Title', - body: 'Body', - } - - const noticesState = { - metamask: { - noActiveNotices: false, - nextUnreadNotice: notice, - }, - } - - const state = reduceMetamask(noticesState, { - type: actions.CLEAR_NOTICES, - }) - - assert.equal(state.noActiveNotices, true) - assert.equal(state.nextUnreadNotice, null) - }) - it('unlocks MetaMask', () => { const state = reduceMetamask({}, { type: actions.UNLOCK_METAMASK, |