fix after the review

This commit is contained in:
mauriziovitale84
2016-10-13 10:40:30 +01:00
parent 72e33756fb
commit 2d28db0383
3 changed files with 31 additions and 84 deletions

View File

@@ -71,8 +71,7 @@ export class AnalyticsReportListComponent implements OnInit {
(err: any) => { (err: any) => {
this.onError.emit(err); this.onError.emit(err);
console.log(err); console.log(err);
}, }
() => console.log('Reports loaded')
); );
} }

View File

@@ -30,12 +30,7 @@ import { ReportModel, ReportQuery } from '../models/report.model';
import { Chart } from '../models/chart.model'; import { Chart } from '../models/chart.model';
import * as moment from 'moment'; import * as moment from 'moment';
import { DebugElement, SimpleChange } from '@angular/core'; import { DebugElement, SimpleChange } from '@angular/core';
import { import * as analyticMock from '../assets/analyticsComponent.mock';
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';
export const ANALYTICS_DIRECTIVES: any[] = [ export const ANALYTICS_DIRECTIVES: any[] = [
AnalyticsComponent, AnalyticsComponent,
@@ -86,7 +81,6 @@ describe('Test ng2-activiti-analytics Report ', () => {
}); });
describe('Rendering tests', () => { describe('Rendering tests', () => {
beforeEach(() => { beforeEach(() => {
jasmine.Ajax.install(); jasmine.Ajax.install();
}); });
@@ -96,16 +90,12 @@ describe('Test ng2-activiti-analytics Report ', () => {
}); });
it('Should initialize the Report form with a Form Group ', () => { it('Should initialize the Report form with a Form Group ', () => {
fixture.detectChanges();
expect(component.reportForm.get('dateRange')).toBeDefined(); expect(component.reportForm.get('dateRange')).toBeDefined();
expect(component.reportForm.get('dateRange').get('startDate')).toBeDefined(); expect(component.reportForm.get('dateRange').get('startDate')).toBeDefined();
expect(component.reportForm.get('dateRange').get('endDate')).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) => { it('Should render a dropdown with all the status when the definition parameter type is \'status\' ', (done) => {
fixture.detectChanges();
component.onSuccessParamsReport.subscribe(() => { component.onSuccessParamsReport.subscribe(() => {
fixture.detectChanges(); fixture.detectChanges();
let dropDown: any = element.querySelector('#select-status'); let dropDown: any = element.querySelector('#select-status');
@@ -126,13 +116,11 @@ describe('Test ng2-activiti-analytics Report ', () => {
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, status: 200,
contentType: 'json', contentType: 'json',
responseText: reportDefParamStatus responseText: analyticMock.reportDefParamStatus
}); });
}); });
it('Should render a number with the default value when the definition parameter type is \'integer\' ', (done) => { it('Should render a number with the default value when the definition parameter type is \'integer\' ', (done) => {
fixture.detectChanges();
component.onSuccessParamsReport.subscribe(() => { component.onSuccessParamsReport.subscribe(() => {
fixture.detectChanges(); fixture.detectChanges();
let numberElement: any = element.querySelector('#slowProcessInstanceInteger'); let numberElement: any = element.querySelector('#slowProcessInstanceInteger');
@@ -148,13 +136,11 @@ describe('Test ng2-activiti-analytics Report ', () => {
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, status: 200,
contentType: 'json', contentType: 'json',
responseText: reportDefParamNumber responseText: analyticMock.reportDefParamNumber
}); });
}); });
it('Should render a duration component when the definition parameter type is \'duration\' ', (done) => { it('Should render a duration component when the definition parameter type is \'duration\' ', (done) => {
fixture.detectChanges();
component.onSuccessParamsReport.subscribe(() => { component.onSuccessParamsReport.subscribe(() => {
fixture.detectChanges(); fixture.detectChanges();
let numberElement: any = element.querySelector('#duration'); let numberElement: any = element.querySelector('#duration');
@@ -177,13 +163,11 @@ describe('Test ng2-activiti-analytics Report ', () => {
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, status: 200,
contentType: 'json', contentType: 'json',
responseText: reportDefParamDuration responseText: analyticMock.reportDefParamDuration
}); });
}); });
it('Should render a checkbox with the value true when the definition parameter type is \'boolean\' ', (done) => { it('Should render a checkbox with the value true when the definition parameter type is \'boolean\' ', (done) => {
fixture.detectChanges();
component.onSuccessParamsReport.subscribe(() => { component.onSuccessParamsReport.subscribe(() => {
fixture.detectChanges(); fixture.detectChanges();
let checkElement: any = element.querySelector('#typeFiltering'); let checkElement: any = element.querySelector('#typeFiltering');
@@ -198,13 +182,11 @@ describe('Test ng2-activiti-analytics Report ', () => {
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, status: 200,
contentType: 'json', contentType: 'json',
responseText: reportDefParamCheck responseText: analyticMock.reportDefParamCheck
}); });
}); });
it('Should render a date range components when the definition parameter type is \'dateRange\' ', (done) => { it('Should render a date range components when the definition parameter type is \'dateRange\' ', (done) => {
fixture.detectChanges();
component.onSuccessParamsReport.subscribe(() => { component.onSuccessParamsReport.subscribe(() => {
fixture.detectChanges(); fixture.detectChanges();
let today = moment().format('YYYY-MM-DD'); let today = moment().format('YYYY-MM-DD');
@@ -224,13 +206,11 @@ describe('Test ng2-activiti-analytics Report ', () => {
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, status: 200,
contentType: 'json', contentType: 'json',
responseText: reportDefParamDateRange responseText: analyticMock.reportDefParamDateRange
}); });
}); });
it('Should render a dropdown with all the RangeInterval when the definition parameter type is \'dateRangeInterval\' ', (done) => { it('Should render a dropdown with all the RangeInterval when the definition parameter type is \'dateRangeInterval\' ', (done) => {
fixture.detectChanges();
component.onSuccessParamsReport.subscribe(() => { component.onSuccessParamsReport.subscribe(() => {
fixture.detectChanges(); fixture.detectChanges();
let dropDown: any = element.querySelector('#select-dateRangeInterval'); let dropDown: any = element.querySelector('#select-dateRangeInterval');
@@ -251,15 +231,12 @@ describe('Test ng2-activiti-analytics Report ', () => {
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, status: 200,
contentType: 'json', 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' + it('Should render a dropdown with all the process definition when the definition parameter type is \'processDefinition\' and the' +
' reportId change' + ' reportId change', (done) => {
' ', (done) => {
fixture.detectChanges();
component.onSuccessParamOpt.subscribe(() => { component.onSuccessParamOpt.subscribe(() => {
fixture.detectChanges(); fixture.detectChanges();
let dropDown: any = element.querySelector('#select-processDefinitionId'); let dropDown: any = element.querySelector('#select-processDefinitionId');
@@ -280,22 +257,18 @@ describe('Test ng2-activiti-analytics Report ', () => {
jasmine.Ajax.requests.first().respondWith({ jasmine.Ajax.requests.first().respondWith({
status: 200, status: 200,
contentType: 'json', contentType: 'json',
responseText: reportDefParamProcessDef responseText: analyticMock.reportDefParamProcessDef
}); });
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, status: 200,
contentType: 'json', 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' + it('Should render a dropdown with all the process definition when the definition parameter type is \'processDefinition\' and the' +
' appId change' + ' appId change', (done) => {
' ', (done) => {
fixture.detectChanges();
component.onSuccessParamOpt.subscribe(() => { component.onSuccessParamOpt.subscribe(() => {
fixture.detectChanges(); fixture.detectChanges();
let dropDown: any = element.querySelector('#select-processDefinitionId'); let dropDown: any = element.querySelector('#select-processDefinitionId');
@@ -315,23 +288,18 @@ describe('Test ng2-activiti-analytics Report ', () => {
jasmine.Ajax.requests.first().respondWith({ jasmine.Ajax.requests.first().respondWith({
status: 200, status: 200,
contentType: 'json', contentType: 'json',
responseText: reportDefParamProcessDef responseText: analyticMock.reportDefParamProcessDef
}); });
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, status: 200,
contentType: 'json', contentType: 'json',
responseText: reportDefParamProcessDefOptionsApp responseText: analyticMock.reportDefParamProcessDefOptionsApp
}); });
}); });
it('Should render the Process definition overview report ', (done) => { it('Should render the Process definition overview report ', (done) => {
fixture.detectChanges();
component.onShowReport.subscribe((res) => { component.onShowReport.subscribe((res) => {
// fixture.detectChanges();
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res.length).toEqual(3); expect(res.length).toEqual(3);
@@ -369,16 +337,12 @@ describe('Test ng2-activiti-analytics Report ', () => {
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, status: 200,
contentType: 'json', contentType: 'json',
responseText: chartProcessDefOverview responseText: analyticMock.chartProcessDefOverview
}); });
}); });
it('Should render the Task overview report ', (done) => { it('Should render the Task overview report ', (done) => {
fixture.detectChanges();
component.onShowReport.subscribe((res) => { component.onShowReport.subscribe((res) => {
// fixture.detectChanges();
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res.length).toEqual(2); expect(res.length).toEqual(2);
@@ -426,13 +390,13 @@ describe('Test ng2-activiti-analytics Report ', () => {
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, status: 200,
contentType: 'json', contentType: 'json',
responseText: chartTaskOverview responseText: analyticMock.chartTaskOverview
}); });
}); });
it('Should reset the report and save the number value onNumberChanges method', () => { it('Should reset the report and save the number value onNumberChanges method', () => {
component.reports = [ new Chart({id: 'fake', type: 'fake-type'})]; component.reports = [ new Chart({id: 'fake', type: 'fake-type'})];
component.onNumberChanges(fieldNumber); component.onNumberChanges(analyticMock.fieldNumber);
expect(component.reports).toBeNull(); expect(component.reports).toBeNull();
expect(component.reportParamQuery.slowProcessInstanceInteger).toEqual(102); 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', () => { it('Should reset the report and save the duration value onDurationChanges method', () => {
component.reports = [ new Chart({id: 'fake', type: 'fake-type'})]; component.reports = [ new Chart({id: 'fake', type: 'fake-type'})];
component.onDurationChanges(fieldDuration); component.onDurationChanges(analyticMock.fieldDuration);
expect(component.reports).toBeNull(); expect(component.reports).toBeNull();
expect(component.reportParamQuery.duration).toEqual(30); 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', () => { it('Should reset the report and save the status value onStatusChanges method', () => {
component.reports = [ new Chart({id: 'fake', type: 'fake-type'})]; component.reports = [ new Chart({id: 'fake', type: 'fake-type'})];
component.onStatusChanges(fieldStatus); component.onStatusChanges(analyticMock.fieldStatus);
expect(component.reports).toBeNull(); expect(component.reports).toBeNull();
expect(component.reportParamQuery.status).toEqual('fake-value'); 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', () => { it('Should reset the report and save the typeFiltering value onTypeFilteringChanges method', () => {
component.reports = [ new Chart({id: 'fake', type: 'fake-type'})]; component.reports = [ new Chart({id: 'fake', type: 'fake-type'})];
component.onTypeFilteringChanges(fieldTypeFiltering); component.onTypeFilteringChanges(analyticMock.fieldTypeFiltering);
expect(component.reports).toBeNull(); expect(component.reports).toBeNull();
expect(component.reportParamQuery.typeFiltering).toBeFalsy(); 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', () => { it('Should reset the report and save the taskName value onTaskChanges method', () => {
component.reports = [ new Chart({id: 'fake', type: 'fake-type'})]; component.reports = [ new Chart({id: 'fake', type: 'fake-type'})];
component.onTaskChanges(fieldTask); component.onTaskChanges(analyticMock.fieldTask);
expect(component.reports).toBeNull(); expect(component.reports).toBeNull();
expect(component.reportParamQuery.taskName).toEqual('fake-task-name'); 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', () => { it('Should reset the report and save the dateRange value onDateRangeChange method', () => {
component.reports = [ new Chart({id: 'fake', type: 'fake-type'})]; component.reports = [ new Chart({id: 'fake', type: 'fake-type'})];
component.onDateRangeChange(fieldDateRange); component.onDateRangeChange(analyticMock.fieldDateRange);
expect(component.reports).toBeNull(); expect(component.reports).toBeNull();
expect(component.reportParamQuery.dateRange.startDate).toEqual('2016-10-12T00:00:00.000Z'); 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', () => { it('Should reset the report and save the dateRangeInterval value onDateRangeIntervalChange method', () => {
component.reports = [ new Chart({id: 'fake', type: 'fake-type'})]; component.reports = [ new Chart({id: 'fake', type: 'fake-type'})];
component.onDateRangeIntervalChange(fieldDateRangeInterval); component.onDateRangeIntervalChange(analyticMock.fieldDateRangeInterval);
expect(component.reports).toBeNull(); expect(component.reports).toBeNull();
expect(component.reportParamQuery.dateRangeInterval).toEqual('fake-date-interval'); expect(component.reportParamQuery.dateRangeInterval).toEqual('fake-date-interval');
@@ -494,16 +458,14 @@ describe('Test ng2-activiti-analytics Report ', () => {
definition: definition:
'{ "parameters" :[{"id":"processDefinitionId","type":"processDefinition","value":null}]}' '{ "parameters" :[{"id":"processDefinitionId","type":"processDefinition","value":null}]}'
}); });
component.onProcessDefinitionChanges(fieldProcessDef); component.onProcessDefinitionChanges(analyticMock.fieldProcessDef);
expect(component.reports).toBeNull(); expect(component.reports).toBeNull();
expect(component.reportParamQuery.processDefinitionId).toEqual('fake-process-name:1:15027'); expect(component.reportParamQuery.processDefinitionId).toEqual('fake-process-name:1:15027');
}); });
it('Should load the task list when a process definition is selected', () => { it('Should load the task list when a process definition is selected', () => {
component.onSuccessParamsReport.subscribe((res) => { component.onSuccessParamsReport.subscribe((res) => {
expect(res).toBeDefined(); expect(res).toBeDefined();
expect(res.length).toEqual(2); expect(res.length).toEqual(2);
expect(res[0].id).toEqual('Fake task name 1'); expect(res[0].id).toEqual('Fake task name 1');
@@ -514,13 +476,13 @@ describe('Test ng2-activiti-analytics Report ', () => {
component.reportId = 100; component.reportId = 100;
component.reports = [ new Chart({id: 'fake', type: 'fake-type'})]; component.reports = [ new Chart({id: 'fake', type: 'fake-type'})];
component.reportDetails = new ReportModel(reportDefParamTask); component.reportDetails = new ReportModel(analyticMock.reportDefParamTask);
component.onProcessDefinitionChanges(fieldProcessDef); component.onProcessDefinitionChanges(analyticMock.fieldProcessDef);
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, status: 200,
contentType: 'json', 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) => { it('Should emit an error with a 404 response when the options response is not found', (done) => {
fixture.detectChanges();
component.onError.subscribe((err) => { component.onError.subscribe((err) => {
expect(err).toBeDefined(); expect(err).toBeDefined();
done(); done();
@@ -544,7 +504,7 @@ describe('Test ng2-activiti-analytics Report ', () => {
jasmine.Ajax.requests.first().respondWith({ jasmine.Ajax.requests.first().respondWith({
status: 200, status: 200,
contentType: 'json', contentType: 'json',
responseText: reportDefParamProcessDef responseText: analyticMock.reportDefParamProcessDef
}); });
jasmine.Ajax.requests.mostRecent().respondWith({ 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) => { 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) => { component.onError.subscribe((err) => {
expect(err).toBeDefined(); expect(err).toBeDefined();
done(); done();
@@ -576,12 +534,9 @@ describe('Test ng2-activiti-analytics Report ', () => {
contentType: 'json', contentType: 'json',
responseText: [] responseText: []
}); });
}); });
it('Should emit an error with a 404 response when the report parameters response is not found', (done) => { it('Should emit an error with a 404 response when the report parameters response is not found', (done) => {
fixture.detectChanges();
component.onError.subscribe((err) => { component.onError.subscribe((err) => {
expect(err).toBeDefined(); expect(err).toBeDefined();
done(); done();
@@ -597,7 +552,5 @@ describe('Test ng2-activiti-analytics Report ', () => {
responseText: [] responseText: []
}); });
}); });
}); });
}); });

View File

@@ -103,13 +103,11 @@ export class AnalyticsComponent implements OnInit, OnChanges {
let reportId = changes['reportId']; let reportId = changes['reportId'];
if (reportId && reportId.currentValue) { if (reportId && reportId.currentValue) {
this.getParamsReports(reportId.currentValue); this.getParamsReports(reportId.currentValue);
return;
} }
let appId = changes['appId']; let appId = changes['appId'];
if (appId && (appId.currentValue || appId.currentValue === null)) { if (appId && (appId.currentValue || appId.currentValue === null)) {
this.getParamsReports(this.reportId); this.getParamsReports(this.reportId);
return;
} }
} }
@@ -123,8 +121,7 @@ export class AnalyticsComponent implements OnInit, OnChanges {
(err: any) => { (err: any) => {
console.log(err); console.log(err);
this.onError.emit(err); this.onError.emit(err);
}, }
() => console.log('retrive done')
); );
} }
@@ -138,8 +135,7 @@ export class AnalyticsComponent implements OnInit, OnChanges {
(err: any) => { (err: any) => {
console.log(err); console.log(err);
this.onError.emit(err); this.onError.emit(err);
}, }
() => console.log(`${param.type} options loaded`)
); );
}); });
} }
@@ -153,8 +149,7 @@ export class AnalyticsComponent implements OnInit, OnChanges {
(err: any) => { (err: any) => {
this.onError.emit(err); this.onError.emit(err);
console.log(err); console.log(err);
}, }
() => console.log('Login done')
); );
} }