Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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: []
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down Expand Up @@ -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 } };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
}
}
Expand Down
Loading
Loading