WIP - Front end tests

This commit is contained in:
Matthew Ross 2017-02-14 06:35:19 -05:00
parent 54c5d0ae8b
commit a6967e0a5e
4 changed files with 91 additions and 65 deletions

View File

@ -46,6 +46,7 @@ export class UserAdmin {
auth.userChanged auth.userChanged
.subscribe(activeUser => { .subscribe(activeUser => {
console.log('userChanged');
this.activeUser = new User(+activeUser.default_board_id, this.activeUser = new User(+activeUser.default_board_id,
activeUser.email, activeUser.email,
+activeUser.id, +activeUser.id,
@ -59,16 +60,19 @@ export class UserAdmin {
settings.boardsChanged settings.boardsChanged
.subscribe(boards => { .subscribe(boards => {
console.log('boardsChanged');
this.boards = boards; this.boards = boards;
}); });
settings.getUsers() settings.getUsers()
.subscribe((response: ApiResponse) => { .subscribe((response: ApiResponse) => {
console.log('getUsers');
if (response.data[1]) { if (response.data[1]) {
response.data[1].forEach((user: any) => { response.data[1].forEach((user: any) => {
this.users.push(this.convertUser(user)); this.users.push(this.convertUser(user));
}); });
} }
console.log(this.users);
this.getBoards(); this.getBoards();
}); });
@ -86,6 +90,7 @@ export class UserAdmin {
if (isAdd) { if (isAdd) {
this.userService.addUser(this.modalProps.user) this.userService.addUser(this.modalProps.user)
.subscribe((response: ApiResponse) => { .subscribe((response: ApiResponse) => {
console.log('addUser');
response.alerts.forEach(note => this.notes.add(note)); response.alerts.forEach(note => this.notes.add(note));
this.replaceUserList(response); this.replaceUserList(response);
@ -127,6 +132,7 @@ export class UserAdmin {
} }
private getBoards(): void { private getBoards(): void {
console.log('getBoards');
this.settings.getBoards() this.settings.getBoards()
.subscribe((response: ApiResponse) => { .subscribe((response: ApiResponse) => {
let boards = response.data[1]; let boards = response.data[1];
@ -184,6 +190,7 @@ export class UserAdmin {
response.data[1].forEach((user: any) => { response.data[1].forEach((user: any) => {
this.users.push(this.convertUser(user)); this.users.push(this.convertUser(user));
}); });
console.log('replaceUserList', this.users);
this.updateUserList(); this.updateUserList();
} }
@ -213,8 +220,7 @@ export class UserAdmin {
let match = user.email.match(emailRegex); let match = user.email.match(emailRegex);
if (!match && user.email !== '') { if (!match && user.email !== '') {
this.notes.add(new Notification('error', this.notes.add(new Notification('error', 'Invalid email address.'));
'Invalid email address.'));
return false; return false;
} }
@ -264,6 +270,7 @@ export class UserAdmin {
user.can_admin = false; user.can_admin = false;
} }
}); });
console.log('updateUserList', this.users);
this.settings.updateUsers(<Array<User>> this.users); this.settings.updateUsers(<Array<User>> this.users);
} }

View File

@ -128,8 +128,22 @@ global.ModalServiceMock = function() {
}; };
var users = [ 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 = [ var boards = [
@ -185,9 +199,9 @@ var actions = [
]; ];
global.SettingsServiceMock = function() { global.SettingsServiceMock = function() {
var userList = new RxJs.BehaviorSubject(users), var userList = new RxJs.BehaviorSubject([]),
boardList = new RxJs.BehaviorSubject(boards), boardList = new RxJs.BehaviorSubject([]),
actionList = new RxJs.BehaviorSubject(actions); actionList = new RxJs.BehaviorSubject([]);
return { return {
usersChanged: userList.asObservable(), usersChanged: userList.asObservable(),

View File

@ -31,18 +31,18 @@ describe('BoardAdmin', () => {
// This is just a cheap way to get a little more coverage. // This is just a cheap way to get a little more coverage.
boardAdmin.ngAfterContentInit(); boardAdmin.ngAfterContentInit();
} catch (ex) { } catch (ex) {
// Ignore errors // Ignore errors)
} }
}); });
it('fails to add an invalid board', done => { // it('fails to add an invalid board', done => {
boardAdmin.addEditBoard(); // boardAdmin.addEditBoard();
//
setTimeout(() => { // setTimeout(() => {
expect(boardAdmin.boards.length).to.equal(2); // expect(boardAdmin.boards.length).to.equal(2);
done(); // done();
}, 10); // }, 10);
}); // });
it('allows a board to be added', done => { it('allows a board to be added', done => {
boardAdmin.modalProps.title = 'Add'; boardAdmin.modalProps.title = 'Add';
@ -145,37 +145,37 @@ describe('BoardAdmin', () => {
}); });
}); });
it('filters the list of display boards by user', () => { // it('filters the list of display boards by user', () => {
boardAdmin.userFilter = 1; // boardAdmin.userFilter = 1;
//
var boards = boardAdmin.filterBoardsByUser(); // var boards = boardAdmin.filterBoardsByUser();
//
expect(boards.length).to.equal(1); // expect(boards.length).to.equal(1);
}); // });
//
it('filters the list of display boards by status', () => { // it('filters the list of display boards by status', () => {
boardAdmin.statusFilter = 1; // boardAdmin.statusFilter = 1;
//
var boards = boardAdmin.filterBoardsByStatus(); // var boards = boardAdmin.filterBoardsByStatus();
//
expect(boards.length).to.equal(1); // expect(boards.length).to.equal(1);
}); // });
//
it('displays a modal for adding or editing a board', () => { // it('displays a modal for adding or editing a board', () => {
boardAdmin.showModal('Add'); // boardAdmin.showModal('Add');
expect(boardAdmin.users[0].selected).to.equal(false); // expect(boardAdmin.users[0].selected).to.equal(false);
//
var editBoard = { // var editBoard = {
id: 1, // id: 1,
name: 'test', // name: 'test',
columns: [], // columns: [],
categories: [], // categories: [],
issue_trackers: [], // issue_trackers: [],
users: [] // users: []
}; // };
//
boardAdmin.showModal('Edit', editBoard); // boardAdmin.showModal('Edit', editBoard);
expect(boardAdmin.modalProps.id).to.equal(1); // expect(boardAdmin.modalProps.id).to.equal(1);
}); // });
}); });

View File

@ -6,30 +6,35 @@ describe('UserAdmin', () => {
var userAdmin, var userAdmin,
modalService, modalService,
newUser = { newUser = {
id: 3,
default_board_id: 0,
username: 'testing', username: 'testing',
security_level: 3,
user_option_id: 0,
password: 'test', password: 'test',
verifyPassword: 'test', password_verify: 'test',
email: '' email: '',
board_access: []
}; };
// beforeEach(() => { beforeEach(() => {
// modalService = new ModalServiceMock(); modalService = new ModalServiceMock();
// userAdmin = new UserAdmin(new UserAdminServiceMock(), userAdmin = new UserAdmin(new UserAdminServiceMock(),
// new NotificationsServiceMock(), AuthServiceMock, new NotificationsServiceMock(), AuthServiceMock,
// new SettingsServiceMock(), modalService); new SettingsServiceMock(), modalService);
// }); });
// it('has a function to add or edit a user - Add', done => { // it('has a function to add or edit a user - Add', done => {
// userAdmin.modalProps.title = 'Add'; // userAdmin.modalProps.title = 'Add';
// userAdmin.modalProps.user = newUser; // userAdmin.modalProps.user = newUser;
//
// userAdmin.addEditUser(); // userAdmin.addEditUser();
//
// setTimeout(() => { // setTimeout(() => {
// expect(userAdmin.users.length).to.equal(3); // expect(userAdmin.users.length).to.equal(3);
// done(); // done();
// }, 10); // }, 10);
// }); // });
// it('has a function to add or edit a user - Edit', done => { // it('has a function to add or edit a user - Edit', done => {