unit test performance (#3194)

* DataTable (-4 sec)

* PaginationComponent (-1 sec)

* DocumentList

* custom testbed setup, test upgrades

* test fixes

* more test fixes

* remove fdescribe

* test fixes

* test fixes

* more test fixes

* test fixes

* upgrade tests

* update tests

* upgrade tests

* upgrade tests

* upgrade tests

* upgrade tests

* update tests

* translate loader fixes

* auth and cookie fixes

* upgrade tests

* upgrade tests

* test fixes

* almost there

* diable broken tests

* process tests (part 1)

* fix lint issues

* another test upgrade

* almost there

* cleanup

* insights testing upgrade

* improve tests

* tests cleanup

* tests cleanup

* cleanup tests

* test cleanup

* favorite nodes tests

* rebase fix syntax

* fix core test

* give up test focus

* flush tabs

* fix search test

* Update document-list.component.spec.ts

* fix document list lock

* increase tick time

* remove duplicate test
This commit is contained in:
Denys Vuika
2018-04-23 09:55:22 +01:00
committed by Eugenio Romano
parent 9fbfcfa96e
commit 382ea3c1b3
204 changed files with 3093 additions and 4389 deletions

View File

@@ -16,13 +16,39 @@
*/
import { Component } from '@angular/core';
import { async, ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable';
import { ProcessService } from './../services/process.service';
import { ProcessAuditDirective } from './process-audit.directive';
import { setupTestBed, CoreModule } from '@alfresco/adf-core';
declare let jasmine: any;
@Component({
selector: 'adf-basic-button',
template: `
<button id="auditButton"
adf-process-audit
[process-id]="currentProcessId"
[download]="download"
[fileName]="fileName"
[format]="format"
(clicked)="onAuditClick($event)">My button
</button>`
})
class BasicButtonComponent {
download: boolean = false;
fileName: string;
format: string;
constructor() {
}
onAuditClick(event: any) {
}
}
describe('ProcessAuditDirective', () => {
let fixture: ComponentFixture<BasicButtonComponent>;
@@ -47,20 +73,24 @@ describe('ProcessAuditDirective', () => {
return new Blob([pdfData], {type: 'application/pdf'});
}
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [BasicButtonComponent, ProcessAuditDirective],
providers: [ProcessService]
});
TestBed.compileComponents();
setupTestBed({
imports: [
CoreModule.forRoot()
],
declarations: [
BasicButtonComponent,
ProcessAuditDirective
],
providers: [ProcessService]
});
beforeEach(() => {
fixture = TestBed.createComponent(BasicButtonComponent);
component = fixture.componentInstance;
service = TestBed.get(ProcessService);
jasmine.Ajax.install();
}));
});
afterEach(() => {
jasmine.Ajax.uninstall();
@@ -143,28 +173,3 @@ describe('ProcessAuditDirective', () => {
}));
});
@Component({
selector: 'adf-basic-button',
template: `
<button id="auditButton"
adf-process-audit
[process-id]="currentProcessId"
[download]="download"
[fileName]="fileName"
[format]="format"
(clicked)="onAuditClick($event)">My button
</button>`
})
class BasicButtonComponent {
download: boolean = false;
fileName: string;
format: string;
constructor() {
}
onAuditClick(event: any) {
}
}

View File

@@ -22,40 +22,38 @@ import { FilterProcessRepresentationModel } from '../models/filter-process.model
import { ProcessFilterService } from '../services/process-filter.service';
import { ProcessFiltersComponent } from './process-filters.component';
describe('ActivitiFilters', () => {
describe('ProcessFiltersComponent', () => {
let filterList: ProcessFiltersComponent;
let processFilterService: ProcessFilterService;
let appsProcessService: AppsProcessService;
let fakeGlobalFilter = [];
fakeGlobalFilter.push(new FilterProcessRepresentationModel({
name: 'FakeInvolvedTasks',
filter: { state: 'open', assignment: 'fake-involved' }
}));
fakeGlobalFilter.push(new FilterProcessRepresentationModel({
name: 'FakeMyTasks',
filter: { state: 'open', assignment: 'fake-assignee' }
}));
fakeGlobalFilter.push(new FilterProcessRepresentationModel({
name: 'Running',
filter: { state: 'open', assignment: 'fake-running' }
}));
let fakeGlobalFilterPromise = new Promise(function (resolve, reject) {
resolve(fakeGlobalFilter);
});
let mockErrorFilterList = {
error: 'wrong request'
};
let mockErrorFilterPromise = new Promise(function (resolve, reject) {
reject(mockErrorFilterList);
});
let fakeGlobalFilterPromise;
let mockErrorFilterPromise;
beforeEach(() => {
fakeGlobalFilterPromise = new Promise(function (resolve, reject) {
resolve([
new FilterProcessRepresentationModel({
name: 'FakeInvolvedTasks',
filter: { state: 'open', assignment: 'fake-involved' }
}),
new FilterProcessRepresentationModel({
name: 'FakeMyTasks',
filter: { state: 'open', assignment: 'fake-assignee' }
}),
new FilterProcessRepresentationModel({
name: 'Running',
filter: { state: 'open', assignment: 'fake-running' }
})
]);
});
mockErrorFilterPromise = new Promise(function (resolve, reject) {
reject({
error: 'wrong request'
});
});
processFilterService = new ProcessFilterService(null);
appsProcessService = new AppsProcessService(null, null);
filterList = new ProcessFiltersComponent(processFilterService, appsProcessService);

View File

@@ -20,13 +20,14 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Observable } from 'rxjs/Observable';
import { FormModule } from '@alfresco/adf-core';
import { FormModule, setupTestBed } from '@alfresco/adf-core';
import { TaskListModule } from '../../task-list/task-list.module';
import { ProcessInstance } from '../models/process-instance.model';
import { exampleProcess, exampleProcessNoName } from './../../mock';
import { ProcessService } from './../services/process.service';
import { ProcessInstanceDetailsComponent } from './process-instance-details.component';
import { ProcessTestingModule } from '../../testing/process.testing.module';
describe('ProcessInstanceDetailsComponent', () => {
@@ -35,21 +36,17 @@ describe('ProcessInstanceDetailsComponent', () => {
let fixture: ComponentFixture<ProcessInstanceDetailsComponent>;
let getProcessSpy: jasmine.Spy;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
FormModule,
TaskListModule
],
declarations: [
ProcessInstanceDetailsComponent
],
providers: [
ProcessService
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
setupTestBed({
imports: [
ProcessTestingModule,
FormModule,
TaskListModule
],
providers: [
ProcessService
],
schemas: [NO_ERRORS_SCHEMA]
});
beforeEach(() => {
@@ -139,7 +136,7 @@ describe('ProcessInstanceDetailsComponent', () => {
describe('Diagram', () => {
it('should diagram button be enabled if the process is running', () => {
it('should diagram button be enabled if the process is running', async(() => {
component.processInstanceDetails = new ProcessInstance({
ended: null
});
@@ -150,9 +147,9 @@ describe('ProcessInstanceDetailsComponent', () => {
expect(diagramButton).not.toBeNull();
expect(diagramButton.nativeElement.disabled).toBe(false);
});
});
}));
it('should diagram button be enabled if the process is running', () => {
it('should diagram button be enabled if the process is running', async(() => {
component.processInstanceDetails = new ProcessInstance({
ended: new Date()
});
@@ -164,7 +161,7 @@ describe('ProcessInstanceDetailsComponent', () => {
expect(diagramButton).not.toBeNull();
expect(diagramButton.nativeElement.disabled).toBe(true);
});
});
}));
});
});
});

View File

@@ -16,12 +16,11 @@
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AppConfigService, CardViewUpdateService } from '@alfresco/adf-core';
import { AppConfigService, setupTestBed } from '@alfresco/adf-core';
import { ProcessInstance } from '../models/process-instance.model';
import { exampleProcess } from '../../mock';
import { ProcessService } from './../services/process.service';
import { ProcessInstanceHeaderComponent } from './process-instance-header.component';
import { ProcessTestingModule } from '../../testing/process.testing.module';
describe('ProcessInstanceHeaderComponent', () => {
@@ -29,25 +28,20 @@ describe('ProcessInstanceHeaderComponent', () => {
let fixture: ComponentFixture<ProcessInstanceHeaderComponent>;
let appConfigService: AppConfigService;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
ProcessInstanceHeaderComponent
],
providers: [
ProcessService,
CardViewUpdateService,
AppConfigService
]
}).compileComponents();
}));
setupTestBed({
imports: [
ProcessTestingModule
]
});
beforeEach(() => {
fixture = TestBed.createComponent(ProcessInstanceHeaderComponent);
component = fixture.componentInstance;
component.processInstance = new ProcessInstance(exampleProcess);
appConfigService = TestBed.get(AppConfigService);
appConfigService.config['adf-process-instance-header'] = {};
});
it('should render empty component if no process details provided', () => {
@@ -163,13 +157,11 @@ describe('ProcessInstanceHeaderComponent', () => {
describe('Config Filtering', () => {
it('should show only the properties from the configuration file', () => {
appConfigService.config = Object.assign(appConfigService.config, {
'adf-process-instance-header': {
'presets': {
'properties': ['status', 'ended']
}
appConfigService.config['adf-process-instance-header'] = {
'presets': {
'properties': ['status', 'ended']
}
});
};
component.ngOnChanges({});
fixture.detectChanges();
const propertyList = fixture.nativeElement.querySelectorAll('.adf-property-list .adf-property');
@@ -180,17 +172,19 @@ describe('ProcessInstanceHeaderComponent', () => {
expect(propertyList[1].innerText).toContain('ADF_PROCESS_LIST.PROPERTIES.END_DATE');
});
it('should show all the default properties if there is no configuration', () => {
appConfigService.config = Object.assign(appConfigService.config, {});
it('should show all the default properties if there is no configuration', async(() => {
appConfigService.config['adf-process-instance-header'] = {};
component.ngOnChanges({});
fixture.detectChanges();
const propertyList = fixture.nativeElement.querySelectorAll('.adf-property-list .adf-property');
expect(propertyList).toBeDefined();
expect(propertyList).not.toBeNull();
expect(propertyList.length).toBe(component.properties.length);
expect(propertyList[0].innerText).toContain('ADF_PROCESS_LIST.PROPERTIES.STATUS');
expect(propertyList[2].innerText).toContain('ADF_PROCESS_LIST.PROPERTIES.CATEGORY');
});
fixture.whenStable().then(() => {
const propertyList = fixture.nativeElement.querySelectorAll('.adf-property-list .adf-property');
expect(propertyList).toBeDefined();
expect(propertyList).not.toBeNull();
expect(propertyList.length).toBe(component.properties.length);
expect(propertyList[0].innerText).toContain('ADF_PROCESS_LIST.PROPERTIES.STATUS');
expect(propertyList[2].innerText).toContain('ADF_PROCESS_LIST.PROPERTIES.CATEGORY');
});
}));
});
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core';
import { SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Observable } from 'rxjs/Observable';
@@ -26,35 +26,35 @@ import { taskDetailsMock } from '../../mock';
import { ProcessInstance } from './../models/process-instance.model';
import { ProcessService } from './../services/process.service';
import { ProcessInstanceTasksComponent } from './process-instance-tasks.component';
import { setupTestBed } from '@alfresco/adf-core';
import { ProcessTestingModule } from '../../testing/process.testing.module';
describe('ProcessInstanceTasksComponent', () => {
let component: ProcessInstanceTasksComponent;
let fixture: ComponentFixture<ProcessInstanceTasksComponent>;
let service: ProcessService;
let getProcessTasksSpy: jasmine.Spy;
// let getProcessTasksSpy: jasmine.Spy;
let exampleProcessInstance = new ProcessInstance({ id: '123' });
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
ProcessInstanceTasksComponent
],
providers: [
ProcessService
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
setupTestBed({
imports: [
ProcessTestingModule
]
});
beforeEach(() => {
fixture = TestBed.createComponent(ProcessInstanceTasksComponent);
component = fixture.componentInstance;
service = fixture.debugElement.injector.get(ProcessService);
getProcessTasksSpy = spyOn(service, 'getProcessTasks').and.returnValue(Observable.of([new TaskDetailsModel(taskDetailsMock)]));
service = TestBed.get(ProcessService);
spyOn(service, 'getProcessTasks').and.returnValue(Observable.of([new TaskDetailsModel(taskDetailsMock)]));
});
afterEach(() => {
fixture.destroy();
});
it('should initially render message about no active tasks if no process instance ID provided', async(() => {
@@ -89,7 +89,7 @@ describe('ProcessInstanceTasksComponent', () => {
expect(listEl).toBeNull();
});
it('should display active tasks', () => {
it('should display active tasks', async(() => {
let change = new SimpleChange(null, exampleProcessInstance, true);
fixture.detectChanges();
component.ngOnChanges({ 'processInstanceDetails': change });
@@ -100,9 +100,9 @@ describe('ProcessInstanceTasksComponent', () => {
expect(listEl).not.toBeNull();
expect(listEl.queryAll(By.css('mat-list-item')).length).toBe(1);
});
});
}));
it('should display completed tasks', () => {
it('should display completed tasks', async(() => {
let change = new SimpleChange(null, exampleProcessInstance, true);
fixture.detectChanges();
component.ngOnChanges({ 'processInstanceDetails': change });
@@ -112,36 +112,43 @@ describe('ProcessInstanceTasksComponent', () => {
expect(listEl).not.toBeNull();
expect(listEl.queryAll(By.css('mat-list-item')).length).toBe(1);
});
});
}));
describe('task reloading', () => {
beforeEach(async(() => {
beforeEach(() => {
component.processInstanceDetails = exampleProcessInstance;
});
it('should render a refresh button by default', async(() => {
fixture.detectChanges();
fixture.whenStable();
fixture.whenStable().then(() => {
expect(fixture.debugElement.query(By.css('.process-tasks-refresh'))).not.toBeNull();
});
}));
it('should render a refresh button by default', () => {
expect(fixture.debugElement.query(By.css('.process-tasks-refresh'))).not.toBeNull();
});
it('should render a refresh button if configured to', () => {
it('should render a refresh button if configured to', async(() => {
component.showRefreshButton = true;
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('.process-tasks-refresh'))).not.toBeNull();
});
fixture.whenStable().then(() => {
expect(fixture.debugElement.query(By.css('.process-tasks-refresh'))).not.toBeNull();
});
}));
it('should NOT render a refresh button if configured not to', () => {
it('should NOT render a refresh button if configured not to', async(() => {
component.showRefreshButton = false;
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('.process-tasks-refresh'))).toBeNull();
});
fixture.whenStable().then(() => {
expect(fixture.debugElement.query(By.css('.process-tasks-refresh'))).toBeNull();
});
}));
it('should call service to get tasks when reload button clicked', () => {
getProcessTasksSpy.calls.reset();
component.onRefreshClicked();
expect(getProcessTasksSpy).toHaveBeenCalled();
});
it('should call service to get tasks when reload button clicked', async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
component.onRefreshClicked();
expect(service.getProcessTasks).toHaveBeenCalled();
});
}));
});
});

View File

@@ -17,15 +17,15 @@
import { Component, SimpleChange, ViewChild } from '@angular/core';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { MatProgressSpinnerModule } from '@angular/material';
import { Observable } from 'rxjs/Observable';
import { ProcessInstanceListComponent } from './process-list.component';
import { AppConfigService } from '@alfresco/adf-core';
import { AppConfigService, setupTestBed, CoreModule } from '@alfresco/adf-core';
import { DataRowEvent, DataSorting, ObjectDataRow, ObjectDataTableAdapter } from '@alfresco/adf-core';
import { fakeProcessInstance, fakeProcessInstancesWithNoName } from '../../mock';
import { ProcessService } from '../services/process.service';
import { ProcessTestingModule } from '../../testing/process.testing.module';
describe('ProcessInstanceListComponent', () => {
@@ -68,45 +68,37 @@ describe('ProcessInstanceListComponent', () => {
]
, fakeCutomSchema };
setupTestBed({
imports: [
ProcessTestingModule
]
});
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MatProgressSpinnerModule
],
declarations: [ ProcessInstanceListComponent ],
providers: [
ProcessService
]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(ProcessInstanceListComponent);
component = fixture.componentInstance;
appConfig = TestBed.get(AppConfigService);
service = fixture.debugElement.injector.get(ProcessService);
fixture = TestBed.createComponent(ProcessInstanceListComponent);
component = fixture.componentInstance;
appConfig = TestBed.get(AppConfigService);
service = TestBed.get(ProcessService);
getProcessInstancesSpy = spyOn(service, 'getProcessInstances').and.returnValue(Observable.of(fakeProcessInstance));
appConfig.config = Object.assign(appConfig.config, {
'adf-process-list': {
'presets': {
'fakeCutomSchema': [
{
'key': 'fakeName',
'type': 'text',
'title': 'ADF_PROCESS_LIST.PROPERTIES.FAKE',
'sortable': true
},
{
'key': 'fakeProcessName',
'type': 'text',
'title': 'ADF_PROCESS_LIST.PROPERTIES.PROCESS_FAKE',
'sortable': true
}
]
getProcessInstancesSpy = spyOn(service, 'getProcessInstances').and.returnValue(Observable.of(fakeProcessInstance));
appConfig.config['adf-process-list'] = {
'presets': {
'fakeCutomSchema': [
{
'key': 'fakeName',
'type': 'text',
'title': 'ADF_PROCESS_LIST.PROPERTIES.FAKE',
'sortable': true
},
{
'key': 'fakeProcessName',
'type': 'text',
'title': 'ADF_PROCESS_LIST.PROPERTIES.PROCESS_FAKE',
'sortable': true
}
}
]
}
);
});
};
}));
it('should use the default schemaColumn as default', () => {
@@ -530,17 +522,11 @@ describe('CustomProcessListComponent', () => {
let fixture: ComponentFixture<CustomProcessListComponent>;
let component: CustomProcessListComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
ProcessInstanceListComponent,
CustomProcessListComponent
],
providers: [
ProcessService
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreModule.forRoot()],
declarations: [ProcessInstanceListComponent, CustomProcessListComponent],
providers: [ProcessService]
});
beforeEach(() => {
fixture = TestBed.createComponent(CustomProcessListComponent);

View File

@@ -17,13 +17,7 @@
import { SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import {
MatButtonModule,
MatCardModule,
MatInputModule,
MatSelectModule
} from '@angular/material';
import { ActivitiContentService, AppConfigService, FormModule, FormService } from '@alfresco/adf-core';
import { ActivitiContentService, AppConfigService, FormService, setupTestBed } from '@alfresco/adf-core';
import { Observable } from 'rxjs/Observable';
import { ProcessInstanceVariable } from '../models/process-instance-variable.model';
@@ -37,6 +31,7 @@ import {
testProcessDefinitions
} from '../../mock';
import { StartProcessInstanceComponent } from './start-process.component';
import { ProcessTestingModule } from '../../testing/process.testing.module';
describe('StartFormComponent', () => {
@@ -50,33 +45,19 @@ describe('StartFormComponent', () => {
let getStartFormDefinitionSpy: jasmine.Spy;
let startProcessSpy: jasmine.Spy;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
FormModule,
MatButtonModule,
MatCardModule,
MatInputModule,
MatSelectModule
],
declarations: [
StartProcessInstanceComponent
],
providers: [
ActivitiContentService,
ProcessService,
FormService
]
}).compileComponents();
}));
setupTestBed({
imports: [
ProcessTestingModule
]
});
beforeEach(() => {
appConfig = TestBed.get(AppConfigService);
activitiContentService = TestBed.get(ActivitiContentService);
fixture = TestBed.createComponent(StartProcessInstanceComponent);
component = fixture.componentInstance;
processService = fixture.debugElement.injector.get(ProcessService);
formService = fixture.debugElement.injector.get(FormService);
processService = TestBed.get(ProcessService);
formService = TestBed.get(FormService);
getDefinitionsSpy = spyOn(processService, 'getProcessDefinitions').and.returnValue(Observable.of(testMultipleProcessDefs));
startProcessSpy = spyOn(processService, 'startProcess').and.returnValue(Observable.of(newProcess));

View File

@@ -36,9 +36,6 @@ import { ProcessInstanceTasksComponent } from './components/process-instance-tas
import { ProcessInstanceListComponent } from './components/process-list.component';
import { StartProcessInstanceComponent } from './components/start-process.component';
import { ProcessService } from './services/process.service';
import { ProcessFilterService } from './services/process-filter.service';
@NgModule({
imports: [
CommonModule,
@@ -68,10 +65,6 @@ import { ProcessFilterService } from './services/process-filter.service';
ProcessInstanceTasksComponent,
StartProcessInstanceComponent
],
providers: [
ProcessService,
ProcessFilterService
],
exports: [
ProcessInstanceListComponent,
ProcessFiltersComponent,