Skip to content

Commit

Permalink
AAE-23830 fix tests and add a loop tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
wojd0 committed Aug 1, 2024
1 parent a48a7a6 commit 76c211d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<ng-container *ngIf="!isLoading">
<form [formGroup]="editProcessFilterForm" *ngIf="editProcessFilterForm" class="adf-edit-process-filter-content">
<div class="adf-edit-process-filter-form">
<ng-container *ngFor="let processFilterProperty of processFilterProperties">
<ng-container *ngFor="let processFilterProperty of processFilterProperties; trackBy: filterTracker">
<mat-form-field [floatLabel]="'auto'" *ngIf="processFilterProperty.type === 'select'" [attr.data-automation-id]="processFilterProperty.key">
<mat-label class="adf-edit-process-filter-content__select-label">{{processFilterProperty.label | translate}}</mat-label>
<mat-select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,61 @@ describe('EditProcessFilterCloudComponent', () => {
expect(await options[0].getText()).toEqual('ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.PROCESS_NAME');
});

it('should not reset process definitions instance after filter update', () => {
const getProcessDefinitionsSpy = spyOn(processService, 'getProcessDefinitions').and.returnValue(
of([new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })])
);
component.filterProperties = ['processDefinitionName'];

const processFilterIdChange = new SimpleChange(null, 'changed-mock-process-filter-id', true);
component.ngOnChanges({ id: processFilterIdChange });
fixture.detectChanges();

const formerProcessDefinitions = component.processDefinitionNames;
const processFilterIdChange2 = new SimpleChange(null, 'changed-mock-process-filter-id', true);
component.ngOnChanges({ id: processFilterIdChange2 });
fixture.detectChanges();

expect(getProcessDefinitionsSpy).toHaveBeenCalledTimes(2);
expect(component.processDefinitionNames).toBeTruthy();
expect(component.processDefinitionNames).toBe(formerProcessDefinitions);
});

it('should not reset application names instance after filter update', () => {
component.filterProperties = ['appName'];

const processFilterIdChange = new SimpleChange(null, 'changed-mock-process-filter-id', true);
component.ngOnChanges({ id: processFilterIdChange });
fixture.detectChanges();

const formerProcessDefinitions = component.applicationNames;
const processFilterIdChange2 = new SimpleChange(null, 'changed-mock-process-filter-id', true);
component.ngOnChanges({ id: processFilterIdChange2 });
fixture.detectChanges();

expect(getRunningApplicationsSpy).toHaveBeenCalledTimes(2);
expect(component.applicationNames).toBeTruthy();
expect(component.applicationNames).toBe(formerProcessDefinitions);
});

it('should not reset application versions instance after filter update', () => {
const getApplicationVersionsSpy = spyOn(processService, 'getApplicationVersions').and.returnValue(of(mockAppVersions));
component.filterProperties = ['appVersionMultiple'];

const processFilterIdChange = new SimpleChange(null, 'changed-mock-process-filter-id', true);
component.ngOnChanges({ id: processFilterIdChange });
fixture.detectChanges();

const formerProcessDefinitions = component.appVersionOptions;
const processFilterIdChange2 = new SimpleChange(null, 'changed-mock-process-filter-id', true);
component.ngOnChanges({ id: processFilterIdChange2 });
fixture.detectChanges();

expect(getApplicationVersionsSpy).toHaveBeenCalledTimes(2);
expect(component.appVersionOptions).toBeTruthy();
expect(component.appVersionOptions).toBe(formerProcessDefinitions);
});

describe('edit filter actions', () => {
beforeEach(() => {
const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes
this.onDestroy$.complete();
}

filterTracker(_index: number, item: ProcessFilterProperties) {
return item.key;
}

buildForm(processFilterProperties: ProcessFilterProperties[]) {
this.editProcessFilterForm = this.formBuilder.group(this.getFormControlsConfig(processFilterProperties));
this.onFilterChange();
Expand Down Expand Up @@ -349,9 +353,8 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes
}

getAppVersionOptions() {
this.appVersionOptions = [];

this.processCloudService.getApplicationVersions(this.appName).subscribe((appVersions) => {
this.appVersionOptions.length = 0;
appVersions.forEach((appVersion) => {
this.appVersionOptions.push({ label: appVersion.entry.version, value: appVersion.entry.version });
});
Expand Down Expand Up @@ -432,10 +435,9 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes
}

getRunningApplications() {
this.applicationNames = [];

this.appsProcessCloudService.getDeployedApplicationsByStatus('RUNNING', this.role).subscribe((applications) => {
if (applications && applications.length > 0) {
this.applicationNames.length = 0;
applications.map((application) => {
this.applicationNames.push({
label: this.appsProcessCloudService.getApplicationLabel(application, this.environmentList),
Expand All @@ -447,10 +449,9 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes
}

getProcessDefinitions() {
this.processDefinitionNames = [];

this.processCloudService.getProcessDefinitions(this.appName).subscribe((processDefinitions) => {
if (processDefinitions && processDefinitions.length > 0) {
this.processDefinitionNames.length = 0;
this.processDefinitionNames.push(this.allProcessDefinitionNamesOption);
processDefinitions.map((processDefinition) => {
this.processDefinitionNames.push({ label: processDefinition.name, value: processDefinition.name });
Expand Down

0 comments on commit 76c211d

Please sign in to comment.