[ACS-8771] bug fixes in insights, reduce jasmine.ajax (#10214)

* bug fixes in insights, reduce jasmine.ajax

* bug fixes in insights, reduce jasmine.ajax
This commit is contained in:
Denys Vuika 2024-12-13 05:32:19 -05:00 committed by GitHub
parent 3a8ad1a596
commit b58f1c9daa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 177 additions and 219 deletions

View File

@ -16,36 +16,36 @@
*/
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Chart } from '../../diagram/models/chart/chart.model';
import { ReportQuery } from '../../diagram/models/report/report-query.model';
import * as analyticMock from '../../mock';
import { AnalyticsGeneratorComponent } from '../components/analytics-generator.component';
import { InsightsTestingModule } from '../../testing/insights.testing.module';
declare let jasmine: any;
import { AnalyticsService } from '@alfresco/adf-insights';
describe('AnalyticsGeneratorComponent', () => {
let component: any;
let component: AnalyticsGeneratorComponent;
let fixture: ComponentFixture<AnalyticsGeneratorComponent>;
let analyticsService: AnalyticsService;
let getReportsByParamsSpy: jasmine.Spy;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [InsightsTestingModule]
});
analyticsService = TestBed.inject(AnalyticsService);
getReportsByParamsSpy = spyOn(analyticsService.reportApi, 'getReportsByParams').and.stub();
fixture = TestBed.createComponent(AnalyticsGeneratorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('Should render the Process definition overview report ', (done) => {
getReportsByParamsSpy.and.returnValue(Promise.resolve(analyticMock.chartProcessDefOverview));
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(res.length).toEqual(3);
@ -80,22 +80,14 @@ describe('AnalyticsGeneratorComponent', () => {
done();
});
component.reportId = 1001;
component.reportId = '1001';
component.reportParamQuery = new ReportQuery({ status: 'All' });
component.ngOnChanges();
fixture.detectChanges();
fixture.whenStable().then(() => {
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: analyticMock.chartProcessDefOverview
});
});
});
it('Should render the Process definition overview report when [onChanges] is called ', (done) => {
getReportsByParamsSpy.and.returnValue(Promise.resolve(analyticMock.chartProcessDefOverview));
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(res.length).toEqual(3);
@ -130,22 +122,14 @@ describe('AnalyticsGeneratorComponent', () => {
done();
});
component.reportId = 1001;
component.reportId = '1001';
component.reportParamQuery = new ReportQuery({ status: 'All' });
component.ngOnChanges();
fixture.detectChanges();
fixture.whenStable().then(() => {
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: analyticMock.chartProcessDefOverview
});
});
});
it('Should render the Task overview report ', (done) => {
getReportsByParamsSpy.and.returnValue(Promise.resolve(analyticMock.chartTaskOverview));
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(res.length).toEqual(3);
@ -183,9 +167,9 @@ describe('AnalyticsGeneratorComponent', () => {
expect(res[2].type).toEqual('multiBar');
expect(res[2].labels).toBeDefined();
expect(res[2].labels.length).toEqual(3);
expect(res[2].labels[0]).toEqual(1);
expect(res[2].labels[1]).toEqual(2);
expect(res[2].labels[2]).toEqual(3);
expect(res[2].labels[0]).toEqual('1');
expect(res[2].labels[1]).toEqual('2');
expect(res[2].labels[2]).toEqual('3');
expect(res[2].datasets[0].label).toEqual('averages');
expect(res[2].datasets[0].data[0]).toEqual(0);
expect(res[2].datasets[0].data[1]).toEqual(5);
@ -202,24 +186,14 @@ describe('AnalyticsGeneratorComponent', () => {
done();
});
component.reportId = 1;
component.reportId = '1';
component.reportParamQuery = new ReportQuery({ status: 'All' });
component.ngOnChanges();
fixture.detectChanges();
fixture.whenStable().then(() => {
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: analyticMock.chartTaskOverview
});
});
});
it('Should reset the reports when the onChanged is call', async () => {
component.reports = [new Chart({ id: 'fake', type: 'fake-type' })];
component.reportId = 1;
component.reportId = '1';
component.ngOnChanges();
fixture.detectChanges();
@ -229,23 +203,15 @@ describe('AnalyticsGeneratorComponent', () => {
});
it('Should emit onError event with a 404 response ', (done) => {
getReportsByParamsSpy.and.returnValue(Promise.reject(new Error('404')));
component.error.subscribe((err) => {
expect(err).toBeDefined();
done();
});
component.reportId = 1;
component.reportId = '1';
component.reportParamQuery = new ReportQuery({ status: 'All' });
component.ngOnChanges();
fixture.detectChanges();
fixture.whenStable().then(() => {
jasmine.Ajax.requests.mostRecent().respondWith({
status: 404,
contentType: 'json',
responseText: []
});
});
});
});

View File

@ -101,18 +101,18 @@ export class AnalyticsGeneratorComponent implements OnChanges {
if (reportParamQuery === undefined || reportParamQuery === null) {
reportParamQuery = new ReportQuery();
}
this.analyticsService.getReportsByParams(reportId, reportParamQuery).subscribe(
(res) => {
this.analyticsService.getReportsByParams(reportId, reportParamQuery).subscribe({
next: (res) => {
this.reports = res;
if (this.reports) {
this.selectFirstReport();
}
this.success.emit(res);
},
(err: any) => {
error: (err: any) => {
this.error.emit(err);
}
);
});
}
public reset() {

View File

@ -19,8 +19,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AnalyticsReportHeatMapComponent } from '../components/analytics-report-heat-map.component';
import { InsightsTestingModule } from '../../testing/insights.testing.module';
declare let jasmine: any;
describe('AnalyticsReportHeatMapComponent', () => {
let component: AnalyticsReportHeatMapComponent;
let fixture: ComponentFixture<AnalyticsReportHeatMapComponent>;
@ -53,14 +51,6 @@ describe('AnalyticsReportHeatMapComponent', () => {
});
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 } };

View File

@ -64,42 +64,6 @@ describe('AnalyticsReportListComponent', () => {
expect(component.isReportsEmpty()).toBeTruthy();
});
// TODO: very flaky test, to be refactored
// eslint-disable-next-line ban/ban
xit('should return the default reports when the report list is empty', (done) => {
jasmine.Ajax.stubRequest('http://localhost:9876/bpm/activiti-app/app/rest/reporting/reports').andReturn({
status: 200,
contentType: 'json',
responseText: []
});
fixture.detectChanges();
jasmine.Ajax.stubRequest('http://localhost:9876/bpm/activiti-app/app/rest/reporting/default-reports').andReturn({
status: 200,
contentType: 'json',
responseText: []
});
jasmine.Ajax.stubRequest('http://localhost:9876/bpm/activiti-app/app/rest/reporting/reports').andReturn({
status: 200,
contentType: 'json',
responseText: reportList
});
component.success.subscribe(() => {
fixture.detectChanges();
expect(element.querySelector('#report-list-0 .adf-activiti-filters__entry-icon').innerHTML).toBe('assignment');
expect(element.querySelector('#report-list-0 > span').innerHTML).toBe('Fake Test Process definition heat map');
expect(element.querySelector('#report-list-1 > span').innerHTML).toBe('Fake Test Process definition overview');
expect(element.querySelector('#report-list-2 > span').innerHTML).toBe('Fake Test Process instances overview');
expect(element.querySelector('#report-list-3 > span').innerHTML).toBe('Fake Test Task overview');
expect(element.querySelector('#report-list-4 > span').innerHTML).toBe('Fake Test Task service level agreement');
expect(component.isReportsEmpty()).toBeFalsy();
done();
});
});
it('Report render the report list relative to a single app', (done) => {
fixture.detectChanges();

View File

@ -53,8 +53,8 @@ export class BarChart extends Chart {
params.values.forEach((info: any) => {
info.forEach((value: any, index: any) => {
if (index % 2 === 0) {
if (!this.labels.includes(value)) {
this.labels.push(value);
if (!this.labels.includes(value.toString())) {
this.labels.push(value.toString());
}
} else {
dataValue.push(value);

View File

@ -23,7 +23,7 @@ export class PieChart extends Chart {
if (obj.values) {
obj.values.forEach((value: any) => {
this.add(value.key, value.y);
this.add(value.key.toString(), value.y.toString());
});
}
}

View File

@ -16,100 +16,136 @@
*/
export const chartProcessDefOverview = {
elements: [{
id: 'id1585876275153',
type: 'table',
rows: [
['__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-TOTAL-PROCESS-DEFINITIONS', '9'],
['__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-TOTAL-PROCESS-INSTANCES', '41'],
['__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-ACTIVE-PROCESS-INSTANCES', '3'],
['__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-COMPLETED-PROCESS-INSTANCES', '38']
]
}, {
id: 'id1585876413072',
type: 'pieChart',
title: 'Total process instances overview',
titleKey: 'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.PROC-INST-CHART-TITLE',
values: [{
key: 'Second Process',
y: 4,
keyAndValue: ['Second Process', '4']
}, {
key: 'Simple process',
y: 30,
keyAndValue: ['Simple process', '30']
}, {
key: 'Third Process',
y: 7,
keyAndValue: ['Third Process', '7']
}]
}, {
id: 'id1585877659181',
type: 'table',
title: 'Process definition details',
titleKey: 'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.DETAIL-TABLE',
columnNames: ['Process definition', 'Total', 'Active', 'Completed'],
columnNameKeys: ['REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.DETAIL-TABLE-PROCESS',
'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.DETAIL-TABLE-TOTAL',
'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.DETAIL-TABLE-ACTIVE',
'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.DETAIL-TABLE-COMPLETED'],
columnsCentered: [false, false, false, false],
rows: [
['Second Process', '4', '0', '4'],
['Simple process', '30', '3', '27'],
['Third Process', '7', '0', '7']
]
}]
elements: [
{
id: 'id1585876275153',
type: 'table',
rows: [
['__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-TOTAL-PROCESS-DEFINITIONS', '9'],
['__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-TOTAL-PROCESS-INSTANCES', '41'],
['__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-ACTIVE-PROCESS-INSTANCES', '3'],
['__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-COMPLETED-PROCESS-INSTANCES', '38']
]
},
{
id: 'id1585876413072',
type: 'pieChart',
title: 'Total process instances overview',
titleKey: 'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.PROC-INST-CHART-TITLE',
values: [
{
key: 'Second Process',
y: 4,
keyAndValue: ['Second Process', '4']
},
{
key: 'Simple process',
y: 30,
keyAndValue: ['Simple process', '30']
},
{
key: 'Third Process',
y: 7,
keyAndValue: ['Third Process', '7']
}
]
},
{
id: 'id1585877659181',
type: 'table',
title: 'Process definition details',
titleKey: 'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.DETAIL-TABLE',
columnNames: ['Process definition', 'Total', 'Active', 'Completed'],
columnNameKeys: [
'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.DETAIL-TABLE-PROCESS',
'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.DETAIL-TABLE-TOTAL',
'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.DETAIL-TABLE-ACTIVE',
'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.DETAIL-TABLE-COMPLETED'
],
columnsCentered: [false, false, false, false],
rows: [
['Second Process', '4', '0', '4'],
['Simple process', '30', '3', '27'],
['Third Process', '7', '0', '7']
]
}
]
};
export const chartTaskOverview = {
elements: [{
id: 'id792351752194',
type: 'barChart',
title: 'title',
titleKey: 'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.TASK-HISTOGRAM-TITLE',
values: [{
key: 'series1',
values: [['2016-09-30T00:00:00.000+0000', 3], ['2016-10-04T00:00:00.000+0000', 1]]
}],
xAxisType: 'date_month',
yAxisType: 'count'
}, {
id: 'id792349721129',
type: 'masterDetailTable',
title: 'Detailed task statistics',
titleKey: 'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.DETAILED-TASK-STATS-TITLE',
/* cspell:disable-next-line */
columnNames: ['Task', 'Count', 'Sum', 'Min duration', 'Max duration', 'Average duration', 'Stddev duration'],
columnNameKeys: [
'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.DETAILED-TASK-STATS-TASK',
'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.COUNT',
'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.SUM',
'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.MIN-DURATION',
'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.MAX-DURATION',
'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.AVERAGE',
elements: [
{
id: 'id792351752194',
type: 'barChart',
title: 'title',
titleKey: 'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.TASK-HISTOGRAM-TITLE',
values: [
{
key: 'series1',
values: [
['2016-09-30T00:00:00.000+0000', 3],
['2016-10-04T00:00:00.000+0000', 1]
]
}
],
xAxisType: 'date_month',
yAxisType: 'count'
},
{
id: 'id792349721129',
type: 'masterDetailTable',
title: 'Detailed task statistics',
titleKey: 'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.DETAILED-TASK-STATS-TITLE',
/* cspell:disable-next-line */
'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.STDDE'],
columnsCentered: [false, false, false, false],
rows: [
['fake 1 user task', '1', '2.0', '3.0', '4.0', '5.0', '6.0'],
['fake 2 user task', '1', '2.0', '3.0', '4.0', '5.0', '6.0']
]
}, {
id: 'id10931125229538',
type: 'multiBarChart',
title: 'Task duration',
titleKey: 'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.TASK-DURATIONS-TITLE',
values: [{
key: 'averages',
values: [[1, 0], [2, 5], [3, 2]]
}, {
key: 'minima',
values: [[1, 0], [2, 0], [3, 0]]
}, {
key: 'maxima',
values: [[1, 0], [2, 29], [3, 29]]
}],
yAxisType: 'count'
}]
columnNames: ['Task', 'Count', 'Sum', 'Min duration', 'Max duration', 'Average duration', 'Stddev duration'],
columnNameKeys: [
'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.DETAILED-TASK-STATS-TASK',
'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.COUNT',
'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.SUM',
'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.MIN-DURATION',
'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.MAX-DURATION',
'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.AVERAGE',
/* cspell:disable-next-line */
'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.STDDE'
],
columnsCentered: [false, false, false, false],
rows: [
['fake 1 user task', '1', '2.0', '3.0', '4.0', '5.0', '6.0'],
['fake 2 user task', '1', '2.0', '3.0', '4.0', '5.0', '6.0']
]
},
{
id: 'id10931125229538',
type: 'multiBarChart',
title: 'Task duration',
titleKey: 'REPORTING.DEFAULT-REPORTS.TASK-OVERVIEW.TASK-DURATIONS-TITLE',
values: [
{
key: 'averages',
values: [
[1, 0],
[2, 5],
[3, 2]
]
},
{
key: 'minima',
values: [
[1, 0],
[2, 0],
[3, 0]
]
},
{
key: 'maxima',
values: [
[1, 0],
[2, 29],
[3, 29]
]
}
],
yAxisType: 'count'
}
]
};

View File

@ -28,24 +28,21 @@ export const reportDefParamNumber = {
id: 2005,
name: 'Fake Process instances overview',
created: '2016-10-05T15:39:40.222+0000',
definition: '{ "parameters"' +
' :[{"id":"slowProcessInstanceInteger","name":null,"nameKey":null,"type":"integer","value":10,"dependsOn":null}]}'
definition: '{ "parameters"' + ' :[{"id":"slowProcessInstanceInteger","name":null,"nameKey":null,"type":"integer","value":10,"dependsOn":null}]}'
};
export const reportDefParamDuration = {
id: 2005,
name: 'Fake Task service level agreement',
created: '2016-10-05T15:39:40.222+0000',
definition: '{ "parameters"' +
' :[{"id":"duration","name":null,"nameKey":null,"type":"duration","value":null,"dependsOn":null}]}'
definition: '{ "parameters"' + ' :[{"id":"duration","name":null,"nameKey":null,"type":"duration","value":null,"dependsOn":null}]}'
};
export const reportDefParamCheck = {
id: 2005,
name: 'Fake Task service level agreement',
created: '2016-10-05T15:39:40.222+0000',
definition: '{ "parameters"' +
' :[{"id":"typeFiltering","name":null,"nameKey":null,"type":"boolean","value":true,"dependsOn":null}]}'
definition: '{ "parameters"' + ' :[{"id":"typeFiltering","name":null,"nameKey":null,"type":"boolean","value":true,"dependsOn":null}]}'
};
export const reportDefParamDateRange = {
@ -93,7 +90,10 @@ export const reportDefParamProcessDefOptionsNoApp = [
];
export const reportDefParamProcessDefOptions = {
size: 4, total: 4, start: 0, data: [
size: 4,
total: 4,
start: 0,
data: [
{
id: 'FakeProcessTest 1:1:1',
name: 'Fake Process Test 1 Name ',
@ -118,7 +118,10 @@ export const reportDefParamProcessDefOptions = {
};
export const reportDefParamProcessDefOptionsApp = {
size: 2, total: 2, start: 2, data: [
size: 2,
total: 2,
start: 2,
data: [
{
id: 'FakeProcessTest 1:1:1',
name: 'Fake Process Test 1 Name ',
@ -148,10 +151,8 @@ export const reportNoParameterDefinitions = {
export const reportDefParamTaskOptions = ['Fake task name 1', 'Fake task name 2'];
export const fieldProcessDef = new ReportParameterDetailsModel(
{
id: 'processDefinitionId',
type: 'processDefinition',
value: 'fake-process-name:1:15027'
}
);
export const fieldProcessDef = new ReportParameterDetailsModel({
id: 'processDefinitionId',
type: 'processDefinition',
value: 'fake-process-name:1:15027'
});

View File

@ -19,9 +19,10 @@ import { NgModule } from '@angular/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { AppConfigService, AppConfigServiceMock, AuthModule, JWT_STORAGE_SERVICE, NoopTranslateModule, StorageService } from '@alfresco/adf-core';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
import { HttpClientTestingModule } from '@angular/common/http/testing';
@NgModule({
imports: [AuthModule.forRoot({ useHash: true }), NoopAnimationsModule, NoopTranslateModule],
imports: [AuthModule.forRoot({ useHash: true }), NoopAnimationsModule, NoopTranslateModule, HttpClientTestingModule],
providers: [
{ provide: JWT_STORAGE_SERVICE, useClass: StorageService },
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },