App unit tests up-to-date
This commit is contained in:
parent
5ea5d4d28d
commit
df1280c6d4
@ -158,7 +158,10 @@ var boards = [
|
||||
board_id: 1,
|
||||
tasks: []
|
||||
}],
|
||||
categories: [],
|
||||
categories: [{
|
||||
id: 1,
|
||||
name: 'Category 1'
|
||||
}],
|
||||
issue_trackers: [],
|
||||
users: [ users[1] ]
|
||||
},
|
||||
@ -199,14 +202,14 @@ var actions = [
|
||||
];
|
||||
|
||||
global.SettingsServiceMock = function() {
|
||||
var userList = new RxJs.BehaviorSubject([]),
|
||||
boardList = new RxJs.BehaviorSubject([]),
|
||||
actionList = new RxJs.BehaviorSubject([]);
|
||||
var userList = new RxJs.BehaviorSubject(users),
|
||||
boardList = new RxJs.BehaviorSubject(boards),
|
||||
actionList = new RxJs.BehaviorSubject(actions);
|
||||
|
||||
return {
|
||||
usersChanged: userList.asObservable(),
|
||||
boardsChanged: boardList.asObservable(),
|
||||
actionsChanged: boardList.asObservable(),
|
||||
actionsChanged: actionList.asObservable(),
|
||||
|
||||
updateUsers: users => {
|
||||
userList.next(users);
|
||||
@ -215,7 +218,7 @@ global.SettingsServiceMock = function() {
|
||||
return RxJs.Observable.of({
|
||||
status: 'success',
|
||||
alerts: [],
|
||||
data: [ null, userList ]
|
||||
data: [ null, users ]
|
||||
});
|
||||
},
|
||||
|
||||
@ -226,7 +229,7 @@ global.SettingsServiceMock = function() {
|
||||
return RxJs.Observable.of({
|
||||
status: 'success',
|
||||
alerts: [],
|
||||
data: [ null, boardList ]
|
||||
data: [ null, boards ]
|
||||
});
|
||||
},
|
||||
|
||||
@ -237,15 +240,13 @@ global.SettingsServiceMock = function() {
|
||||
return RxJs.Observable.of({
|
||||
status: 'success',
|
||||
alerts: [],
|
||||
data: [ null, actionList ]
|
||||
data: [ null, actions ]
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
global.UserAdminServiceMock = function() {
|
||||
var userList = users;
|
||||
|
||||
return {
|
||||
addUser: user => {
|
||||
return RxJs.Observable.of({
|
||||
@ -253,7 +254,7 @@ global.UserAdminServiceMock = function() {
|
||||
alerts: [],
|
||||
data: [
|
||||
null,
|
||||
userList.concat(user)
|
||||
users.concat(user)
|
||||
]
|
||||
});
|
||||
},
|
||||
@ -263,11 +264,8 @@ global.UserAdminServiceMock = function() {
|
||||
alerts: [],
|
||||
data: [
|
||||
null,
|
||||
JSON.stringify({
|
||||
id: 1,
|
||||
username: 'changed',
|
||||
security_level: 3
|
||||
})
|
||||
JSON.stringify(users[1]),
|
||||
users
|
||||
]
|
||||
});
|
||||
},
|
||||
@ -277,7 +275,7 @@ global.UserAdminServiceMock = function() {
|
||||
alerts: [],
|
||||
data: [
|
||||
null,
|
||||
userList.slice(1)
|
||||
users.slice(1)
|
||||
]
|
||||
});
|
||||
}
|
||||
@ -285,8 +283,6 @@ global.UserAdminServiceMock = function() {
|
||||
};
|
||||
|
||||
global.BoardAdminServiceMock = function() {
|
||||
var boardList = boards;
|
||||
|
||||
return {
|
||||
addBoard: board => {
|
||||
return RxJs.Observable.of({
|
||||
@ -294,7 +290,7 @@ global.BoardAdminServiceMock = function() {
|
||||
alerts: [],
|
||||
data: [
|
||||
null,
|
||||
boardList.concat(board)
|
||||
boards.concat(board)
|
||||
]
|
||||
});
|
||||
},
|
||||
@ -304,7 +300,7 @@ global.BoardAdminServiceMock = function() {
|
||||
alerts: [],
|
||||
data: [
|
||||
null,
|
||||
boardList
|
||||
boards
|
||||
]
|
||||
});
|
||||
},
|
||||
@ -314,7 +310,32 @@ global.BoardAdminServiceMock = function() {
|
||||
alerts: [],
|
||||
data: [
|
||||
null,
|
||||
boardList.slice(1)
|
||||
boards.slice(1)
|
||||
]
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
global.AutoActionsServiceMock = function() {
|
||||
return {
|
||||
addAction: action => {
|
||||
return RxJs.Observable.of({
|
||||
status: 'success',
|
||||
alerts: [],
|
||||
data: [
|
||||
null,
|
||||
actions.concat(action)
|
||||
]
|
||||
});
|
||||
},
|
||||
removeAction: boardId => {
|
||||
return RxJs.Observable.of({
|
||||
status: 'success',
|
||||
alerts: [],
|
||||
data: [
|
||||
null,
|
||||
actions.slice(1)
|
||||
]
|
||||
});
|
||||
}
|
||||
@ -365,3 +386,10 @@ global.HttpMock = {
|
||||
}
|
||||
};
|
||||
|
||||
global.SanitizerMock = {
|
||||
bypassSecurityTrustHtml: html => {
|
||||
return html;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
159
test/app/settings/auto-actions/auto-actions.component.spec.js
Normal file
159
test/app/settings/auto-actions/auto-actions.component.spec.js
Normal file
@ -0,0 +1,159 @@
|
||||
/* global expect AuthServiceMock SettingsServiceMock ModalServiceMock
|
||||
NotificationsServiceMock AutoActionsServiceMock SanitizerMock */
|
||||
var dirs = '../../../../',
|
||||
path = dirs + 'build/settings/auto-actions/',
|
||||
AutoActions = require(path + 'auto-actions.component.js').AutoActions;
|
||||
|
||||
describe('AutoActions', () => {
|
||||
var autoActions,
|
||||
modalService;
|
||||
|
||||
beforeEach(() => {
|
||||
modalService = new ModalServiceMock();
|
||||
|
||||
autoActions = new AutoActions(AuthServiceMock, modalService,
|
||||
new SettingsServiceMock(), new AutoActionsServiceMock(),
|
||||
new NotificationsServiceMock(), SanitizerMock);
|
||||
});
|
||||
|
||||
it('has a function to add an action', done => {
|
||||
autoActions.removeAutoAction();
|
||||
|
||||
setTimeout(() => {
|
||||
expect(autoActions.autoActions.length).to.equal(1);
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
it('has a function to remove an action', done => {
|
||||
autoActions.addNewAction();
|
||||
|
||||
setTimeout(() => {
|
||||
expect(autoActions.newAction.id).to.equal(0);
|
||||
expect(autoActions.autoActions.length).to.equal(3);
|
||||
done();
|
||||
}, 10);
|
||||
|
||||
});
|
||||
|
||||
it('has a function to update the list of triggers', () => {
|
||||
autoActions.newAction.board_id = 1;
|
||||
|
||||
autoActions.newAction.trigger = 1;
|
||||
autoActions.updateTriggerSources();
|
||||
|
||||
expect(autoActions.triggerSources[1][1]).to.equal('Column 1');
|
||||
|
||||
autoActions.newAction.trigger = 2;
|
||||
autoActions.updateTriggerSources();
|
||||
|
||||
expect(autoActions.triggerSources[1][1]).to.equal('test');
|
||||
|
||||
autoActions.newAction.trigger = 3;
|
||||
autoActions.updateTriggerSources();
|
||||
|
||||
expect(autoActions.triggerSources[1][1]).to.equal('Category 1');
|
||||
|
||||
autoActions.newAction.trigger = 4;
|
||||
autoActions.updateTriggerSources();
|
||||
|
||||
expect(autoActions.triggerSources.length).to.equal(0);
|
||||
});
|
||||
|
||||
it('has a function to update the list of action sources', () => {
|
||||
autoActions.newAction.type = 1;
|
||||
autoActions.updateActionSources();
|
||||
|
||||
expect(autoActions.newAction.change_to).to.equal('#000000');
|
||||
|
||||
autoActions.newAction.type = 2; // 2 and 3 are the same
|
||||
autoActions.updateActionSources();
|
||||
|
||||
expect(autoActions.actionSources[0][1]).to.equal('Select Category');
|
||||
|
||||
autoActions.newAction.type = 4; // 4 and 5 are the same
|
||||
autoActions.updateActionSources();
|
||||
|
||||
expect(autoActions.actionSources[0][1]).to.equal('Select Assignee');
|
||||
});
|
||||
|
||||
it('provides a description for a trigger', () => {
|
||||
var action = {
|
||||
id: 1,
|
||||
trigger: 1,
|
||||
source_id: 1,
|
||||
type: 1,
|
||||
change_to: 'test',
|
||||
board_id: 1
|
||||
};
|
||||
|
||||
var desc = autoActions.getTriggerDescription(action);
|
||||
expect(desc).to.equal('Item moves to column: Column 1');
|
||||
|
||||
action.trigger = 2;
|
||||
action.source_id = 2;
|
||||
|
||||
desc = autoActions.getTriggerDescription(action);
|
||||
expect(desc).to.equal('Item assigned to user: test');
|
||||
|
||||
action.trigger = 3;
|
||||
action.source_id = 1;
|
||||
|
||||
desc = autoActions.getTriggerDescription(action);
|
||||
expect(desc).to.equal('Item added to category: Category 1');
|
||||
|
||||
action.trigger = 4;
|
||||
|
||||
desc = autoActions.getTriggerDescription(action);
|
||||
expect(desc).to.equal('Item points changed.');
|
||||
});
|
||||
|
||||
it('provides a description for an action type', () => {
|
||||
var action = {
|
||||
id: 1,
|
||||
trigger: 1,
|
||||
source_id: 1,
|
||||
type: 1,
|
||||
change_to: '#fff',
|
||||
board_id: 1
|
||||
};
|
||||
|
||||
var desc = autoActions.getTypeDescription(action);
|
||||
expect(desc).to.equal('Set item color: <span style="color: #fff;">#fff</span>');
|
||||
|
||||
action.type = 2;
|
||||
action.change_to = 1;
|
||||
desc = autoActions.getTypeDescription(action);
|
||||
|
||||
expect(desc).to.equal('Set item category: Category 1');
|
||||
|
||||
action.type = 3;
|
||||
action.change_to = 1;
|
||||
desc = autoActions.getTypeDescription(action);
|
||||
|
||||
expect(desc).to.equal('Add item category: Category 1');
|
||||
|
||||
action.type = 4;
|
||||
action.change_to = 2;
|
||||
desc = autoActions.getTypeDescription(action);
|
||||
|
||||
expect(desc).to.equal('Set item assignee: test');
|
||||
|
||||
action.type = 5;
|
||||
action.change_to = 2;
|
||||
desc = autoActions.getTypeDescription(action);
|
||||
|
||||
expect(desc).to.equal('Add item assignee: test');
|
||||
|
||||
action.type = 6;
|
||||
desc = autoActions.getTypeDescription(action);
|
||||
|
||||
expect(desc).to.equal('Clear item due date.');
|
||||
|
||||
action.type = 7;
|
||||
desc = autoActions.getTypeDescription(action);
|
||||
|
||||
expect(desc).to.equal('Alter item color by points.');
|
||||
});
|
||||
});
|
||||
|
27
test/app/settings/auto-actions/auto-actions.service.spec.js
Normal file
27
test/app/settings/auto-actions/auto-actions.service.spec.js
Normal file
@ -0,0 +1,27 @@
|
||||
/* globals expect HttpMock */
|
||||
var dirs = '../../../../',
|
||||
path = dirs + 'build/settings/auto-actions/',
|
||||
AutoActionsService = require(path + 'auto-actions.service.js').AutoActionsService;
|
||||
|
||||
describe('AutoActionsService', () => {
|
||||
var service;
|
||||
|
||||
beforeEach(() => {
|
||||
service = new AutoActionsService(HttpMock);
|
||||
});
|
||||
|
||||
it('allows an action to be added', done => {
|
||||
service.addAction(null).subscribe(action => {
|
||||
expect(action.endpoint).to.equal('api/autoactions');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('allows an action to be removed', done => {
|
||||
service.removeAction({ id: 1 }).subscribe(action => {
|
||||
expect(action.endpoint).to.equal('api/autoactions/1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -35,14 +35,14 @@ describe('BoardAdmin', () => {
|
||||
}
|
||||
});
|
||||
|
||||
// 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);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -25,81 +25,79 @@ describe('UserAdmin', () => {
|
||||
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);
|
||||
// });
|
||||
it('has a function to add or edit a user - Add', done => {
|
||||
userAdmin.modalProps.title = 'Add';
|
||||
userAdmin.modalProps.user = newUser;
|
||||
|
||||
// it('has a function to add or edit a user - Edit', done => {
|
||||
// userAdmin.modalProps.title = 'Edit';
|
||||
// userAdmin.modalProps.user = newUser;
|
||||
// userAdmin.modalProps.user.id = 1;
|
||||
userAdmin.addEditUser();
|
||||
|
||||
// userAdmin.addEditUser();
|
||||
setTimeout(() => {
|
||||
expect(userAdmin.users.length).to.equal(3);
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
// setTimeout(() => {
|
||||
// expect(userAdmin.users.length).to.equal(2);
|
||||
// expect(userAdmin.users[0].username).to.equal('changed');
|
||||
// done();
|
||||
// }, 10);
|
||||
// });
|
||||
it('has a function to add or edit a user - Edit', done => {
|
||||
userAdmin.modalProps.title = 'Edit';
|
||||
userAdmin.modalProps.user = newUser;
|
||||
|
||||
// it('has a function to validate a user', () => {
|
||||
// userAdmin.modalProps.title = 'Add';
|
||||
userAdmin.addEditUser();
|
||||
|
||||
// userAdmin.modalProps.user = { username: '' };
|
||||
// expect(userAdmin.validateModalUser()).to.equal(false);
|
||||
setTimeout(() => {
|
||||
expect(userAdmin.users.length).to.equal(2);
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
// userAdmin.modalProps.user.username = 'user';
|
||||
// userAdmin.modalProps.user.password = '';
|
||||
// expect(userAdmin.validateModalUser()).to.equal(false);
|
||||
it('has a function to validate a user', () => {
|
||||
userAdmin.modalProps.title = 'Add';
|
||||
|
||||
// userAdmin.modalProps.user.password = 'test';
|
||||
// userAdmin.modalProps.user.verifyPassword = '';
|
||||
// expect(userAdmin.validateModalUser()).to.equal(false);
|
||||
userAdmin.modalProps.user = { username: '' };
|
||||
expect(userAdmin.validateModalUser()).to.equal(false);
|
||||
|
||||
// userAdmin.modalProps.user.verifyPassword = 'test';
|
||||
// userAdmin.modalProps.user.email = 'invalid';
|
||||
// expect(userAdmin.validateModalUser()).to.equal(false);
|
||||
userAdmin.modalProps.user.username = 'user';
|
||||
userAdmin.modalProps.user.password = '';
|
||||
expect(userAdmin.validateModalUser()).to.equal(false);
|
||||
|
||||
// userAdmin.modalProps.user.email = 'email@test.com';
|
||||
// expect(userAdmin.validateModalUser()).to.equal(true);
|
||||
// });
|
||||
userAdmin.modalProps.user.password = 'test';
|
||||
userAdmin.modalProps.user.password_verify = '';
|
||||
expect(userAdmin.validateModalUser()).to.equal(false);
|
||||
|
||||
// it('has a function to remove a user', done => {
|
||||
// userAdmin.userToRemove = { id: 1 };
|
||||
// userAdmin.removeUser();
|
||||
userAdmin.modalProps.user.password_verify = 'test';
|
||||
userAdmin.modalProps.user.email = 'invalid';
|
||||
expect(userAdmin.validateModalUser()).to.equal(false);
|
||||
|
||||
// setTimeout(() => {
|
||||
// expect(userAdmin.users.length).to.equal(1);
|
||||
// done();
|
||||
// }, 10);
|
||||
// });
|
||||
userAdmin.modalProps.user.email = 'email@test.com';
|
||||
expect(userAdmin.validateModalUser()).to.equal(true);
|
||||
});
|
||||
|
||||
// it('has a showModal function', done => {
|
||||
// modalService.openCalled.subscribe(modalId => {
|
||||
// expect(modalId).to.equal(userAdmin.MODAL_ID);
|
||||
// done();
|
||||
// });
|
||||
it('has a function to remove a user', done => {
|
||||
userAdmin.userToRemove = { id: 1 };
|
||||
userAdmin.removeUser();
|
||||
|
||||
// userAdmin.showModal('Add');
|
||||
// });
|
||||
setTimeout(() => {
|
||||
expect(userAdmin.users.length).to.equal(1);
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
// it('has a showConfirmModal function', done => {
|
||||
// modalService.openCalled.subscribe(modalId => {
|
||||
// expect(modalId).to.equal(userAdmin.MODAL_CONFIRM_ID);
|
||||
// expect(userAdmin.userToRemove).to.equal(true);
|
||||
// done();
|
||||
// });
|
||||
it('has a showModal function', done => {
|
||||
modalService.openCalled.subscribe(modalId => {
|
||||
expect(modalId).to.equal(userAdmin.MODAL_ID);
|
||||
done();
|
||||
});
|
||||
|
||||
// userAdmin.showConfirmModal(true);
|
||||
// });
|
||||
userAdmin.showModal('Add');
|
||||
});
|
||||
|
||||
it('has a showConfirmModal function', done => {
|
||||
modalService.openCalled.subscribe(modalId => {
|
||||
expect(modalId).to.equal(userAdmin.MODAL_CONFIRM_ID);
|
||||
expect(userAdmin.userToRemove).to.equal(true);
|
||||
done();
|
||||
});
|
||||
|
||||
userAdmin.showConfirmModal(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user