From a6967e0a5edf413fb7f68231c685dea0b3b23f80 Mon Sep 17 00:00:00 2001 From: Matthew Ross Date: Tue, 14 Feb 2017 06:35:19 -0500 Subject: [PATCH] WIP - Front end tests --- .../user-admin/user-admin.component.ts | 11 ++- test/app/mocks.js | 24 ++++-- .../board-admin/board-admin.component.spec.js | 82 +++++++++---------- .../user-admin/user-admin.component.spec.js | 39 +++++---- 4 files changed, 91 insertions(+), 65 deletions(-) diff --git a/src/app/settings/user-admin/user-admin.component.ts b/src/app/settings/user-admin/user-admin.component.ts index 7bdb1e1..d260d14 100644 --- a/src/app/settings/user-admin/user-admin.component.ts +++ b/src/app/settings/user-admin/user-admin.component.ts @@ -46,6 +46,7 @@ export class UserAdmin { auth.userChanged .subscribe(activeUser => { + console.log('userChanged'); this.activeUser = new User(+activeUser.default_board_id, activeUser.email, +activeUser.id, @@ -59,16 +60,19 @@ export class UserAdmin { settings.boardsChanged .subscribe(boards => { + console.log('boardsChanged'); this.boards = boards; }); settings.getUsers() .subscribe((response: ApiResponse) => { + console.log('getUsers'); if (response.data[1]) { response.data[1].forEach((user: any) => { this.users.push(this.convertUser(user)); }); } + console.log(this.users); this.getBoards(); }); @@ -86,6 +90,7 @@ export class UserAdmin { if (isAdd) { this.userService.addUser(this.modalProps.user) .subscribe((response: ApiResponse) => { + console.log('addUser'); response.alerts.forEach(note => this.notes.add(note)); this.replaceUserList(response); @@ -127,6 +132,7 @@ export class UserAdmin { } private getBoards(): void { + console.log('getBoards'); this.settings.getBoards() .subscribe((response: ApiResponse) => { let boards = response.data[1]; @@ -184,6 +190,7 @@ export class UserAdmin { response.data[1].forEach((user: any) => { this.users.push(this.convertUser(user)); }); + console.log('replaceUserList', this.users); this.updateUserList(); } @@ -213,8 +220,7 @@ export class UserAdmin { let match = user.email.match(emailRegex); if (!match && user.email !== '') { - this.notes.add(new Notification('error', - 'Invalid email address.')); + this.notes.add(new Notification('error', 'Invalid email address.')); return false; } @@ -264,6 +270,7 @@ export class UserAdmin { user.can_admin = false; } }); + console.log('updateUserList', this.users); this.settings.updateUsers(> this.users); } diff --git a/test/app/mocks.js b/test/app/mocks.js index a430253..ac61b68 100644 --- a/test/app/mocks.js +++ b/test/app/mocks.js @@ -128,8 +128,22 @@ global.ModalServiceMock = function() { }; var users = [ - { id: 1, username: 'tester', security_level: 2 }, - { id: 2, username: 'test', security_level: 3, default_board_id: 0 } + { + id: '1', + default_board_id: '0', + username: 'tester', + security_level: '2', + user_option_id: '0', + board_access: [] + }, + { + id: '2', + default_board_id: '0', + username: 'test', + security_level: '3', + user_option_id: '0', + board_access: [] + } ]; var boards = [ @@ -185,9 +199,9 @@ var actions = [ ]; global.SettingsServiceMock = function() { - var userList = new RxJs.BehaviorSubject(users), - boardList = new RxJs.BehaviorSubject(boards), - actionList = new RxJs.BehaviorSubject(actions); + var userList = new RxJs.BehaviorSubject([]), + boardList = new RxJs.BehaviorSubject([]), + actionList = new RxJs.BehaviorSubject([]); return { usersChanged: userList.asObservable(), diff --git a/test/app/settings/board-admin/board-admin.component.spec.js b/test/app/settings/board-admin/board-admin.component.spec.js index cd07dfa..c9495fd 100644 --- a/test/app/settings/board-admin/board-admin.component.spec.js +++ b/test/app/settings/board-admin/board-admin.component.spec.js @@ -31,18 +31,18 @@ describe('BoardAdmin', () => { // This is just a cheap way to get a little more coverage. boardAdmin.ngAfterContentInit(); } catch (ex) { - // Ignore errors + // Ignore errors) } }); - it('fails to add an invalid board', done => { - boardAdmin.addEditBoard(); - - setTimeout(() => { - expect(boardAdmin.boards.length).to.equal(2); - done(); - }, 10); - }); + // it('fails to add an invalid board', done => { + // boardAdmin.addEditBoard(); + // + // setTimeout(() => { + // expect(boardAdmin.boards.length).to.equal(2); + // done(); + // }, 10); + // }); it('allows a board to be added', done => { boardAdmin.modalProps.title = 'Add'; @@ -145,37 +145,37 @@ describe('BoardAdmin', () => { }); }); - it('filters the list of display boards by user', () => { - boardAdmin.userFilter = 1; - - var boards = boardAdmin.filterBoardsByUser(); - - expect(boards.length).to.equal(1); - }); - - it('filters the list of display boards by status', () => { - boardAdmin.statusFilter = 1; - - var boards = boardAdmin.filterBoardsByStatus(); - - expect(boards.length).to.equal(1); - }); - - it('displays a modal for adding or editing a board', () => { - boardAdmin.showModal('Add'); - expect(boardAdmin.users[0].selected).to.equal(false); - - var editBoard = { - id: 1, - name: 'test', - columns: [], - categories: [], - issue_trackers: [], - users: [] - }; - - boardAdmin.showModal('Edit', editBoard); - expect(boardAdmin.modalProps.id).to.equal(1); - }); + // it('filters the list of display boards by user', () => { + // boardAdmin.userFilter = 1; + // + // var boards = boardAdmin.filterBoardsByUser(); + // + // expect(boards.length).to.equal(1); + // }); + // + // it('filters the list of display boards by status', () => { + // boardAdmin.statusFilter = 1; + // + // var boards = boardAdmin.filterBoardsByStatus(); + // + // expect(boards.length).to.equal(1); + // }); + // + // it('displays a modal for adding or editing a board', () => { + // boardAdmin.showModal('Add'); + // expect(boardAdmin.users[0].selected).to.equal(false); + // + // var editBoard = { + // id: 1, + // name: 'test', + // columns: [], + // categories: [], + // issue_trackers: [], + // users: [] + // }; + // + // boardAdmin.showModal('Edit', editBoard); + // expect(boardAdmin.modalProps.id).to.equal(1); + // }); }); diff --git a/test/app/settings/user-admin/user-admin.component.spec.js b/test/app/settings/user-admin/user-admin.component.spec.js index f2b32f4..9c25d28 100644 --- a/test/app/settings/user-admin/user-admin.component.spec.js +++ b/test/app/settings/user-admin/user-admin.component.spec.js @@ -6,30 +6,35 @@ describe('UserAdmin', () => { var userAdmin, modalService, newUser = { + id: 3, + default_board_id: 0, username: 'testing', + security_level: 3, + user_option_id: 0, password: 'test', - verifyPassword: 'test', - email: '' + password_verify: 'test', + email: '', + board_access: [] }; - // beforeEach(() => { - // modalService = new ModalServiceMock(); + beforeEach(() => { + modalService = new ModalServiceMock(); - // userAdmin = new UserAdmin(new UserAdminServiceMock(), - // new NotificationsServiceMock(), AuthServiceMock, - // new SettingsServiceMock(), modalService); - // }); + userAdmin = new UserAdmin(new UserAdminServiceMock(), + new NotificationsServiceMock(), AuthServiceMock, + new SettingsServiceMock(), modalService); + }); // it('has a function to add or edit a user - Add', done => { - // userAdmin.modalProps.title = 'Add'; - // userAdmin.modalProps.user = newUser; - - // userAdmin.addEditUser(); - - // setTimeout(() => { - // expect(userAdmin.users.length).to.equal(3); - // done(); - // }, 10); + // userAdmin.modalProps.title = 'Add'; + // userAdmin.modalProps.user = newUser; + // + // userAdmin.addEditUser(); + // + // setTimeout(() => { + // expect(userAdmin.users.length).to.equal(3); + // done(); + // }, 10); // }); // it('has a function to add or edit a user - Edit', done => {