[AAE-10317] - Fix APS unit tests warning "Test has no expectations" (#7850)

* [AAE-10317] - Fix process and task attachment list has no expectations

* [AAE-10317] - More APS unit test fixes

* Fix test excluded by mistake

* Fix lint errors
This commit is contained in:
Ardit Domi 2022-09-22 16:28:49 +01:00 committed by GitHub
parent 3fdedae769
commit b33b188807
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 407 additions and 463 deletions

View File

@ -23,6 +23,7 @@ import { of, throwError } from 'rxjs';
import { ProcessAttachmentListComponent } from './process-attachment-list.component'; import { ProcessAttachmentListComponent } from './process-attachment-list.component';
import { ProcessTestingModule } from '../testing/process.testing.module'; import { ProcessTestingModule } from '../testing/process.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { mockEmittedProcessAttachments, mockProcessAttachments } from '../mock/process/process-attachments.mock';
describe('ProcessAttachmentListComponent', () => { describe('ProcessAttachmentListComponent', () => {
@ -30,7 +31,6 @@ describe('ProcessAttachmentListComponent', () => {
let component: ProcessAttachmentListComponent; let component: ProcessAttachmentListComponent;
let fixture: ComponentFixture<ProcessAttachmentListComponent>; let fixture: ComponentFixture<ProcessAttachmentListComponent>;
let getProcessRelatedContentSpy: jasmine.Spy; let getProcessRelatedContentSpy: jasmine.Spy;
let mockAttachment: any;
setupTestBed({ setupTestBed({
imports: [ imports: [
@ -45,53 +45,7 @@ describe('ProcessAttachmentListComponent', () => {
component = fixture.componentInstance; component = fixture.componentInstance;
service = fixture.debugElement.injector.get(ProcessContentService); service = fixture.debugElement.injector.get(ProcessContentService);
mockAttachment = { getProcessRelatedContentSpy = spyOn(service, 'getProcessRelatedContent').and.returnValue(of(mockProcessAttachments));
size: 2,
total: 2,
start: 0,
data: [{
id: 4001,
name: 'Invoice01.pdf',
created: '2017-05-12T12:50:05.522+0000',
createdBy: {
id: 1,
firstName: 'Apps',
lastName: 'Administrator',
email: 'admin@app.activiti.com',
company: 'Alfresco.com',
pictureId: 3003
},
relatedContent: true,
contentAvailable: true,
link: false,
mimeType: 'application/pdf',
simpleType: 'pdf',
previewStatus: 'created',
thumbnailStatus: 'created'
},
{
id: 4002,
name: 'Invoice02.pdf',
created: '2017-05-12T12:50:05.522+0000',
createdBy: {
id: 1,
firstName: 'Apps',
lastName: 'Administrator',
email: 'admin@app.activiti.com',
company: 'Alfresco.com',
pictureId: 3003
},
relatedContent: true,
contentAvailable: true,
link: false,
mimeType: 'application/pdf',
simpleType: 'pdf',
previewStatus: 'created',
thumbnailStatus: 'created'
}]
};
getProcessRelatedContentSpy = spyOn(service, 'getProcessRelatedContent').and.returnValue(of(mockAttachment));
spyOn(service, 'deleteRelatedContent').and.returnValue(of({ successCode: true })); spyOn(service, 'deleteRelatedContent').and.returnValue(of({ successCode: true }));
const blobObj = new Blob(); const blobObj = new Blob();
@ -123,12 +77,10 @@ describe('ProcessAttachmentListComponent', () => {
it('should emit a success event when the attachments are loaded', () => { it('should emit a success event when the attachments are loaded', () => {
const change = new SimpleChange(null, '123', true); const change = new SimpleChange(null, '123', true);
component.success.subscribe((attachments) => { const spySuccessEmitter = spyOn(component.success, 'emit');
expect(attachments[0].name).toEqual(mockAttachment.data[0].name); component.ngOnChanges({ processInstanceId: change });
expect(attachments[0].id).toEqual(mockAttachment.data[0].id);
});
component.ngOnChanges({ taskId: change }); expect(spySuccessEmitter).toHaveBeenCalledWith(mockEmittedProcessAttachments);
}); });
it('should not attach when no processInstanceId is specified', () => { it('should not attach when no processInstanceId is specified', () => {
@ -234,7 +186,7 @@ describe('ProcessAttachmentListComponent', () => {
}); });
it('should not show the empty list component when the attachments list is not empty for completed process', async () => { it('should not show the empty list component when the attachments list is not empty for completed process', async () => {
getProcessRelatedContentSpy.and.returnValue(of(mockAttachment)); getProcessRelatedContentSpy.and.returnValue(of(mockProcessAttachments));
const change = new SimpleChange(null, '123', true); const change = new SimpleChange(null, '123', true);
component.ngOnChanges({ processInstanceId: change }); component.ngOnChanges({ processInstanceId: change });
component.disabled = true; component.disabled = true;
@ -245,7 +197,7 @@ describe('ProcessAttachmentListComponent', () => {
}); });
it('should call getProcessRelatedContent with opt isRelatedContent=true', () => { it('should call getProcessRelatedContent with opt isRelatedContent=true', () => {
getProcessRelatedContentSpy.and.returnValue(of(mockAttachment)); getProcessRelatedContentSpy.and.returnValue(of(mockProcessAttachments));
const change = new SimpleChange(null, '123', true); const change = new SimpleChange(null, '123', true);
const isRelatedContent = 'true'; const isRelatedContent = 'true';
component.ngOnChanges({ processInstanceId: change }); component.ngOnChanges({ processInstanceId: change });

View File

@ -23,6 +23,7 @@ import { TaskAttachmentListComponent } from './task-attachment-list.component';
import { ProcessContentService, setupTestBed } from '@alfresco/adf-core'; import { ProcessContentService, setupTestBed } from '@alfresco/adf-core';
import { ProcessTestingModule } from '../testing/process.testing.module'; import { ProcessTestingModule } from '../testing/process.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { mockEmittedTaskAttachments, mockTaskAttachments } from '../mock/task/task-attachments.mock';
describe('TaskAttachmentList', () => { describe('TaskAttachmentList', () => {
@ -30,7 +31,6 @@ describe('TaskAttachmentList', () => {
let fixture: ComponentFixture<TaskAttachmentListComponent>; let fixture: ComponentFixture<TaskAttachmentListComponent>;
let service: ProcessContentService; let service: ProcessContentService;
let getTaskRelatedContentSpy: jasmine.Spy; let getTaskRelatedContentSpy: jasmine.Spy;
let mockAttachment: any;
let deleteContentSpy: jasmine.Spy; let deleteContentSpy: jasmine.Spy;
let getFileRawContentSpy: jasmine.Spy; let getFileRawContentSpy: jasmine.Spy;
let getContentPreviewSpy: jasmine.Spy; let getContentPreviewSpy: jasmine.Spy;
@ -51,43 +51,7 @@ describe('TaskAttachmentList', () => {
service = TestBed.inject(ProcessContentService); service = TestBed.inject(ProcessContentService);
mockAttachment = { getTaskRelatedContentSpy = spyOn(service, 'getTaskRelatedContent').and.returnValue(of(mockTaskAttachments));
size: 2,
total: 2,
start: 0,
data: [
{
id: 8,
name: 'fake.zip',
created: 1494595697381,
createdBy: { id: 2, firstName: 'user', lastName: 'user', email: 'user@user.com' },
relatedContent: true,
contentAvailable: true,
link: false,
mimeType: 'application/zip',
simpleType: 'content',
previewStatus: 'unsupported',
thumbnailStatus: 'unsupported'
},
{
id: 9,
name: 'fake.jpg',
created: 1494595655381,
createdBy: { id: 2, firstName: 'user', lastName: 'user', email: 'user@user.com' },
relatedContent: true,
contentAvailable: true,
link: false,
mimeType: 'image/jpeg',
simpleType: 'image',
previewStatus: 'unsupported',
thumbnailStatus: 'unsupported'
}
]
};
getTaskRelatedContentSpy = spyOn(service, 'getTaskRelatedContent').and.returnValue(of(
mockAttachment
));
deleteContentSpy = spyOn(service, 'deleteRelatedContent').and.returnValue(of({ successCode: true })); deleteContentSpy = spyOn(service, 'deleteRelatedContent').and.returnValue(of({ successCode: true }));
@ -124,12 +88,10 @@ describe('TaskAttachmentList', () => {
it('should emit a success event when the attachments are loaded', () => { it('should emit a success event when the attachments are loaded', () => {
const change = new SimpleChange(null, '123', true); const change = new SimpleChange(null, '123', true);
disposableSuccess = component.success.subscribe((attachments) => { const spySuccessEmitter = spyOn(component.success, 'emit');
expect(attachments[0].name).toEqual(mockAttachment.data[0].name);
expect(attachments[0].id).toEqual(mockAttachment.data[0].id);
});
component.ngOnChanges({ taskId: change }); component.ngOnChanges({ taskId: change });
expect(spySuccessEmitter).toHaveBeenCalledWith(mockEmittedTaskAttachments);
}); });
it('should not attach when no taskId is specified', () => { it('should not attach when no taskId is specified', () => {
@ -146,13 +108,13 @@ describe('TaskAttachmentList', () => {
}); });
it('emit document when a user wants to view the document', () => { it('emit document when a user wants to view the document', () => {
component.emitDocumentContent(mockAttachment.data[1]); component.emitDocumentContent(mockTaskAttachments.data[1]);
fixture.detectChanges(); fixture.detectChanges();
expect(getContentPreviewSpy).toHaveBeenCalled(); expect(getContentPreviewSpy).toHaveBeenCalled();
}); });
it('download document when a user wants to view the document', () => { it('download document when a user wants to view the document', () => {
component.downloadContent(mockAttachment.data[1]); component.downloadContent(mockTaskAttachments.data[1]);
fixture.detectChanges(); fixture.detectChanges();
expect(getFileRawContentSpy).toHaveBeenCalled(); expect(getFileRawContentSpy).toHaveBeenCalled();
}); });
@ -247,7 +209,7 @@ describe('TaskAttachmentList', () => {
}); });
it('should not show the empty list component when the attachments list is not empty for completed task', async () => { it('should not show the empty list component when the attachments list is not empty for completed task', async () => {
getTaskRelatedContentSpy.and.returnValue(of(mockAttachment)); getTaskRelatedContentSpy.and.returnValue(of(mockTaskAttachments));
const change = new SimpleChange(null, '123', true); const change = new SimpleChange(null, '123', true);
component.ngOnChanges({ taskId: change }); component.ngOnChanges({ taskId: change });
component.disabled = true; component.disabled = true;

View File

@ -945,18 +945,18 @@ describe('FormComponent', () => {
expect(formComponent.isOutcomeButtonEnabled(startProcessOutcome)).toBeFalsy(); expect(formComponent.isOutcomeButtonEnabled(startProcessOutcome)).toBeFalsy();
}); });
it('should raise [executeOutcome] event for formService', (done) => { it('should raise [executeOutcome] event for formService', () => {
formService.executeOutcome.subscribe(() => { const executeOutcomeSpy = spyOn(formService.executeOutcome, 'next');
done();
});
const outcome = new FormOutcomeModel(new FormModel(), { const outcome = new FormOutcomeModel(new FormModel(), {
id: FormComponent.CUSTOM_OUTCOME_ID, id: FormComponent.CUSTOM_OUTCOME_ID,
name: 'Custom' name: 'Custom'
}); });
const expectedEmittedOutcome = new FormOutcomeEvent(outcome);
formComponent.form = new FormModel(); formComponent.form = new FormModel();
formComponent.onOutcomeClicked(outcome); formComponent.onOutcomeClicked(outcome);
expect(executeOutcomeSpy).toHaveBeenCalledWith(expectedEmittedOutcome);
}); });
it('should refresh form values when data is changed', () => { it('should refresh form values when data is changed', () => {

View File

@ -149,14 +149,14 @@ export const startFormDropdownDefinitionMock = {
id: 'mockTypeDropDown', id: 'mockTypeDropDown',
name: 'mock DropDown', name: 'mock DropDown',
type: 'dropdown', type: 'dropdown',
value: 'Chooseone...', value: 'Choose one...',
required: false, required: false,
readOnly: false, readOnly: false,
overrideId: false, overrideId: false,
options: [ options: [
{ {
id: 'empty', id: 'empty',
name: 'Chooseone...' name: 'Choose one...'
}, },
{ {
id: 'opt1', id: 'opt1',
@ -471,7 +471,7 @@ export const startMockForm = {
id: 'claimtype', id: 'claimtype',
name: 'ClaimType', name: 'ClaimType',
type: 'dropdown', type: 'dropdown',
value: 'Chooseone...', value: 'Choose one...',
required: false, required: false,
readOnly: false, readOnly: false,
overrideId: false, overrideId: false,
@ -487,7 +487,7 @@ export const startMockForm = {
options: [ options: [
{ {
id: 'empty', id: 'empty',
name: 'Chooseone...' name: 'Choose one...'
}, },
{ {
id: 'cashless', id: 'cashless',

View File

@ -16,8 +16,8 @@
*/ */
import { CUSTOM_ELEMENTS_SCHEMA, SimpleChange } from '@angular/core'; import { CUSTOM_ELEMENTS_SCHEMA, SimpleChange } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { of, throwError } from 'rxjs'; import { of } from 'rxjs';
import { import {
startFormDateWidgetMock, startFormDropdownDefinitionMock, startFormDateWidgetMock, startFormDropdownDefinitionMock,
startFormTextDefinitionMock, startMockForm, startMockFormWithTab, startFormTextDefinitionMock, startMockForm, startMockFormWithTab,
@ -114,12 +114,6 @@ describe('StartFormComponent', () => {
expect(component.form.getFieldById('fake-multiple-upload').value).toBe(preselectedMultipleeNode['fake-multiple-upload']); expect(component.form.getFieldById('fake-multiple-upload').value).toBe(preselectedMultipleeNode['fake-multiple-upload']);
}); });
it('should consume errors encountered when loading start form', () => {
getStartFormSpy.and.returnValue(throwError({}));
component.processDefinitionId = exampleId1;
component.ngOnInit();
});
it('should show outcome buttons by default', () => { it('should show outcome buttons by default', () => {
getStartFormSpy.and.returnValue(of({ getStartFormSpy.and.returnValue(of({
id: '1', id: '1',
@ -164,115 +158,120 @@ describe('StartFormComponent', () => {
describe('Display widgets', () => { describe('Display widgets', () => {
it('should be able to display a textWidget from a process definition', () => { it('should be able to display a textWidget from a process definition', async () => {
getStartFormSpy.and.returnValue(of(startFormTextDefinitionMock)); getStartFormSpy.and.returnValue(of(startFormTextDefinitionMock));
component.processDefinitionId = exampleId1; component.processDefinitionId = exampleId1;
component.showOutcomeButtons = true; component.showOutcomeButtons = true;
component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) }); component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) });
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { await fixture.whenStable();
fixture.detectChanges(); fixture.detectChanges();
const formFields = component.form.getFormFields();
const labelField = formFields.find((field) => field.id === 'mocktext'); const formFields = component.form.getFormFields();
const textWidget = fixture.debugElement.nativeElement.querySelector('text-widget'); const labelField = formFields.find((field) => field.id === 'mocktext');
const textWidgetLabel = fixture.debugElement.nativeElement.querySelector('.adf-label'); const textWidget = fixture.debugElement.nativeElement.querySelector('text-widget');
expect(labelField.type).toBe('text'); const textWidgetLabel = fixture.debugElement.nativeElement.querySelector('.adf-label');
expect(textWidget).toBeDefined();
expect(textWidgetLabel.innerText).toBe('mockText'); expect(labelField.type).toBe('text');
}); expect(textWidget).toBeTruthy();
expect(textWidgetLabel.innerText).toBe('mockText');
}); });
it('should be able to display a radioButtonWidget from a process definition', () => { it('should be able to display a radioButtonWidget from a process definition', async () => {
getStartFormSpy.and.returnValue(of(startFormRadioButtonWidgetMock)); getStartFormSpy.and.returnValue(of(startFormRadioButtonWidgetMock));
component.processDefinitionId = exampleId1; component.processDefinitionId = exampleId1;
component.showOutcomeButtons = true; component.showOutcomeButtons = true;
component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) }); component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) });
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { await fixture.whenStable();
fixture.detectChanges();
const formFields = component.form.getFormFields(); const formFields = component.form.getFormFields();
const labelField = formFields.find((field) => field.id === 'radio-but'); const labelField = formFields.find((field) => field.id === 'radio-but');
const radioButtonWidget = fixture.debugElement.nativeElement.querySelector('radio-buttons-widget'); const radioButtonWidget = fixture.debugElement.nativeElement.querySelector('radio-buttons-widget');
const radioButtonWidgetLabel = fixture.debugElement.nativeElement.querySelector('.adf-input'); const radioButtonWidgetLabel = fixture.debugElement.nativeElement.querySelector('.adf-radio-button-container .adf-label');
expect(labelField.type).toBe('radio-buttons');
expect(radioButtonWidget).toBeDefined(); expect(labelField.type).toBe('radio-buttons');
expect(radioButtonWidgetLabel.innerText).toBe('radio-buttons'); expect(radioButtonWidget).toBeDefined();
}); expect(radioButtonWidgetLabel.innerText).toBe('radio-buttons');
}); });
it('should be able to display a amountWidget from a process definition', () => { it('should be able to display a amountWidget from a process definition', async () => {
getStartFormSpy.and.returnValue(of(startFormAmountWidgetMock)); getStartFormSpy.and.returnValue(of(startFormAmountWidgetMock));
component.processDefinitionId = exampleId1; component.processDefinitionId = exampleId1;
component.showOutcomeButtons = true; component.showOutcomeButtons = true;
component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) }); component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) });
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { await fixture.whenStable();
fixture.detectChanges();
const formFields = component.form.getFormFields(); const formFields = component.form.getFormFields();
const labelField = formFields.find((field) => field.id === 'amount'); const labelField = formFields.find((field) => field.id === 'amount');
const amountWidget = fixture.debugElement.nativeElement.querySelector('amount-widget'); const amountWidget = fixture.debugElement.nativeElement.querySelector('amount-widget');
const amountWidgetLabel = fixture.debugElement.nativeElement.querySelector('.adf-input');
expect(labelField.type).toBe('amount'); expect(labelField.type).toBe('amount');
expect(amountWidget).toBeDefined(); expect(amountWidget).toBeTruthy();
expect(amountWidgetLabel.innerText).toBe('amount');
});
}); });
it('should be able to display a numberWidget from a process definition', () => { it('should be able to display a numberWidget from a process definition', async () => {
getStartFormSpy.and.returnValue(of(startFormNumberWidgetMock)); getStartFormSpy.and.returnValue(of(startFormNumberWidgetMock));
component.processDefinitionId = exampleId1; component.processDefinitionId = exampleId1;
component.showOutcomeButtons = true; component.showOutcomeButtons = true;
component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) }); component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) });
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { await fixture.whenStable();
fixture.detectChanges();
const formFields = component.form.getFormFields(); const formFields = component.form.getFormFields();
const labelField = formFields.find((field) => field.id === 'number'); const labelField = formFields.find((field) => field.id === 'number');
const numberWidget = fixture.debugElement.nativeElement.querySelector('number-widget'); const numberWidget = fixture.debugElement.nativeElement.querySelector('number-widget');
expect(labelField.type).toBe('integer');
expect(numberWidget).toBeDefined(); expect(labelField.type).toBe('integer');
}); expect(numberWidget).toBeTruthy();
}); });
it('should be able to display a dropDown Widget from a process definition', () => { it('should be able to display a dropdown Widget for selecting a process definition', async () => {
getStartFormSpy.and.returnValue(of(startFormDropdownDefinitionMock)); getStartFormSpy.and.returnValue(of(startFormDropdownDefinitionMock));
component.processDefinitionId = exampleId1; component.processDefinitionId = exampleId1;
component.showOutcomeButtons = true; component.showOutcomeButtons = true;
component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) }); component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) });
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { await fixture.whenStable();
fixture.detectChanges();
const formFields = component.form.getFormFields(); const formFields = component.form.getFormFields();
const labelField = formFields.find((field) => field.id === 'mockTypeDropDown'); const dropdownField = formFields.find((field) => field.id === 'mockTypeDropDown');
const dropDownWidget = fixture.debugElement.nativeElement.querySelector('dropdown-widget'); const dropdownWidget = fixture.debugElement.nativeElement.querySelector('dropdown-widget');
const selectElement = fixture.debugElement.nativeElement.querySelector('.adf-dropdown-widget>mat-select .mat-select-trigger'); const dropdownLabel = fixture.debugElement.nativeElement.querySelector('.adf-dropdown-widget .adf-label');
selectElement.click(); const selectElement = fixture.debugElement.nativeElement.querySelector('.adf-select .mat-select-trigger');
expect(selectElement).toBeDefined(); selectElement.click();
expect(dropDownWidget).toBeDefined();
expect(selectElement.innerText).toBe('Choose one...'); expect(selectElement).toBeTruthy();
expect(labelField.type).toBe('dropdown'); expect(dropdownWidget).toBeTruthy();
expect(labelField.options[0].name).toBe('Chooseone...'); expect(dropdownLabel.innerText).toEqual('mock DropDown');
expect(labelField.options[1].name).toBe('Option-1'); expect(dropdownField.type).toBe('dropdown');
expect(labelField.options[2].name).toBe('Option-2'); expect(dropdownField.options[0].name).toBe('Choose one...');
}); expect(dropdownField.options[1].name).toBe('Option-1');
expect(dropdownField.options[2].name).toBe('Option-2');
}); });
it('should be able to display a date Widget from a process definition', () => { it('should be able to display a date Widget from a process definition', async () => {
getStartFormSpy.and.returnValue(of(startFormDateWidgetMock)); getStartFormSpy.and.returnValue(of(startFormDateWidgetMock));
component.processDefinitionId = exampleId1; component.processDefinitionId = exampleId1;
component.showOutcomeButtons = true; component.showOutcomeButtons = true;
component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) }); component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) });
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { await fixture.whenStable();
fixture.detectChanges();
const formFields = component.form.getFormFields(); const formFields = component.form.getFormFields();
const labelField = formFields.find((field) => field.id === 'date'); const labelField = formFields.find((field) => field.id === 'date');
const dateWidget = fixture.debugElement.nativeElement.querySelector('dropdown-widget'); const dateWidget = fixture.debugElement.nativeElement.querySelector('date-widget');
const dateLabelElement = fixture.debugElement.nativeElement.querySelector('#data-widget .mat-form-field-infix> .adf-label'); const dateLabelElement = fixture.debugElement.nativeElement.querySelector('#data-widget .mat-form-field-infix> .adf-label');
expect(dateWidget).toBeDefined();
expect(labelField.type).toBe('date'); expect(dateWidget).toBeTruthy();
expect(dateLabelElement.innerText).toBe('date (D-M-YYYY)'); expect(labelField.type).toBe('date');
}); expect(dateLabelElement.innerText).toBe('date (D-M-YYYY)');
}); });
it('should fetch and define form fields with proper type', () => { it('should fetch and define form fields with proper type', () => {
@ -290,22 +289,6 @@ describe('StartFormComponent', () => {
expect(labelField1.type).toBe('dropdown'); expect(labelField1.type).toBe('dropdown');
}); });
it('should show dropdown options', () => {
getStartFormSpy.and.returnValue(of(startMockForm));
component.processDefinitionId = exampleId1;
component.showOutcomeButtons = true;
component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) });
fixture.detectChanges();
fixture.whenStable().then(() => {
const formFields = component.form.getFormFields();
const labelField = formFields.find((field) => field.id === 'claimtype');
expect(labelField.type).toBe('dropdown');
expect(labelField.options[0].name).toBe('Chooseone...');
expect(labelField.options[1].name).toBe('Cashless');
expect(labelField.options[2].name).toBe('Reimbursement');
});
});
it('should display start form with fields ', async () => { it('should display start form with fields ', async () => {
getStartFormSpy.and.returnValue(of(startMockForm)); getStartFormSpy.and.returnValue(of(startMockForm));
component.processDefinitionId = exampleId1; component.processDefinitionId = exampleId1;
@ -356,46 +339,49 @@ describe('StartFormComponent', () => {
expect(translate.instant(selectLabelElement.innerText)).toBe('ClaimType'); expect(translate.instant(selectLabelElement.innerText)).toBe('ClaimType');
}); });
it('should define custom-tabs ', fakeAsync(() => { it('should define custom-tabs ', async () => {
getStartFormSpy.and.returnValue(of(startMockFormWithTab)); getStartFormSpy.and.returnValue(of(startMockFormWithTab));
component.processDefinitionId = exampleId1; component.processDefinitionId = exampleId1;
component.showOutcomeButtons = true; component.showOutcomeButtons = true;
component.showRefreshButton = true; component.showRefreshButton = true;
component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) }); component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) });
fixture.detectChanges();
fixture.whenStable().then(() => {
const formTabs = component.form.tabs;
const tabField1 = formTabs.find((tab) => tab.id === 'form1');
const tabField2 = formTabs.find((tab) => tab.id === 'form2');
const tabsWidgetElement = fixture.debugElement.nativeElement.querySelector('tabs-widget');
expect(tabField1.name).toBe('Tab 1');
expect(tabField2.name).toBe('Tab 2');
expect(tabsWidgetElement).toBeDefined();
});
}));
it('should define title and [custom-action-buttons]', fakeAsync(() => { fixture.detectChanges();
await fixture.whenStable();
const formTabs = component.form.tabs;
const tabField1 = formTabs.find((tab) => tab.id === 'form1');
const tabField2 = formTabs.find((tab) => tab.id === 'form2');
const tabsWidgetElement = fixture.debugElement.nativeElement.querySelector('.alfresco-tabs-widget');
expect(tabField1.name).toBe('Tab 1');
expect(tabField2.name).toBe('Tab 2');
expect(tabsWidgetElement).toBeTruthy();
});
it('should define title and [custom-action-buttons]', async () => {
getStartFormSpy.and.returnValue(of(startMockFormWithTab)); getStartFormSpy.and.returnValue(of(startMockFormWithTab));
component.processDefinitionId = exampleId1; component.processDefinitionId = exampleId1;
component.showOutcomeButtons = true; component.showOutcomeButtons = true;
component.showRefreshButton = true; component.showRefreshButton = true;
component.showTitle = true;
component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) }); component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) });
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { await fixture.whenStable();
const titleIcon = fixture.debugElement.nativeElement.querySelector('mat-card-title>mat-icon');
const titleElement = fixture.debugElement.nativeElement.querySelector('mat-card-title>h2'); const titleElement = fixture.debugElement.nativeElement.querySelector('mat-card-title>h2');
const actionButtons = fixture.debugElement.nativeElement.querySelectorAll('.mat-button'); const actionButtons = fixture.debugElement.nativeElement.querySelectorAll('.mat-button');
expect(titleIcon).toBeDefined();
expect(titleElement).toBeDefined(); expect(titleElement.innerText.trim()).toEqual('Mock Title');
expect(actionButtons.length).toBe(4); expect(actionButtons.length).toBe(4);
expect(actionButtons[0].innerText).toBe('Save'); expect(actionButtons[0].innerText.trim()).toBe('SAVE');
expect(actionButtons[0].disabled).toBeFalsy(); expect(actionButtons[0].disabled).toBeFalsy();
expect(actionButtons[1].innerText).toBe('Approve'); expect(actionButtons[1].innerText.trim()).toBe('APPROVE');
expect(actionButtons[1].disabled).toBeTruthy(); expect(actionButtons[1].disabled).toBeTruthy();
expect(actionButtons[2].innerText).toBe('Complete'); expect(actionButtons[2].innerText.trim()).toBe('COMPLETE');
expect(actionButtons[2].disabled).toBeTruthy(); expect(actionButtons[2].disabled).toBeTruthy();
}); });
}));
}); });
describe('OutCome Actions', () => { describe('OutCome Actions', () => {

View File

@ -0,0 +1,81 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export const mockProcessAttachments = {
size: 2,
total: 2,
start: 0,
data: [
{
id: 4001,
name: 'Invoice01.pdf',
created: '2017-05-12T12:50:05.522+0000',
createdBy: {
id: 1,
firstName: 'Apps',
lastName: 'Administrator',
email: 'admin@app.activiti.com',
company: 'Alfresco.com',
pictureId: 3003
},
relatedContent: true,
contentAvailable: true,
link: false,
mimeType: 'application/pdf',
simpleType: 'pdf',
previewStatus: 'created',
thumbnailStatus: 'created'
},
{
id: 4002,
name: 'Invoice02.pdf',
created: '2017-05-12T12:50:05.522+0000',
createdBy: {
id: 1,
firstName: 'Apps',
lastName: 'Administrator',
email: 'admin@app.activiti.com',
company: 'Alfresco.com',
pictureId: 3003
},
relatedContent: true,
contentAvailable: true,
link: false,
mimeType: 'application/pdf',
simpleType: 'pdf',
previewStatus: 'created',
thumbnailStatus: 'created'
}
]
};
export const mockEmittedProcessAttachments = [
{
id: 4001,
name: 'Invoice01.pdf',
created: '2017-05-12T12:50:05.522+0000',
createdBy: 'Apps Administrator',
icon: './assets/images/ft_ic_pdf.svg'
},
{
id: 4002,
name: 'Invoice02.pdf',
created: '2017-05-12T12:50:05.522+0000',
createdBy: 'Apps Administrator',
icon: './assets/images/ft_ic_pdf.svg'
}
];

View File

@ -0,0 +1,67 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export const mockTaskAttachments = {
size: 2,
total: 2,
start: 0,
data: [
{
id: 8,
name: 'fake.zip',
created: 1494595697381,
createdBy: { id: 2, firstName: 'user1', lastName: 'last1', email: 'user1@user.com' },
relatedContent: true,
contentAvailable: true,
link: false,
mimeType: 'application/zip',
simpleType: 'content',
previewStatus: 'unsupported',
thumbnailStatus: 'unsupported'
},
{
id: 9,
name: 'fake.jpg',
created: 1494595655381,
createdBy: { id: 2, firstName: 'user2', lastName: 'last2', email: 'user2@user.com' },
relatedContent: true,
contentAvailable: true,
link: false,
mimeType: 'image/jpeg',
simpleType: 'image',
previewStatus: 'unsupported',
thumbnailStatus: 'unsupported'
}
]
};
export const mockEmittedTaskAttachments = [
{
id: 8,
name: 'fake.zip',
created: 1494595697381,
createdBy: 'user1 last1',
icon: './assets/images/ft_ic_archive.svg'
},
{
id: 9,
name: 'fake.jpg',
created: 1494595655381,
createdBy: 'user2 last2',
icon: './assets/images/ft_ic_raster_image.svg'
}
];

View File

@ -24,16 +24,16 @@ import { TranslateModule } from '@ngx-translate/core';
const fakeUser: UserProcessModel = new UserProcessModel({ const fakeUser: UserProcessModel = new UserProcessModel({
id: '1', id: '1',
firstName: 'fake-name', firstName: 'John',
lastName: 'fake-last', lastName: 'Doe',
email: 'fake@mail.com' email: 'JohnDoe@fake.com'
}); });
const fakeSecondUser: UserProcessModel = new UserProcessModel({ const fakeSecondUser: UserProcessModel = new UserProcessModel({
id: '2', id: '2',
firstName: 'fake-involve-name', firstName: 'Jane',
lastName: 'fake-involve-last', lastName: 'Jackson',
email: 'fake-involve@mail.com' email: 'JaneJackson@fake.com'
}); });
describe('PeopleSearchComponent', () => { describe('PeopleSearchComponent', () => {
@ -55,80 +55,40 @@ describe('PeopleSearchComponent', () => {
fixture = TestBed.createComponent(PeopleSearchComponent); fixture = TestBed.createComponent(PeopleSearchComponent);
peopleSearchComponent = fixture.componentInstance; peopleSearchComponent = fixture.componentInstance;
element = fixture.nativeElement; element = fixture.nativeElement;
peopleSearchComponent.results = of([]); peopleSearchComponent.results = of(userArray);
fixture.detectChanges(); fixture.detectChanges();
}); });
function triggerSearch() {
searchInput = element.querySelector('#userSearchText');
searchInput.value = 'fake-search';
searchInput.dispatchEvent(new Event('input'));
}
it('should show input search text', () => { it('should show input search text', () => {
expect(element.querySelector('#userSearchText')).toBeDefined(); expect(element.querySelector('#userSearchText')).toBeTruthy();
expect(element.querySelector('#userSearchText')).not.toBeNull();
}); });
it('should hide people-list container', () => { it('should display user search results', async () => {
triggerSearch();
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable() await fixture.whenStable();
.then(() => {
expect(element.querySelector('#search-people-list')).toBeNull();
});
});
it('should show user which can be involved ', (done) => {
peopleSearchComponent.results = of(userArray);
peopleSearchComponent.ngOnInit();
fixture.detectChanges(); fixture.detectChanges();
const datatableBodyElement = element.querySelector('adf-people-search-field .adf-datatable-body');
const peopleResultElements = element.querySelectorAll('.adf-people-full-name');
searchInput = element.querySelector('#userSearchText'); expect(datatableBodyElement).not.toBeNull();
searchInput.value = 'fake-search'; expect(peopleResultElements.length).toBe(2);
searchInput.dispatchEvent(new Event('input')); expect(peopleResultElements[0].textContent.trim()).toBe('John Doe');
expect(peopleResultElements[1].textContent.trim()).toBe('Jane Jackson');
fixture.whenStable().then(() => {
fixture.detectChanges();
const gatewayElement: any = element.querySelector('#search-people-list .adf-datatable-body');
expect(gatewayElement).not.toBeNull();
expect(gatewayElement.children.length).toBe(2);
done();
});
}); });
it('should send an event when an user is clicked', (done) => { it('should emit a success event when a user is selected from the search results', () => {
peopleSearchComponent.success.subscribe((user) => { const successEventSpy = spyOn(peopleSearchComponent.success, 'emit');
expect(user).toBeDefined();
expect(user.firstName).toBe('fake-name');
done();
});
peopleSearchComponent.results = of(userArray);
peopleSearchComponent.ngOnInit();
fixture.detectChanges();
fixture.whenStable()
.then(() => {
peopleSearchComponent.onRowClick(fakeUser);
const addUserButton = element.querySelector<HTMLElement>('#add-people');
addUserButton.click();
});
});
it('should remove clicked user', (done) => {
peopleSearchComponent.results = of(userArray);
peopleSearchComponent.ngOnInit();
fixture.detectChanges();
searchInput = element.querySelector('#userSearchText');
searchInput.value = 'fake-search';
searchInput.dispatchEvent(new Event('input'));
fixture.detectChanges();
peopleSearchComponent.onRowClick(fakeUser); peopleSearchComponent.onRowClick(fakeUser);
const addUserButton = element.querySelector<HTMLElement>('#add-people'); const addUserButton = element.querySelector<HTMLElement>('#add-people');
addUserButton.click(); addUserButton.click();
fixture.detectChanges();
fixture.whenStable() expect(successEventSpy).toHaveBeenCalledWith(fakeUser);
.then(() => {
fixture.detectChanges();
const gatewayElement: any = element.querySelector('#search-people-list .adf-datatable-body');
expect(gatewayElement).not.toBeNull();
expect(gatewayElement.children.length).toBe(1);
done();
});
}); });
}); });

View File

@ -16,10 +16,11 @@
*/ */
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing'; import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { LogService, setupTestBed, UserProcessModel } from '@alfresco/adf-core'; import { LogService, PeopleProcessService, setupTestBed, UserProcessModel } from '@alfresco/adf-core';
import { PeopleComponent } from './people.component'; import { PeopleComponent } from './people.component';
import { ProcessTestingModule } from '../../../testing/process.testing.module'; import { ProcessTestingModule } from '../../../testing/process.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { throwError } from 'rxjs';
declare let jasmine: any; declare let jasmine: any;
@ -44,6 +45,7 @@ describe('PeopleComponent', () => {
let element: HTMLElement; let element: HTMLElement;
const userArray = [fakeUser, fakeSecondUser]; const userArray = [fakeUser, fakeSecondUser];
let logService: LogService; let logService: LogService;
let peopleProcessService: PeopleProcessService;
setupTestBed({ setupTestBed({
imports: [ imports: [
@ -54,6 +56,7 @@ describe('PeopleComponent', () => {
beforeEach(() => { beforeEach(() => {
logService = TestBed.inject(LogService); logService = TestBed.inject(LogService);
peopleProcessService = TestBed.inject(PeopleProcessService);
fixture = TestBed.createComponent(PeopleComponent); fixture = TestBed.createComponent(PeopleComponent);
activitiPeopleComponent = fixture.componentInstance; activitiPeopleComponent = fixture.componentInstance;
element = fixture.nativeElement; element = fixture.nativeElement;
@ -192,13 +195,13 @@ describe('PeopleComponent', () => {
}); });
it('should log error message when search fails', async () => { it('should log error message when search fails', async () => {
await activitiPeopleComponent.peopleSearch$.subscribe(() => { const logServiceErrorSpy = spyOn(logService, 'error');
expect(logService.error).toHaveBeenCalledWith('Could not load users'); const mockThrownError = { error: 'Could not load users'};
});
spyOn(peopleProcessService, 'getWorkflowUsers').and.returnValue(throwError(mockThrownError));
activitiPeopleComponent.searchUser('fake-search'); activitiPeopleComponent.searchUser('fake-search');
jasmine.Ajax.requests.mostRecent().respondWith({
status: 403 expect(logServiceErrorSpy).toHaveBeenCalledWith(mockThrownError);
});
}); });
it('should not remove user if remove involved user fail', async () => { it('should not remove user if remove involved user fail', async () => {

View File

@ -38,7 +38,7 @@ import { deployedApps } from '../../mock/apps-list.mock';
import { ProcessNamePipe } from '../../pipes/process-name.pipe'; import { ProcessNamePipe } from '../../pipes/process-name.pipe';
import { ProcessInstance } from '../models/process-instance.model'; import { ProcessInstance } from '../models/process-instance.model';
describe('StartFormComponent', () => { describe('StartProcessComponent', () => {
let appConfig: AppConfigService; let appConfig: AppConfigService;
let activitiContentService: ActivitiContentService; let activitiContentService: ActivitiContentService;
@ -72,6 +72,12 @@ describe('StartFormComponent', () => {
} }
}; };
function changeAppId(appId: number) {
const change = new SimpleChange(null, appId, true);
component.appId = appId;
component.ngOnChanges({ appId: change });
}
beforeEach(() => { beforeEach(() => {
appConfig = TestBed.inject(AppConfigService); appConfig = TestBed.inject(AppConfigService);
activitiContentService = TestBed.inject(ActivitiContentService); activitiContentService = TestBed.inject(ActivitiContentService);
@ -100,8 +106,7 @@ describe('StartFormComponent', () => {
beforeEach(() => { beforeEach(() => {
fixture.detectChanges(); fixture.detectChanges();
component.name = 'My new process'; component.name = 'My new process';
const change = new SimpleChange(null, 123, true); changeAppId(123);
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
}); });
@ -162,8 +167,7 @@ describe('StartFormComponent', () => {
beforeEach(() => { beforeEach(() => {
fixture.detectChanges(); fixture.detectChanges();
getDefinitionsSpy.and.returnValue(of(testProcessDefWithForm)); getDefinitionsSpy.and.returnValue(of(testProcessDefWithForm));
const change = new SimpleChange(null, 123, true); changeAppId(123);
component.ngOnChanges({ appId: change });
}); });
it('should initialize start form', async () => { it('should initialize start form', async () => {
@ -305,43 +309,31 @@ describe('StartFormComponent', () => {
beforeEach(() => { beforeEach(() => {
fixture.detectChanges(); fixture.detectChanges();
component.name = 'My new process'; component.name = 'My new process';
component.appId = 123; changeAppId(123);
component.ngOnChanges({});
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should call service to fetch process definitions with appId', () => { it('should call service to fetch process definitions with appId', async () => {
fixture.whenStable().then(() => { await fixture.whenStable();
expect(getDefinitionsSpy).toHaveBeenCalledWith(123); expect(getDefinitionsSpy).toHaveBeenCalledWith(123);
});
}); });
it('should display the correct number of processes in the select list', () => { it('should display the correct number of processes in the select list', async () => {
fixture.whenStable().then(() => { const selectElement = fixture.nativeElement.querySelector('button#adf-select-process-dropdown');
const selectElement = fixture.nativeElement.querySelector('mat-select'); selectElement.click();
expect(selectElement.children.length).toBe(1);
});
});
it('should display the option def details', () => {
component.processDefinitions = testMultipleProcessDefs;
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { await fixture.whenStable();
const selectElement = fixture.nativeElement.querySelector('mat-select > .mat-select-trigger'); const options: any = fixture.debugElement.queryAll(By.css('.mat-option-text'));
const optionElement = fixture.nativeElement.querySelectorAll('mat-option');
selectElement.click(); expect(options.length).toBe(2);
expect(selectElement).not.toBeNull(); expect(options[0].nativeElement.innerText).toBe('My Process 1');
expect(selectElement).toBeDefined(); expect(options[1].nativeElement.innerText).toBe('My Process 2');
expect(optionElement).not.toBeNull();
expect(optionElement).toBeDefined();
});
}); });
it('should show no process available message when no process definition is loaded', async () => { it('should show no process available message when no process definition is loaded', async () => {
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of([])); getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of([]));
component.appId = 123; changeAppId(123);
const change = new SimpleChange(null, 123, true);
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
@ -365,9 +357,7 @@ describe('StartFormComponent', () => {
it('should select automatically the processDefinition if the app contain only one', async () => { it('should select automatically the processDefinition if the app contain only one', async () => {
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(testProcessDefinitions)); getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(testProcessDefinitions));
component.appId = 123; changeAppId(123);
const change = new SimpleChange(null, 123, true);
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
@ -377,9 +367,7 @@ describe('StartFormComponent', () => {
it('should not select automatically any processDefinition if the app contain multiple process and does not have any processDefinition as input', async () => { it('should not select automatically any processDefinition if the app contain multiple process and does not have any processDefinition as input', async () => {
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(testMultipleProcessDefs)); getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(testMultipleProcessDefs));
component.appId = 123; changeAppId(123);
const change = new SimpleChange(null, 123, true);
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
@ -438,26 +426,20 @@ describe('StartFormComponent', () => {
describe('input changes', () => { describe('input changes', () => {
const change = new SimpleChange(123, 456, true);
beforeEach(async () => { beforeEach(async () => {
component.appId = 123; component.appId = 123;
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should reload processes when appId input changed', async () => { it('should reload processes when appId input changed', async () => {
component.appId = 456; changeAppId(456);
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable();
expect(getDefinitionsSpy).toHaveBeenCalledWith(456); expect(getDefinitionsSpy).toHaveBeenCalledWith(456);
}); });
it('should get current processDef', () => { it('should get current processDef', () => {
component.appId = 456; changeAppId(456);
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
expect(getDefinitionsSpy).toHaveBeenCalled(); expect(getDefinitionsSpy).toHaveBeenCalled();
expect(component.processDefinitions).toBe(testMultipleProcessDefs); expect(component.processDefinitions).toBe(testMultipleProcessDefs);
@ -469,8 +451,7 @@ describe('StartFormComponent', () => {
beforeEach(() => { beforeEach(() => {
fixture.detectChanges(); fixture.detectChanges();
component.name = 'My new process'; component.name = 'My new process';
component.appId = 123; changeAppId(123);
component.ngOnChanges({});
}); });
it('should call service to start process if required fields provided', async () => { it('should call service to start process if required fields provided', async () => {
@ -533,25 +514,21 @@ describe('StartFormComponent', () => {
expect(emitSpy).toHaveBeenCalledWith(newProcess); expect(emitSpy).toHaveBeenCalledWith(newProcess);
}); });
it('should emit start event when start select a process and add a name', (done) => { it('should emit start event when start select a process and add a name', () => {
const disposableStart = component.start.subscribe(() => { const startProcessEmitterSpy = spyOn(component.start, 'emit');
disposableStart.unsubscribe();
done();
});
component.processDefinitionSelectionChanged(testProcessDef); component.processDefinitionSelectionChanged(testProcessDef);
component.name = 'my:Process'; component.name = 'my:Process';
component.startProcess(); component.startProcess();
fixture.detectChanges();
expect(startProcessEmitterSpy).toHaveBeenCalledWith(newProcess);
}); });
it('should emit processDefinitionSelection event when a process definition is selected', (done) => { it('should emit processDefinitionSelection event when a process definition is selected', () => {
component.processDefinitionSelection.subscribe((processDefinition) => { const processDefinitionSelectionSpy = spyOn(component.processDefinitionSelection, 'emit');
expect(processDefinition).toEqual(testProcessDef);
done();
});
fixture.detectChanges(); fixture.detectChanges();
selectOptionByName(testProcessDef.name); selectOptionByName(testProcessDef.name);
expect(processDefinitionSelectionSpy).toHaveBeenCalledWith(testProcessDef);
}); });
it('should set the process name using the processName pipe when a process definition gets selected', () => { it('should set the process name using the processName pipe when a process definition gets selected', () => {
@ -560,9 +537,7 @@ describe('StartFormComponent', () => {
const expectedProcessInstanceDetails = new ProcessInstance({ processDefinitionName: testProcessDef.name }); const expectedProcessInstanceDetails = new ProcessInstance({ processDefinitionName: testProcessDef.name });
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(testMultipleProcessDefs)); getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(testMultipleProcessDefs));
component.appId = 123; changeAppId(123);
const appIdChange = new SimpleChange(null, 123, true);
component.ngOnChanges({ appId: appIdChange });
fixture.detectChanges(); fixture.detectChanges();
selectOptionByName(testProcessDef.name); selectOptionByName(testProcessDef.name);
@ -597,24 +572,10 @@ describe('StartFormComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
expect(startSpy).not.toHaveBeenCalled(); expect(startSpy).not.toHaveBeenCalled();
}); });
it('should able to start the process when the required fields are filled up', (done) => {
component.name = 'my:process1';
component.processDefinitionSelectionChanged(testProcessDef);
const disposableStart = component.start.subscribe(() => {
disposableStart.unsubscribe();
done();
});
component.startProcess();
});
}); });
describe('Select applications', () => { describe('Select applications', () => {
const mockAppId = 3;
beforeEach(() => { beforeEach(() => {
fixture.detectChanges(); fixture.detectChanges();
component.name = 'My new process'; component.name = 'My new process';
@ -624,21 +585,20 @@ describe('StartFormComponent', () => {
it('Should be able to show application drop-down if showSelectApplicationDropdown set to true', () => { it('Should be able to show application drop-down if showSelectApplicationDropdown set to true', () => {
getDefinitionsSpy.and.returnValue(of(testMultipleProcessDefs)); getDefinitionsSpy.and.returnValue(of(testMultipleProcessDefs));
changeAppId(3);
const change = new SimpleChange(null, 3, true);
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
const appsSelector = fixture.nativeElement.querySelector('[data-automation-id="adf-start-process-apps-drop-down"]'); const appsSelector = fixture.nativeElement.querySelector('[data-automation-id="adf-start-process-apps-drop-down"]');
const lableElement = fixture.nativeElement.querySelector('.adf-start-process-app-list .mat-form-field-label'); const labelElement = fixture.nativeElement.querySelector('.adf-start-process-app-list .mat-form-field-label');
expect(appsSelector).not.toBeNull(); expect(appsSelector).not.toBeNull();
expect(lableElement.innerText).toEqual('ADF_PROCESS_LIST.START_PROCESS.FORM.LABEL.SELECT_APPLICATION'); expect(labelElement.innerText).toEqual('ADF_PROCESS_LIST.START_PROCESS.FORM.LABEL.SELECT_APPLICATION');
expect(getDeployedApplicationsSpy).toHaveBeenCalled(); expect(getDeployedApplicationsSpy).toHaveBeenCalled();
expect(component.applications.length).toBe(6); expect(component.applications.length).toBe(6);
expect(component.selectedApplication).toEqual(deployedApps[2]); expect(component.selectedApplication).toEqual(deployedApps[2]);
expect(component.selectedApplication.id).toEqual(component.appId); expect(component.selectedApplication.id).toEqual(3);
expect(component.selectedApplication.name).toEqual('App3'); expect(component.selectedApplication.name).toEqual('App3');
}); });
@ -651,20 +611,16 @@ describe('StartFormComponent', () => {
it('Should be able to list process-definition based on selected application', () => { it('Should be able to list process-definition based on selected application', () => {
getDefinitionsSpy.and.returnValue(of(testMultipleProcessDefs)); getDefinitionsSpy.and.returnValue(of(testMultipleProcessDefs));
changeAppId(3);
const change = new SimpleChange(null, 3, true);
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
expect(component.appId).toBe(component.selectedApplication.id);
expect(component.selectedApplication).toEqual(deployedApps[2]); expect(component.selectedApplication).toEqual(deployedApps[2]);
expect(component.selectedApplication.name).toEqual('App3'); expect(component.selectedApplication.name).toEqual('App3');
expect(getDefinitionsSpy).toHaveBeenCalledWith(mockAppId); expect(getDefinitionsSpy).toHaveBeenCalledWith(3);
expect(component.processDefinitions.length).toEqual(2); expect(component.processDefinitions.length).toEqual(2);
expect(component.processDefinitions[0].name).toEqual('My Process 1'); expect(component.processDefinitions[0].name).toEqual('My Process 1');
expect(component.processDefinitions[1].name).toEqual('My Process 2'); expect(component.processDefinitions[1].name).toEqual('My Process 2');
const changedAppId = 2;
getDefinitionsSpy.and.returnValue(of([ { id: 'my:process 3', name: 'My Process 3', hasStartForm: true } ])); getDefinitionsSpy.and.returnValue(of([ { id: 'my:process 3', name: 'My Process 3', hasStartForm: true } ]));
fixture.detectChanges(); fixture.detectChanges();
@ -675,7 +631,7 @@ describe('StartFormComponent', () => {
expect(component.selectedApplication).toEqual(deployedApps[1]); expect(component.selectedApplication).toEqual(deployedApps[1]);
expect(component.selectedApplication.name).toEqual('App2'); expect(component.selectedApplication.name).toEqual('App2');
expect(getDefinitionsSpy).toHaveBeenCalledWith(changedAppId); expect(getDefinitionsSpy).toHaveBeenCalledWith(2);
expect(component.processDefinitions.length).toEqual(1); expect(component.processDefinitions.length).toEqual(1);
expect(component.processDefinitions[0].name).toEqual('My Process 3'); expect(component.processDefinitions[0].name).toEqual('My Process 3');
}); });
@ -683,10 +639,9 @@ describe('StartFormComponent', () => {
it('Should be able to pre-select an application if the list has one application', () => { it('Should be able to pre-select an application if the list has one application', () => {
getDeployedApplicationsSpy.and.returnValues(of([deployedApps[0]])); getDeployedApplicationsSpy.and.returnValues(of([deployedApps[0]]));
getDefinitionsSpy.and.returnValue(of(testMultipleProcessDefs)); getDefinitionsSpy.and.returnValue(of(testMultipleProcessDefs));
changeAppId(123);
const change = new SimpleChange(null, 123, true);
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
expect(getDeployedApplicationsSpy).toHaveBeenCalled(); expect(getDeployedApplicationsSpy).toHaveBeenCalled();
expect(component.applications.length).toEqual(1); expect(component.applications.length).toEqual(1);
expect(component.selectedApplication.name).toEqual('App1'); expect(component.selectedApplication.name).toEqual('App1');
@ -695,10 +650,8 @@ describe('StartFormComponent', () => {
it('[C333511] Should be able to preselect single app deployed with single process and start event Form', async () => { it('[C333511] Should be able to preselect single app deployed with single process and start event Form', async () => {
getDeployedApplicationsSpy.and.returnValues(of([deployedApps[0]])); getDeployedApplicationsSpy.and.returnValues(of([deployedApps[0]]));
getDefinitionsSpy.and.returnValues(of(testProcessDefWithForm)); getDefinitionsSpy.and.returnValues(of(testProcessDefWithForm));
changeAppId(123);
const change = new SimpleChange(null, 123, true);
component.appId = 123;
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
@ -728,10 +681,8 @@ describe('StartFormComponent', () => {
it('[C333511] Should be able to preselect single app deployed with single process and no form', async () => { it('[C333511] Should be able to preselect single app deployed with single process and no form', async () => {
getDeployedApplicationsSpy.and.returnValues(of([deployedApps[0]])); getDeployedApplicationsSpy.and.returnValues(of([deployedApps[0]]));
getDefinitionsSpy.and.returnValues(of(testProcessDefinitions)); getDefinitionsSpy.and.returnValues(of(testProcessDefinitions));
changeAppId(123);
const change = new SimpleChange(null, 123, true);
component.appId = 123;
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
@ -760,62 +711,55 @@ describe('StartFormComponent', () => {
}); });
it('Should be able to pre-select an application from the apps based given appId', () => { it('Should be able to pre-select an application from the apps based given appId', () => {
component.appId = 2; changeAppId(2);
const change = new SimpleChange(null, 2, true);
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
expect(getDeployedApplicationsSpy).toHaveBeenCalled(); expect(getDeployedApplicationsSpy).toHaveBeenCalled();
expect(component.applications.length).toEqual(6); expect(component.applications.length).toEqual(6);
expect(component.selectedApplication.id).toEqual(component.appId); expect(component.selectedApplication.id).toEqual(2);
expect(component.selectedApplication.id).toEqual(2); expect(component.selectedApplication.id).toEqual(2);
expect(component.selectedApplication.name).toEqual('App2'); expect(component.selectedApplication.name).toEqual('App2');
}); });
it('Should be able to disable process name and definitions inputs if there is no application selected by default', () => { it('Should be able to disable process name and definitions inputs if there is no application selected by default', () => {
component.appId = 12345; changeAppId(12345);
const change = new SimpleChange(null, 12345, true);
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
expect(getDeployedApplicationsSpy).toHaveBeenCalled();
expect(component.applications.length).toEqual(6);
expect(component.selectedApplication).toBeUndefined();
const processDefinitionSelectInput = fixture.nativeElement.querySelector('#processDefinitionName'); const processDefinitionSelectInput = fixture.nativeElement.querySelector('#processDefinitionName');
const processNameInput = fixture.nativeElement.querySelector('#processName'); const processNameInput = fixture.nativeElement.querySelector('#processName');
expect(getDeployedApplicationsSpy).toHaveBeenCalled();
expect(component.applications.length).toEqual(6);
expect(component.selectedApplication).toBeUndefined();
expect(processDefinitionSelectInput.disabled).toEqual(true); expect(processDefinitionSelectInput.disabled).toEqual(true);
expect(processNameInput.disabled).toEqual(true); expect(processNameInput.disabled).toEqual(true);
}); });
it('Should be able to enable process name and definitions inputs if the application selected by given appId', () => { it('Should be able to enable process name and definitions inputs if the application selected by given appId', () => {
component.appId = 2; changeAppId(2);
const change = new SimpleChange(null, 2, true);
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
expect(getDeployedApplicationsSpy).toHaveBeenCalled();
expect(component.applications.length).toEqual(6);
expect(component.selectedApplication.id).toEqual(component.appId);
const processDefinitionSelectInput = fixture.nativeElement.querySelector('#processDefinitionName'); const processDefinitionSelectInput = fixture.nativeElement.querySelector('#processDefinitionName');
const processNameInput = fixture.nativeElement.querySelector('#processName'); const processNameInput = fixture.nativeElement.querySelector('#processName');
expect(getDeployedApplicationsSpy).toHaveBeenCalled();
expect(component.applications.length).toEqual(6);
expect(component.selectedApplication.id).toEqual(2);
expect(processDefinitionSelectInput.disabled).toEqual(false); expect(processDefinitionSelectInput.disabled).toEqual(false);
expect(processNameInput.disabled).toEqual(false); expect(processNameInput.disabled).toEqual(false);
}); });
it('Should be able to enable process name and definitions inputs when the application selected from the apps drop-down', () => { it('Should be able to enable process name and definitions inputs when the application selected from the apps drop-down', () => {
component.appId = 12345; changeAppId(12345);
const change = new SimpleChange(null, 12345, true);
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
expect(getDeployedApplicationsSpy).toHaveBeenCalled();
expect(component.applications.length).toEqual(6);
expect(component.selectedApplication).toBeUndefined();
const appsSelectElement = fixture.nativeElement.querySelector('[data-automation-id="adf-start-process-apps-drop-down"]'); const appsSelectElement = fixture.nativeElement.querySelector('[data-automation-id="adf-start-process-apps-drop-down"]');
const processDefinitionSelectInput = fixture.nativeElement.querySelector('#processDefinitionName'); const processDefinitionSelectInput = fixture.nativeElement.querySelector('#processDefinitionName');
const processNameInput = fixture.nativeElement.querySelector('#processName'); const processNameInput = fixture.nativeElement.querySelector('#processName');
expect(getDeployedApplicationsSpy).toHaveBeenCalled();
expect(component.applications.length).toEqual(6);
expect(component.selectedApplication).toBeUndefined();
expect(processDefinitionSelectInput.disabled).toEqual(true); expect(processDefinitionSelectInput.disabled).toEqual(true);
expect(processNameInput.disabled).toEqual(true); expect(processNameInput.disabled).toEqual(true);
@ -833,18 +777,15 @@ describe('StartFormComponent', () => {
it('[C333521] Should be able to pre-select single deployed application with multiple processes', () => { it('[C333521] Should be able to pre-select single deployed application with multiple processes', () => {
const singleDeployedApp = deployedApps[0]; const singleDeployedApp = deployedApps[0];
const mockAppid = 1;
getDeployedApplicationsSpy.and.returnValues(of([singleDeployedApp])); getDeployedApplicationsSpy.and.returnValues(of([singleDeployedApp]));
changeAppId(1);
const change = new SimpleChange(null, mockAppid, true);
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
expect(getDeployedApplicationsSpy).toHaveBeenCalled(); expect(getDeployedApplicationsSpy).toHaveBeenCalled();
expect(component.applications.length).toBe(1); expect(component.applications.length).toBe(1);
expect(component.selectedApplication).toEqual(singleDeployedApp); expect(component.selectedApplication).toEqual(singleDeployedApp);
expect(getDefinitionsSpy).toHaveBeenCalledWith(mockAppid); expect(getDefinitionsSpy).toHaveBeenCalledWith(1);
expect(component.processDefinitions.length).toEqual(2); expect(component.processDefinitions.length).toEqual(2);
const processDefWithStartForm = testMultipleProcessDefs[1]; const processDefWithStartForm = testMultipleProcessDefs[1];
@ -865,9 +806,7 @@ describe('StartFormComponent', () => {
}); });
it('[C333522] Should be able to list multiple deployed apps with multiple process', async () => { it('[C333522] Should be able to list multiple deployed apps with multiple process', async () => {
changeAppId(123);
const change = new SimpleChange(null, 123, true);
component.ngOnChanges({ appId: change });
fixture.detectChanges(); fixture.detectChanges();
const application1 = deployedApps[0]; const application1 = deployedApps[0];

View File

@ -182,12 +182,6 @@ describe('ProcessService', () => {
expect(deleteProcessInstance).toHaveBeenCalledWith(processInstanceId); expect(deleteProcessInstance).toHaveBeenCalledWith(processInstanceId);
}); });
it('should run the success callback', (done) => {
service.cancelProcess(processInstanceId).subscribe(() => {
done();
});
});
it('should pass on any error that is returned by the API', (done) => { it('should pass on any error that is returned by the API', (done) => {
deleteProcessInstance = deleteProcessInstance.and.returnValue(Promise.reject(mockError)); deleteProcessInstance = deleteProcessInstance.and.returnValue(Promise.reject(mockError));
service.cancelProcess(null).subscribe( service.cancelProcess(null).subscribe(

View File

@ -137,12 +137,12 @@ describe('TaskDetailsComponent', () => {
component.onClaimAction('FAKE-TASK-CLAIM'); component.onClaimAction('FAKE-TASK-CLAIM');
}); });
it('should send a unclaim task event when a task is unclaimed', fakeAsync(() => { it('should send a unclaim task event when a task is unclaimed', async () => {
component.claimedTask.subscribe((taskId) => { const taskUnclaimedSpy = spyOn(component.unClaimedTask, 'emit');
expect(taskId).toBe('FAKE-TASK-UNCLAIM');
});
component.onUnclaimAction('FAKE-TASK-UNCLAIM'); component.onUnclaimAction('FAKE-TASK-UNCLAIM');
}));
expect(taskUnclaimedSpy).toHaveBeenCalledWith('FAKE-TASK-UNCLAIM');
});
it('should set a placeholder message when taskId not initialised', () => { it('should set a placeholder message when taskId not initialised', () => {
fixture.detectChanges(); fixture.detectChanges();
@ -163,25 +163,25 @@ describe('TaskDetailsComponent', () => {
expect(fixture.debugElement.query(By.css('.adf-readonly-form'))).not.toBeNull(); expect(fixture.debugElement.query(By.css('.adf-readonly-form'))).not.toBeNull();
})); }));
it('should not display a form when the task does not have an associated form', fakeAsync(() => { it('should not display a form when the task does not have an associated form', async () => {
component.taskId = '123'; component.taskId = '123';
taskDetailsMock.formKey = undefined; taskDetailsMock.formKey = undefined;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('adf-form'))).toBeNull();
});
}));
it('should display the claim message when the task is not assigned', fakeAsync(() => { fixture.detectChanges();
await fixture.whenStable();
expect(fixture.debugElement.query(By.css('adf-form'))).toBeNull();
});
it('should display the claim message when the task is not assigned', async () => {
component.taskDetails = taskDetailsWithOutAssigneeMock; component.taskDetails = taskDetailsWithOutAssigneeMock;
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { await fixture.whenStable();
const claimMessage = fixture.nativeElement.querySelector('#claim-message-id'); const claimMessage = fixture.nativeElement.querySelector('#claim-message-id');
expect(claimMessage).toBeDefined();
expect(claimMessage.innerText).toBe('ADF_TASK_LIST.DETAILS.MESSAGES.CLAIM'); expect(claimMessage).toBeTruthy();
}); expect(claimMessage.innerText).toBe('ADF_TASK_LIST.DETAILS.MESSAGES.CLAIM');
})); });
it('should not display the claim message when the task is assigned', fakeAsync(() => { it('should not display the claim message when the task is assigned', fakeAsync(() => {
fixture.detectChanges(); fixture.detectChanges();
@ -430,12 +430,12 @@ describe('TaskDetailsComponent', () => {
}); });
it('should log error message when search fails', async () => { it('should log error message when search fails', async () => {
spyOn(peopleProcessService, 'getWorkflowUsers').and.returnValue(throwError('')); const logServiceErrorSpy = spyOn(logService, 'error');
await component.peopleSearch.subscribe(() => { spyOn(peopleProcessService, 'getWorkflowUsers').and.returnValue(throwError('fake-error'));
expect(logService.error).toHaveBeenCalledWith('Could not load users');
});
component.searchUser('fake-search'); component.searchUser('fake-search');
expect(logServiceErrorSpy).toHaveBeenCalledWith('Could not load users');
}); });
it('should assign task to user', () => { it('should assign task to user', () => {

View File

@ -431,7 +431,7 @@ describe('Activiti TaskList Service', () => {
}); });
}); });
it('should unclaim a task', async() => { it('should unclaim a task', async () => {
const taskId = '111'; const taskId = '111';
await service.unclaimTask(taskId).subscribe((res) => { await service.unclaimTask(taskId).subscribe((res) => {
@ -445,7 +445,7 @@ describe('Activiti TaskList Service', () => {
}); });
}); });
it('should update a task', async() => { it('should update a task', async () => {
const taskId = '111'; const taskId = '111';
const updated: TaskUpdateRepresentation = { const updated: TaskUpdateRepresentation = {
name: 'someName' name: 'someName'