Unit tests
This commit is contained in:
parent
0b1243b9bd
commit
4e2843499e
@ -172,12 +172,14 @@ export class ColumnDisplay implements OnInit, OnDestroy {
|
||||
return a.position - b.position;
|
||||
});
|
||||
break;
|
||||
|
||||
case 'due':
|
||||
this.columnData.tasks.sort((a, b) => {
|
||||
return new Date(a.due_date).getTime() -
|
||||
new Date(b.due_date).getTime();
|
||||
});
|
||||
break;
|
||||
|
||||
case 'pnt':
|
||||
this.columnData.tasks.sort((a, b) => {
|
||||
return b.points - a.points;
|
||||
|
@ -32,18 +32,20 @@ export class AutoActions {
|
||||
private autoActions: Array<AutoAction>;
|
||||
|
||||
private triggers: Array<Array<any>>;
|
||||
private triggerSources: Array<Array<any>>;
|
||||
private types: Array<Array<any>>;
|
||||
private typesList: Array<Array<any>>;
|
||||
private actionSources: Array<Array<any>>;
|
||||
private subs: Array<any>;
|
||||
|
||||
private firstRun = true;
|
||||
private isAddDisabled = true;
|
||||
|
||||
public boards: Array<Board>;
|
||||
public triggerSources: Array<Array<any>>;
|
||||
public actionSources: Array<Array<any>>;
|
||||
public types: Array<Array<any>>;
|
||||
public typesList: Array<Array<any>>;
|
||||
|
||||
public newAction: AutoAction;
|
||||
public activeUser: User;
|
||||
public boards: Array<Board>;
|
||||
|
||||
public strings: any;
|
||||
public MODAL_CONFIRM_ID: string;
|
||||
|
||||
@ -186,17 +188,17 @@ export class AutoActions {
|
||||
|
||||
switch (this.newAction.trigger) {
|
||||
case ActionTrigger.MovedToColumn:
|
||||
this.buildSourcesArray('triggerSources',
|
||||
'Column', 'columns');
|
||||
this.buildSourcesArray('triggerSources', 'Column', 'columns');
|
||||
break;
|
||||
|
||||
case ActionTrigger.AssignedToUser:
|
||||
this.buildSourcesArray('triggerSources',
|
||||
'User', 'users', 'username');
|
||||
this.buildSourcesArray('triggerSources', 'User', 'users', 'username');
|
||||
break;
|
||||
|
||||
case ActionTrigger.AddedToCategory:
|
||||
this.buildSourcesArray('triggerSources',
|
||||
'Category', 'categories');
|
||||
this.buildSourcesArray('triggerSources', 'Category', 'categories');
|
||||
break;
|
||||
|
||||
case ActionTrigger.PointsChanged:
|
||||
// Leave triggerSources empty
|
||||
this.types = [ [
|
||||
@ -219,14 +221,14 @@ export class AutoActions {
|
||||
switch (this.newAction.type) {
|
||||
case ActionType.SetCategory:
|
||||
case ActionType.AddCategory:
|
||||
this.buildSourcesArray('actionSources',
|
||||
'Category', 'categories');
|
||||
this.buildSourcesArray('actionSources', 'Category', 'categories');
|
||||
break;
|
||||
|
||||
case ActionType.SetAssignee:
|
||||
case ActionType.AddAssignee:
|
||||
this.buildSourcesArray('actionSources',
|
||||
'Assignee', 'users', 'username');
|
||||
this.buildSourcesArray('actionSources', 'Assignee', 'users', 'username');
|
||||
break;
|
||||
|
||||
case ActionType.SetColor:
|
||||
this.newAction.change_to = '#000000';
|
||||
break;
|
||||
@ -279,16 +281,19 @@ export class AutoActions {
|
||||
desc = this.strings.settings_triggerMoveToColumn + ' ';
|
||||
desc += this.getNameFromArray(board.columns, action.source_id);
|
||||
break;
|
||||
|
||||
case ActionTrigger.AssignedToUser:
|
||||
desc = this.strings.settings_triggerAssignedToUser + ' ';
|
||||
desc += this.getNameFromArray(board.users,
|
||||
action.source_id, 'username');
|
||||
break;
|
||||
|
||||
case ActionTrigger.AddedToCategory:
|
||||
desc = this.strings.settings_triggerAddedToCategory + ' ';
|
||||
desc += this.getNameFromArray(board.categories,
|
||||
action.source_id);
|
||||
break;
|
||||
|
||||
case ActionTrigger.PointsChanged:
|
||||
desc = this.strings.settings_triggerPointsChanged;
|
||||
break;
|
||||
@ -310,29 +315,35 @@ export class AutoActions {
|
||||
desc = this.strings.settings_actionSetColor + ' <span style="background-color: ' +
|
||||
action.change_to + ';">' + action.change_to + '</span>';
|
||||
break;
|
||||
|
||||
case ActionType.SetCategory:
|
||||
desc = this.strings.settings_actionSetCategory + ' ';
|
||||
desc += this.getNameFromArray(board.categories,
|
||||
+action.change_to);
|
||||
break;
|
||||
|
||||
case ActionType.AddCategory:
|
||||
desc = this.strings.settings_actionAddCategory + ' ';
|
||||
desc += this.getNameFromArray(board.categories,
|
||||
+action.change_to);
|
||||
break;
|
||||
|
||||
case ActionType.SetAssignee:
|
||||
desc = this.strings.settings_actionSetAssignee + ' ';
|
||||
desc += this.getNameFromArray(board.users,
|
||||
+action.change_to, 'username');
|
||||
break;
|
||||
|
||||
case ActionType.AddAssignee:
|
||||
desc = this.strings.settings_actionAddAssignee + ' ';
|
||||
desc += this.getNameFromArray(board.users,
|
||||
+action.change_to, 'username');
|
||||
break;
|
||||
|
||||
case ActionType.ClearDueDate:
|
||||
desc = this.strings.settings_actionClearDueDate;
|
||||
break;
|
||||
|
||||
case ActionType.AlterColorByPoints:
|
||||
desc = this.strings.settings_actionAlterColor;
|
||||
break;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, OnDestroy } from '@angular/core';
|
||||
|
||||
import { DragulaService } from 'ng2-dragula/ng2-dragula';
|
||||
|
||||
@ -29,7 +29,7 @@ class SelectableUser extends User {
|
||||
providers: [ BoardAdminService ],
|
||||
viewProviders: [ DragulaService ]
|
||||
})
|
||||
export class BoardAdmin {
|
||||
export class BoardAdmin implements OnDestroy {
|
||||
private displayBoards: Array<Board>;
|
||||
private noBoardsMessage: string;
|
||||
private boardToRemove: Board;
|
||||
@ -39,6 +39,7 @@ export class BoardAdmin {
|
||||
private sortFilter: string;
|
||||
|
||||
private firstRun = true;
|
||||
private subs: Array<any>;
|
||||
|
||||
public users: Array<User>;
|
||||
public boards: Array<Board>;
|
||||
@ -66,6 +67,7 @@ export class BoardAdmin {
|
||||
this.users = [];
|
||||
this.boards = [];
|
||||
this.displayBoards = [];
|
||||
this.subs = [];
|
||||
|
||||
this.modalProps = new BoardData();
|
||||
this.activeUser = new User();
|
||||
@ -74,19 +76,30 @@ export class BoardAdmin {
|
||||
this.statusFilter = '-1'; // Any active status
|
||||
this.sortFilter = 'name-asc';
|
||||
|
||||
auth.userChanged.subscribe((user: User) => {
|
||||
let sub = auth.userChanged.subscribe((user: User) => {
|
||||
this.updateActiveUser(user);
|
||||
});
|
||||
settings.usersChanged.subscribe((users: Array<User>) => {
|
||||
this.subs.push(sub);
|
||||
|
||||
sub = settings.usersChanged.subscribe((users: Array<User>) => {
|
||||
this.updateUsersList(users);
|
||||
});
|
||||
settings.boardsChanged.subscribe((boards: Array<Board>) => {
|
||||
this.subs.push(sub);
|
||||
|
||||
sub = settings.boardsChanged.subscribe((boards: Array<Board>) => {
|
||||
this.updateBoardsList(boards);
|
||||
});
|
||||
stringsService.stringsChanged.subscribe(newStrings => {
|
||||
this.subs.push(sub);
|
||||
|
||||
sub = stringsService.stringsChanged.subscribe(newStrings => {
|
||||
this.strings = newStrings;
|
||||
this.updateActiveUser(this.activeUser);
|
||||
});
|
||||
this.subs.push(sub);
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subs.forEach(sub => sub.unsubscribe());
|
||||
}
|
||||
|
||||
ngAfterContentInit() {
|
||||
@ -206,16 +219,19 @@ export class BoardAdmin {
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
break;
|
||||
|
||||
case 'name-desc':
|
||||
this.displayBoards.sort((a: Board, b: Board) => {
|
||||
return b.name.localeCompare(a.name);
|
||||
});
|
||||
break;
|
||||
|
||||
case 'id-desc':
|
||||
this.displayBoards.sort((a: Board, b: Board) => {
|
||||
return b.id - a.id;
|
||||
});
|
||||
break;
|
||||
|
||||
case 'id-asc':
|
||||
this.displayBoards.sort((a: Board, b: Board) => {
|
||||
return a.id - b.id;
|
||||
|
@ -69,15 +69,19 @@ export class UserSettings implements OnInit {
|
||||
case 'new_tasks':
|
||||
this.userOptions.new_tasks_at_bottom = event === 'true';
|
||||
break;
|
||||
|
||||
case 'mult_tasks':
|
||||
this.userOptions.multiple_tasks_per_row = event;
|
||||
break;
|
||||
|
||||
case 'show_anim':
|
||||
this.userOptions.show_animations = event;
|
||||
break;
|
||||
|
||||
case 'show_assign':
|
||||
this.userOptions.show_assignee = event;
|
||||
break;
|
||||
|
||||
case 'language':
|
||||
this.userOptions.language = event;
|
||||
break;
|
||||
|
@ -6,7 +6,10 @@ import { DomSanitizer } from '@angular/platform-browser';
|
||||
|
||||
import { SharedModule } from '../../../../src/app/shared/shared.module';
|
||||
|
||||
import { ActionTrigger } from '../../../../src/app/shared/models';
|
||||
import {
|
||||
ActionTrigger,
|
||||
ActionType
|
||||
} from '../../../../src/app/shared/models';
|
||||
import {
|
||||
AuthService,
|
||||
ModalService,
|
||||
@ -79,15 +82,230 @@ describe('AutoActions', () => {
|
||||
|
||||
it('updates trigger sources', () => {
|
||||
component.boards = <any>[{
|
||||
id: 1
|
||||
}];
|
||||
id: 1,
|
||||
columns: [{ id: 1, name: 'TestCol' }],
|
||||
users: [{ id: 1, username: 'tester' }],
|
||||
categories: [{ id: 1, name: 'TestCat' }]
|
||||
}, { id: 2 }];
|
||||
|
||||
component.newAction = <any>{
|
||||
trigger: ActionTrigger.MovedToColumn
|
||||
trigger: ActionTrigger.MovedToColumn,
|
||||
board_id: 1
|
||||
};
|
||||
component.updateTriggerSources();
|
||||
|
||||
expect()
|
||||
expect(component.triggerSources.length).toEqual(2);
|
||||
|
||||
component.newAction = <any>{
|
||||
trigger: ActionTrigger.AssignedToUser,
|
||||
board_id: 1
|
||||
};
|
||||
component.updateTriggerSources();
|
||||
|
||||
expect(component.triggerSources.length).toEqual(2);
|
||||
|
||||
component.newAction = <any>{
|
||||
trigger: ActionTrigger.AddedToCategory,
|
||||
board_id: 1
|
||||
};
|
||||
component.updateTriggerSources();
|
||||
|
||||
expect(component.triggerSources.length).toEqual(2);
|
||||
|
||||
component.newAction = <any>{
|
||||
trigger: ActionTrigger.PointsChanged,
|
||||
board_id: 1
|
||||
};
|
||||
component.updateTriggerSources();
|
||||
|
||||
expect(component.types.length).toEqual(1);
|
||||
|
||||
component.newAction = <any>{ trigger: -1 };
|
||||
component.typesList = null;
|
||||
component.updateTriggerSources();
|
||||
|
||||
expect(component.newAction.type).toEqual(ActionType.SetColor);
|
||||
});
|
||||
|
||||
it('updates action sources', () => {
|
||||
component.boards = <any>[{
|
||||
id: 1,
|
||||
columns: [{ id: 1, name: 'TestCol' }],
|
||||
users: [{ id: 1, username: 'tester' }],
|
||||
categories: [{ id: 1, name: 'TestCat' }]
|
||||
}, { id: 2 }];
|
||||
|
||||
component.newAction = <any>{
|
||||
type: ActionType.SetCategory,
|
||||
board_id: 1
|
||||
};
|
||||
component.updateActionSources();
|
||||
|
||||
expect(component.actionSources.length).toEqual(2);
|
||||
|
||||
component.newAction = <any>{
|
||||
type: ActionType.AddCategory,
|
||||
board_id: 1
|
||||
};
|
||||
component.updateActionSources();
|
||||
|
||||
expect(component.actionSources.length).toEqual(2);
|
||||
|
||||
component.newAction = <any>{
|
||||
type: ActionType.SetAssignee,
|
||||
board_id: 1
|
||||
};
|
||||
component.updateActionSources();
|
||||
|
||||
expect(component.actionSources.length).toEqual(2);
|
||||
|
||||
component.newAction = <any>{
|
||||
type: ActionType.AddAssignee,
|
||||
board_id: 1
|
||||
};
|
||||
component.updateActionSources();
|
||||
|
||||
expect(component.actionSources.length).toEqual(2);
|
||||
|
||||
component.newAction = <any>{ type: ActionType.SetColor };
|
||||
component.updateActionSources();
|
||||
|
||||
expect(component.newAction.change_to).toEqual('#000000');
|
||||
});
|
||||
|
||||
it('provides the name of a board by its ID', () => {
|
||||
component.boards = <any>[{ id: 1, name: 'Test' }];
|
||||
|
||||
let actual = component.getBoardName(1);
|
||||
expect(actual).toEqual('Test*');
|
||||
|
||||
actual = component.getBoardName(2);
|
||||
expect(actual).toEqual('');
|
||||
});
|
||||
|
||||
it('provides the description of an action\'s trigger', () => {
|
||||
component.strings = {
|
||||
settings_triggerMoveToColumn: 'Move To Column',
|
||||
settings_triggerAssignedToUser: 'Assigned To User',
|
||||
settings_triggerAddedToCategory: 'Added To Category',
|
||||
settings_triggerPointsChanged: 'Points Changed'
|
||||
};
|
||||
component.boards = <any>[{
|
||||
id: 1,
|
||||
columns: [{ id: 1, name: 'Test' }],
|
||||
users: [{ id: 1, username: 'tester' }],
|
||||
categories: [{ id: 1, name: 'Test' }]
|
||||
}];
|
||||
|
||||
const action = <any>{
|
||||
source_id: 1,
|
||||
board_id: 0,
|
||||
trigger: ActionTrigger.MovedToColumn
|
||||
};
|
||||
let actual = component.getTriggerDescription(action);
|
||||
|
||||
expect(actual).toEqual(undefined);
|
||||
|
||||
action.board_id = 1;
|
||||
actual = component.getTriggerDescription(action);
|
||||
|
||||
expect(actual).toEqual('Move To Column Test');
|
||||
|
||||
action.trigger = ActionTrigger.AssignedToUser;
|
||||
actual = component.getTriggerDescription(action);
|
||||
|
||||
expect(actual).toEqual('Assigned To User tester');
|
||||
|
||||
action.trigger = ActionTrigger.AddedToCategory;
|
||||
actual = component.getTriggerDescription(action);
|
||||
|
||||
expect(actual).toEqual('Added To Category Test');
|
||||
|
||||
action.trigger = ActionTrigger.PointsChanged;
|
||||
actual = component.getTriggerDescription(action);
|
||||
|
||||
expect(actual).toEqual('Points Changed');
|
||||
});
|
||||
|
||||
it('provides HTML for the description of an action\'s type', () => {
|
||||
component.boards = <any>[{
|
||||
id: 1,
|
||||
columns: [{ id: 1, name: 'Test' }],
|
||||
users: [{ id: 1, username: 'tester' }],
|
||||
categories: [{ id: 1, name: 'Test' }]
|
||||
}];
|
||||
|
||||
const action = <any>{
|
||||
change_to: 'red',
|
||||
board_id: 0,
|
||||
type: ActionType.SetColor
|
||||
},
|
||||
safeValuePre = 'SafeValue must use [property]=binding: undefined ',
|
||||
safeValuePost = ' (see http://g.co/ng/security#xss)';
|
||||
let actual = component.getTypeDescription(action);
|
||||
|
||||
expect(actual).toEqual(undefined);
|
||||
|
||||
action.board_id = 1;
|
||||
actual = component.getTypeDescription(action);
|
||||
|
||||
expect(actual.toString())
|
||||
.toEqual(
|
||||
safeValuePre + '<span style="background-color: red;">red</span>' + safeValuePost
|
||||
);
|
||||
|
||||
action.type = ActionType.SetCategory;
|
||||
action.change_to = 1;
|
||||
|
||||
actual = component.getTypeDescription(action);
|
||||
|
||||
expect(actual.toString()).toEqual(safeValuePre + 'Test' + safeValuePost);
|
||||
|
||||
action.type = ActionType.AddCategory;
|
||||
action.change_to = 1;
|
||||
|
||||
actual = component.getTypeDescription(action);
|
||||
|
||||
expect(actual.toString()).toEqual(safeValuePre + 'Test' + safeValuePost);
|
||||
|
||||
action.type = ActionType.SetAssignee;
|
||||
action.change_to = 1;
|
||||
|
||||
actual = component.getTypeDescription(action);
|
||||
|
||||
expect(actual.toString()).toEqual(safeValuePre + 'tester' + safeValuePost);
|
||||
|
||||
action.type = ActionType.AddAssignee;
|
||||
action.change_to = 1;
|
||||
|
||||
actual = component.getTypeDescription(action);
|
||||
|
||||
expect(actual.toString()).toEqual(safeValuePre + 'tester' + safeValuePost);
|
||||
|
||||
action.type = ActionType.ClearDueDate;
|
||||
action.change_to = 1;
|
||||
|
||||
actual = component.getTypeDescription(action);
|
||||
|
||||
expect(actual.toString()).toEqual(safeValuePre + safeValuePost.trim());
|
||||
|
||||
action.type = ActionType.AlterColorByPoints;
|
||||
action.change_to = 1;
|
||||
|
||||
actual = component.getTypeDescription(action);
|
||||
|
||||
expect(actual.toString()).toEqual(safeValuePre + safeValuePost.trim());
|
||||
});
|
||||
|
||||
it('calls aservice to remove an automatic action', () => {
|
||||
(<any>component.actions).removeAction = () => {
|
||||
return { subscribe: fn => { fn({ alerts: [], data: [{}, []] }); } };
|
||||
};
|
||||
|
||||
component.saving = true;
|
||||
component.removeAutoAction();
|
||||
|
||||
expect(component.saving).toEqual(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -0,0 +1,79 @@
|
||||
import { TestBed, getTestBed } from '@angular/core/testing'
|
||||
import {
|
||||
HttpClientTestingModule,
|
||||
HttpTestingController
|
||||
} from '@angular/common/http/testing';
|
||||
|
||||
import {
|
||||
AutoActionsService
|
||||
} from '../../../../src/app/settings/auto-actions/auto-actions.service';
|
||||
|
||||
describe('AutoActionsService', () => {
|
||||
let injector: TestBed;
|
||||
let service: AutoActionsService;
|
||||
let httpMock: HttpTestingController;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule],
|
||||
providers: [AutoActionsService]
|
||||
});
|
||||
|
||||
injector = getTestBed();
|
||||
service = injector.get(AutoActionsService);
|
||||
httpMock = injector.get(HttpTestingController);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
httpMock.verify();
|
||||
})
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
|
||||
it('adds an action', () => {
|
||||
service.addAction(<any>{}).subscribe(response => {
|
||||
expect(response.data.length).toEqual(0);
|
||||
});
|
||||
|
||||
testCall('api/autoactions', 'POST');
|
||||
});
|
||||
|
||||
it('handles errors when adding an action', () => {
|
||||
service.addAction(<any>{}).subscribe(() => {}, response => {
|
||||
expect(response.alerts.length).toEqual(1);
|
||||
});
|
||||
|
||||
testCall('api/autoactions', 'POST', true);
|
||||
});
|
||||
|
||||
it('removes an action', () => {
|
||||
service.removeAction(<any>{ id: 1 }).subscribe(response => {
|
||||
expect(response.data.length).toEqual(0);
|
||||
});
|
||||
|
||||
testCall('api/autoactions/1', 'DELETE');
|
||||
});
|
||||
|
||||
it('handles errors when removing an action', () => {
|
||||
service.removeAction(<any>{ id: 1 }).subscribe(() => {}, response => {
|
||||
expect(response.alerts.length).toEqual(1);
|
||||
});
|
||||
|
||||
testCall('api/autoactions/1', 'DELETE', true);
|
||||
});
|
||||
|
||||
const testCall = (url, method, isError = false) => {
|
||||
const req = httpMock.expectOne(url);
|
||||
expect(req.request.method).toEqual(method);
|
||||
|
||||
if (isError) {
|
||||
req.flush({ alerts: [{}] }, { status: 500, statusText: '' });
|
||||
} else {
|
||||
req.flush({ data: [] });
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -1,182 +0,0 @@
|
||||
/* global expect AuthServiceMock SettingsServiceMock BoardAdminServiceMock
|
||||
ModalServiceMock NotificationsServiceMock StringsServiceMock */
|
||||
var dirs = '../../../../',
|
||||
path = dirs + 'build/settings/board-admin/',
|
||||
pathDrag = dirs + 'node_modules/ng2-dragula/components/',
|
||||
BoardAdmin = require(path + 'board-admin.component.js').BoardAdmin,
|
||||
DragulaService = require(pathDrag + 'dragula.provider.js').DragulaService;
|
||||
|
||||
describe('BoardAdmin', () => {
|
||||
var boardAdmin,
|
||||
modalService;
|
||||
|
||||
beforeEach(() => {
|
||||
modalService = new ModalServiceMock();
|
||||
|
||||
boardAdmin = new BoardAdmin(AuthServiceMock, modalService,
|
||||
new SettingsServiceMock(), new BoardAdminServiceMock(),
|
||||
new NotificationsServiceMock(), StringsServiceMock,
|
||||
new DragulaService());
|
||||
});
|
||||
|
||||
it('has a function to get a color', () => {
|
||||
var color = boardAdmin.getColor({ defaultColor: 'test' });
|
||||
expect(color).to.equal('test');
|
||||
});
|
||||
|
||||
it('implements ngAfterContentInit', () => {
|
||||
expect(boardAdmin.ngAfterContentInit).to.be.a('function');
|
||||
|
||||
try {
|
||||
// Dragula throws when trying to subscribe to an event.
|
||||
// This is just a cheap way to get a little more coverage.
|
||||
boardAdmin.ngAfterContentInit();
|
||||
} catch (ex) {
|
||||
// Ignore errors)
|
||||
}
|
||||
});
|
||||
|
||||
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';
|
||||
boardAdmin.modalProps.name = 'tester';
|
||||
boardAdmin.modalProps.columns = [{
|
||||
id: 0,
|
||||
name: 'Column 1',
|
||||
position: 0,
|
||||
board_id: 0,
|
||||
tasks: []
|
||||
}];
|
||||
|
||||
boardAdmin.addEditBoard();
|
||||
|
||||
setTimeout(() => {
|
||||
expect(boardAdmin.boards.length).to.equal(3);
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
it('allows a board to be edited', done => {
|
||||
boardAdmin.modalProps.title = 'Edit';
|
||||
boardAdmin.modalProps.name = 'tester';
|
||||
boardAdmin.modalProps.columns = [{
|
||||
id: 0,
|
||||
name: 'Column 1',
|
||||
position: 0,
|
||||
board_id: 0,
|
||||
tasks: []
|
||||
}];
|
||||
|
||||
boardAdmin.addEditBoard();
|
||||
|
||||
setTimeout(() => {
|
||||
expect(boardAdmin.boards.length).to.equal(2);
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
it('allows a board to be removed', done => {
|
||||
boardAdmin.boardToRemove = {
|
||||
id: 2,
|
||||
name: 'test',
|
||||
is_active: true,
|
||||
columns: [{
|
||||
id: 2,
|
||||
name: 'Column 1',
|
||||
position: 0,
|
||||
board_id: 2,
|
||||
tasks: []
|
||||
}],
|
||||
categories: [],
|
||||
issue_trackers: [],
|
||||
users: []
|
||||
};
|
||||
|
||||
boardAdmin.removeBoard();
|
||||
|
||||
setTimeout(() => {
|
||||
expect(boardAdmin.boards.length).to.equal(1);
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
it('can toggle the active status of a board', done => {
|
||||
boardAdmin.toggleBoardStatus({
|
||||
id: 1,
|
||||
name: '',
|
||||
is_active: false,
|
||||
columns: [],
|
||||
categories: [],
|
||||
issue_trackers: [],
|
||||
users: []
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
expect(boardAdmin.boards.length).to.equal(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('captures Enter key events', () => {
|
||||
var stopCalled = false,
|
||||
eventStop = {
|
||||
stopPropagation: () => {
|
||||
stopCalled = true;
|
||||
}
|
||||
};
|
||||
|
||||
boardAdmin.cancelEnterKey(eventStop);
|
||||
expect(stopCalled).to.equal(true);
|
||||
});
|
||||
|
||||
it('sorts boards for display', () => {
|
||||
var filters = [ 'name-asc', 'name-desc', 'id-desc', 'id-asc' ];
|
||||
|
||||
filters.forEach(filter => {
|
||||
boardAdmin.sortFilter = filter;
|
||||
boardAdmin.sortBoards();
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
67
test/app/settings/board-admin/board-admin.component.spec.ts
Normal file
67
test/app/settings/board-admin/board-admin.component.spec.ts
Normal file
@ -0,0 +1,67 @@
|
||||
import { TestBed, ComponentFixture } from '@angular/core/testing'
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
|
||||
import { DragulaService } from 'ng2-dragula/ng2-dragula';
|
||||
import { DragulaModule } from 'ng2-dragula/ng2-dragula';
|
||||
|
||||
import { SharedModule } from '../../../../src/app/shared/shared.module';
|
||||
|
||||
import {
|
||||
AuthService,
|
||||
ModalService,
|
||||
NotificationsService,
|
||||
StringsService
|
||||
} from '../../../../src/app/shared/services';
|
||||
import { SettingsService } from '../../../../src/app/settings/settings.service';
|
||||
import { BoardAdminService } from '../../../../src/app/settings/board-admin/board-admin.service';
|
||||
|
||||
import { BoardAdmin } from '../../../../src/app/settings/board-admin/board-admin.component';
|
||||
|
||||
describe('BoardAdmin', () => {
|
||||
let component: BoardAdmin,
|
||||
fixture: ComponentFixture<BoardAdmin>;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
RouterTestingModule,
|
||||
HttpClientTestingModule,
|
||||
FormsModule,
|
||||
SharedModule,
|
||||
DragulaModule
|
||||
],
|
||||
declarations: [
|
||||
BoardAdmin
|
||||
],
|
||||
providers: [
|
||||
AuthService,
|
||||
ModalService,
|
||||
NotificationsService,
|
||||
StringsService,
|
||||
SettingsService,
|
||||
BoardAdminService,
|
||||
DragulaService
|
||||
]
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(BoardAdmin);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('can be constructed', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
// it('calls a service to add a board', () => {
|
||||
// component.modalProps.title = 'Add';
|
||||
//
|
||||
// });
|
||||
|
||||
});
|
||||
|
@ -1,33 +0,0 @@
|
||||
/* global expect HttpMock */
|
||||
var dirs = '../../../../',
|
||||
path = dirs + 'build/settings/board-admin/',
|
||||
BoardAdminService = require(path + 'board-admin.service.js').BoardAdminService;
|
||||
|
||||
describe('BoardAdmin', () => {
|
||||
var service;
|
||||
|
||||
beforeEach(() => {
|
||||
service = new BoardAdminService(HttpMock);
|
||||
});
|
||||
|
||||
it('allows a board to be added', done => {
|
||||
service.addBoard(null).subscribe(board => {
|
||||
expect(board.endpoint).to.equal('api/boards');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('allows a board to be edited', done => {
|
||||
service.editBoard({ id: 1 }).subscribe(board => {
|
||||
expect(board.endpoint).to.equal('api/boards/1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('allows a board to be removed', done => {
|
||||
service.removeBoard(1).subscribe(board => {
|
||||
expect(board.endpoint).to.equal('api/boards/1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
@ -1,137 +0,0 @@
|
||||
/* global expect */
|
||||
var path = '../../../../build/settings/board-admin/',
|
||||
BoardData = require(path + 'board-data.model.js').BoardData;
|
||||
|
||||
describe('BoardData', () => {
|
||||
var boardData;
|
||||
|
||||
beforeEach(() => {
|
||||
boardData = new BoardData();
|
||||
});
|
||||
|
||||
it('has a title property', () => {
|
||||
expect(boardData.title).to.be.a('string');
|
||||
});
|
||||
|
||||
it('has an id property', () => {
|
||||
expect(boardData.id).to.be.a('number');
|
||||
});
|
||||
|
||||
it('has a name property', () => {
|
||||
expect(boardData.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('has an is_active property', () => {
|
||||
expect(boardData.is_active).to.be.a('boolean');
|
||||
});
|
||||
|
||||
it('has a columns property', () => {
|
||||
expect(boardData.columns).to.be.an('array');
|
||||
});
|
||||
|
||||
it('has a categories property', () => {
|
||||
expect(boardData.categories).to.be.an('array');
|
||||
});
|
||||
|
||||
it('has an issue_trackers property', () => {
|
||||
expect(boardData.issue_trackers).to.be.an('array');
|
||||
});
|
||||
|
||||
it('has a users property', () => {
|
||||
expect(boardData.users).to.be.an('array');
|
||||
});
|
||||
|
||||
it('has a categoryDefaultColor property', () => {
|
||||
expect(boardData.categoryDefaultColor).to.be.a('string');
|
||||
});
|
||||
|
||||
it('has a newColumnName property', () => {
|
||||
expect(boardData.newColumnName).to.be.a('string');
|
||||
});
|
||||
|
||||
it('has a newCategoryName property', () => {
|
||||
expect(boardData.newCategoryName).to.be.a('string');
|
||||
});
|
||||
|
||||
it('has an issueTrackerUrl property', () => {
|
||||
expect(boardData.issueTrackerUrl).to.be.a('string');
|
||||
});
|
||||
|
||||
it('has an issueTrackerBugId property', () => {
|
||||
expect(boardData.issueTrackerBugId).to.be.a('string');
|
||||
});
|
||||
|
||||
it('allows a column to be added', () => {
|
||||
boardData.addColumn();
|
||||
expect(boardData.columns.length).to.equal(0);
|
||||
|
||||
boardData.newColumnName = 'test';
|
||||
boardData.addColumn();
|
||||
|
||||
expect(boardData.columns.length).to.equal(1);
|
||||
expect(boardData.columns[0].name).to.equal('test');
|
||||
expect(boardData.newColumnName).to.equal('');
|
||||
});
|
||||
|
||||
it('allows a column to be removed', () => {
|
||||
var column = { name: 'test' };
|
||||
boardData.removeColumn(column);
|
||||
|
||||
boardData.columns.push(column);
|
||||
expect(boardData.columns.length).to.equal(1);
|
||||
|
||||
boardData.removeColumn(column);
|
||||
expect(boardData.columns.length).to.equal(0);
|
||||
});
|
||||
|
||||
it('allows a category to be added', () => {
|
||||
boardData.addCategory();
|
||||
expect(boardData.categories.length).to.equal(0);
|
||||
|
||||
boardData.newCategoryName = 'test';
|
||||
boardData.categoryDefaultColor = '#ffffe0';
|
||||
boardData.addCategory();
|
||||
|
||||
expect(boardData.categories.length).to.equal(1);
|
||||
expect(boardData.categories[0].name).to.equal('test');
|
||||
expect(boardData.newCategoryName).to.equal('');
|
||||
expect(boardData.categoryDefaultColor).to.equal('#ffffe0');
|
||||
});
|
||||
|
||||
it('allows a category to be removed', () => {
|
||||
var category = { name: 'test', defaultColor: '#ffffe0' };
|
||||
boardData.removeCategory(category);
|
||||
|
||||
boardData.categories.push(category);
|
||||
expect(boardData.categories.length).to.equal(1);
|
||||
|
||||
boardData.removeCategory(category);
|
||||
expect(boardData.categories.length).to.equal(0);
|
||||
});
|
||||
|
||||
it('allows an issue tracker to be added', () => {
|
||||
boardData.addIssueTracker();
|
||||
expect(boardData.issue_trackers.length).to.equal(0);
|
||||
|
||||
boardData.issueTrackerUrl = 'test';
|
||||
boardData.issueTrackerBugId = 'test';
|
||||
boardData.addIssueTracker();
|
||||
|
||||
expect(boardData.issue_trackers.length).to.equal(1);
|
||||
expect(boardData.issue_trackers[0].url).to.equal('test');
|
||||
expect(boardData.issueTrackerUrl).to.equal('');
|
||||
expect(boardData.issueTrackerBugId).to.equal('');
|
||||
});
|
||||
|
||||
it('allows an issue tracker to be removed', () => {
|
||||
var issueTracker = { url: 'test', bugId: 'test' };
|
||||
boardData.removeIssueTracker(issueTracker);
|
||||
|
||||
boardData.issue_trackers.push(issueTracker);
|
||||
expect(boardData.issue_trackers.length).to.equal(1);
|
||||
|
||||
boardData.removeIssueTracker(issueTracker);
|
||||
expect(boardData.issue_trackers.length).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user