More unit testing

This commit is contained in:
Matthew Ross 2018-03-22 21:27:17 -04:00
parent 705fe0e407
commit f12da9b370
2 changed files with 122 additions and 10 deletions

View File

@ -38,7 +38,6 @@ import { BoardService } from '../board.service';
templateUrl: './column.component.html'
})
export class ColumnDisplay implements OnInit, OnDestroy {
private saving: boolean;
private showLimitEditor: boolean;
private isOverdue: boolean;
private isNearlyDue: boolean;
@ -48,10 +47,8 @@ export class ColumnDisplay implements OnInit, OnDestroy {
private MODAL_ID: string;
private MODAL_VIEW_ID: string;
private modalProps: Task;
private viewModalProps: Task;
private viewTaskActivities: Array<ActivitySimple>;
private taskToRemove: number;
private taskLimit: number;
private commentEdit: Comment;
private commentToRemove: Comment;
@ -62,13 +59,17 @@ export class ColumnDisplay implements OnInit, OnDestroy {
private subs = [];
public templateElement: any;
public userOptions: UserOptions;
public strings: any;
public collapseTasks: boolean;
public sortOption: string;
public saving: boolean;
public taskToRemove: number;
public modalProps: Task;
public userOptions: UserOptions;
public activeUser: User;
public activeBoard: Board;
public contextMenuItems: Array<ContextMenuItem>;
public sortOption: string;
public quickAdd: Task;
public MODAL_CONFIRM_ID: string;
@ -84,7 +85,7 @@ export class ColumnDisplay implements OnInit, OnDestroy {
private notes: NotificationsService,
public modal: ModalService,
private stringsService: StringsService,
private boardService: BoardService,
public boardService: BoardService,
private sanitizer: DomSanitizer) {
this.templateElement = elRef.nativeElement;
this.tasks = [];
@ -218,14 +219,16 @@ export class ColumnDisplay implements OnInit, OnDestroy {
.subscribe((response: ApiResponse) => {
response.alerts.forEach(note => this.notes.add(note));
this.modal.close(this.MODAL_ID + this.columnData.id);
if (response.status !== 'success') {
this.saving = false;
return;
}
let boardData = response.data[2][0];
this.modal.close(this.MODAL_ID + (this.columnData
? this.columnData.id + ''
: ''));
let boardData = response.data[2][0];
boardData.ownColumn.forEach((column: any) => {
if (!column.ownTask) {
column.ownTask = [];
@ -251,11 +254,14 @@ export class ColumnDisplay implements OnInit, OnDestroy {
response.alerts.forEach(note => this.notes.add(note));
if (response.status !== 'success') {
this.saving = false;
return;
}
this.boardService.updateActiveBoard(response.data[2][0]);
this.modal.close(this.MODAL_ID + this.columnData.id);
this.modal.close(this.MODAL_ID + (this.columnData
? this.columnData.id + ''
: ''));
this.boardService.refreshToken();
this.saving = false;

View File

@ -88,5 +88,111 @@ describe('ColumnDisplay', () => {
expect(component.columnData.tasks[0].points).toEqual(3);
});
it('calls a service to toggle collapsed state', () => {
(<any>component.boardService.toggleCollapsed) = () => {
return { subscribe: fn => fn(<any>{ data: [{}, [1]] }) };
};
component.activeUser = <any>{ id: 1, collapsed: [] };
component.columnData = <any>{ id: 1 };
component.toggleCollapsed();
expect(component.templateElement.classList
.contains('collapsed')).toEqual(true);
expect(component.activeUser.collapsed[0]).toEqual(1);
});
it('toggles task collapsing', () => {
component.collapseTasks = false;
component.toggleTaskCollapse();
expect(component.collapseTasks).toEqual(true);
});
it('updates task color by category', () => {
const mock = [<any>{ default_task_color: 'red' }];
component.updateTaskColorByCategory(mock);
expect(component.modalProps.categories).toEqual(mock);
expect(component.modalProps.color).toEqual('red');
});
it('calls a service to add a task', () => {
component.addTask();
expect(component.saving).toEqual(false);
(<any>component.boardService.addTask) = () => {
return { subscribe: fn => fn(<any>{ status: 'error', alerts: [{}] }) };
};
component.modalProps = <any>{ title: 'Testing' };
component.addTask();
expect(component.saving).toEqual(false);
(<any>component.boardService.addTask) = () => {
return { subscribe: fn => fn(<any>{
status: 'success',
alerts: [],
data: [{}, {}, [{ ownColumn: [{}] }]]
}) };
};
component.addTask();
expect(component.saving).toEqual(false);
});
it('calls a service to update a task', () => {
component.updateTask();
expect(component.saving).toEqual(false);
(<any>component.boardService.updateTask) = () => {
return { subscribe: fn => fn(<any>{ status: 'error', alerts: [{}] }) };
};
component.modalProps = <any>{ title: 'Testing' };
component.updateTask();
expect(component.saving).toEqual(false);
(<any>component.boardService.updateTask) = () => {
return { subscribe: fn => fn(<any>{
status: 'success',
alerts: [],
data: [{}, {}, [{ ownColumn: [{}] }]]
}) };
};
component.updateTask();
expect(component.saving).toEqual(false);
});
it('calls a service to remove a task', () => {
let called = false;
component.taskToRemove = 1;
(<any>component.boardService.removeTask) = () => {
return { subscribe: fn => {
called = true;
fn(<any>{ status: 'error', alerts: [{}] });
} };
};
component.removeTask();
expect(called).toEqual(true);
(<any>component.boardService.removeTask) = () => {
return { subscribe: fn => {
called = true;
fn(<any>{
status: 'success',
alerts: [{}],
data: [{}, [{}]]
});
} };
};
component.removeTask();
expect(called).toEqual(true);
});
});