[AAE-1695] reduce manual tests (#5455)

* tests cleanup

* cleanup search control tests

* EmptyContentComponent tests

* fix names

* search filter category test

* task list test and code polish

* process list tests and cleanup

* extra task-list tests

* extra start-task tests

* code cleanup
This commit is contained in:
Denys Vuika
2020-02-08 01:08:35 +00:00
committed by GitHub
parent a3cbf9bcd3
commit f54bc24317
20 changed files with 471 additions and 297 deletions

View File

@@ -11,12 +11,11 @@
(row-keyup)="onRowKeyUp($event)">
<adf-loading-content-template>
<ng-template>
<!--Add your custom loading template here-->
<mat-progress-spinner
*ngIf="!customLoadingContent"
class="adf-process-list-loading-margin"
[color]="'primary'"
[mode]="'indeterminate'">
color="primary"
mode="indeterminate">
</mat-progress-spinner>
<ng-content select="adf-custom-loading-content-template"></ng-content>
</ng-template>
@@ -25,7 +24,7 @@
<ng-template>
<adf-empty-content *ngIf="!customEmptyContent"
icon="assessment"
[title]="(requestNode ? 'ADF_PROCESS_LIST.LIST.TITLE' : 'ADF_PROCESS_LIST.FILTERS.MESSAGES.NONE') | translate "
[title]="(requestNode ? 'ADF_PROCESS_LIST.LIST.TITLE' : 'ADF_PROCESS_LIST.FILTERS.MESSAGES.NONE') | translate"
[subtitle]="'ADF_PROCESS_LIST.LIST.SUBTITLE'| translate">
</adf-empty-content>
<ng-content select="adf-custom-empty-content-template"></ng-content>

View File

@@ -36,6 +36,7 @@ describe('ProcessInstanceListComponent', () => {
let service: ProcessService;
let getProcessInstancesSpy: jasmine.Spy;
let appConfig: AppConfigService;
const resolverfn = (row: DataRow, col: DataColumn) => {
const value = row.getValue(col.key);
if (col.key === 'variables') {
@@ -77,6 +78,13 @@ describe('ProcessInstanceListComponent', () => {
};
}));
it('should display loading spinner', () => {
component.isLoading = true;
const spinner = fixture.debugElement.query(By.css('.mat-progress-spinner'));
expect(spinner).toBeDefined();
});
it('should use the default schemaColumn as default', () => {
component.ngAfterContentInit();
expect(component.columns).toBeDefined();

View File

@@ -29,7 +29,6 @@ import {
PaginationModel,
UserPreferencesService
} from '@alfresco/adf-core';
import { DatePipe } from '@angular/common';
import {
AfterContentInit,
Component,
@@ -45,7 +44,7 @@ import { processPresetsDefaultModel } from '../models/process-preset.model';
import { ProcessService } from '../services/process.service';
import { BehaviorSubject } from 'rxjs';
import { ProcessListModel } from '../models/process-list.model';
import { ProcessInstanceRepresentation } from '@alfresco/js-api';
import { finalize } from 'rxjs/operators';
@Component({
selector: 'adf-process-instance-list',
@@ -120,22 +119,21 @@ export class ProcessInstanceListComponent extends DataTableSchema implements OnC
/** Emitted when a row in the process list is clicked. */
@Output()
rowClick: EventEmitter<string> = new EventEmitter<string>();
rowClick = new EventEmitter<string>();
/** Emitted when the list of process instances has been loaded successfully from the server. */
@Output()
success: EventEmitter<ProcessListModel> = new EventEmitter<ProcessListModel>();
success = new EventEmitter<ProcessListModel>();
/** Emitted when an error occurs while loading the list of process instances from the server. */
@Output()
error: EventEmitter<any> = new EventEmitter<any>();
error = new EventEmitter<any>();
requestNode: ProcessFilterParamRepresentationModel;
currentInstanceId: string;
isLoading: boolean = true;
rows: any[] = [];
sorting: any[] = ['created', 'desc'];
pagination: BehaviorSubject<PaginationModel>;
constructor(private processService: ProcessService,
@@ -153,6 +151,7 @@ export class ProcessInstanceListComponent extends DataTableSchema implements OnC
ngAfterContentInit() {
this.createDatatableSchema();
if (this.data && this.data.getColumns().length === 0) {
this.data.setColumns(this.columns);
}
@@ -213,12 +212,12 @@ export class ProcessInstanceListComponent extends DataTableSchema implements OnC
private load(requestNode: ProcessFilterParamRepresentationModel) {
this.isLoading = true;
this.processService.getProcesses(requestNode)
.pipe(finalize(() => this.isLoading = false))
.subscribe(
(response) => {
this.rows = this.optimizeProcessDetails(response.data);
response => {
this.rows = response.data;
this.selectFirst();
this.success.emit(response);
this.isLoading = false;
this.pagination.next({
count: response.data.length,
maxItems: this.size,
@@ -226,10 +225,10 @@ export class ProcessInstanceListComponent extends DataTableSchema implements OnC
totalItems: response.total
});
},
(error) => {
error => {
this.error.emit(error);
this.isLoading = false;
});
}
);
}
/**
@@ -267,6 +266,7 @@ export class ProcessInstanceListComponent extends DataTableSchema implements OnC
*/
onRowClick(event: DataRowEvent) {
const item = event;
this.currentInstanceId = item.value.getValue('id');
this.rowClick.emit(this.currentInstanceId);
}
@@ -278,43 +278,14 @@ export class ProcessInstanceListComponent extends DataTableSchema implements OnC
onRowKeyUp(event: CustomEvent) {
if (event.detail.keyboardEvent.key === 'Enter') {
event.preventDefault();
this.currentInstanceId = event.detail.row.getValue('id');
this.rowClick.emit(this.currentInstanceId);
}
}
/**
* Optimize name field
* @param instances
*/
private optimizeProcessDetails(instances: ProcessInstanceRepresentation[]): ProcessInstanceRepresentation[] {
instances = instances.map((instance) => {
instance.name = this.getProcessNameOrDescription(instance, 'medium');
return instance;
});
return instances;
}
getProcessNameOrDescription(processInstance: ProcessInstanceRepresentation, dateFormat: string): string {
let name = '';
if (processInstance) {
name = processInstance.name ||
processInstance.processDefinitionName + ' - ' + this.getFormatDate(processInstance.started, dateFormat);
}
return name;
}
getFormatDate(value: Date, format: string) {
const datePipe = new DatePipe('en-US');
try {
return datePipe.transform(value, format);
} catch (err) {
return '';
}
}
private createRequestNode(): ProcessFilterParamRepresentationModel {
const requestNode = {
return new ProcessFilterParamRepresentationModel({
appDefinitionId: this.appId,
processDefinitionId: this.processDefinitionId,
processInstanceId: this.processInstanceId,
@@ -323,14 +294,15 @@ export class ProcessInstanceListComponent extends DataTableSchema implements OnC
page: this.page,
size: this.size,
start: 0
};
return new ProcessFilterParamRepresentationModel(requestNode);
});
}
updatePagination(params: PaginationModel) {
const needsReload = params.maxItems || params.skipCount;
this.size = params.maxItems;
this.page = this.currentPage(params.skipCount, params.maxItems);
if (needsReload) {
this.reload();
}

View File

@@ -17,7 +17,7 @@
import { AlfrescoApiService, FormValues } from '@alfresco/adf-core';
import { Injectable } from '@angular/core';
import { RestVariable } from '@alfresco/js-api';
import { RestVariable, ProcessInstanceRepresentation } from '@alfresco/js-api';
import { Observable, from, throwError, of } from 'rxjs';
import { TaskDetailsModel } from '../../task-list';
import { ProcessFilterParamRepresentationModel } from '../models/filter-process.model';
@@ -26,6 +26,7 @@ import { ProcessInstanceVariable } from '../models/process-instance-variable.mod
import { ProcessInstance } from '../models/process-instance.model';
import { ProcessListModel } from '../models/process-list.model';
import { map, catchError } from 'rxjs/operators';
import { DatePipe } from '@angular/common';
declare let moment: any;
@@ -67,9 +68,39 @@ export class ProcessService {
*/
getProcesses(requestNode: ProcessFilterParamRepresentationModel, processDefinitionKey?: string): Observable<ProcessListModel> {
return this.getProcessInstances(requestNode, processDefinitionKey)
.pipe(catchError(() => {
return of(new ProcessListModel({}));
}));
.pipe(
map(response => {
return {
...response,
data: (response.data || []).map(instance => {
instance.name = this.getProcessNameOrDescription(instance, 'medium');
return instance;
})
};
}),
catchError(() => of(new ProcessListModel({})))
);
}
private getProcessNameOrDescription(processInstance: ProcessInstanceRepresentation, dateFormat: string): string {
let name = '';
if (processInstance) {
name = processInstance.name ||
processInstance.processDefinitionName + ' - ' + this.getFormatDate(processInstance.started, dateFormat);
}
return name;
}
private getFormatDate(value: Date, format: string) {
const datePipe = new DatePipe('en-US');
try {
return datePipe.transform(value, format);
} catch (err) {
return '';
}
}
/**

View File

@@ -81,17 +81,19 @@
<div class="adf-new-task-footer" fxLayout="row" fxLayoutAlign="end end">
<button
mat-button
class="adf-uppercase"
(click)="onCancel()"
id="button-cancel">
{{'ADF_TASK_LIST.START_TASK.FORM.ACTION.CANCEL'|translate}}
{{ 'ADF_TASK_LIST.START_TASK.FORM.ACTION.CANCEL' | translate }}
</button>
<button
color="primary"
mat-button
class="adf-uppercase"
[disabled]="!isFormValid()"
(click)="saveTask()"
id="button-start">
{{'ADF_TASK_LIST.START_TASK.FORM.ACTION.START'|translate}}
{{ 'ADF_TASK_LIST.START_TASK.FORM.ACTION.START' | translate }}
</button>
</div>
</mat-card-actions>

View File

@@ -34,6 +34,10 @@
adf-start-task {
.mat-button.adf-uppercase {
text-transform: uppercase;
}
people-widget {
width: 100%;
.mat-form-field-label-wrapper {
@@ -54,13 +58,6 @@
}
.adf {
&-new-task-footer {
.mat-button {
text-transform: uppercase !important;
}
}
&-start-task-input-container .mat-form-field-wrapper {
padding-top: 8px;
}

View File

@@ -34,6 +34,7 @@ describe('StartTaskComponent', () => {
let getFormListSpy: jasmine.Spy;
let createNewTaskSpy: jasmine.Spy;
let logSpy: jasmine.Spy;
const fakeForms$ = [
{
id: 123,
@@ -58,6 +59,7 @@ describe('StartTaskComponent', () => {
service = TestBed.get(TaskListService);
logService = TestBed.get(LogService);
getFormListSpy = spyOn(service, 'getFormList').and.returnValue(new Observable((observer) => {
observer.next(fakeForms$);
observer.complete();
@@ -71,10 +73,6 @@ describe('StartTaskComponent', () => {
TestBed.resetTestingModule();
});
it('should create instance of StartTaskComponent', () => {
expect(component instanceof StartTaskComponent).toBe(true, 'should create StartTaskComponent');
});
it('should fetch fake form on init', () => {
component.ngOnInit();
fixture.detectChanges();
@@ -309,6 +307,21 @@ describe('StartTaskComponent', () => {
expect(element.querySelector('#button-start').textContent).toContain('ADF_TASK_LIST.START_TASK.FORM.ACTION.START');
});
it('should render start task button with primary color', () => {
fixture.detectChanges();
expect(element.querySelector('#button-start').classList.contains('mat-primary')).toBeTruthy();
});
it('should render task buttons with uppercase text', () => {
fixture.detectChanges();
const startButton = element.querySelector<HTMLButtonElement>('#button-start');
expect(startButton.classList.contains('adf-uppercase')).toBeTruthy();
const cancelButton = element.querySelector<HTMLButtonElement>('#button-cancel');
expect(cancelButton.classList.contains('adf-uppercase')).toBeTruthy();
});
it('should not emit TaskDetails OnCancel', () => {
const emitSpy = spyOn(component.cancel, 'emit');
component.onCancel();

View File

@@ -18,8 +18,8 @@
<mat-progress-spinner
*ngIf="!customLoadingContent"
class="adf-task-list-loading-margin"
[color]="'primary'"
[mode]="'indeterminate'">
color="primary"
mode="indeterminate">
</mat-progress-spinner>
<ng-content select="adf-custom-loading-content-template"></ng-content>
</ng-template>

View File

@@ -16,7 +16,7 @@
*/
import { Component, SimpleChange, ViewChild } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AppConfigService, setupTestBed, CoreModule, DataTableModule, DataRowEvent, ObjectDataRow } from '@alfresco/adf-core';
import { TaskListService } from '../services/tasklist.service';
@@ -79,6 +79,29 @@ describe('TaskListComponent', () => {
fixture.destroy();
});
it('should display loading spinner', () => {
component.isLoading = true;
const spinner = fixture.debugElement.query(By.css('.mat-progress-spinner'));
expect(spinner).toBeDefined();
});
it('should hide loading spinner upon loading complete', async(() => {
component.isLoading = true;
fixture.detectChanges();
let spinner = fixture.debugElement.query(By.css('.mat-progress-spinner'));
expect(spinner).toBeDefined();
component.isLoading = false;
fixture.detectChanges();
fixture.whenStable().then(() => {
spinner = fixture.debugElement.query(By.css('.mat-progress-spinner'));
expect(spinner).toBeNull();
});
}));
it('should use the default schemaColumn as default', () => {
component.ngAfterContentInit();
expect(component.columns).toBeDefined();

View File

@@ -29,7 +29,7 @@ import { TaskListModel } from '../models/task-list.model';
import { taskPresetsDefaultModel } from '../models/task-preset.model';
import { TaskListService } from './../services/tasklist.service';
import moment from 'moment-es6';
import { takeUntil } from 'rxjs/operators';
import { takeUntil, finalize } from 'rxjs/operators';
import { TaskDetailsModel } from '../models/task-details.model';
@Component({
@@ -125,19 +125,19 @@ export class TaskListComponent extends DataTableSchema implements OnChanges, Aft
/** Emitted when a task in the list is clicked */
@Output()
rowClick: EventEmitter<string> = new EventEmitter<string>();
rowClick = new EventEmitter<string>();
/** Emitted when rows are selected/unselected */
@Output()
rowsSelected: EventEmitter<any[]> = new EventEmitter<any[]>();
rowsSelected = new EventEmitter<any[]>();
/** Emitted when the task list is loaded */
@Output()
success: EventEmitter<any> = new EventEmitter<any>();
success = new EventEmitter<any>();
/** Emitted when an error occurs. */
@Output()
error: EventEmitter<any> = new EventEmitter<any>();
error = new EventEmitter<any>();
currentInstanceId: string;
selectedInstances: any[];
@@ -258,22 +258,24 @@ export class TaskListComponent extends DataTableSchema implements OnChanges, Aft
private load() {
this.isLoading = true;
this.loadTasksByState().subscribe(
(tasks) => {
this.rows = this.optimizeTaskDetails(tasks.data);
this.selectTask(this.landingTaskId);
this.success.emit(tasks);
this.isLoading = false;
this.pagination.next({
count: tasks.data.length,
maxItems: this.size,
skipCount: this.page * this.size,
totalItems: tasks.total
this.loadTasksByState()
.pipe(finalize(() => this.isLoading = false))
.subscribe(
tasks => {
this.rows = this.optimizeTaskDetails(tasks.data);
this.selectTask(this.landingTaskId);
this.success.emit(tasks);
this.pagination.next({
count: tasks.data.length,
maxItems: this.size,
skipCount: this.page * this.size,
totalItems: tasks.total
});
},
error => {
this.error.emit(error);
});
}, (error) => {
this.error.emit(error);
this.isLoading = false;
});
}
private loadTasksByState(): Observable<TaskListModel> {
@@ -288,14 +290,17 @@ export class TaskListComponent extends DataTableSchema implements OnChanges, Aft
selectTask(taskIdSelected: string): void {
if (!this.isListEmpty()) {
let dataRow = null;
if (taskIdSelected) {
dataRow = this.rows.find((currentRow: any) => {
return currentRow['id'] === taskIdSelected;
});
}
if (!dataRow && this.selectFirstRow) {
dataRow = this.rows[0];
}
if (dataRow) {
dataRow.isSelected = true;
this.currentInstanceId = dataRow['id'];
@@ -345,6 +350,7 @@ export class TaskListComponent extends DataTableSchema implements OnChanges, Aft
onRowKeyUp(event: CustomEvent) {
if (event.detail.keyboardEvent.key === 'Enter') {
event.preventDefault();
this.currentInstanceId = event.detail.row.getValue('id');
this.rowClick.emit(this.currentInstanceId);
}
@@ -365,7 +371,6 @@ export class TaskListComponent extends DataTableSchema implements OnChanges, Aft
}
private createRequestNode() {
const requestNode = {
appDefinitionId: this.appId,
dueAfter: this.dueAfter ? moment(this.dueAfter).toDate() : null,
@@ -387,8 +392,10 @@ export class TaskListComponent extends DataTableSchema implements OnChanges, Aft
updatePagination(params: PaginationModel) {
const needsReload = params.maxItems || params.skipCount;
this.size = params.maxItems;
this.page = this.currentPage(params.skipCount, params.maxItems);
if (needsReload) {
this.reload();
}