Fix unit test

This commit is contained in:
mauriziovitale84
2016-10-26 17:25:13 +01:00
parent 95025b4baf
commit ecfe3a8617
5 changed files with 145 additions and 34 deletions

View File

@@ -0,0 +1,128 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { CoreModule } from 'ng2-alfresco-core';
import { DiagramsModule } from 'ng2-activiti-diagrams';
import { AnalyticsReportHeatMapComponent } from '../components/analytics-report-heat-map.component';
import { WIDGET_DIRECTIVES } from '../components/widgets/index';
import { AnalyticsService } from '../services/analytics.service';
import { DebugElement } from '@angular/core';
declare let jasmine: any;
describe('Test ng2-activiti-analytics-report-heat-map', () => {
let componentHandler: any;
let component: any;
let fixture: ComponentFixture<AnalyticsReportHeatMapComponent>;
let debug: DebugElement;
let element: HTMLElement;
let totalCountPerc = {'sid-fake-id': 0, 'fake-start-event': 100};
let totalTimePerc = {'sid-fake-id': 10, 'fake-start-event': 30};
let avgTimePercentages = {'sid-fake-id': 5, 'fake-start-event': 50};
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
CoreModule,
DiagramsModule
],
declarations: [
AnalyticsReportHeatMapComponent,
...WIDGET_DIRECTIVES
],
providers: [
AnalyticsService
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AnalyticsReportHeatMapComponent);
component = fixture.componentInstance;
debug = fixture.debugElement;
element = fixture.nativeElement;
componentHandler = jasmine.createSpyObj('componentHandler', [
'upgradeAllRegistered'
]);
window['componentHandler'] = componentHandler;
component.report = {
totalCountsPercentages: totalCountPerc,
totalTimePercentages: totalTimePerc,
avgTimePercentages: avgTimePercentages
};
});
describe('Rendering tests: Heat Map', () => {
beforeEach(() => {
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('should render the dropdown with the metric options', async(() => {
component.report = {totalCountsPercentages: {'sid-fake-id': 10, 'fake-start-event': 30}};
component.onSuccess.subscribe(() => {
fixture.whenStable().then(() => {
let dropDown: any = element.querySelector('#select-metrics');
expect(dropDown).toBeDefined();
expect(dropDown.length).toEqual(3);
expect(dropDown[0].innerHTML).toEqual('Number of times a step is executed');
expect(dropDown[1].innerHTML).toEqual('Total time spent in a process step');
expect(dropDown[2].innerHTML).toEqual('Average time spent in a process step');
});
});
fixture.detectChanges();
}));
it('should return false when no metrics are defined in the report', async(() => {
component.report = {};
expect(component.hasMetric()).toBeFalsy();
}));
it('should return true when the metrics are defined in the report', async(() => {
expect(component.hasMetric()).toBeTruthy();
}));
it('should change the currentmetric width totalCount', async(() => {
let field = {value: 'totalCount'};
component.onMetricChanges(field);
expect(component.currentMetric).toEqual(totalCountPerc);
}));
it('should change the currentmetric width totalTime', async(() => {
let field = {value: 'totalTime'};
component.onMetricChanges(field);
expect(component.currentMetric).toEqual(totalTimePerc);
}));
it('should change the currentmetric width avgTime', async(() => {
let field = {value: 'avgTime'};
component.onMetricChanges(field);
expect(component.currentMetric).toEqual(avgTimePercentages);
}));
});
});

View File

@@ -23,14 +23,16 @@ import { FormGroup, FormBuilder, FormControl } from '@angular/forms';
@Component({ @Component({
moduleId: module.id, moduleId: module.id,
selector: 'analytics-report-heat-map', selector: 'analytics-report-heat-map',
templateUrl: './analytics-report-heat-map.component.html', templateUrl: './analytics-report-heat-map.component.html'
styleUrls: ['./analytics-report-heat-map.component.css']
}) })
export class AnalyticsReportHeatMapComponent implements OnInit { export class AnalyticsReportHeatMapComponent implements OnInit {
@Input() @Input()
report: any; report: any;
@Output()
onSuccess = new EventEmitter();
@Output() @Output()
onError = new EventEmitter(); onError = new EventEmitter();
@@ -55,10 +57,7 @@ export class AnalyticsReportHeatMapComponent implements OnInit {
this.analyticsService.getMetricValues().subscribe( this.analyticsService.getMetricValues().subscribe(
(opts: any[]) => { (opts: any[]) => {
this.field.options = opts; this.field.options = opts;
}, this.onSuccess.emit(opts);
(err: any) => {
console.log(err);
this.onError.emit(err);
} }
); );
} }

View File

@@ -20,11 +20,8 @@ import {
CoreModule CoreModule
} from 'ng2-alfresco-core'; } from 'ng2-alfresco-core';
import { AnalyticsReportListComponent } from '../components/analytics-report-list.component';
import { AnalyticsComponent } from '../components/analytics.component';
import { AnalyticsReportParametersComponent } from '../components/analytics-report-parameters.component'; import { AnalyticsReportParametersComponent } from '../components/analytics-report-parameters.component';
import { WIDGET_DIRECTIVES } from '../components/widgets/index'; import { WIDGET_DIRECTIVES } from '../components/widgets/index';
import { CHART_DIRECTIVES } from 'ng2-charts/ng2-charts';
import { AnalyticsService } from '../services/analytics.service'; import { AnalyticsService } from '../services/analytics.service';
import { ReportParametersModel } from '../models/report.model'; import { ReportParametersModel } from '../models/report.model';
@@ -32,16 +29,6 @@ import * as moment from 'moment';
import { DebugElement, SimpleChange } from '@angular/core'; import { DebugElement, SimpleChange } from '@angular/core';
import * as analyticParamsMock from '../assets/analyticsParamsReportComponent.mock'; import * as analyticParamsMock from '../assets/analyticsParamsReportComponent.mock';
export const ANALYTICS_DIRECTIVES: any[] = [
AnalyticsComponent,
AnalyticsReportParametersComponent,
AnalyticsReportListComponent,
WIDGET_DIRECTIVES
];
export const ANALYTICS_PROVIDERS: any[] = [
AnalyticsService
];
declare let jasmine: any; declare let jasmine: any;
declare let mdDateTimePicker: any; declare let mdDateTimePicker: any;
@@ -60,11 +47,11 @@ describe('Test ng2-analytics-report-parameters Report Parameters ', () => {
CoreModule CoreModule
], ],
declarations: [ declarations: [
...ANALYTICS_DIRECTIVES, AnalyticsReportParametersComponent,
...CHART_DIRECTIVES ...WIDGET_DIRECTIVES
], ],
providers: [ providers: [
...ANALYTICS_PROVIDERS AnalyticsService
] ]
}).compileComponents(); }).compileComponents();
})); }));
@@ -178,6 +165,7 @@ describe('Test ng2-analytics-report-parameters Report Parameters ', () => {
expect(res.duration).toEqual(22); expect(res.duration).toEqual(22);
expect(res.dateRangeInterval).toEqual(120); expect(res.dateRangeInterval).toEqual(120);
expect(res.slowProcessInstanceInteger).toEqual(2); expect(res.slowProcessInstanceInteger).toEqual(2);
expect(res.typeFiltering).toEqual(true);
}); });
let values: any = { let values: any = {
@@ -201,6 +189,9 @@ describe('Test ng2-analytics-report-parameters Report Parameters ', () => {
}, },
processInstanceGroup: { processInstanceGroup: {
slowProcessInstanceInteger: 2 slowProcessInstanceInteger: 2
},
typeFilteringGroup: {
typeFiltering: true
} }
}; };
component.submit(values); component.submit(values);

View File

@@ -19,10 +19,12 @@ import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { import {
CoreModule CoreModule
} from 'ng2-alfresco-core'; } from 'ng2-alfresco-core';
import { DiagramsModule } from 'ng2-activiti-diagrams';
import { AnalyticsReportListComponent } from '../components/analytics-report-list.component'; import { AnalyticsReportListComponent } from '../components/analytics-report-list.component';
import { AnalyticsComponent } from '../components/analytics.component'; import { AnalyticsComponent } from '../components/analytics.component';
import { AnalyticsReportParametersComponent } from '../components/analytics-report-parameters.component'; import { AnalyticsReportParametersComponent } from '../components/analytics-report-parameters.component';
import { AnalyticsReportHeatMapComponent } from '../components/analytics-report-heat-map.component';
import { WIDGET_DIRECTIVES } from '../components/widgets/index'; import { WIDGET_DIRECTIVES } from '../components/widgets/index';
import { CHART_DIRECTIVES } from 'ng2-charts/ng2-charts'; import { CHART_DIRECTIVES } from 'ng2-charts/ng2-charts';
import { Chart } from '../models/chart.model'; import { Chart } from '../models/chart.model';
@@ -35,6 +37,7 @@ export const ANALYTICS_DIRECTIVES: any[] = [
AnalyticsComponent, AnalyticsComponent,
AnalyticsReportParametersComponent, AnalyticsReportParametersComponent,
AnalyticsReportListComponent, AnalyticsReportListComponent,
AnalyticsReportHeatMapComponent,
WIDGET_DIRECTIVES WIDGET_DIRECTIVES
]; ];
export const ANALYTICS_PROVIDERS: any[] = [ export const ANALYTICS_PROVIDERS: any[] = [
@@ -56,7 +59,8 @@ describe('Test ng2-activiti-analytics Report ', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
CoreModule CoreModule,
DiagramsModule
], ],
declarations: [ declarations: [
...ANALYTICS_DIRECTIVES, ...ANALYTICS_DIRECTIVES,

View File

@@ -142,17 +142,6 @@ export class AnalyticsService {
}).catch(this.handleError); }).catch(this.handleError);
} }
getProcessDefinitionModel(processDefinitionId: string): Observable<any> {
let url = `${this.alfrescoSettingsService.getBPMApiBaseUrl()}/app/rest/process-definitions/${processDefinitionId}/model-json`;
let options = this.getRequestOptions();
return this.http
.get(url, options)
.map((res: any) => {
let body = res.json();
return body;
}).catch(this.handleError);
}
getTasksByProcessDefinitionId(reportId: string, processDefinitionId: string): Observable<any> { getTasksByProcessDefinitionId(reportId: string, processDefinitionId: string): Observable<any> {
if (reportId && processDefinitionId) { if (reportId && processDefinitionId) {
let url = `${this.alfrescoSettingsService.getBPMApiBaseUrl()}/app/rest/reporting/report-params/${reportId}/tasks`; let url = `${this.alfrescoSettingsService.getBPMApiBaseUrl()}/app/rest/reporting/report-params/${reportId}/tasks`;