Remove duplication in app test code

This commit is contained in:
Matthew Ross 2017-01-14 12:25:22 -05:00
parent 13872686b6
commit 6f2cf5c206
2 changed files with 16 additions and 22 deletions

View File

@ -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 => {

View File

@ -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();
});
}
});