User settings and initial dashboard unit tests

This commit is contained in:
kiswa 2016-08-02 17:50:36 +00:00
parent c8af0ca903
commit de0c919395
5 changed files with 148 additions and 9 deletions

View File

@ -0,0 +1,53 @@
require('../../mocks.js');
var chai = require('chai'),
expect = chai.expect,
path = '../../../../build/dashboard/charts/',
Charts = require(path + 'charts.component.js').Charts;
describe('Charts', () => {
var charts;
beforeEach(() => {
charts = new Charts();
});
it('has a chartName property', () => {
expect(charts.chartName).to.be.a('string');
expect(charts.chartName).to.equal('');
});
it('has a chartType property', () => {
expect(charts.chartType).to.be.a('string');
expect(charts.chartType).to.equal('pie');
});
it('has a series property', () => {
expect(charts.series).to.be.a('string');
expect(charts.series).to.equal('');
});
it('has a labels property', () => {
expect(charts.labels).to.be.a('string');
expect(charts.labels).to.equal('');
});
it('has a tableHead property', () => {
expect(charts.tableHead).to.be.a('string');
expect(charts.tableHead).to.equal('');
});
it('implements AfterViewInit', () => {
charts.series = '1,2,3';
charts.labels = 'a,b,c';
charts.ngAfterViewInit();
expect(charts.data).to.be.an('array');
expect(charts.data[0]).to.equal(1);
expect(charts.words).to.be.an('array');
expect(charts.words[0]).to.equal('a');
});
});

View File

@ -1,5 +1,10 @@
var RxJs = require('rxjs/Rx'); var RxJs = require('rxjs/Rx');
global.Chartist = {
Pie: function() {},
Line: function() {}
};
global.ConstantsMock = { global.ConstantsMock = {
VERSION: 'TEST' VERSION: 'TEST'
}; };
@ -21,6 +26,8 @@ global.AuthServiceMock = {
default_board_id: 0, default_board_id: 0,
security_level: 2 security_level: 2
}), }),
updateUser: (user) => {
},
login: () => { login: () => {
return RxJs.Observable.of({ return RxJs.Observable.of({
alerts: [ 'Logged in' ], alerts: [ 'Logged in' ],
@ -53,7 +60,7 @@ global.ResponseMock = function(endpoint) {
json: () => { json: () => {
return { return {
alerts: [], alerts: [],
data: [ 'jwt', 'data1', 'data2' ], data: [ 'jwt', 'true', 'true' ],
status: 'success', status: 'success',
endpoint: endpoint endpoint: endpoint
}; };
@ -143,13 +150,18 @@ global.UserSettingsServiceMock = {
}, },
changeUsername: (newName) => { changeUsername: (newName) => {
return RxJs.Observable.of({ return RxJs.Observable.of({
alerts: [] alerts: [{ type: 'success', text: ''}]
}); });
}, },
changePassword: (newPass) => { changePassword: (newPass) => {
return RxJs.Observable.of({ return RxJs.Observable.of({
alerts: [] alerts: [{ type: 'success', text: ''}]
}) });
},
changeEmail: (newEmail) => {
return RxJs.Observable.of({
alerts: [{ type: 'success', text: ''}]
});
} }
}; };

View File

@ -4,14 +4,14 @@ var chai = require('chai'),
path = '../../../../build/settings/user-settings/', path = '../../../../build/settings/user-settings/',
UserSettings = require(path + 'user-settings.component.js').UserSettings; UserSettings = require(path + 'user-settings.component.js').UserSettings;
describe('UserAdminService', () => { describe('UserSettings', () => {
var userSettings, var userSettings,
notifications; notifications;
beforeEach(() => { beforeEach(() => {
notifications = new NotificationsServiceMock(); notifications = new NotificationsServiceMock();
userSettings = new UserSettings(AuthServiceMock, userSettings = new UserSettings(AuthServiceMock,
notifications, UserSettingsServiceMock) notifications, UserSettingsServiceMock);
}); });
it('resets forms on init', () => { it('resets forms on init', () => {
@ -41,18 +41,29 @@ describe('UserAdminService', () => {
current: '' current: ''
}; };
var first = true; var first = true,
second = true;
notifications.noteAdded.subscribe(note => { notifications.noteAdded.subscribe(note => {
if (first) { if (first) {
expect(note.type).to.equal('error'); expect(note.type).to.equal('error');
first = false; first = false;
} else if (second) {
expect(note.type).to.equal('error');
second = false;
} else { } else {
expect(note.type).to.equal('success'); expect(note.type).to.equal('success');
done();
} }
done();
}); });
userSettings.updatePassword(); userSettings.updatePassword();
userSettings.changePassword = {
current: 'old',
newPass: 'new',
verPass: 'err'
};
userSettings.updatePassword();
userSettings.changePassword = { userSettings.changePassword = {
current: 'old', current: 'old',
newPass: 'new', newPass: 'new',
@ -71,13 +82,32 @@ describe('UserAdminService', () => {
first = false; first = false;
} else { } else {
expect(note.type).to.equal('success'); expect(note.type).to.equal('success');
done();
} }
done();
}); });
userSettings.updateUsername(); userSettings.updateUsername();
userSettings.changeUsername = { newName: 'test' }; userSettings.changeUsername = { newName: 'test' };
userSettings.updateUsername(); userSettings.updateUsername();
}); });
it('has a function to update email', (done) => {
userSettings.changeEmail = { newEmail: 'asdf' };
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();
}
});
userSettings.updateEmail();
userSettings.changeEmail.newEmail = 'test@example.com';
userSettings.updateEmail();
});
}); });

View File

@ -0,0 +1,44 @@
/* global AuthServiceMock HttpMock */
var chai = require('chai'),
expect = chai.expect,
path = '../../../../build/settings/user-settings/',
UserSettingsService =
require(path + 'user-settings.service.js').UserSettingsService;
describe('UserSettingsService', () => {
var userSettingsService;
beforeEach(() => {
userSettingsService = new UserSettingsService(AuthServiceMock,
HttpMock);
});
it('calls the api to change a password', (done) => {
userSettingsService.changePassword('old', 'new').subscribe(data => {
expect(data.endpoint).to.equal('api/users/1');
done();
});
});
it('calls the api to change a username', (done) => {
userSettingsService.changeUsername('tester').subscribe(data => {
expect(data.endpoint).to.equal('api/users/1');
done();
});
});
it('calls the api to change an email', (done) => {
userSettingsService.changeEmail('newEmail').subscribe(data => {
expect(data.endpoint).to.equal('api/users/1');
done();
});
});
it('calls the api to change a user option', (done) => {
userSettingsService.changeUserOptions({}).subscribe(data => {
expect(data.endpoint).to.equal('api/users/1/opts');
done();
});
});
});