From c43374a553c28459be4cac116a72a4f34dddba72 Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Wed, 20 Mar 2019 20:26:48 -0500 Subject: Clear notices when setCompletedOnboarding is called --- .../unit/app/controllers/notice-controller-test.js | 26 ++++++++++++++++++++++ test/unit/ui/app/actions.spec.js | 24 ++++++++++++++++++++ 2 files changed, 50 insertions(+) (limited to 'test') diff --git a/test/unit/app/controllers/notice-controller-test.js b/test/unit/app/controllers/notice-controller-test.js index 834c88f7b..95e3ea9bd 100644 --- a/test/unit/app/controllers/notice-controller-test.js +++ b/test/unit/app/controllers/notice-controller-test.js @@ -39,6 +39,32 @@ describe('notice-controller', function () { }) }) + describe('#markAllNoticesRead', () => { + it('marks all notices read', (done) => { + const testList = [{ + id: 0, + read: false, + title: 'Notice 1', + }, { + id: 1, + read: false, + title: 'Notice 2', + }, { + id: 2, + read: false, + title: 'Notice 3', + }] + + noticeController.setNoticesList(testList) + + noticeController.markAllNoticesRead() + + const unreadNotices = noticeController.getUnreadNotices() + assert.equal(unreadNotices.length, 0) + done() + }) + }) + describe('#getNextUnreadNotice', function () { it('should retrieve the latest unread notice', function (done) { var testList = [ diff --git a/test/unit/ui/app/actions.spec.js b/test/unit/ui/app/actions.spec.js index 8d7de8b02..d27521088 100644 --- a/test/unit/ui/app/actions.spec.js +++ b/test/unit/ui/app/actions.spec.js @@ -1308,6 +1308,30 @@ describe('Actions', () => { }) }) + describe.only('#setCompletedOnboarding', () => { + let markAllNoticesReadSpy, completeOnboardingSpy + + beforeEach(() => { + markAllNoticesReadSpy = sinon.stub(background, 'markAllNoticesRead') + completeOnboardingSpy = sinon.stub(background, 'completeOnboarding') + }) + + after(() => { + markAllNoticesReadSpy.restore() + completeOnboardingSpy.restore() + }) + + it('', (done) => { + const store = mockStore() + store.dispatch(actions.setCompletedOnboarding()) + .then(() => { + assert.equal(markAllNoticesReadSpy.callCount, 1) + assert.equal(completeOnboardingSpy.callCount, 1) + }) + done() + }) + }) + describe('#updateNetworkNonce', () => { let getTransactionCountSpy -- cgit v1.2.3 From 07c974525859eba81471ec7591821ea010addf5a Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Wed, 20 Mar 2019 21:29:08 -0500 Subject: Remove exclusive test --- test/unit/ui/app/actions.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/ui/app/actions.spec.js b/test/unit/ui/app/actions.spec.js index d27521088..bfc6459b1 100644 --- a/test/unit/ui/app/actions.spec.js +++ b/test/unit/ui/app/actions.spec.js @@ -1308,7 +1308,7 @@ describe('Actions', () => { }) }) - describe.only('#setCompletedOnboarding', () => { + describe('#setCompletedOnboarding', () => { let markAllNoticesReadSpy, completeOnboardingSpy beforeEach(() => { -- cgit v1.2.3 From a64855ef4940f1a409b4a168a60d0f5f06836086 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 29 Mar 2019 12:03:31 +0800 Subject: notices - markAllNoticesRead - use async/await --- test/unit/app/controllers/notice-controller-test.js | 5 ++--- test/unit/ui/app/actions.spec.js | 11 ++++------- 2 files changed, 6 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/unit/app/controllers/notice-controller-test.js b/test/unit/app/controllers/notice-controller-test.js index 95e3ea9bd..d550d86cd 100644 --- a/test/unit/app/controllers/notice-controller-test.js +++ b/test/unit/app/controllers/notice-controller-test.js @@ -40,7 +40,7 @@ describe('notice-controller', function () { }) describe('#markAllNoticesRead', () => { - it('marks all notices read', (done) => { + it('marks all notices read', async () => { const testList = [{ id: 0, read: false, @@ -57,11 +57,10 @@ describe('notice-controller', function () { noticeController.setNoticesList(testList) - noticeController.markAllNoticesRead() + await noticeController.markAllNoticesRead() const unreadNotices = noticeController.getUnreadNotices() assert.equal(unreadNotices.length, 0) - done() }) }) diff --git a/test/unit/ui/app/actions.spec.js b/test/unit/ui/app/actions.spec.js index d395c9adb..a3b979d75 100644 --- a/test/unit/ui/app/actions.spec.js +++ b/test/unit/ui/app/actions.spec.js @@ -1321,14 +1321,11 @@ describe('Actions', () => { completeOnboardingSpy.restore() }) - it('', (done) => { + it('completing onboarding marks all notices as read', async () => { const store = mockStore() - store.dispatch(actions.setCompletedOnboarding()) - .then(() => { - assert.equal(markAllNoticesReadSpy.callCount, 1) - assert.equal(completeOnboardingSpy.callCount, 1) - }) - done() + await store.dispatch(actions.setCompletedOnboarding()) + assert.equal(markAllNoticesReadSpy.callCount, 1) + assert.equal(completeOnboardingSpy.callCount, 1) }) }) -- cgit v1.2.3 From e04f0c877ba94c126bbf94622640700c728f74c7 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 29 Mar 2019 12:37:40 +0800 Subject: lib - nodeify - correctly wrap synchronous functions --- test/unit/app/nodeify-test.js | 49 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/unit/app/nodeify-test.js b/test/unit/app/nodeify-test.js index 938b76c68..0dafc6653 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}`)) + } + }) }) -- cgit v1.2.3 From 846038a69c4cde10417ce54b280de3624d87d45c Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 29 Mar 2019 12:39:29 +0800 Subject: notice-controller - make markAllNoticesRead sync --- test/unit/app/controllers/notice-controller-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/app/controllers/notice-controller-test.js b/test/unit/app/controllers/notice-controller-test.js index d550d86cd..caa50a03e 100644 --- a/test/unit/app/controllers/notice-controller-test.js +++ b/test/unit/app/controllers/notice-controller-test.js @@ -57,7 +57,7 @@ describe('notice-controller', function () { noticeController.setNoticesList(testList) - await noticeController.markAllNoticesRead() + noticeController.markAllNoticesRead() const unreadNotices = noticeController.getUnreadNotices() assert.equal(unreadNotices.length, 0) -- cgit v1.2.3 From 02585c0bd023b379778fb850e53eecb9c45e5509 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 29 Mar 2019 12:51:54 +0800 Subject: lint fix --- test/unit/app/nodeify-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/app/nodeify-test.js b/test/unit/app/nodeify-test.js index 0dafc6653..fa5e49fb2 100644 --- a/test/unit/app/nodeify-test.js +++ b/test/unit/app/nodeify-test.js @@ -42,7 +42,7 @@ describe('nodeify', function () { try { nodified('baz') } catch (err) { - done(new Error('should not have thrown an error synchronously')) + done(new Error('should not have thrown an error synchronously')) } }) -- cgit v1.2.3 From ed381f5b2a3a85d351248769b3d150742acb703b Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 29 Mar 2019 13:10:42 +0800 Subject: test - unit - ui - actions - setCompletedOnboarding - fix stub to call callback --- test/unit/ui/app/actions.spec.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test') diff --git a/test/unit/ui/app/actions.spec.js b/test/unit/ui/app/actions.spec.js index a3b979d75..a578ec89c 100644 --- a/test/unit/ui/app/actions.spec.js +++ b/test/unit/ui/app/actions.spec.js @@ -1313,7 +1313,9 @@ describe('Actions', () => { beforeEach(() => { markAllNoticesReadSpy = sinon.stub(background, 'markAllNoticesRead') + markAllNoticesReadSpy.callsFake(cb => cb()) completeOnboardingSpy = sinon.stub(background, 'completeOnboarding') + completeOnboardingSpy.callsFake(cb => cb()) }) after(() => { -- cgit v1.2.3