From 6f2cf5c20608c21f8da4bdf5b6c3e1309a9f837b Mon Sep 17 00:00:00 2001 From: Matthew Ross Date: Sat, 14 Jan 2017 12:25:22 -0500 Subject: [PATCH] Remove duplication in app test code --- test/app/mocks.js | 13 +++++----- .../user-settings.component.spec.js | 25 ++++++++----------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/test/app/mocks.js b/test/app/mocks.js index de8f066..5e9ff57 100644 --- a/test/app/mocks.js +++ b/test/app/mocks.js @@ -122,11 +122,13 @@ global.ModalServiceMock = function() { }; }; -global.SettingsServiceMock = function() { - var userList = [ +var users = [ { id: 1, username: 'tester', security_level: 2 }, { id: 2, username: 'test', security_level: 3, default_board_id: 0 } - ], +]; + +global.SettingsServiceMock = function() { + var userList = users, boardsList = [ { id: 1, name: 'Testing' } ]; @@ -160,10 +162,7 @@ global.SettingsServiceMock = function() { }; global.UserAdminServiceMock = function() { - var userList = [ - { id: 1, username: 'tester', security_level: 2 }, - { id: 2, username: 'test', security_level: 3, default_board_id: 0 } - ]; + var userList = users; return { addUser: user => { diff --git a/test/app/settings/user-settings/user-settings.component.spec.js b/test/app/settings/user-settings/user-settings.component.spec.js index 71057f7..c66c3bb 100644 --- a/test/app/settings/user-settings/user-settings.component.spec.js +++ b/test/app/settings/user-settings/user-settings.component.spec.js @@ -83,16 +83,7 @@ describe('UserSettings', () => { it('has a function to update username', done => { userSettings.changeUsername = { newName: '' }; - var first = true; - notifications.noteAdded.subscribe(note => { - if (first) { - expect(note.type).to.equal('error'); - first = false; - } else { - expect(note.type).to.equal('success'); - done(); - } - }); + checkNotifications(done); userSettings.updateUsername(); userSettings.changeUsername = { newName: 'test' }; @@ -102,6 +93,14 @@ describe('UserSettings', () => { it('has a function to update email', done => { userSettings.changeEmail = { newEmail: 'asdf' }; + checkNotifications(done); + userSettings.updateEmail(); + + userSettings.changeEmail.newEmail = 'test@example.com'; + userSettings.updateEmail(); + }); + + function checkNotifications(done) { var first = true; notifications.noteAdded.subscribe(note => { if (first) { @@ -112,10 +111,6 @@ describe('UserSettings', () => { done(); } }); - userSettings.updateEmail(); - - userSettings.changeEmail.newEmail = 'test@example.com'; - userSettings.updateEmail(); - }); + } });