From c65ebbcb29ede43192df3af950fd5d70e446bdcf Mon Sep 17 00:00:00 2001 From: mauriziovitale84 Date: Mon, 10 Oct 2016 16:56:35 +0100 Subject: [PATCH 1/5] Add analytics component unit test --- .../components/analytics.component.spec.ts | 153 +++++++++++++++++- .../src/components/analytics.component.ts | 8 +- .../widgets/dropdown/dropdown.widget.html | 2 +- .../widgets/dropdown/dropdown.widget.ts | 5 - .../src/models/report.model.ts | 4 + 5 files changed, 159 insertions(+), 13 deletions(-) diff --git a/ng2-components/ng2-activiti-analytics/src/components/analytics.component.spec.ts b/ng2-components/ng2-activiti-analytics/src/components/analytics.component.spec.ts index f1bf40c4a9..d95f64ed2d 100644 --- a/ng2-components/ng2-activiti-analytics/src/components/analytics.component.spec.ts +++ b/ng2-components/ng2-activiti-analytics/src/components/analytics.component.spec.ts @@ -27,7 +27,7 @@ import { CHART_DIRECTIVES } from 'ng2-charts/ng2-charts'; import { AnalyticsService } from '../services/analytics.service'; -import { DebugElement } from '@angular/core'; +import { DebugElement, SimpleChange } from '@angular/core'; export const ANALYTICS_DIRECTIVES: any[] = [ AnalyticsComponent, @@ -38,13 +38,38 @@ export const ANALYTICS_PROVIDERS: any[] = [ AnalyticsService ]; -describe('Show component HTML', () => { +declare let jasmine: any; + +describe('Test ng2-activiti-analytics Report ', () => { + + let reportDefParamStatus = { + 'id': 2005, + 'name': 'Fake Task overview status', + 'created': '2016-10-05T15:39:40.222+0000', + 'definition': '{ "parameters" :[{"id":"status","name":null,"nameKey":null,"type":"status","value":null,"dependsOn":null}]}' + }; + + let reportDefParamRangeInterval = { + 'id': 2006, + 'name': 'Fake Task overview RangeInterval', + 'created': '2016-10-05T15:39:40.222+0000', + 'definition': '{ "parameters" :[{"id":"dateRangeInterval","name":null,"nameKey":null,"type":"dateInterval","value":null,"dependsOn":null}]}' + }; + + let reportDefParamProcessDef = { + 'id': 2006, + 'name': 'Fake Task overview ProcessDefinition', + 'created': '2016-10-05T15:39:40.222+0000', + 'definition': '{ "parameters" :[{"id":"processDefinitionId","name":null,"nameKey":null,"type":"processDefinition","value":null,"dependsOn":null}]}' + }; let component: any; let fixture: ComponentFixture; let debug: DebugElement; let element: HTMLElement; + let componentHandler: any; + beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ @@ -66,10 +91,130 @@ describe('Show component HTML', () => { debug = fixture.debugElement; element = fixture.nativeElement; fixture.detectChanges(); + componentHandler = jasmine.createSpyObj('componentHandler', [ + 'upgradeAllRegistered' + ]); + window['componentHandler'] = componentHandler; }); - it('Display component tag base-chart', () => { - expect(true).toBe(true); + describe('Rendering tests', () => { + + beforeEach(() => { + jasmine.Ajax.install(); + }); + + afterEach(() => { + jasmine.Ajax.uninstall(); + }); + + it('Should initialize the Report form with a Form Group ', () => { + fixture.detectChanges(); + + expect(component.reportForm.get('dateRange')).toBeDefined(); + expect(component.reportForm.get('dateRange').get('startDate')).toBeDefined(); + expect(component.reportForm.get('dateRange').get('endDate')).toBeDefined(); + }); + + it('Should render a dropdown with all the status when the definition parameter type is \'status\' ', (done) => { + fixture.detectChanges(); + + component.onSuccess.subscribe(() => { + fixture.detectChanges(); + let dropDown: any = element.querySelector('#select-status'); + expect(element.querySelector('h1').innerHTML).toEqual('Fake Task overview status'); + expect(dropDown).toBeDefined(); + expect(dropDown.length).toEqual(4); + expect(dropDown[0].innerHTML).toEqual('Choose One'); + expect(dropDown[1].innerHTML).toEqual('All'); + expect(dropDown[2].innerHTML).toEqual('Active'); + expect(dropDown[3].innerHTML).toEqual('Complete'); + done(); + }); + + let reportId = 1; + let change = new SimpleChange(null, reportId); + component.ngOnChanges({ 'reportId': change }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: reportDefParamStatus + }); + }); + + it('Should render a dropdown with all the RangeInterval when the definition parameter type is \'dateRangeInterval\' ', (done) => { + fixture.detectChanges(); + + component.onSuccess.subscribe(() => { + fixture.detectChanges(); + let dropDown: any = element.querySelector('#select-dateRangeInterval'); + expect(dropDown).toBeDefined(); + expect(dropDown.length).toEqual(5); + expect(dropDown[0].innerHTML).toEqual('By hour'); + expect(dropDown[1].innerHTML).toEqual('By day'); + expect(dropDown[2].innerHTML).toEqual('By week'); + expect(dropDown[3].innerHTML).toEqual('By month'); + expect(dropDown[4].innerHTML).toEqual('By year'); + done(); + }); + + let reportId = 1; + let change = new SimpleChange(null, reportId); + component.ngOnChanges({ 'reportId': change }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: reportDefParamRangeInterval + }); + }); + + it('Should render a dropdown with all the process definition when the definition parameter type is \'processDefinition\' ', (done) => { + fixture.detectChanges(); + + component.onSuccess.subscribe(() => { + fixture.detectChanges(); + let dropDown: any = element.querySelector('#select-processDefinition'); + expect(dropDown).toBeDefined(); + expect(dropDown.length).toEqual(5); + expect(dropDown[0].innerHTML).toEqual('By hour'); + expect(dropDown[1].innerHTML).toEqual('By day'); + expect(dropDown[2].innerHTML).toEqual('By week'); + expect(dropDown[3].innerHTML).toEqual('By month'); + expect(dropDown[4].innerHTML).toEqual('By year'); + done(); + }); + + let reportId = 1; + let change = new SimpleChange(null, reportId); + component.ngOnChanges({ 'reportId': change }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: reportDefParamProcessDef + }); + }); + + it('Should emit an error with a 404 response', (done) => { + fixture.detectChanges(); + + component.onError.subscribe((err) => { + expect(err).toBeDefined(); + done(); + }); + + let reportId = 1; + let change = new SimpleChange(null, reportId); + component.ngOnChanges({ 'reportId': change }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 404, + contentType: 'json', + responseText: [] + }); + }); + }); }); diff --git a/ng2-components/ng2-activiti-analytics/src/components/analytics.component.ts b/ng2-components/ng2-activiti-analytics/src/components/analytics.component.ts index 4ceb45da21..9bc16d3d5e 100644 --- a/ng2-components/ng2-activiti-analytics/src/components/analytics.component.ts +++ b/ng2-components/ng2-activiti-analytics/src/components/analytics.component.ts @@ -85,7 +85,9 @@ export class AnalyticsComponent implements OnInit, OnChanges { this.analyticsService.getParamsReports(reportId).subscribe( (res: ReportModel) => { this.reportDetails = res; - this.retriveParameterOptions(); + if (this.reportDetails.hasParameters()) { + this.retriveParameterOptions(this.reportDetails.definition.parameters); + } this.onSuccess.emit(res); }, (err: any) => { @@ -96,8 +98,8 @@ export class AnalyticsComponent implements OnInit, OnChanges { ); } - private retriveParameterOptions() { - this.reportDetails.definition.parameters.forEach((param) => { + private retriveParameterOptions(parameters: ReportParameterModel[]) { + parameters.forEach((param) => { this.analyticsService.getParamValuesByType(param.type).subscribe( (opts: ParameterValueModel[]) => { param.options = opts; diff --git a/ng2-components/ng2-activiti-analytics/src/components/widgets/dropdown/dropdown.widget.html b/ng2-components/ng2-activiti-analytics/src/components/widgets/dropdown/dropdown.widget.html index 0066152f30..3cad3a1852 100644 --- a/ng2-components/ng2-activiti-analytics/src/components/widgets/dropdown/dropdown.widget.html +++ b/ng2-components/ng2-activiti-analytics/src/components/widgets/dropdown/dropdown.widget.html @@ -1,6 +1,6 @@ diff --git a/ng2-components/ng2-activiti-analytics/src/components/widgets/date/date.widget.ts b/ng2-components/ng2-activiti-analytics/src/components/widgets/date/date.widget.ts deleted file mode 100644 index 78bf35a398..0000000000 --- a/ng2-components/ng2-activiti-analytics/src/components/widgets/date/date.widget.ts +++ /dev/null @@ -1,50 +0,0 @@ -/*! - * @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 { Component, ElementRef } from '@angular/core'; -import { WidgetComponent } from './../widget.component'; - -@Component({ - moduleId: module.id, - selector: 'date-widget', - templateUrl: './date.widget.html', - styleUrls: ['./date.widget.css'] -}) -export class DateWidget extends WidgetComponent { - - constructor(private elementRef: ElementRef) { - super(); - } - - setupMaterialComponents(componentHandler: any): boolean { - // workaround for MDL issues with dynamic components - if (componentHandler) { - componentHandler.upgradeAllRegistered(); - if (this.elementRef && this.hasValue()) { - let el = this.elementRef.nativeElement; - let container = el.querySelector('.mdl-textfield'); - if (container) { - container.MaterialTextfield.change(this.field.value); - } - } - - return true; - } - return false; - } - -} diff --git a/ng2-components/ng2-activiti-analytics/src/components/widgets/duration/duration.widget.html b/ng2-components/ng2-activiti-analytics/src/components/widgets/duration/duration.widget.html index 2db7992288..629574bd09 100644 --- a/ng2-components/ng2-activiti-analytics/src/components/widgets/duration/duration.widget.html +++ b/ng2-components/ng2-activiti-analytics/src/components/widgets/duration/duration.widget.html @@ -5,6 +5,7 @@ type="text" pattern="-?[0-9]*(\.[0-9]+)?" [attr.id]="field.id" + [value]="field.value" [(ngModel)]="field.value" (ngModelChange)="calculateDuration()"> diff --git a/ng2-components/ng2-activiti-analytics/src/components/widgets/index.ts b/ng2-components/ng2-activiti-analytics/src/components/widgets/index.ts index efc2d86d5f..c044bc245b 100644 --- a/ng2-components/ng2-activiti-analytics/src/components/widgets/index.ts +++ b/ng2-components/ng2-activiti-analytics/src/components/widgets/index.ts @@ -19,7 +19,6 @@ import { DropdownWidget } from './dropdown/dropdown.widget'; import { NumberWidget } from './number/number.widget'; import { DurationWidget } from './duration/duration.widget'; import { CheckboxWidget } from './checkbox/checkbox.widget'; -import { DateWidget } from './date/date.widget'; import { DateRangeWidget } from './date-range/date-range.widget'; // primitives @@ -27,7 +26,6 @@ export * from './dropdown/dropdown.widget'; export * from './number/number.widget'; export * from './duration/duration.widget'; export * from './checkbox/checkbox.widget'; -export * from './date/date.widget'; export * from './date-range/date-range.widget'; export const WIDGET_DIRECTIVES: any[] = [ @@ -35,6 +33,5 @@ export const WIDGET_DIRECTIVES: any[] = [ NumberWidget, DurationWidget, CheckboxWidget, - DateWidget, DateRangeWidget ]; diff --git a/ng2-components/ng2-activiti-analytics/src/components/widgets/number/number.widget.html b/ng2-components/ng2-activiti-analytics/src/components/widgets/number/number.widget.html index 64acbf818e..babd53fc39 100644 --- a/ng2-components/ng2-activiti-analytics/src/components/widgets/number/number.widget.html +++ b/ng2-components/ng2-activiti-analytics/src/components/widgets/number/number.widget.html @@ -3,6 +3,7 @@ type="text" pattern="-?[0-9]*(\.[0-9]+)?" [attr.id]="field.id" + [value]="field.value" [(ngModel)]="field.value" (ngModelChange)="changeValue(field)"> diff --git a/ng2-components/ng2-activiti-analytics/src/components/widgets/number/number.widget.ts b/ng2-components/ng2-activiti-analytics/src/components/widgets/number/number.widget.ts index d5ef372c94..cfe12f51af 100644 --- a/ng2-components/ng2-activiti-analytics/src/components/widgets/number/number.widget.ts +++ b/ng2-components/ng2-activiti-analytics/src/components/widgets/number/number.widget.ts @@ -36,7 +36,7 @@ export class NumberWidget extends WidgetComponent { handler.upgradeAllRegistered(); if (this.elementRef && this.hasValue()) { let container = this.elementRef.nativeElement.querySelector('.mdl-textfield'); - if (container) { + if (container && container.MaterialTextfield) { container.MaterialTextfield.change(this.field.value.toString()); } } diff --git a/ng2-components/ng2-activiti-analytics/src/services/analytics.service.ts b/ng2-components/ng2-activiti-analytics/src/services/analytics.service.ts index 8e87303a80..b51182e18d 100644 --- a/ng2-components/ng2-activiti-analytics/src/services/analytics.service.ts +++ b/ng2-components/ng2-activiti-analytics/src/services/analytics.service.ts @@ -130,7 +130,7 @@ export class AnalyticsService { } getTasksByProcessDefinitionId(reportId: string, processDefinitionId: string): Observable { - if (processDefinitionId) { + if (reportId && processDefinitionId) { let url = `${this.alfrescoSettingsService.getBPMApiBaseUrl()}/app/rest/reporting/report-params/${reportId}/tasks`; let params: URLSearchParams; if (processDefinitionId) { From 72e33756fb64fef08e40385974eada1bcf2dfa6e Mon Sep 17 00:00:00 2001 From: mauriziovitale84 Date: Wed, 12 Oct 2016 20:16:25 +0100 Subject: [PATCH 4/5] Add reports filter by appId --- .../activiti/activiti-demo.component.html | 2 +- .../src/assets/analyticsComponent.mock.ts | 61 ++++++++++++------- .../components/analytics.component.spec.ts | 43 ++++++++++++- .../src/components/analytics.component.ts | 17 ++++-- .../src/services/analytics.service.ts | 10 +-- 5 files changed, 98 insertions(+), 35 deletions(-) diff --git a/demo-shell-ng2/app/components/activiti/activiti-demo.component.html b/demo-shell-ng2/app/components/activiti/activiti-demo.component.html index a9a9a45019..eb25883a76 100644 --- a/demo-shell-ng2/app/components/activiti/activiti-demo.component.html +++ b/demo-shell-ng2/app/components/activiti/activiti-demo.component.html @@ -69,7 +69,7 @@
- +
diff --git a/ng2-components/ng2-activiti-analytics/src/assets/analyticsComponent.mock.ts b/ng2-components/ng2-activiti-analytics/src/assets/analyticsComponent.mock.ts index 6994e2e761..606fca6c11 100644 --- a/ng2-components/ng2-activiti-analytics/src/assets/analyticsComponent.mock.ts +++ b/ng2-components/ng2-activiti-analytics/src/assets/analyticsComponent.mock.ts @@ -69,28 +69,45 @@ export var reportDefParamProcessDef = { 'definition': '{ "parameters" :[{"id":"processDefinitionId","name":null,"nameKey":null,"type":"processDefinition","value":null,"dependsOn":null}]}' }; -export var reportDefParamProcessDefOptions = [ - { - 'id': 'FakeProcessTest 1:1:1', - 'name': 'Fake Process Test 1 Name ', - 'version': 1 - }, - { - 'id': 'FakeProcessTest 1:2:1', - 'name': 'Fake Process Test 1 Name ', - 'version': 2 - }, - { - 'id': 'FakeProcessTest 2:1:1', - 'name': 'Fake Process Test 2 Name ', - 'version': 1 - }, - { - 'id': 'FakeProcessTest 3:1:1', - 'name': 'Fake Process Test 3 Name ', - 'version': 1 - } -]; +export var reportDefParamProcessDefOptions = { + 'size': 4, 'total': 4, 'start': 0, 'data': [ + { + 'id': 'FakeProcessTest 1:1:1', + 'name': 'Fake Process Test 1 Name ', + 'version': 1 + }, + { + 'id': 'FakeProcessTest 1:2:1', + 'name': 'Fake Process Test 1 Name ', + 'version': 2 + }, + { + 'id': 'FakeProcessTest 2:1:1', + 'name': 'Fake Process Test 2 Name ', + 'version': 1 + }, + { + 'id': 'FakeProcessTest 3:1:1', + 'name': 'Fake Process Test 3 Name ', + 'version': 1 + } + ] +}; + +export var reportDefParamProcessDefOptionsApp = { + 'size': 2, 'total': 2, 'start': 2, 'data': [ + { + 'id': 'FakeProcessTest 1:1:1', + 'name': 'Fake Process Test 1 Name ', + 'version': 1 + }, + { + 'id': 'FakeProcessTest 1:2:1', + 'name': 'Fake Process Test 1 Name ', + 'version': 2 + } + ] +}; export var reportDefParamTask = { 'id': 2006, diff --git a/ng2-components/ng2-activiti-analytics/src/components/analytics.component.spec.ts b/ng2-components/ng2-activiti-analytics/src/components/analytics.component.spec.ts index ee662468e9..6882cb02a4 100644 --- a/ng2-components/ng2-activiti-analytics/src/components/analytics.component.spec.ts +++ b/ng2-components/ng2-activiti-analytics/src/components/analytics.component.spec.ts @@ -33,8 +33,8 @@ import { DebugElement, SimpleChange } from '@angular/core'; import { reportDefParamCheck, reportDefParamDateRange, chartProcessDefOverview, chartTaskOverview, fieldDateRange, fieldDateRangeInterval, fieldDuration, fieldNumber, fieldProcessDef, fieldStatus, fieldTask, fieldTypeFiltering, - reportDefParamDuration, reportDefParamNumber, reportDefParamTaskOptions, reportDefParamStatus, - reportDefParamRangeInterval, reportDefParamProcessDef, reportDefParamProcessDefOptions, reportDefParamTask + reportDefParamDuration, reportDefParamNumber, reportDefParamTaskOptions, reportDefParamStatus, reportDefParamRangeInterval, + reportDefParamProcessDef, reportDefParamProcessDefOptions, reportDefParamProcessDefOptionsApp, reportDefParamTask } from '../assets/analyticsComponent.mock'; export const ANALYTICS_DIRECTIVES: any[] = [ @@ -255,7 +255,9 @@ describe('Test ng2-activiti-analytics Report ', () => { }); }); - it('Should render a dropdown with all the process definition when the definition parameter type is \'processDefinition\' ', (done) => { + it('Should render a dropdown with all the process definition when the definition parameter type is \'processDefinition\' and the' + + ' reportId change' + + ' ', (done) => { fixture.detectChanges(); component.onSuccessParamOpt.subscribe(() => { @@ -289,6 +291,41 @@ describe('Test ng2-activiti-analytics Report ', () => { }); + it('Should render a dropdown with all the process definition when the definition parameter type is \'processDefinition\' and the' + + ' appId change' + + ' ', (done) => { + fixture.detectChanges(); + + component.onSuccessParamOpt.subscribe(() => { + fixture.detectChanges(); + let dropDown: any = element.querySelector('#select-processDefinitionId'); + expect(dropDown).toBeDefined(); + expect(dropDown.length).toEqual(3); + expect(dropDown[0].innerHTML).toEqual('Choose One'); + expect(dropDown[1].innerHTML).toEqual('Fake Process Test 1 Name (v 1) '); + expect(dropDown[2].innerHTML).toEqual('Fake Process Test 1 Name (v 2) '); + done(); + }); + + let appId = 1; + component.appId = appId; + let change = new SimpleChange(null, appId); + component.ngOnChanges({ 'appId': change }); + + jasmine.Ajax.requests.first().respondWith({ + status: 200, + contentType: 'json', + responseText: reportDefParamProcessDef + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: reportDefParamProcessDefOptionsApp + }); + + }); + it('Should render the Process definition overview report ', (done) => { fixture.detectChanges(); diff --git a/ng2-components/ng2-activiti-analytics/src/components/analytics.component.ts b/ng2-components/ng2-activiti-analytics/src/components/analytics.component.ts index 2363677531..4cf8214e26 100644 --- a/ng2-components/ng2-activiti-analytics/src/components/analytics.component.ts +++ b/ng2-components/ng2-activiti-analytics/src/components/analytics.component.ts @@ -33,6 +33,9 @@ export class AnalyticsComponent implements OnInit, OnChanges { @ViewChild('processDefinition') processDefinition: any; + @Input() + appId: string; + @Input() reportId: string; @@ -85,13 +88,13 @@ export class AnalyticsComponent implements OnInit, OnChanges { this.dropDownSub = this.onDropdownChanged.subscribe((field) => { let paramDependOn: ReportParameterModel = this.reportDetails.definition.parameters.find(p => p.dependsOn === field.id); if (paramDependOn) { - this.retrieveParameterOptions(this.reportDetails.definition.parameters, this.reportId, field.value); + this.retrieveParameterOptions(this.reportDetails.definition.parameters, this.appId, this.reportId, field.value); } }); this.paramOpts = this.onSuccessParamsReport.subscribe((report: ReportModel) => { if (report.hasParameters()) { - this.retrieveParameterOptions(report.definition.parameters); + this.retrieveParameterOptions(report.definition.parameters, this.appId); } }); } @@ -102,6 +105,12 @@ export class AnalyticsComponent implements OnInit, OnChanges { this.getParamsReports(reportId.currentValue); return; } + + let appId = changes['appId']; + if (appId && (appId.currentValue || appId.currentValue === null)) { + this.getParamsReports(this.reportId); + return; + } } public getParamsReports(reportId: string) { @@ -119,9 +128,9 @@ export class AnalyticsComponent implements OnInit, OnChanges { ); } - private retrieveParameterOptions(parameters: ReportParameterModel[], reportId?: string, processDefinitionId?: string) { + private retrieveParameterOptions(parameters: ReportParameterModel[], appId: string, reportId?: string, processDefinitionId?: string) { parameters.forEach((param) => { - this.analyticsService.getParamValuesByType(param.type, this.reportId, processDefinitionId).subscribe( + this.analyticsService.getParamValuesByType(param.type, appId, reportId, processDefinitionId).subscribe( (opts: ParameterValueModel[]) => { param.options = opts; this.onSuccessParamOpt.emit(opts); diff --git a/ng2-components/ng2-activiti-analytics/src/services/analytics.service.ts b/ng2-components/ng2-activiti-analytics/src/services/analytics.service.ts index b51182e18d..fbef18f7ee 100644 --- a/ng2-components/ng2-activiti-analytics/src/services/analytics.service.ts +++ b/ng2-components/ng2-activiti-analytics/src/services/analytics.service.ts @@ -64,11 +64,11 @@ export class AnalyticsService { }).catch(this.handleError); } - getParamValuesByType(type: string, reportId?: string, processDefinitionId?: string) { + getParamValuesByType(type: string, appId: string, reportId?: string, processDefinitionId?: string) { if (type === 'status') { return this.getProcessStatusValues(); } else if (type === 'processDefinition') { - return this.getProcessDefinitionsValues(); + return this.getProcessDefinitionsValues(appId); } else if (type === 'dateInterval') { return this.getDateIntervalValues(); } else if (type === 'task') { @@ -109,8 +109,8 @@ export class AnalyticsService { }); } - getProcessDefinitionsValues(appId?: string): Observable { - let url = `${this.alfrescoSettingsService.getBPMApiBaseUrl()}/app/rest/reporting/process-definitions`; + getProcessDefinitionsValues(appId: string): Observable { + let url = `${this.alfrescoSettingsService.getBPMApiBaseUrl()}/app/rest/process-definitions`; let params: URLSearchParams; if (appId) { params = new URLSearchParams(); @@ -122,7 +122,7 @@ export class AnalyticsService { .map((res: any) => { let paramOptions: ParameterValueModel[] = []; let body = res.json(); - body.forEach((opt) => { + body.data.forEach((opt) => { paramOptions.push(new ParameterValueModel(opt)); }); return paramOptions; From 2d28db0383eb77f31655c828480872030d28dc53 Mon Sep 17 00:00:00 2001 From: mauriziovitale84 Date: Thu, 13 Oct 2016 10:40:30 +0100 Subject: [PATCH 5/5] fix after the review --- .../analytics-report-list.component.ts | 3 +- .../components/analytics.component.spec.ts | 101 +++++------------- .../src/components/analytics.component.ts | 11 +- 3 files changed, 31 insertions(+), 84 deletions(-) diff --git a/ng2-components/ng2-activiti-analytics/src/components/analytics-report-list.component.ts b/ng2-components/ng2-activiti-analytics/src/components/analytics-report-list.component.ts index a80a98d4ff..2445989824 100644 --- a/ng2-components/ng2-activiti-analytics/src/components/analytics-report-list.component.ts +++ b/ng2-components/ng2-activiti-analytics/src/components/analytics-report-list.component.ts @@ -71,8 +71,7 @@ export class AnalyticsReportListComponent implements OnInit { (err: any) => { this.onError.emit(err); console.log(err); - }, - () => console.log('Reports loaded') + } ); } diff --git a/ng2-components/ng2-activiti-analytics/src/components/analytics.component.spec.ts b/ng2-components/ng2-activiti-analytics/src/components/analytics.component.spec.ts index 6882cb02a4..47ff595574 100644 --- a/ng2-components/ng2-activiti-analytics/src/components/analytics.component.spec.ts +++ b/ng2-components/ng2-activiti-analytics/src/components/analytics.component.spec.ts @@ -30,12 +30,7 @@ import { ReportModel, ReportQuery } from '../models/report.model'; import { Chart } from '../models/chart.model'; import * as moment from 'moment'; import { DebugElement, SimpleChange } from '@angular/core'; -import { - reportDefParamCheck, reportDefParamDateRange, chartProcessDefOverview, chartTaskOverview, fieldDateRange, - fieldDateRangeInterval, fieldDuration, fieldNumber, fieldProcessDef, fieldStatus, fieldTask, fieldTypeFiltering, - reportDefParamDuration, reportDefParamNumber, reportDefParamTaskOptions, reportDefParamStatus, reportDefParamRangeInterval, - reportDefParamProcessDef, reportDefParamProcessDefOptions, reportDefParamProcessDefOptionsApp, reportDefParamTask -} from '../assets/analyticsComponent.mock'; +import * as analyticMock from '../assets/analyticsComponent.mock'; export const ANALYTICS_DIRECTIVES: any[] = [ AnalyticsComponent, @@ -86,7 +81,6 @@ describe('Test ng2-activiti-analytics Report ', () => { }); describe('Rendering tests', () => { - beforeEach(() => { jasmine.Ajax.install(); }); @@ -96,16 +90,12 @@ describe('Test ng2-activiti-analytics Report ', () => { }); it('Should initialize the Report form with a Form Group ', () => { - fixture.detectChanges(); - expect(component.reportForm.get('dateRange')).toBeDefined(); expect(component.reportForm.get('dateRange').get('startDate')).toBeDefined(); expect(component.reportForm.get('dateRange').get('endDate')).toBeDefined(); }); it('Should render a dropdown with all the status when the definition parameter type is \'status\' ', (done) => { - fixture.detectChanges(); - component.onSuccessParamsReport.subscribe(() => { fixture.detectChanges(); let dropDown: any = element.querySelector('#select-status'); @@ -126,13 +116,11 @@ describe('Test ng2-activiti-analytics Report ', () => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', - responseText: reportDefParamStatus + responseText: analyticMock.reportDefParamStatus }); }); it('Should render a number with the default value when the definition parameter type is \'integer\' ', (done) => { - fixture.detectChanges(); - component.onSuccessParamsReport.subscribe(() => { fixture.detectChanges(); let numberElement: any = element.querySelector('#slowProcessInstanceInteger'); @@ -148,13 +136,11 @@ describe('Test ng2-activiti-analytics Report ', () => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', - responseText: reportDefParamNumber + responseText: analyticMock.reportDefParamNumber }); }); it('Should render a duration component when the definition parameter type is \'duration\' ', (done) => { - fixture.detectChanges(); - component.onSuccessParamsReport.subscribe(() => { fixture.detectChanges(); let numberElement: any = element.querySelector('#duration'); @@ -177,13 +163,11 @@ describe('Test ng2-activiti-analytics Report ', () => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', - responseText: reportDefParamDuration + responseText: analyticMock.reportDefParamDuration }); }); it('Should render a checkbox with the value true when the definition parameter type is \'boolean\' ', (done) => { - fixture.detectChanges(); - component.onSuccessParamsReport.subscribe(() => { fixture.detectChanges(); let checkElement: any = element.querySelector('#typeFiltering'); @@ -198,13 +182,11 @@ describe('Test ng2-activiti-analytics Report ', () => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', - responseText: reportDefParamCheck + responseText: analyticMock.reportDefParamCheck }); }); it('Should render a date range components when the definition parameter type is \'dateRange\' ', (done) => { - fixture.detectChanges(); - component.onSuccessParamsReport.subscribe(() => { fixture.detectChanges(); let today = moment().format('YYYY-MM-DD'); @@ -224,13 +206,11 @@ describe('Test ng2-activiti-analytics Report ', () => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', - responseText: reportDefParamDateRange + responseText: analyticMock.reportDefParamDateRange }); }); it('Should render a dropdown with all the RangeInterval when the definition parameter type is \'dateRangeInterval\' ', (done) => { - fixture.detectChanges(); - component.onSuccessParamsReport.subscribe(() => { fixture.detectChanges(); let dropDown: any = element.querySelector('#select-dateRangeInterval'); @@ -251,15 +231,12 @@ describe('Test ng2-activiti-analytics Report ', () => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', - responseText: reportDefParamRangeInterval + responseText: analyticMock.reportDefParamRangeInterval }); }); it('Should render a dropdown with all the process definition when the definition parameter type is \'processDefinition\' and the' + - ' reportId change' + - ' ', (done) => { - fixture.detectChanges(); - + ' reportId change', (done) => { component.onSuccessParamOpt.subscribe(() => { fixture.detectChanges(); let dropDown: any = element.querySelector('#select-processDefinitionId'); @@ -280,22 +257,18 @@ describe('Test ng2-activiti-analytics Report ', () => { jasmine.Ajax.requests.first().respondWith({ status: 200, contentType: 'json', - responseText: reportDefParamProcessDef + responseText: analyticMock.reportDefParamProcessDef }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', - responseText: reportDefParamProcessDefOptions + responseText: analyticMock.reportDefParamProcessDefOptions }); - }); it('Should render a dropdown with all the process definition when the definition parameter type is \'processDefinition\' and the' + - ' appId change' + - ' ', (done) => { - fixture.detectChanges(); - + ' appId change', (done) => { component.onSuccessParamOpt.subscribe(() => { fixture.detectChanges(); let dropDown: any = element.querySelector('#select-processDefinitionId'); @@ -315,23 +288,18 @@ describe('Test ng2-activiti-analytics Report ', () => { jasmine.Ajax.requests.first().respondWith({ status: 200, contentType: 'json', - responseText: reportDefParamProcessDef + responseText: analyticMock.reportDefParamProcessDef }); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', - responseText: reportDefParamProcessDefOptionsApp + responseText: analyticMock.reportDefParamProcessDefOptionsApp }); - }); it('Should render the Process definition overview report ', (done) => { - fixture.detectChanges(); - component.onShowReport.subscribe((res) => { - // fixture.detectChanges(); - expect(res).toBeDefined(); expect(res.length).toEqual(3); @@ -369,16 +337,12 @@ describe('Test ng2-activiti-analytics Report ', () => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', - responseText: chartProcessDefOverview + responseText: analyticMock.chartProcessDefOverview }); }); it('Should render the Task overview report ', (done) => { - fixture.detectChanges(); - component.onShowReport.subscribe((res) => { - // fixture.detectChanges(); - expect(res).toBeDefined(); expect(res.length).toEqual(2); @@ -426,13 +390,13 @@ describe('Test ng2-activiti-analytics Report ', () => { jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', - responseText: chartTaskOverview + responseText: analyticMock.chartTaskOverview }); }); it('Should reset the report and save the number value onNumberChanges method', () => { component.reports = [ new Chart({id: 'fake', type: 'fake-type'})]; - component.onNumberChanges(fieldNumber); + component.onNumberChanges(analyticMock.fieldNumber); expect(component.reports).toBeNull(); expect(component.reportParamQuery.slowProcessInstanceInteger).toEqual(102); @@ -440,7 +404,7 @@ describe('Test ng2-activiti-analytics Report ', () => { it('Should reset the report and save the duration value onDurationChanges method', () => { component.reports = [ new Chart({id: 'fake', type: 'fake-type'})]; - component.onDurationChanges(fieldDuration); + component.onDurationChanges(analyticMock.fieldDuration); expect(component.reports).toBeNull(); expect(component.reportParamQuery.duration).toEqual(30); @@ -448,7 +412,7 @@ describe('Test ng2-activiti-analytics Report ', () => { it('Should reset the report and save the status value onStatusChanges method', () => { component.reports = [ new Chart({id: 'fake', type: 'fake-type'})]; - component.onStatusChanges(fieldStatus); + component.onStatusChanges(analyticMock.fieldStatus); expect(component.reports).toBeNull(); expect(component.reportParamQuery.status).toEqual('fake-value'); @@ -456,7 +420,7 @@ describe('Test ng2-activiti-analytics Report ', () => { it('Should reset the report and save the typeFiltering value onTypeFilteringChanges method', () => { component.reports = [ new Chart({id: 'fake', type: 'fake-type'})]; - component.onTypeFilteringChanges(fieldTypeFiltering); + component.onTypeFilteringChanges(analyticMock.fieldTypeFiltering); expect(component.reports).toBeNull(); expect(component.reportParamQuery.typeFiltering).toBeFalsy(); @@ -464,7 +428,7 @@ describe('Test ng2-activiti-analytics Report ', () => { it('Should reset the report and save the taskName value onTaskChanges method', () => { component.reports = [ new Chart({id: 'fake', type: 'fake-type'})]; - component.onTaskChanges(fieldTask); + component.onTaskChanges(analyticMock.fieldTask); expect(component.reports).toBeNull(); expect(component.reportParamQuery.taskName).toEqual('fake-task-name'); @@ -472,7 +436,7 @@ describe('Test ng2-activiti-analytics Report ', () => { it('Should reset the report and save the dateRange value onDateRangeChange method', () => { component.reports = [ new Chart({id: 'fake', type: 'fake-type'})]; - component.onDateRangeChange(fieldDateRange); + component.onDateRangeChange(analyticMock.fieldDateRange); expect(component.reports).toBeNull(); expect(component.reportParamQuery.dateRange.startDate).toEqual('2016-10-12T00:00:00.000Z'); @@ -481,7 +445,7 @@ describe('Test ng2-activiti-analytics Report ', () => { it('Should reset the report and save the dateRangeInterval value onDateRangeIntervalChange method', () => { component.reports = [ new Chart({id: 'fake', type: 'fake-type'})]; - component.onDateRangeIntervalChange(fieldDateRangeInterval); + component.onDateRangeIntervalChange(analyticMock.fieldDateRangeInterval); expect(component.reports).toBeNull(); expect(component.reportParamQuery.dateRangeInterval).toEqual('fake-date-interval'); @@ -494,16 +458,14 @@ describe('Test ng2-activiti-analytics Report ', () => { definition: '{ "parameters" :[{"id":"processDefinitionId","type":"processDefinition","value":null}]}' }); - component.onProcessDefinitionChanges(fieldProcessDef); + component.onProcessDefinitionChanges(analyticMock.fieldProcessDef); expect(component.reports).toBeNull(); expect(component.reportParamQuery.processDefinitionId).toEqual('fake-process-name:1:15027'); }); it('Should load the task list when a process definition is selected', () => { - component.onSuccessParamsReport.subscribe((res) => { - expect(res).toBeDefined(); expect(res.length).toEqual(2); expect(res[0].id).toEqual('Fake task name 1'); @@ -514,13 +476,13 @@ describe('Test ng2-activiti-analytics Report ', () => { component.reportId = 100; component.reports = [ new Chart({id: 'fake', type: 'fake-type'})]; - component.reportDetails = new ReportModel(reportDefParamTask); - component.onProcessDefinitionChanges(fieldProcessDef); + component.reportDetails = new ReportModel(analyticMock.reportDefParamTask); + component.onProcessDefinitionChanges(analyticMock.fieldProcessDef); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', - responseText: reportDefParamTaskOptions + responseText: analyticMock.reportDefParamTaskOptions }); }); @@ -530,8 +492,6 @@ describe('Test ng2-activiti-analytics Report ', () => { }); it('Should emit an error with a 404 response when the options response is not found', (done) => { - fixture.detectChanges(); - component.onError.subscribe((err) => { expect(err).toBeDefined(); done(); @@ -544,7 +504,7 @@ describe('Test ng2-activiti-analytics Report ', () => { jasmine.Ajax.requests.first().respondWith({ status: 200, contentType: 'json', - responseText: reportDefParamProcessDef + responseText: analyticMock.reportDefParamProcessDef }); jasmine.Ajax.requests.mostRecent().respondWith({ @@ -555,8 +515,6 @@ describe('Test ng2-activiti-analytics Report ', () => { }); it('Should emit an error with a 404 response when the Process definition overview response is not found ', (done) => { - fixture.detectChanges(); - component.onError.subscribe((err) => { expect(err).toBeDefined(); done(); @@ -576,12 +534,9 @@ describe('Test ng2-activiti-analytics Report ', () => { contentType: 'json', responseText: [] }); - }); it('Should emit an error with a 404 response when the report parameters response is not found', (done) => { - fixture.detectChanges(); - component.onError.subscribe((err) => { expect(err).toBeDefined(); done(); @@ -597,7 +552,5 @@ describe('Test ng2-activiti-analytics Report ', () => { responseText: [] }); }); - }); - }); diff --git a/ng2-components/ng2-activiti-analytics/src/components/analytics.component.ts b/ng2-components/ng2-activiti-analytics/src/components/analytics.component.ts index 4cf8214e26..86ae04a74d 100644 --- a/ng2-components/ng2-activiti-analytics/src/components/analytics.component.ts +++ b/ng2-components/ng2-activiti-analytics/src/components/analytics.component.ts @@ -103,13 +103,11 @@ export class AnalyticsComponent implements OnInit, OnChanges { let reportId = changes['reportId']; if (reportId && reportId.currentValue) { this.getParamsReports(reportId.currentValue); - return; } let appId = changes['appId']; if (appId && (appId.currentValue || appId.currentValue === null)) { this.getParamsReports(this.reportId); - return; } } @@ -123,8 +121,7 @@ export class AnalyticsComponent implements OnInit, OnChanges { (err: any) => { console.log(err); this.onError.emit(err); - }, - () => console.log('retrive done') + } ); } @@ -138,8 +135,7 @@ export class AnalyticsComponent implements OnInit, OnChanges { (err: any) => { console.log(err); this.onError.emit(err); - }, - () => console.log(`${param.type} options loaded`) + } ); }); } @@ -153,8 +149,7 @@ export class AnalyticsComponent implements OnInit, OnChanges { (err: any) => { this.onError.emit(err); console.log(err); - }, - () => console.log('Login done') + } ); }