mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Fix unit test
This commit is contained in:
@@ -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);
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
});
|
@@ -23,14 +23,16 @@ import { FormGroup, FormBuilder, FormControl } from '@angular/forms';
|
||||
@Component({
|
||||
moduleId: module.id,
|
||||
selector: 'analytics-report-heat-map',
|
||||
templateUrl: './analytics-report-heat-map.component.html',
|
||||
styleUrls: ['./analytics-report-heat-map.component.css']
|
||||
templateUrl: './analytics-report-heat-map.component.html'
|
||||
})
|
||||
export class AnalyticsReportHeatMapComponent implements OnInit {
|
||||
|
||||
@Input()
|
||||
report: any;
|
||||
|
||||
@Output()
|
||||
onSuccess = new EventEmitter();
|
||||
|
||||
@Output()
|
||||
onError = new EventEmitter();
|
||||
|
||||
@@ -55,10 +57,7 @@ export class AnalyticsReportHeatMapComponent implements OnInit {
|
||||
this.analyticsService.getMetricValues().subscribe(
|
||||
(opts: any[]) => {
|
||||
this.field.options = opts;
|
||||
},
|
||||
(err: any) => {
|
||||
console.log(err);
|
||||
this.onError.emit(err);
|
||||
this.onSuccess.emit(opts);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@@ -20,11 +20,8 @@ import {
|
||||
CoreModule
|
||||
} 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 { WIDGET_DIRECTIVES } from '../components/widgets/index';
|
||||
import { CHART_DIRECTIVES } from 'ng2-charts/ng2-charts';
|
||||
|
||||
import { AnalyticsService } from '../services/analytics.service';
|
||||
import { ReportParametersModel } from '../models/report.model';
|
||||
@@ -32,16 +29,6 @@ import * as moment from 'moment';
|
||||
import { DebugElement, SimpleChange } from '@angular/core';
|
||||
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 mdDateTimePicker: any;
|
||||
|
||||
@@ -60,11 +47,11 @@ describe('Test ng2-analytics-report-parameters Report Parameters ', () => {
|
||||
CoreModule
|
||||
],
|
||||
declarations: [
|
||||
...ANALYTICS_DIRECTIVES,
|
||||
...CHART_DIRECTIVES
|
||||
AnalyticsReportParametersComponent,
|
||||
...WIDGET_DIRECTIVES
|
||||
],
|
||||
providers: [
|
||||
...ANALYTICS_PROVIDERS
|
||||
AnalyticsService
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
@@ -178,6 +165,7 @@ describe('Test ng2-analytics-report-parameters Report Parameters ', () => {
|
||||
expect(res.duration).toEqual(22);
|
||||
expect(res.dateRangeInterval).toEqual(120);
|
||||
expect(res.slowProcessInstanceInteger).toEqual(2);
|
||||
expect(res.typeFiltering).toEqual(true);
|
||||
});
|
||||
|
||||
let values: any = {
|
||||
@@ -201,6 +189,9 @@ describe('Test ng2-analytics-report-parameters Report Parameters ', () => {
|
||||
},
|
||||
processInstanceGroup: {
|
||||
slowProcessInstanceInteger: 2
|
||||
},
|
||||
typeFilteringGroup: {
|
||||
typeFiltering: true
|
||||
}
|
||||
};
|
||||
component.submit(values);
|
||||
|
@@ -19,10 +19,12 @@ import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import {
|
||||
CoreModule
|
||||
} from 'ng2-alfresco-core';
|
||||
import { DiagramsModule } from 'ng2-activiti-diagrams';
|
||||
|
||||
import { AnalyticsReportListComponent } from '../components/analytics-report-list.component';
|
||||
import { AnalyticsComponent } from '../components/analytics.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 { CHART_DIRECTIVES } from 'ng2-charts/ng2-charts';
|
||||
import { Chart } from '../models/chart.model';
|
||||
@@ -35,6 +37,7 @@ export const ANALYTICS_DIRECTIVES: any[] = [
|
||||
AnalyticsComponent,
|
||||
AnalyticsReportParametersComponent,
|
||||
AnalyticsReportListComponent,
|
||||
AnalyticsReportHeatMapComponent,
|
||||
WIDGET_DIRECTIVES
|
||||
];
|
||||
export const ANALYTICS_PROVIDERS: any[] = [
|
||||
@@ -56,7 +59,8 @@ describe('Test ng2-activiti-analytics Report ', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule
|
||||
CoreModule,
|
||||
DiagramsModule
|
||||
],
|
||||
declarations: [
|
||||
...ANALYTICS_DIRECTIVES,
|
||||
|
@@ -142,17 +142,6 @@ export class AnalyticsService {
|
||||
}).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> {
|
||||
if (reportId && processDefinitionId) {
|
||||
let url = `${this.alfrescoSettingsService.getBPMApiBaseUrl()}/app/rest/reporting/report-params/${reportId}/tasks`;
|
||||
|
Reference in New Issue
Block a user