Skip to content

Commit

Permalink
[ACS-6251] remove dead code and imports from insights (#9059)
Browse files Browse the repository at this point in the history
* remove dead code and imports from insights

* [ci:force] base class to reduce code duplications

* [ci:force] reduce code by introducing base class

* [ci:force] fix import paths

* [ci:force] fix types

* [ci:force] remove pdf from insights unit tests

* [ci:force] improve test performance

* remove obsolete mock file

* remove deleted export
  • Loading branch information
DenysVuika committed Nov 6, 2023
1 parent adf5a5e commit fe8f4a5
Show file tree
Hide file tree
Showing 99 changed files with 617 additions and 1,323 deletions.
34 changes: 7 additions & 27 deletions lib/insights/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,22 @@ module.exports = function (config) {
basePath: '../../',

files: [
{pattern: 'node_modules/tslib/tslib.js', included: true, watched: false},

// pdf-js
{pattern: 'node_modules/pdfjs-dist/build/pdf.js', included: true, watched: false},
{pattern: 'node_modules/pdfjs-dist/build/pdf.worker.js', included: true, watched: false},
{pattern: 'node_modules/pdfjs-dist/web/pdf_viewer.js', included: true, watched: false},

{
pattern: 'node_modules/@angular/material/prebuilt-themes/indigo-pink.css',
included: true,
watched: false
},

{pattern: 'node_modules/chart.js/dist/Chart.js', included: true, watched: false},
{pattern: 'node_modules/raphael/raphael.min.js', included: true, watched: false},
{ pattern: 'node_modules/chart.js/dist/Chart.js', included: true, watched: false },
{ pattern: 'node_modules/raphael/raphael.min.js', included: true, watched: false },
{
pattern: 'node_modules/ng2-charts/bundles/ng2-charts.umd.js',
included: false,
served: true,
watched: false
},

{pattern: 'lib/insights/src/lib/i18n/**/en.json', included: false, served: true, watched: false},
{pattern: 'lib/insights/**/*.ts', included: false, served: true, watched: false},
{pattern: 'lib/config/app.config.json', included: false, served: true, watched: false},
{ pattern: 'lib/insights/src/lib/i18n/**/en.json', included: false, served: true, watched: false },
{ pattern: 'lib/config/app.config.json', included: false, served: true, watched: false }
],

frameworks: ['jasmine-ajax', 'jasmine', '@angular-devkit/build-angular'],

proxies: {
'/base/assets/' :'/base/lib/insights/src/lib/assets/',
'/base/assets/': '/base/lib/insights/src/lib/assets/',
'/assets/adf-insights/i18n/en.json': '/base/lib/insights/src/lib/i18n/en.json',
'/app.config.json': '/base/lib/config/app.config.json'
},
Expand All @@ -60,7 +45,7 @@ module.exports = function (config) {
},

jasmineHtmlReporter: {
suppressAll: true, // removes the duplicated traces
suppressAll: true // removes the duplicated traces
},

coverageReporter: {
Expand All @@ -80,12 +65,7 @@ module.exports = function (config) {
customLaunchers: {
ChromeHeadless: {
base: 'Chrome',
flags: [
'--no-sandbox',
'--headless',
'--disable-gpu',
'--remote-debugging-port=9222'
]
flags: ['--no-sandbox', '--headless', '--disable-gpu', '--remote-debugging-port=9222']
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,12 @@ import { TranslateModule } from '@ngx-translate/core';
declare let jasmine: any;

describe('AnalyticsGeneratorComponent', () => {

let component: any;
let fixture: ComponentFixture<AnalyticsGeneratorComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
InsightsTestingModule
]
imports: [TranslateModule.forRoot(), InsightsTestingModule]
});
fixture = TestBed.createComponent(AnalyticsGeneratorComponent);
component = fixture.componentInstance;
Expand All @@ -59,13 +55,21 @@ describe('AnalyticsGeneratorComponent', () => {
expect(res[0].type).toEqual('table');
expect(res[0].datasets).toBeDefined();
expect(res[0].datasets.length).toEqual(4);
expect(res[0].datasets[0][0]).toEqual('__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-TOTAL-PROCESS-DEFINITIONS');
expect(res[0].datasets[0][0]).toEqual(
'__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-TOTAL-PROCESS-DEFINITIONS'
);
expect(res[0].datasets[0][1]).toEqual('9');
expect(res[0].datasets[1][0]).toEqual('__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-TOTAL-PROCESS-INSTANCES');
expect(res[0].datasets[1][0]).toEqual(
'__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-TOTAL-PROCESS-INSTANCES'
);
expect(res[0].datasets[1][1]).toEqual('41');
expect(res[0].datasets[2][0]).toEqual('__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-ACTIVE-PROCESS-INSTANCES');
expect(res[0].datasets[2][0]).toEqual(
'__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-ACTIVE-PROCESS-INSTANCES'
);
expect(res[0].datasets[2][1]).toEqual('3');
expect(res[0].datasets[3][0]).toEqual('__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-COMPLETED-PROCESS-INSTANCES');
expect(res[0].datasets[3][0]).toEqual(
'__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-COMPLETED-PROCESS-INSTANCES'
);
expect(res[0].datasets[3][1]).toEqual('38');

expect(res[1]).toBeDefined();
Expand All @@ -78,7 +82,7 @@ describe('AnalyticsGeneratorComponent', () => {
});

component.reportId = 1001;
component.reportParamQuery = new ReportQuery({status: 'All'});
component.reportParamQuery = new ReportQuery({ status: 'All' });
component.ngOnChanges();

fixture.detectChanges();
Expand All @@ -101,13 +105,21 @@ describe('AnalyticsGeneratorComponent', () => {
expect(res[0].type).toEqual('table');
expect(res[0].datasets).toBeDefined();
expect(res[0].datasets.length).toEqual(4);
expect(res[0].datasets[0][0]).toEqual('__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-TOTAL-PROCESS-DEFINITIONS');
expect(res[0].datasets[0][0]).toEqual(
'__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-TOTAL-PROCESS-DEFINITIONS'
);
expect(res[0].datasets[0][1]).toEqual('9');
expect(res[0].datasets[1][0]).toEqual('__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-TOTAL-PROCESS-INSTANCES');
expect(res[0].datasets[1][0]).toEqual(
'__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-TOTAL-PROCESS-INSTANCES'
);
expect(res[0].datasets[1][1]).toEqual('41');
expect(res[0].datasets[2][0]).toEqual('__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-ACTIVE-PROCESS-INSTANCES');
expect(res[0].datasets[2][0]).toEqual(
'__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-ACTIVE-PROCESS-INSTANCES'
);
expect(res[0].datasets[2][1]).toEqual('3');
expect(res[0].datasets[3][0]).toEqual('__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-COMPLETED-PROCESS-INSTANCES');
expect(res[0].datasets[3][0]).toEqual(
'__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-COMPLETED-PROCESS-INSTANCES'
);
expect(res[0].datasets[3][1]).toEqual('38');

expect(res[1]).toBeDefined();
Expand All @@ -120,7 +132,7 @@ describe('AnalyticsGeneratorComponent', () => {
});

component.reportId = 1001;
component.reportParamQuery = new ReportQuery({status: 'All'});
component.reportParamQuery = new ReportQuery({ status: 'All' });
component.ngOnChanges();

fixture.detectChanges();
Expand Down Expand Up @@ -192,7 +204,7 @@ describe('AnalyticsGeneratorComponent', () => {
});

component.reportId = 1;
component.reportParamQuery = new ReportQuery({status: 'All'});
component.reportParamQuery = new ReportQuery({ status: 'All' });
component.ngOnChanges();

fixture.detectChanges();
Expand All @@ -206,16 +218,15 @@ describe('AnalyticsGeneratorComponent', () => {
});
});

it('Should reset the reports when the onChanged is call', () => {
component.reports = [new Chart({id: 'fake', type: 'fake-type'})];
it('Should reset the reports when the onChanged is call', async () => {
component.reports = [new Chart({ id: 'fake', type: 'fake-type' })];
component.reportId = 1;
component.ngOnChanges();

fixture.detectChanges();
await fixture.whenStable();

fixture.whenStable().then(() => {
expect(component.reports).toBeUndefined();
});
expect(component.reports).toBeUndefined();
});

it('Should emit onError event with a 404 response ', (done) => {
Expand All @@ -225,7 +236,7 @@ describe('AnalyticsGeneratorComponent', () => {
});

component.reportId = 1;
component.reportParamQuery = new ReportQuery({status: 'All'});
component.reportParamQuery = new ReportQuery({ status: 'All' });
component.ngOnChanges();

fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { Component, EventEmitter, Input, OnChanges, Output, ViewEncapsulation } from '@angular/core';
import { Component, EventEmitter, inject, Input, OnChanges, Output, ViewEncapsulation } from '@angular/core';
import { ReportQuery } from '../../diagram/models/report/report-query.model';
import { Chart } from '../../diagram/models/chart/chart.model';
import { AnalyticsService } from '../services/analytics.service';
Expand All @@ -27,6 +27,7 @@ import { AnalyticsService } from '../services/analytics.service';
encapsulation: ViewEncapsulation.None
})
export class AnalyticsGeneratorComponent implements OnChanges {
private analyticsService = inject(AnalyticsService);

/** reportId. */
@Input()
Expand All @@ -38,7 +39,7 @@ export class AnalyticsGeneratorComponent implements OnChanges {

/** success. */
@Output()
success = new EventEmitter();
success = new EventEmitter<Chart[]>();

/** error. */
@Output()
Expand All @@ -52,23 +53,23 @@ export class AnalyticsGeneratorComponent implements OnChanges {
public barChartOptions: any = {
responsive: true,
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
stepSize: 1
yAxes: [
{
ticks: {
beginAtZero: true,
stepSize: 1
}
}
}],
xAxes: [{
ticks: {
},
stacked: true
}]
],
xAxes: [
{
ticks: {},
stacked: true
}
]
}
};

constructor(private analyticsService: AnalyticsService) {
}

ngOnChanges() {
if (this.reportId && this.reportParamQuery) {
this.generateReport(this.reportId, this.reportParamQuery);
Expand All @@ -77,9 +78,9 @@ export class AnalyticsGeneratorComponent implements OnChanges {
}
}

public generateReport(reportId: string, reportParamQuery: any) {
public generateReport(reportId: string, reportParamQuery: ReportQuery) {
if (reportParamQuery === undefined || reportParamQuery === null) {
reportParamQuery = {};
reportParamQuery = new ReportQuery();
}
this.analyticsService.getReportsByParams(reportId, reportParamQuery).subscribe(
(res) => {
Expand All @@ -101,7 +102,7 @@ export class AnalyticsGeneratorComponent implements OnChanges {
}
}

public refresh(report): void {
public refresh(report: Chart): void {
/**
* (My guess), for Angular to recognize the change in the dataset
* it has to change the dataset variable directly,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { AnalyticsService } from '../services/analytics.service';
import { ParameterValueModel } from '../../diagram/models/report/parameter-value.model';

@Component({
selector: 'adf-analytics-report-heat-map, analytics-report-heat-map',
templateUrl: './analytics-report-heat-map.component.html'
})
export class AnalyticsReportHeatMapComponent implements OnInit {

export class AnalyticsReportHeatMapComponent implements OnInit {
/** reportId. */
@Input()
report: any;

/** success. */
@Output()
success = new EventEmitter();
success = new EventEmitter<ParameterValueModel[]>();

/** error. */
@Output()
Expand All @@ -44,21 +44,17 @@ export class AnalyticsReportHeatMapComponent implements OnInit {
currentMetricColors: any;
metricType: string;

constructor(private analyticsService: AnalyticsService,
private formBuilder: UntypedFormBuilder) {
}
constructor(private analyticsService: AnalyticsService, private formBuilder: UntypedFormBuilder) {}

ngOnInit() {
this.initForm();
this.field.id = 'metrics';
this.field.value = 'totalCount';

this.analyticsService.getMetricValues().subscribe(
(opts: any[]) => {
this.field.options = opts;
this.success.emit(opts);
}
);
this.analyticsService.getMetricValues().subscribe((opts) => {
this.field.options = opts;
this.success.emit(opts);
});
}

onMetricChanges(field: any) {
Expand Down Expand Up @@ -86,13 +82,10 @@ export class AnalyticsReportHeatMapComponent implements OnInit {
}

hasMetric(): boolean {
return !!(this.report.totalCountsPercentages ||
this.report.totalTimePercentages ||
this.report.avgTimePercentages);
return !!(this.report.totalCountsPercentages || this.report.totalTimePercentages || this.report.avgTimePercentages);
}

get metricGroup(): UntypedFormGroup {
return this.metricForm.controls.metricGroup as UntypedFormGroup;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { TranslateModule } from '@ngx-translate/core';
declare let jasmine: any;

describe('AnalyticsReportListComponent', () => {

const reportList = [
{ id: 2002, name: 'Fake Test Process definition heat map' },
{ id: 2003, name: 'Fake Test Process definition overview' },
Expand All @@ -33,26 +32,22 @@ describe('AnalyticsReportListComponent', () => {
{ id: 2006, name: 'Fake Test Task service level agreement' }
];

const reportSelected = { id: 2003, name: 'Fake Test Process definition overview' };
const reportSelected = { id: 2003, name: 'Fake Test Process definition overview' } as ReportParametersModel;

let component: AnalyticsReportListComponent;
let fixture: ComponentFixture<AnalyticsReportListComponent>;
let element: HTMLElement;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
InsightsTestingModule
]
imports: [TranslateModule.forRoot(), InsightsTestingModule]
});
fixture = TestBed.createComponent(AnalyticsReportListComponent);
component = fixture.componentInstance;
element = fixture.nativeElement;
});

describe('Rendering tests', () => {

beforeEach(() => {
jasmine.Ajax.install();
});
Expand All @@ -63,7 +58,6 @@ describe('AnalyticsReportListComponent', () => {

it('Report return true with undefined reports', () => {
expect(component.isReportsEmpty()).toBeTruthy();

});

it('Report return true with an empty reports', () => {
Expand Down Expand Up @@ -200,10 +194,9 @@ describe('AnalyticsReportListComponent', () => {
responseText: reportList
});
});
});
});

describe('layout', () => {

it('should display a list by default', () => {
fixture.detectChanges();
expect(component.isGrid()).toBe(false);
Expand Down
Loading

0 comments on commit fe8f4a5

Please sign in to comment.