Skip to content

Commit

Permalink
* Added unit tests and updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sivakumar414ram committed May 15, 2020
1 parent ea6ee2a commit 86d7e8e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 5 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions docs/process-services/components/start-process.component.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,25 @@ The result will be the start form prefilled with the file data:

![Start process load file](../../docassets/images/start_process.png)

### Starting a process with a selected application

Now you can start process based on selected application from the dropdown. The process definition dropdown will display based on the selected application. The application dropdown will be selected application based on the given `appId` otherwise first application will be selected as default.

```html
<adf-start-process
[appId]="YOUR_APP_ID"
[title]="'ADF_PROCESS_LIST.START_PROCESS.FORM.TITLE'"
[name]="PROCESS_NAME"
[showSelectApplicationDropdown]="true"
[processDefinitionName]="PROCESS_DEFINITION_NAME">
</adf-start-process>
```

You can use the `showSelectApplicationDropdown` property to Hide or show application drop down.

![Start process with selected application](../../docassets/images/start-process-with-selected-application.png)


## See also

- [Select Apps Dialog component](select-apps-dialog.component.md)
Original file line number Diff line number Diff line change
Expand Up @@ -600,16 +600,75 @@ describe('StartFormComponent', () => {
component.ngOnChanges({ 'appId': change });
});

it('Should able to show application drop-down if showApplications set to true', () => {
it('Should be able to show application drop-down and respective process definitions if showSelectApplicationDropdown set to true', () => {
fixture.detectChanges();
const appsSelector = fixture.nativeElement.querySelector('[data-automation-id="adf-start-process-apps-drop-down"]');
const lable = fixture.nativeElement.querySelector('.adf-start-process-app-list .mat-form-field-label');
const lableElement = fixture.nativeElement.querySelector('.adf-start-process-app-list .mat-form-field-label');

expect(appsSelector).not.toBeNull();
expect(lable.innerText).toEqual('ADF_PROCESS_LIST.START_PROCESS.FORM.LABEL.APPLICATIONS');
expect(lableElement.innerText).toEqual('ADF_PROCESS_LIST.START_PROCESS.FORM.LABEL.APPLICATIONS');

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

expect(component.selectedApplication).toEqual(deployedApps[2]);
expect(component.selectedApplication.id).toEqual(component.appId);
expect(component.selectedApplication.name).toEqual('App3');

expect(getDefinitionsSpy).toHaveBeenCalled();
expect(component.processDefinitions.length).toEqual(2);
expect(component.processDefinitions[0].name).toEqual('My Process 1');
expect(component.processDefinitions[1].name).toEqual('My Process 2');
});

it('Should able to list process-definition based on selected application', () => {
fixture.detectChanges();
expect(component.appId).toBe(component.selectedApplication.id);
expect(component.selectedApplication).toEqual(deployedApps[2]);
expect(component.selectedApplication.name).toEqual('App3');

expect(component.processDefinitions.length).toEqual(2);
expect(component.processDefinitions[0].name).toEqual('My Process 1');
expect(component.processDefinitions[1].name).toEqual('My Process 2');

getDefinitionsSpy.and.returnValue(of([ { id: 'my:process 3', name: 'My Process 3', hasStartForm: true } ]));
fixture.detectChanges();

const newApplication = {value: deployedApps[1]};
component.onAppSelectionChange(newApplication);
fixture.detectChanges();

expect(component.selectedApplication).toEqual(deployedApps[1]);
expect(component.selectedApplication.name).toEqual('App2');

expect(component.processDefinitions.length).toEqual(1);
expect(component.processDefinitions[0].name).toEqual('My Process 3');
});

it('Should be able to select first application from the apps as default application when appId is not defined', () => {
component.appId = undefined;
const change = new SimpleChange(null, undefined, true);
component.ngOnChanges({ 'appId': change });
fixture.detectChanges();
expect(getDeployedApplicationsSpy).toHaveBeenCalled();
expect(component.applications.length).toEqual(6);
expect(component.selectedApplication).toEqual(deployedApps[0]);
expect(component.selectedApplication.name).toEqual('App1');
});

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

it('Should not be able to show application drop-down if showApplications set to false', () => {
it('Should not be able to show application drop-down if showSelectApplicationDropdown set to false', () => {
component.showSelectApplicationDropdown = false;
fixture.detectChanges();
const appsSelector = fixture.nativeElement.querySelector('[data-automation-id="adf-start-process-apps-drop-down"]');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr
if (applications && applications.length > 0) {
currentApplication = applications[0];
if (this.appId) {
const filteredApp = applications.find( app => app.id === this.appId );
const filteredApp = applications.find( app => app.id === +this.appId );
currentApplication = filteredApp ? filteredApp : applications[0];
}
}
Expand Down

0 comments on commit 86d7e8e

Please sign in to comment.