diff --git a/test/app/dashboard/calendar/calendar.component.spec.js b/test/app/dashboard/calendar/calendar.component.spec.js new file mode 100644 index 0000000..e69de29 diff --git a/test/app/dashboard/charts/charts.component.spec.js b/test/app/dashboard/charts/charts.component.spec.js new file mode 100644 index 0000000..a6fce0c --- /dev/null +++ b/test/app/dashboard/charts/charts.component.spec.js @@ -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'); + }); +}); + diff --git a/test/app/mocks.js b/test/app/mocks.js index 4f9b482..7c5825d 100644 --- a/test/app/mocks.js +++ b/test/app/mocks.js @@ -1,5 +1,10 @@ var RxJs = require('rxjs/Rx'); +global.Chartist = { + Pie: function() {}, + Line: function() {} +}; + global.ConstantsMock = { VERSION: 'TEST' }; @@ -21,6 +26,8 @@ global.AuthServiceMock = { default_board_id: 0, security_level: 2 }), + updateUser: (user) => { + }, login: () => { return RxJs.Observable.of({ alerts: [ 'Logged in' ], @@ -53,7 +60,7 @@ global.ResponseMock = function(endpoint) { json: () => { return { alerts: [], - data: [ 'jwt', 'data1', 'data2' ], + data: [ 'jwt', 'true', 'true' ], status: 'success', endpoint: endpoint }; @@ -143,13 +150,18 @@ global.UserSettingsServiceMock = { }, changeUsername: (newName) => { return RxJs.Observable.of({ - alerts: [] + alerts: [{ type: 'success', text: ''}] }); }, changePassword: (newPass) => { return RxJs.Observable.of({ - alerts: [] - }) + alerts: [{ type: 'success', text: ''}] + }); + }, + changeEmail: (newEmail) => { + return RxJs.Observable.of({ + alerts: [{ type: 'success', text: ''}] + }); } }; 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 4a7b974..9e05b48 100644 --- a/test/app/settings/user-settings/user-settings.component.spec.js +++ b/test/app/settings/user-settings/user-settings.component.spec.js @@ -4,14 +4,14 @@ var chai = require('chai'), path = '../../../../build/settings/user-settings/', UserSettings = require(path + 'user-settings.component.js').UserSettings; -describe('UserAdminService', () => { +describe('UserSettings', () => { var userSettings, notifications; beforeEach(() => { notifications = new NotificationsServiceMock(); userSettings = new UserSettings(AuthServiceMock, - notifications, UserSettingsServiceMock) + notifications, UserSettingsServiceMock); }); it('resets forms on init', () => { @@ -41,18 +41,29 @@ describe('UserAdminService', () => { current: '' }; - var first = true; + var first = true, + second = true; notifications.noteAdded.subscribe(note => { if (first) { expect(note.type).to.equal('error'); first = false; + } else if (second) { + expect(note.type).to.equal('error'); + second = false; } else { expect(note.type).to.equal('success'); + done(); } - done(); }); userSettings.updatePassword(); + userSettings.changePassword = { + current: 'old', + newPass: 'new', + verPass: 'err' + }; + userSettings.updatePassword(); + userSettings.changePassword = { current: 'old', newPass: 'new', @@ -71,13 +82,32 @@ describe('UserAdminService', () => { first = false; } else { expect(note.type).to.equal('success'); + done(); } - done(); }); userSettings.updateUsername(); userSettings.changeUsername = { newName: 'test' }; 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(); + }); }); diff --git a/test/app/settings/user-settings/user-settings.service.spec.js b/test/app/settings/user-settings/user-settings.service.spec.js index e69de29..cf350c0 100644 --- a/test/app/settings/user-settings/user-settings.service.spec.js +++ b/test/app/settings/user-settings/user-settings.service.spec.js @@ -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(); + }); + }); +}); +