Skip to content

Commit

Permalink
* Removed all option
Browse files Browse the repository at this point in the history
* Fixed failing e2e
  • Loading branch information
sivakumar414ram committed May 27, 2020
1 parent 0d40b1e commit 3fddd48
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ describe('StartFormComponent', () => {
expect(lableElement.innerText).toEqual('ADF_PROCESS_LIST.START_PROCESS.FORM.LABEL.SELECT_APPLICATION');

expect(getDeployedApplicationsSpy).toHaveBeenCalled();
expect(component.applications.length).toBe(7);
expect(component.applications.length).toBe(6);

expect(component.selectedApplication).toEqual(deployedApps[2]);
expect(component.selectedApplication.id).toEqual(component.appId);
Expand Down Expand Up @@ -658,25 +658,26 @@ describe('StartFormComponent', () => {
expect(component.processDefinitions[0].name).toEqual('My Process 3');
});

it('Should be able to show all option as default when defined appId is not exists', () => {
it('Should be able to select an application if the list has one application', () => {
getDeployedApplicationsSpy.and.returnValues(of([deployedApps[0]]));
const change = new SimpleChange(null, 123, true);
component.ngOnChanges({ 'appId': change });
fixture.detectChanges();
expect(getDeployedApplicationsSpy).toHaveBeenCalled();
expect(component.applications.length).toEqual(7);
expect(component.selectedApplication.name).toEqual('All');
expect(component.applications.length).toEqual(1);
expect(component.selectedApplication.name).toEqual('App1');
});

it('Should be able to select an application from the apps as default application when given appId is defined', () => {
component.appId = 1;
const change = new SimpleChange(null, 1, true);
component.appId = 2;
const change = new SimpleChange(null, 2, true);
component.ngOnChanges({ 'appId': change });
fixture.detectChanges();
expect(getDeployedApplicationsSpy).toHaveBeenCalled();
expect(component.applications.length).toEqual(7);
expect(component.applications.length).toEqual(6);
expect(component.selectedApplication.id).toEqual(component.appId);
expect(component.selectedApplication.id).toEqual(1);
expect(component.selectedApplication.name).toEqual('App1');
expect(component.selectedApplication.id).toEqual(2);
expect(component.selectedApplication.name).toEqual('App2');
});

it('Should not be able to show application drop-down if showSelectApplicationDropdown set to false', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ import { AppDefinitionRepresentationModel } from '../../task-list';
})
export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestroy {

static ALL_APPS_OPTION = new AppDefinitionRepresentationModel({ id: 0, name: 'All' });

MAX_LENGTH: number = 255;

/** (optional) Limit the list of processes that can be started to those
Expand Down Expand Up @@ -231,9 +229,12 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr
}

if (this.processDefinitionName) {
currentProcessDef = processDefinitionRepresentations.find((processDefinition) => {
const filteredProcessDefinition = processDefinitionRepresentations.find((processDefinition) => {
return processDefinition.name === this.processDefinitionName;
});
if (filteredProcessDefinition) {
currentProcessDef = filteredProcessDefinition;
}
}

return { currentProcessDef, processDefinitionRepresentations };
Expand All @@ -252,10 +253,14 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr

filterProcessDefinitionByName() {
if (this.processDefinitionName) {
this.selectedProcessDef = this.processDefinitions.find((processDefinition) => {
const filteredProcessDef = this.processDefinitions.find((processDefinition) => {
return processDefinition.name === this.processDefinitionName;
});
this.processDefinitionInput.setValue(this.selectedProcessDef ? this.selectedProcessDef.name : '');

if (filteredProcessDef) {
this.selectedProcessDef = filteredProcessDef;
this.processDefinitionInput.setValue(this.selectedProcessDef ? this.selectedProcessDef.name : '');
}
}
}

Expand All @@ -264,9 +269,17 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr
.getDeployedApplications()
.pipe(map((response: AppDefinitionRepresentationModel[]) => {
const applications = this.removeDefaultApps(response);
applications.unshift(this.getAllAppsOption());
let currentApplication: AppDefinitionRepresentationModel;

if (applications && applications.length === 1) {
currentApplication = applications[0];
}

const filteredApp = applications.find( app => app.id === +this.appId );
const currentApplication = filteredApp ? filteredApp : this.getAllAppsOption();

if (filteredApp) {
currentApplication = filteredApp;
}

return { currentApplication, applications };
})
Expand All @@ -290,10 +303,6 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr
this.loadProcessDefinitions(this.selectedApplication.id);
}

private getAllAppsOption() {
return StartProcessInstanceComponent.ALL_APPS_OPTION;
}

private removeDefaultApps(apps: AppDefinitionRepresentationModel []): AppDefinitionRepresentationModel[] {
return apps.filter((app) => app.id);

Expand Down

0 comments on commit 3fddd48

Please sign in to comment.