Skip to content

Commit

Permalink
[AAE-7245] fix Insights eslint warnings (#7489)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysVuika authored Feb 8, 2022
1 parent f9be037 commit 8a03e7a
Show file tree
Hide file tree
Showing 71 changed files with 705 additions and 710 deletions.
14 changes: 2 additions & 12 deletions lib/insights/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,8 @@
"eslint-plugin-rxjs"
],
"rules": {
"jsdoc/newline-after-description": "warn",
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/consistent-type-assertions": "warn",
"@typescript-eslint/prefer-for-of": "warn",
"no-underscore-dangle": "warn",
"no-shadow": "warn",
"quote-props": "warn",
"object-shorthand": "warn",
"prefer-const": "warn",
"arrow-body-style": "warn",
"@angular-eslint/no-output-native": "warn",
"space-before-function-paren": "warn",
"no-underscore-dangle": ["error", { "allowAfterThis": true }],
"@angular-eslint/no-output-native": "off",

"@angular-eslint/component-selector": [
"error",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ describe('AnalyticsReportHeatMapComponent', () => {
let fixture: ComponentFixture<AnalyticsReportHeatMapComponent>;
let element: HTMLElement;

const totalCountPercent: any = { 'sid-fake-id': 0, 'fake-start-event': 100 };
const totalTimePercent: any = { 'sid-fake-id': 10, 'fake-start-event': 30 };
const totalCountsPercentages: any = { 'sid-fake-id': 0, 'fake-start-event': 100 };
const totalTimePercentages: any = { 'sid-fake-id': 10, 'fake-start-event': 30 };
const avgTimePercentages: any = { 'sid-fake-id': 5, 'fake-start-event': 50 };

const totalCountValues: any = { 'sid-fake-id': 2, 'fake-start-event': 3 };
Expand All @@ -50,12 +50,12 @@ describe('AnalyticsReportHeatMapComponent', () => {
element = fixture.nativeElement;

component.report = {
totalCountsPercentages: totalCountPercent,
totalCountValues: totalCountValues,
totalTimePercentages: totalTimePercent,
totalTimeValues: totalTimeValues,
avgTimeValues: avgTimeValues,
avgTimePercentages: avgTimePercentages
totalCountsPercentages,
totalCountValues,
totalTimePercentages,
totalTimeValues,
avgTimeValues,
avgTimePercentages
};
});

Expand Down Expand Up @@ -96,14 +96,14 @@ describe('AnalyticsReportHeatMapComponent', () => {
const field = { value: 'totalCount' };
component.onMetricChanges(field);
expect(component.currentMetric).toEqual(totalCountValues);
expect(component.currentMetricColors).toEqual(totalCountPercent);
expect(component.currentMetricColors).toEqual(totalCountsPercentages);
});

it('should change the currentMetric width totalTime', () => {
const field = { value: 'totalTime' };
component.onMetricChanges(field);
expect(component.currentMetric).toEqual(totalTimeValues);
expect(component.currentMetricColors).toEqual(totalTimePercent);
expect(component.currentMetricColors).toEqual(totalTimePercentages);
});

it('should change the currentMetric width avgTime', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AnalyticsReportListComponent } from '../components/analytics-report-list.component';
import { AnalyticsReportListComponent, LAYOUT_GRID, LAYOUT_LIST } from '../components/analytics-report-list.component';
import { ReportParametersModel } from '../../diagram/models/report/report-parameters.model';
import { setupTestBed } from '@alfresco/adf-core';
import { InsightsTestingModule } from '../../testing/insights.testing.module';
Expand All @@ -27,14 +27,14 @@ 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' },
{ 'id': 2004, 'name': 'Fake Test Process instances overview' },
{ 'id': 2005, 'name': 'Fake Test Task overview' },
{ 'id': 2006, 'name': 'Fake Test Task service level agreement' }
{ id: 2002, name: 'Fake Test Process definition heat map' },
{ id: 2003, name: 'Fake Test Process definition overview' },
{ id: 2004, name: 'Fake Test Process instances overview' },
{ id: 2005, name: 'Fake Test Task overview' },
{ 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' };

let component: AnalyticsReportListComponent;
let fixture: ComponentFixture<AnalyticsReportListComponent>;
Expand Down Expand Up @@ -159,13 +159,13 @@ describe('AnalyticsReportListComponent', () => {

it('Should return false if the current report is different', () => {
component.selectReport(reportSelected);
const anotherReport = { 'id': 111, 'name': 'Another Fake Test Process definition overview' };
const anotherReport = { id: 111, name: 'Another Fake Test Process definition overview' };
expect(component.isSelected(anotherReport)).toBe(false);
});

it('Should reload the report list', (done) => {
component.initObserver();
const report = new ReportParametersModel({ 'id': 2002, 'name': 'Fake Test Process definition heat map' });
const report = new ReportParametersModel({ id: 2002, name: 'Fake Test Process definition heat map' });
component.reports = [report];
expect(component.reports.length).toEqual(1);
component.reload();
Expand Down Expand Up @@ -213,14 +213,14 @@ describe('AnalyticsReportListComponent', () => {
});

it('should display a grid when configured to', () => {
component.layoutType = AnalyticsReportListComponent.LAYOUT_GRID;
component.layoutType = LAYOUT_GRID;
fixture.detectChanges();
expect(component.isGrid()).toBe(true);
expect(component.isList()).toBe(false);
});

it('should display a list when configured to', () => {
component.layoutType = AnalyticsReportListComponent.LAYOUT_LIST;
component.layoutType = LAYOUT_LIST;
fixture.detectChanges();
expect(component.isGrid()).toBe(false);
expect(component.isList()).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@ import { ReportParametersModel } from '../../diagram/models/report/report-parame
import { AnalyticsService } from '../services/analytics.service';
import { share } from 'rxjs/operators';

export const LAYOUT_LIST = 'LIST';
export const LAYOUT_GRID = 'GRID';

@Component({
selector: 'adf-analytics-report-list',
templateUrl: './analytics-report-list.component.html',
styleUrls: ['./analytics-report-list.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class AnalyticsReportListComponent implements OnInit {

public static LAYOUT_LIST: string = 'LIST';
public static LAYOUT_GRID: string = 'GRID';

/** layout Type LIST or GRID. */
@Input()
layoutType: string = AnalyticsReportListComponent.LAYOUT_LIST;
layoutType: string = LAYOUT_LIST;

/** appId ID of the target app. */
@Input()
Expand All @@ -56,13 +55,12 @@ export class AnalyticsReportListComponent implements OnInit {
@Output()
error = new EventEmitter();

private reportObserver: Observer<any>;
report$: Observable<ReportParametersModel>;

currentReport: any;

reports: ReportParametersModel[] = [];

private reportObserver: Observer<any>;

constructor(private analyticsService: AnalyticsService) {
this.report$ = new Observable<ReportParametersModel>((observer) => this.reportObserver = observer)
.pipe(share());
Expand Down Expand Up @@ -140,25 +138,17 @@ export class AnalyticsReportListComponent implements OnInit {
return this.reports === undefined || (this.reports && this.reports.length === 0);
}

/**
* Reset the list
*/
private reset() {
if (!this.isReportsEmpty()) {
this.reports = [];
}
}

/**
* Select the current report
*
* @param report
*/
public selectReport(report: any) {
selectReport(report: any) {
this.currentReport = report;
this.reportClick.emit(report);
}

public selectReportByReportId(reportId: number) {
selectReportByReportId(reportId: number) {
const reportFound = this.reports.find((report) => report.id === reportId);
if (reportFound) {
this.currentReport = reportFound;
Expand All @@ -176,10 +166,19 @@ export class AnalyticsReportListComponent implements OnInit {
}

isList(): boolean {
return this.layoutType === AnalyticsReportListComponent.LAYOUT_LIST;
return this.layoutType === LAYOUT_LIST;
}

isGrid(): boolean {
return this.layoutType === AnalyticsReportListComponent.LAYOUT_GRID;
return this.layoutType === LAYOUT_GRID;
}

/**
* Reset the list
*/
private reset() {
if (!this.isReportsEmpty()) {
this.reports = [];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ describe('AnalyticsReportParametersComponent', () => {
service = TestBed.inject(AnalyticsService);
component = fixture.componentInstance;
element = fixture.nativeElement;
spyOn(component, 'isFormValid').and.callFake(() => {
return validForm;
});
spyOn(component, 'isFormValid').and.callFake(() => validForm);
fixture.detectChanges();
});

Expand Down Expand Up @@ -90,7 +88,7 @@ describe('AnalyticsReportParametersComponent', () => {

const reportId = 1;
const change = new SimpleChange(null, reportId, true);
component.ngOnChanges({'reportId': change});
component.ngOnChanges({reportId: change});

jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
Expand All @@ -110,7 +108,7 @@ describe('AnalyticsReportParametersComponent', () => {

const reportId = 1;
const change = new SimpleChange(null, reportId, true);
component.ngOnChanges({'reportId': change});
component.ngOnChanges({reportId: change});

jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
Expand Down Expand Up @@ -139,7 +137,7 @@ describe('AnalyticsReportParametersComponent', () => {

const reportId = 1;
const change = new SimpleChange(null, reportId, true);
component.ngOnChanges({'reportId': change});
component.ngOnChanges({reportId: change});

jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
Expand Down Expand Up @@ -201,7 +199,7 @@ describe('AnalyticsReportParametersComponent', () => {

const reportId = 1;
const change = new SimpleChange(null, reportId, true);
component.ngOnChanges({'reportId': change});
component.ngOnChanges({reportId: change});

jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
Expand All @@ -220,7 +218,7 @@ describe('AnalyticsReportParametersComponent', () => {
const reportId = 1;
const change = new SimpleChange(null, reportId, true);
component.toggleParameters();
component.ngOnChanges({'reportId': change});
component.ngOnChanges({reportId: change});

jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
Expand All @@ -245,7 +243,7 @@ describe('AnalyticsReportParametersComponent', () => {

const reportId = 1;
const change = new SimpleChange(null, reportId, true);
component.ngOnChanges({'reportId': change});
component.ngOnChanges({reportId: change});

jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
Expand Down Expand Up @@ -283,7 +281,7 @@ describe('AnalyticsReportParametersComponent', () => {

const reportId = 1;
const change = new SimpleChange(null, reportId, true);
component.ngOnChanges({'reportId': change});
component.ngOnChanges({reportId: change});

});

Expand Down Expand Up @@ -317,7 +315,7 @@ describe('AnalyticsReportParametersComponent', () => {
component.appId = appId;
component.reportId = '1';
const change = new SimpleChange(null, appId, true);
component.ngOnChanges({'appId': change});
component.ngOnChanges({appId: change});

});

Expand All @@ -330,7 +328,7 @@ describe('AnalyticsReportParametersComponent', () => {

const reportId = 1;
const change = new SimpleChange(null, reportId, true);
component.ngOnChanges({'reportId': change});
component.ngOnChanges({reportId: change});

jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
Expand Down Expand Up @@ -380,7 +378,7 @@ describe('AnalyticsReportParametersComponent', () => {

const reportId = 1;
const change = new SimpleChange(null, reportId, true);
component.ngOnChanges({'reportId': change});
component.ngOnChanges({reportId: change});

});

Expand All @@ -392,7 +390,7 @@ describe('AnalyticsReportParametersComponent', () => {

const reportId = 1;
const change = new SimpleChange(null, reportId, true);
component.ngOnChanges({'reportId': change});
component.ngOnChanges({reportId: change});

jasmine.Ajax.requests.mostRecent().respondWith({
status: 404,
Expand All @@ -411,7 +409,7 @@ describe('AnalyticsReportParametersComponent', () => {
beforeEach(async () => {
const reportId = 1;
const change = new SimpleChange(null, reportId, true);
component.ngOnChanges({'reportId': change});
component.ngOnChanges({reportId: change});
fixture.detectChanges();

jasmine.Ajax.requests.mostRecent().respondWith({
Expand Down Expand Up @@ -522,17 +520,17 @@ describe('AnalyticsReportParametersComponent', () => {
it('Should show export and save button when the form became valid', fakeAsync(() => {
validForm = false;
fixture.detectChanges();
let saveButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#save-button');
let exportButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#export-button');
let saveButton = element.querySelector<HTMLButtonElement>('#save-button');
let exportButton = element.querySelector<HTMLButtonElement>('#export-button');
expect(saveButton).toBeNull();
expect(exportButton).toBeNull();
validForm = true;

fixture.whenStable().then(() => {
fixture.detectChanges();

saveButton = <HTMLButtonElement> element.querySelector('#save-button');
exportButton = <HTMLButtonElement> element.querySelector('#export-button');
saveButton = element.querySelector<HTMLButtonElement>('#save-button');
exportButton = element.querySelector<HTMLButtonElement>('#export-button');

expect(saveButton).not.toBeNull();
expect(saveButton).toBeDefined();
Expand Down
Loading

0 comments on commit 8a03e7a

Please sign in to comment.