[ADF-5422] remove deprecated "async()" from unit tests (#7109)

* remove angualar async from content services

* upgrade more tests

* upgrade core tests

* upgrade tests

* fix deprecated constant

* fix tests

* fix after rebase
This commit is contained in:
Denys Vuika
2021-06-15 16:16:15 +01:00
committed by GitHub
parent ba03c60adb
commit 3079aa48c3
121 changed files with 5316 additions and 4780 deletions

View File

@@ -16,7 +16,7 @@
*/
import { DebugElement, Component } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AppsProcessService, setupTestBed } from '@alfresco/adf-core';
import { of, throwError } from 'rxjs';
@@ -78,14 +78,15 @@ describe('AppsListComponent', () => {
expect(component.loading).toBeFalsy();
});
it('should show the loading spinner when the apps are loading', async(() => {
it('should show the loading spinner when the apps are loading', async () => {
component.loading = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
await fixture.whenStable();
const loadingSpinner = fixture.nativeElement.querySelector('mat-progress-spinner');
expect(loadingSpinner).toBeDefined();
});
}));
});
it('should show the apps filtered by defaultAppId', () => {
component.filtersAppId = [{defaultAppId: 'fake-app-1'}];
@@ -267,13 +268,13 @@ describe('AppsListComponent', () => {
customFixture.destroy();
});
it('should render the custom no-apps template', async(() => {
it('should render the custom no-apps template', async () => {
customFixture.detectChanges();
customFixture.whenStable().then(() => {
const title: any = customFixture.debugElement.queryAll(By.css('#custom-id'));
expect(title.length).toBe(1);
expect(title[0].nativeElement.innerText).toBe('No Apps');
});
}));
await customFixture.whenStable();
const title: any = customFixture.debugElement.queryAll(By.css('#custom-id'));
expect(title.length).toBe(1);
expect(title[0].nativeElement.innerText).toBe('No Apps');
});
});
});

View File

@@ -16,7 +16,7 @@
*/
import { SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { setupTestBed } from '@alfresco/adf-core';
import { CreateProcessAttachmentComponent } from './create-process-attachment.component';
import { ProcessTestingModule } from '../testing/process.testing.module';
@@ -81,11 +81,12 @@ describe('CreateProcessAttachmentComponent', () => {
expect(component.processInstanceId).toBe('123');
});
it('should emit content created event when the file is uploaded', async(() => {
it('should emit content created event when the file is uploaded', (done) => {
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(res).not.toBeNull();
expect(res.id).toBe(9999);
done();
});
component.onFileUpload(customEvent);
@@ -95,9 +96,9 @@ describe('CreateProcessAttachmentComponent', () => {
contentType: 'application/json',
responseText: JSON.stringify(fakeUploadResponse)
});
}));
});
it('should allow user to upload files via button', async(() => {
it('should allow user to upload files via button', (done) => {
const buttonUpload: HTMLElement = <HTMLElement> element.querySelector('#add_new_process_content_button');
expect(buttonUpload).toBeDefined();
expect(buttonUpload).not.toBeNull();
@@ -106,6 +107,7 @@ describe('CreateProcessAttachmentComponent', () => {
expect(res).toBeDefined();
expect(res).not.toBeNull();
expect(res.id).toBe(9999);
done();
});
const dropEvent = new CustomEvent('upload-files', customEvent);
@@ -117,5 +119,5 @@ describe('CreateProcessAttachmentComponent', () => {
contentType: 'application/json',
responseText: JSON.stringify(fakeUploadResponse)
});
}));
});
});

View File

@@ -16,7 +16,7 @@
*/
import { SimpleChange, Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ProcessContentService, setupTestBed } from '@alfresco/adf-core';
import { of, throwError } from 'rxjs';
@@ -136,52 +136,55 @@ describe('ProcessAttachmentListComponent', () => {
expect(getProcessRelatedContentSpy).not.toHaveBeenCalled();
});
it('should display attachments when the process has attachments', async(() => {
it('should display attachments when the process has attachments', async () => {
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'processInstanceId': change });
fixture.detectChanges();
await fixture.whenStable();
expect(fixture.debugElement.queryAll(By.css('.adf-datatable-body > .adf-datatable-row')).length).toBe(2);
});
fixture.whenStable().then(() => {
expect(fixture.debugElement.queryAll(By.css('.adf-datatable-body > .adf-datatable-row')).length).toBe(2);
});
}));
it('should display all actions if attachments are not read only', async(() => {
it('should display all actions if attachments are not read only', async () => {
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'processInstanceId': change });
fixture.detectChanges();
await fixture.whenStable();
const actionButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="action_menu_0"]');
actionButton.click();
fixture.whenStable().then(() => {
fixture.detectChanges();
const actionMenu = window.document.querySelectorAll('button.mat-menu-item').length;
expect(window.document.querySelector('[data-automation-id="ADF_PROCESS_LIST.MENU_ACTIONS.VIEW_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_PROCESS_LIST.MENU_ACTIONS.REMOVE_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_PROCESS_LIST.MENU_ACTIONS.DOWNLOAD_CONTENT"]')).not.toBeNull();
expect(actionMenu).toBe(3);
});
}));
it('should not display remove action if attachments are read only', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const actionMenu = window.document.querySelectorAll('button.mat-menu-item').length;
expect(window.document.querySelector('[data-automation-id="ADF_PROCESS_LIST.MENU_ACTIONS.VIEW_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_PROCESS_LIST.MENU_ACTIONS.REMOVE_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_PROCESS_LIST.MENU_ACTIONS.DOWNLOAD_CONTENT"]')).not.toBeNull();
expect(actionMenu).toBe(3);
});
it('should not display remove action if attachments are read only', async () => {
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'processInstanceId': change });
component.disabled = true;
fixture.detectChanges();
await fixture.whenStable();
const actionButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="action_menu_0"]');
actionButton.click();
fixture.whenStable().then(() => {
fixture.detectChanges();
const actionMenu = window.document.querySelectorAll('button.mat-menu-item').length;
expect(window.document.querySelector('[data-automation-id="ADF_PROCESS_LIST.MENU_ACTIONS.VIEW_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_PROCESS_LIST.MENU_ACTIONS.DOWNLOAD_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_PROCESS_LIST.MENU_ACTIONS.REMOVE_CONTENT"]')).toBeNull();
expect(actionMenu).toBe(2);
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('should show the empty list component when the attachments list is empty', async(() => {
const actionMenu = window.document.querySelectorAll('button.mat-menu-item').length;
expect(window.document.querySelector('[data-automation-id="ADF_PROCESS_LIST.MENU_ACTIONS.VIEW_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_PROCESS_LIST.MENU_ACTIONS.DOWNLOAD_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_PROCESS_LIST.MENU_ACTIONS.REMOVE_CONTENT"]')).toBeNull();
expect(actionMenu).toBe(2);
});
it('should show the empty list component when the attachments list is empty', async () => {
getProcessRelatedContentSpy.and.returnValue(of({
'size': 0,
'total': 0,
@@ -190,13 +193,12 @@ describe('ProcessAttachmentListComponent', () => {
}));
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({'processInstanceId': change});
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual('ADF_PROCESS_LIST.PROCESS-ATTACHMENT.EMPTY.HEADER');
});
}));
fixture.detectChanges();
await fixture.whenStable();
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual('ADF_PROCESS_LIST.PROCESS-ATTACHMENT.EMPTY.HEADER');
});
it('should not show the empty list drag and drop component when is disabled', async(() => {
it('should not show the empty list drag and drop component when is disabled', async () => {
getProcessRelatedContentSpy.and.returnValue(of({
'size': 0,
'total': 0,
@@ -207,14 +209,13 @@ describe('ProcessAttachmentListComponent', () => {
component.ngOnChanges({'processInstanceId': change});
component.disabled = true;
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('adf-empty-list .adf-empty-list-drag_drop')).toBeNull();
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual('ADF_PROCESS_LIST.PROCESS-ATTACHMENT.EMPTY.HEADER');
});
}));
fixture.detectChanges();
await fixture.whenStable();
expect(fixture.nativeElement.querySelector('adf-empty-list .adf-empty-list-drag_drop')).toBeNull();
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual('ADF_PROCESS_LIST.PROCESS-ATTACHMENT.EMPTY.HEADER');
});
it('should show the empty list component when the attachments list is empty for completed process', async(() => {
it('should show the empty list component when the attachments list is empty for completed process', async () => {
getProcessRelatedContentSpy.and.returnValue(of({
'size': 0,
'total': 0,
@@ -225,24 +226,23 @@ describe('ProcessAttachmentListComponent', () => {
component.ngOnChanges({'processInstanceId': change});
component.disabled = true;
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim())
.toEqual('ADF_PROCESS_LIST.PROCESS-ATTACHMENT.EMPTY.HEADER');
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('should not show the empty list component when the attachments list is not empty for completed process', async(() => {
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim())
.toEqual('ADF_PROCESS_LIST.PROCESS-ATTACHMENT.EMPTY.HEADER');
});
it('should not show the empty list component when the attachments list is not empty for completed process', async () => {
getProcessRelatedContentSpy.and.returnValue(of(mockAttachment));
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({'processInstanceId': change});
component.disabled = true;
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]')).toBeNull();
});
}));
fixture.detectChanges();
await fixture.whenStable();
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]')).toBeNull();
});
it('should call getProcessRelatedContent with opt isRelatedContent=true', () => {
getProcessRelatedContentSpy.and.returnValue(of(mockAttachment));
@@ -258,12 +258,11 @@ describe('ProcessAttachmentListComponent', () => {
const change = new SimpleChange('123', '456', true);
const nullChange = new SimpleChange('123', null, true);
beforeEach(async(() => {
beforeEach(async () => {
component.processInstanceId = '123';
fixture.whenStable().then(() => {
getProcessRelatedContentSpy.calls.reset();
});
}));
await fixture.whenStable();
getProcessRelatedContentSpy.calls.reset();
});
it('should fetch new attachments when processInstanceId changed', () => {
component.ngOnChanges({ 'processInstanceId': change });
@@ -280,18 +279,6 @@ describe('ProcessAttachmentListComponent', () => {
expect(getProcessRelatedContentSpy).not.toHaveBeenCalled();
});
});
describe('Delete attachments', () => {
beforeEach(async(() => {
component.processInstanceId = '123';
fixture.whenStable();
}));
it('should display a dialog to the user when the Add button clicked', () => {
expect(true).toBe(true);
});
});
});
@Component({
@@ -327,12 +314,12 @@ describe('Custom CustomEmptyTemplateComponent', () => {
fixture.destroy();
});
it('should render the custom template', async(() => {
fixture.whenStable().then(() => {
fixture.detectChanges();
const title: any = fixture.debugElement.queryAll(By.css('[adf-empty-list-header]'));
expect(title.length).toBe(1);
expect(title[0].nativeElement.innerText).toBe('Custom header');
});
}));
it('should render the custom template', async () => {
fixture.detectChanges();
await fixture.whenStable();
const title: any = fixture.debugElement.queryAll(By.css('[adf-empty-list-header]'));
expect(title.length).toBe(1);
expect(title[0].nativeElement.innerText).toBe('Custom header');
});
});

View File

@@ -16,7 +16,7 @@
*/
import { SimpleChange, Component, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { of, throwError } from 'rxjs';
import { TaskAttachmentListComponent } from './task-attachment-list.component';
@@ -137,15 +137,12 @@ describe('TaskAttachmentList', () => {
expect(getTaskRelatedContentSpy).not.toHaveBeenCalled();
});
it('should display attachments when the task has attachments', (done) => {
it('should display attachments when the task has attachments', async () => {
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'taskId': change });
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(fixture.debugElement.queryAll(By.css('.adf-datatable-body > .adf-datatable-row')).length).toBe(2);
done();
});
await fixture.whenStable();
expect(fixture.debugElement.queryAll(By.css('.adf-datatable-body > .adf-datatable-row')).length).toBe(2);
});
it('emit document when a user wants to view the document', () => {
@@ -160,7 +157,7 @@ describe('TaskAttachmentList', () => {
expect(getFileRawContentSpy).toHaveBeenCalled();
});
it('should show the empty default message when has no custom template', async(() => {
it('should show the empty default message when has no custom template', async () => {
getTaskRelatedContentSpy.and.returnValue(of({
'size': 0,
'total': 0,
@@ -171,49 +168,52 @@ describe('TaskAttachmentList', () => {
component.ngOnChanges({ 'taskId': change });
component.hasCustomTemplate = false;
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('.adf-custom-empty-template')).toBeNull();
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual('ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER');
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('should display all actions if attachments are not read only', async(() => {
expect(fixture.nativeElement.querySelector('.adf-custom-empty-template')).toBeNull();
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual('ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER');
});
it('should display all actions if attachments are not read only', async () => {
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'taskId': change });
fixture.detectChanges();
await fixture.whenStable();
const actionButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="action_menu_0"]');
actionButton.click();
fixture.whenStable().then(() => {
fixture.detectChanges();
const actionMenu = window.document.querySelectorAll('button.mat-menu-item').length;
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.VIEW_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.REMOVE_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.DOWNLOAD_CONTENT"]')).not.toBeNull();
expect(actionMenu).toBe(3);
});
}));
it('should not display remove action if attachments are read only', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const actionMenu = window.document.querySelectorAll('button.mat-menu-item').length;
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.VIEW_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.REMOVE_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.DOWNLOAD_CONTENT"]')).not.toBeNull();
expect(actionMenu).toBe(3);
});
it('should not display remove action if attachments are read only', async () => {
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'taskId': change });
component.disabled = true;
fixture.detectChanges();
await fixture.whenStable();
const actionButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="action_menu_0"]');
actionButton.click();
fixture.whenStable().then(() => {
fixture.detectChanges();
const actionMenu = window.document.querySelectorAll('button.mat-menu-item').length;
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.VIEW_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.DOWNLOAD_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.REMOVE_CONTENT"]')).toBeNull();
expect(actionMenu).toBe(2);
});
}));
it('should show the empty list component when the attachments list is empty', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const actionMenu = window.document.querySelectorAll('button.mat-menu-item').length;
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.VIEW_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.DOWNLOAD_CONTENT"]')).not.toBeNull();
expect(window.document.querySelector('[data-automation-id="ADF_TASK_LIST.MENU_ACTIONS.REMOVE_CONTENT"]')).toBeNull();
expect(actionMenu).toBe(2);
});
it('should show the empty list component when the attachments list is empty', async () => {
getTaskRelatedContentSpy.and.returnValue(of({
'size': 0,
'total': 0,
@@ -222,14 +222,14 @@ describe('TaskAttachmentList', () => {
}));
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'taskId': change });
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual('ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER');
});
}));
it('should show the empty list component when the attachments list is empty for completed task', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual('ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER');
});
it('should show the empty list component when the attachments list is empty for completed task', async () => {
getTaskRelatedContentSpy.and.returnValue(of({
'size': 0,
'total': 0,
@@ -244,19 +244,18 @@ describe('TaskAttachmentList', () => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual('ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER');
});
}));
});
it('should not show the empty list component when the attachments list is not empty for completed task', (done) => {
it('should not show the empty list component when the attachments list is not empty for completed task', async () => {
getTaskRelatedContentSpy.and.returnValue(of(mockAttachment));
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'taskId': change });
component.disabled = true;
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]')).toBeNull();
done();
});
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]')).toBeNull();
});
it('loading should be false by default', () => {
@@ -265,28 +264,25 @@ describe('TaskAttachmentList', () => {
describe('change detection', () => {
let change;
let nullChange;
let change: SimpleChange;
let nullChange: SimpleChange;
beforeEach(() => {
change = new SimpleChange('123', '456', true);
nullChange = new SimpleChange('123', null, true);
});
beforeEach(async(() => {
beforeEach(() => {
component.taskId = '123';
fixture.whenStable().then(() => {
getTaskRelatedContentSpy.calls.reset();
});
}));
fixture.whenStable();
});
it('should fetch new attachments when taskId changed', (done) => {
it('should fetch new attachments when taskId changed', async () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
component.ngOnChanges({ 'taskId': change });
expect(getTaskRelatedContentSpy).toHaveBeenCalledWith('456', 'true');
done();
});
await fixture.whenStable();
component.ngOnChanges({ 'taskId': change });
expect(getTaskRelatedContentSpy).toHaveBeenCalledWith('456', 'true');
});
it('should NOT fetch new attachments when empty change set made', () => {
@@ -302,18 +298,17 @@ describe('TaskAttachmentList', () => {
describe('Delete attachments', () => {
beforeEach(async(() => {
beforeEach(() => {
component.taskId = '123';
fixture.whenStable();
}));
it('should display a dialog to the user when the Add button clicked', () => {
expect(true).toBe(true);
});
it('delete content by contentId', () => {
it('delete content by contentId', async () => {
component.deleteAttachmentById(5);
fixture.detectChanges();
await fixture.whenStable();
expect(deleteContentSpy).toHaveBeenCalled();
});
});
@@ -352,12 +347,12 @@ describe('Custom CustomEmptyTemplateComponent', () => {
fixture.destroy();
});
it('should render the custom template', async(() => {
fixture.whenStable().then(() => {
fixture.detectChanges();
const title: any = fixture.debugElement.queryAll(By.css('[adf-empty-list-header]'));
expect(title.length).toBe(1);
expect(title[0].nativeElement.innerText).toBe('Custom header');
});
}));
it('should render the custom template', async () => {
fixture.detectChanges();
await fixture.whenStable();
const title: any = fixture.debugElement.queryAll(By.css('[adf-empty-list-header]'));
expect(title.length).toBe(1);
expect(title[0].nativeElement.innerText).toBe('Custom header');
});
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AttachFileWidgetComponent } from './attach-file-widget.component';
import {
@@ -160,7 +160,7 @@ describe('AttachFileWidgetComponent', () => {
]
});
beforeEach(async(() => {
beforeEach(() => {
fixture = TestBed.createComponent(AttachFileWidgetComponent);
widget = fixture.componentInstance;
element = fixture.nativeElement;
@@ -170,17 +170,13 @@ describe('AttachFileWidgetComponent', () => {
downloadService = TestBed.inject(DownloadService);
formService = TestBed.inject(FormService);
attachFileWidgetDialogService = TestBed.inject(AttachFileWidgetDialogService);
}));
});
afterEach(() => {
fixture.destroy();
});
it('should be able to create the widget', () => {
expect(widget).not.toBeNull();
});
it('should show up as simple upload when is configured for only local files', async(() => {
it('should show up as simple upload when is configured for only local files', async () => {
spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(null));
widget.field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.UPLOAD,
@@ -189,12 +185,11 @@ describe('AttachFileWidgetComponent', () => {
widget.field.id = 'simple-upload-button';
widget.field.params = <FormFieldMetadata> onlyLocalParams;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#simple-upload-button')).not.toBeNull();
});
}));
await fixture.whenStable();
expect(element.querySelector('#simple-upload-button')).not.toBeNull();
});
it('should show up all the repository option on menu list', async(done) => {
it('should show up all the repository option on menu list', async() => {
widget.field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.UPLOAD,
value: []
@@ -205,7 +200,7 @@ describe('AttachFileWidgetComponent', () => {
fixture.detectChanges();
await fixture.whenRenderingDone();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-attach');
const attachButton = element.querySelector<HTMLButtonElement>('#attach-file-attach');
expect(attachButton).not.toBeNull();
attachButton.click();
fixture.detectChanges();
@@ -223,11 +218,9 @@ describe('AttachFileWidgetComponent', () => {
expect(fakeRepoOption2.length).toEqual(1);
expect(fakeRepoOption2[0]).not.toBeNull();
done();
});
it ('should show only remote repos when just link to files is true', async (done) => {
it ('should show only remote repos when just link to files is true', async () => {
widget.field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.UPLOAD,
value: []
@@ -238,7 +231,7 @@ describe('AttachFileWidgetComponent', () => {
fixture.detectChanges();
await fixture.whenRenderingDone();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-attach');
const attachButton = element.querySelector<HTMLButtonElement>('#attach-file-attach');
expect(attachButton).not.toBeNull();
attachButton.click();
@@ -256,11 +249,9 @@ describe('AttachFileWidgetComponent', () => {
expect(fakeRepoOption2.length).toEqual(1);
expect(fakeRepoOption2[0]).not.toBeNull();
done();
});
it('should isLink property of the selected node become true when the widget has link enabled', async (done) => {
it('should isLink property of the selected node become true when the widget has link enabled', async () => {
spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(fakeRepositoryListAnswer));
const applyAlfrescoNodeSpy = spyOn(activitiContentService, 'applyAlfrescoNode');
spyOn(contentNodeDialogService, 'openFileBrowseDialogByDefaultLocation').and.returnValue(of([fakeMinimalNode]));
@@ -283,10 +274,9 @@ describe('AttachFileWidgetComponent', () => {
fixture.debugElement.query(By.css('#attach-SHAREME')).nativeElement.click();
expect(applyAlfrescoNodeSpy).toHaveBeenCalledWith({ ...fakeMinimalNode, isLink: true }, undefined, 'alfresco-1000-SHAREME');
done();
});
it('should isLink property of the selected node become false when the widget has link disabled', async (done) => {
it('should isLink property of the selected node become false when the widget has link disabled', async () => {
spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(fakeRepositoryListAnswer));
const applyAlfrescoNodeSpy = spyOn(activitiContentService, 'applyAlfrescoNode');
spyOn(contentNodeDialogService, 'openFileBrowseDialogByDefaultLocation').and.returnValue(of([fakeMinimalNode]));
@@ -300,7 +290,7 @@ describe('AttachFileWidgetComponent', () => {
fixture.detectChanges();
await fixture.whenRenderingDone();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-attach');
const attachButton = element.querySelector<HTMLButtonElement>('#attach-file-attach');
expect(attachButton).not.toBeNull();
attachButton.click();
@@ -309,10 +299,9 @@ describe('AttachFileWidgetComponent', () => {
fixture.debugElement.query(By.css('#attach-SHAREME')).nativeElement.click();
expect(applyAlfrescoNodeSpy).toHaveBeenCalledWith({ ...fakeMinimalNode, isLink: false }, undefined, 'alfresco-1000-SHAREME');
done();
});
it('should be able to upload files coming from content node selector', async(() => {
it('should be able to upload files coming from content node selector', async () => {
spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(fakeRepositoryListAnswer));
spyOn(activitiContentService, 'applyAlfrescoNode').and.returnValue(of(fakePngAnswer));
spyOn(contentNodeDialogService, 'openFileBrowseDialogByDefaultLocation').and.returnValue(of([fakeMinimalNode]));
@@ -322,23 +311,28 @@ describe('AttachFileWidgetComponent', () => {
});
widget.field.id = 'attach-file-attach';
widget.field.params = <FormFieldMetadata> allSourceParams;
fixture.detectChanges();
fixture.whenStable().then(() => {
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-attach');
expect(attachButton).not.toBeNull();
attachButton.click();
fixture.detectChanges();
fixture.debugElement.query(By.css('#attach-SHAREME')).nativeElement.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
});
});
}));
it('should be able to upload more than one file from content node selector', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const attachButton = element.querySelector<HTMLButtonElement>('#attach-file-attach');
expect(attachButton).not.toBeNull();
attachButton.click();
fixture.detectChanges();
await fixture.whenStable();
fixture.debugElement.query(By.css('#attach-SHAREME')).nativeElement.click();
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
});
it('should be able to upload more than one file from content node selector', async () => {
const clickAttachFile = () => {
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-attach');
const attachButton = element.querySelector<HTMLButtonElement>('#attach-file-attach');
expect(attachButton).not.toBeNull();
attachButton.click();
fixture.detectChanges();
@@ -353,22 +347,27 @@ describe('AttachFileWidgetComponent', () => {
widget.field.id = 'attach-file-attach';
widget.field.params = <FormFieldMetadata> allSourceParams;
widget.field.params.multiple = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
clickAttachFile();
fixture.debugElement.query(By.css('#attach-SHAREME')).nativeElement.click();
fixture.detectChanges();
clickAttachFile();
fixture.debugElement.query(By.css('#attach-GOKUSHARE')).nativeElement.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#file-1155')).not.toBeNull();
expect(element.querySelector('#file-1166')).not.toBeNull();
});
});
}));
it('should be able to upload files when a defined folder is selected', async(() => {
fixture.detectChanges();
await fixture.whenStable();
clickAttachFile();
fixture.debugElement.query(By.css('#attach-SHAREME')).nativeElement.click();
fixture.detectChanges();
await fixture.whenStable();
clickAttachFile();
fixture.debugElement.query(By.css('#attach-GOKUSHARE')).nativeElement.click();
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#file-1155')).not.toBeNull();
expect(element.querySelector('#file-1166')).not.toBeNull();
});
it('should be able to upload files when a defined folder is selected', async () => {
widget.field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.UPLOAD,
value: []
@@ -378,20 +377,26 @@ describe('AttachFileWidgetComponent', () => {
spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(fakeRepositoryListAnswer));
spyOn(activitiContentService, 'applyAlfrescoNode').and.returnValue(of(fakePngAnswer));
spyOn(contentNodeDialogService, 'openFileBrowseDialogByFolderId').and.returnValue(of([fakeMinimalNode]));
fixture.detectChanges();
fixture.whenStable().then(() => {
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-attach');
expect(attachButton).not.toBeNull();
attachButton.click();
fixture.detectChanges();
fixture.debugElement.query(By.css('#attach-pippo-baudo')).nativeElement.click();
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
});
}));
const attachButton = element.querySelector<HTMLButtonElement>('#attach-file-attach');
expect(attachButton).not.toBeNull();
attachButton.click();
it('should be able to upload files from local source', async(() => {
fixture.detectChanges();
await fixture.whenStable();
fixture.debugElement.query(By.css('#attach-pippo-baudo')).nativeElement.click();
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
});
it('should be able to upload files from local source', async () => {
spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(null));
widget.field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.UPLOAD,
@@ -400,17 +405,18 @@ describe('AttachFileWidgetComponent', () => {
widget.field.id = 'attach-file-attach';
widget.field.params = <FormFieldMetadata> onlyLocalParams;
spyOn(processContentService, 'createTemporaryRawRelatedContent').and.returnValue(of(fakePngAnswer));
fixture.detectChanges();
fixture.whenStable().then(() => {
const inputDebugElement = fixture.debugElement.query(By.css('#attach-file-attach'));
inputDebugElement.triggerEventHandler('change', { target: { files: [fakePngAnswer] } });
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
});
}));
const inputDebugElement = fixture.debugElement.query(By.css('#attach-file-attach'));
inputDebugElement.triggerEventHandler('change', { target: { files: [fakePngAnswer] } });
fixture.detectChanges();
it('should display file list when field has value', async(() => {
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
});
it('should display file list when field has value', async () => {
widget.field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.UPLOAD,
value: [fakePngAnswer]
@@ -418,15 +424,16 @@ describe('AttachFileWidgetComponent', () => {
spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(null));
widget.field.id = 'attach-file-attach';
widget.field.params = <FormFieldMetadata> onlyLocalParams;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
});
}));
await fixture.whenStable();
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
});
describe('when a file is uploaded', () => {
beforeEach(async(() => {
beforeEach(async () => {
widget.field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.UPLOAD,
value: []
@@ -435,52 +442,66 @@ describe('AttachFileWidgetComponent', () => {
widget.field.params = <FormFieldMetadata> onlyLocalParams;
spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(null));
spyOn(processContentService, 'createTemporaryRawRelatedContent').and.returnValue(of(fakePngAnswer));
fixture.detectChanges();
fixture.whenStable().then(() => {
const inputDebugElement = fixture.debugElement.query(By.css('#attach-file-attach'));
inputDebugElement.triggerEventHandler('change', { target: { files: [fakePngAnswer] } });
fixture.detectChanges();
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
});
}));
it('should show the action menu', async(() => {
const menuButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#file-1155-option-menu');
fixture.detectChanges();
await fixture.whenStable();
const inputDebugElement = fixture.debugElement.query(By.css('#attach-file-attach'));
inputDebugElement.triggerEventHandler('change', { target: { files: [fakePngAnswer] } });
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
});
it('should show the action menu', async () => {
const menuButton = element.querySelector<HTMLButtonElement>('#file-1155-option-menu');
expect(menuButton).not.toBeNull();
menuButton.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(fixture.debugElement.query(By.css('#file-1155-show-file'))).not.toBeNull();
expect(fixture.debugElement.query(By.css('#file-1155-download-file'))).not.toBeNull();
expect(fixture.debugElement.query(By.css('#file-1155-remove'))).not.toBeNull();
});
}));
it('should remove file when remove is clicked', async(() => {
const menuButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#file-1155-option-menu');
fixture.detectChanges();
await fixture.whenStable();
expect(fixture.debugElement.query(By.css('#file-1155-show-file'))).not.toBeNull();
expect(fixture.debugElement.query(By.css('#file-1155-download-file'))).not.toBeNull();
expect(fixture.debugElement.query(By.css('#file-1155-remove'))).not.toBeNull();
});
it('should remove file when remove is clicked', async () => {
const menuButton = element.querySelector<HTMLButtonElement>('#file-1155-option-menu');
expect(menuButton).not.toBeNull();
menuButton.click();
fixture.detectChanges();
const removeOption: HTMLButtonElement = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-remove')).nativeElement;
await fixture.whenStable();
const removeOption = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-remove')).nativeElement;
removeOption.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#file-1155')).toBeNull();
});
}));
it('should download file when download is clicked', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#file-1155')).toBeNull();
});
it('should download file when download is clicked', async () => {
spyOn(downloadService, 'downloadBlob').and.stub();
const menuButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#file-1155-option-menu');
const menuButton = element.querySelector<HTMLButtonElement>('#file-1155-option-menu');
expect(menuButton).not.toBeNull();
menuButton.click();
fixture.detectChanges();
const downloadOption: HTMLButtonElement = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-download-file')).nativeElement;
await fixture.whenStable();
const downloadOption = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-download-file')).nativeElement;
downloadOption.click();
fixture.whenStable().then(() => {
expect(downloadService.downloadBlob).toHaveBeenCalled();
});
}));
fixture.detectChanges();
await fixture.whenStable();
expect(downloadService.downloadBlob).toHaveBeenCalled();
});
it('should raise formContentClicked event when show file is clicked', async() => {
spyOn(processContentService, 'getFileRawContent').and.returnValue(of(fakePngAnswer));
@@ -490,12 +511,12 @@ describe('AttachFileWidgetComponent', () => {
});
fixture.detectChanges();
await fixture.whenStable();
const menuButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#file-1155-option-menu');
const menuButton = element.querySelector<HTMLButtonElement>('#file-1155-option-menu');
expect(menuButton).not.toBeNull();
menuButton.click();
fixture.detectChanges();
await fixture.whenStable();
const showOption: HTMLButtonElement = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-show-file')).nativeElement;
const showOption = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-show-file')).nativeElement;
showOption.click();
fixture.detectChanges();
await fixture.whenStable();
@@ -505,12 +526,12 @@ describe('AttachFileWidgetComponent', () => {
fakePngAnswer.isExternal = true;
spyOn(processContentService, 'getFileRawContent').and.returnValue(of(fakePngAnswer));
const menuButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#file-1155-option-menu');
const menuButton = element.querySelector<HTMLButtonElement>('#file-1155-option-menu');
expect(menuButton).not.toBeNull();
menuButton.click();
fixture.detectChanges();
await fixture.whenStable();
const showOption: HTMLButtonElement = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-show-file')).nativeElement;
const showOption = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-show-file')).nativeElement;
expect(showOption.disabled).toBeTruthy();
});
@@ -518,12 +539,12 @@ describe('AttachFileWidgetComponent', () => {
fakePngAnswer.isExternal = true;
spyOn(processContentService, 'getFileRawContent').and.returnValue(of(fakePngAnswer));
const menuButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#file-1155-option-menu');
const menuButton = element.querySelector<HTMLButtonElement>('#file-1155-option-menu');
expect(menuButton).not.toBeNull();
menuButton.click();
fixture.detectChanges();
await fixture.whenStable();
const downloadOption: HTMLButtonElement = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-download-file')).nativeElement;
const downloadOption = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-download-file')).nativeElement;
expect(downloadOption.disabled).toBeTruthy();
});
@@ -531,7 +552,7 @@ describe('AttachFileWidgetComponent', () => {
fakePngAnswer.isExternal = false;
spyOn(processContentService, 'getFileRawContent').and.returnValue(of(fakePngAnswer));
const menuButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#file-1155-option-menu');
const menuButton = element.querySelector<HTMLButtonElement>('#file-1155-option-menu');
expect(menuButton).not.toBeNull();
menuButton.click();
fixture.detectChanges();
@@ -545,32 +566,38 @@ describe('AttachFileWidgetComponent', () => {
fakePngAnswer.contentAvailable = false;
spyOn(processContentService, 'getFileRawContent').and.returnValue(of(fakePngAnswer));
const menuButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#file-1155-option-menu');
const menuButton = element.querySelector<HTMLButtonElement>('#file-1155-option-menu');
expect(menuButton).not.toBeNull();
menuButton.click();
fixture.detectChanges();
await fixture.whenStable();
const showOption: HTMLButtonElement = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-show-file')).nativeElement;
const showOption = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-show-file')).nativeElement;
expect(showOption.disabled).toBeTruthy();
});
});
it('should be able to upload files when a defined folder from external content service', async(() => {
it('should be able to upload files when a defined folder from external content service', async () => {
widget.field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.UPLOAD, value: [] });
widget.field.id = 'attach-external-file-attach';
widget.field.params = <FormFieldMetadata> externalDefinedSourceParams;
spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(fakeRepositoryListAnswer));
spyOn(activitiContentService, 'applyAlfrescoNode').and.returnValue(of(fakePngAnswer));
spyOn(attachFileWidgetDialogService, 'openLogin').and.returnValue(of([fakeMinimalNode]));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const attachButton: HTMLButtonElement = element.querySelector('#attach-external-file-attach');
attachButton.click();
fixture.detectChanges();
fixture.debugElement.query(By.css('#attach-external')).nativeElement.click();
fixture.detectChanges();
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
});
}));
await fixture.whenStable();
const attachButton = element.querySelector<HTMLButtonElement>('#attach-external-file-attach');
attachButton.click();
fixture.detectChanges();
await fixture.whenStable();
fixture.debugElement.query(By.css('#attach-external')).nativeElement.click();
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
});
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AttachFolderWidgetComponent } from './attach-folder-widget.component';
import {
@@ -61,22 +61,18 @@ describe('AttachFolderWidgetComponent', () => {
]
});
beforeEach(async(() => {
beforeEach(() => {
fixture = TestBed.createComponent(AttachFolderWidgetComponent);
widget = fixture.componentInstance;
element = fixture.nativeElement;
contentNodeDialogService = TestBed.inject(ContentNodeDialogService);
nodeService = TestBed.inject(NodesApiService);
}));
});
afterEach(() => {
fixture.destroy();
});
it('should be able to create the widget', () => {
expect(widget).not.toBeNull();
});
it('should be rendered correctly', () => {
expect(widget).not.toBeNull();
widget.field = new FormFieldModel(new FormModel(), {
@@ -89,7 +85,7 @@ describe('AttachFolderWidgetComponent', () => {
expect(element.querySelector('#folder-fake-widget-button')).not.toBeNull();
});
it('should show the folder selected by content node', async(() => {
it('should show the folder selected by content node', async () => {
spyOn(contentNodeDialogService, 'openFolderBrowseDialogBySite').and.returnValue(of([fakeMinimalNode]));
expect(widget).not.toBeNull();
widget.field = new FormFieldModel(new FormModel(), {
@@ -98,14 +94,17 @@ describe('AttachFolderWidgetComponent', () => {
value: null
});
fixture.detectChanges();
fixture.debugElement.query(By.css('#folder-fake-widget-button')).nativeElement.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#folder-fake-widget')).not.toBeNull();
});
}));
await fixture.whenStable();
it('should show the folder selected by content node opening on a configured folder', async(() => {
fixture.debugElement.query(By.css('#folder-fake-widget-button')).nativeElement.click();
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#folder-fake-widget')).not.toBeNull();
});
it('should show the folder selected by content node opening on a configured folder', async () => {
spyOn(contentNodeDialogService, 'openFolderBrowseDialogByFolderId').and.returnValue(of([fakeMinimalNode]));
expect(widget).not.toBeNull();
widget.field = new FormFieldModel(new FormModel(), {
@@ -114,15 +113,19 @@ describe('AttachFolderWidgetComponent', () => {
value: null,
params: definedSourceParams
});
fixture.detectChanges();
await fixture.whenStable();
fixture.debugElement.query(By.css('#folder-fake-widget-button')).nativeElement.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#folder-fake-widget')).not.toBeNull();
});
}));
it('should retrieve the node information on init', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#folder-fake-widget')).not.toBeNull();
});
it('should retrieve the node information on init', async () => {
spyOn(nodeService, 'getNode').and.returnValue(of(fakeMinimalNode));
expect(widget).not.toBeNull();
widget.field = new FormFieldModel(new FormModel(), {
@@ -130,14 +133,15 @@ describe('AttachFolderWidgetComponent', () => {
id: 'fake-widget',
value: 'fake-pippo-baudo-id'
});
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#folder-fake-widget')).not.toBeNull();
expect(element.querySelector('#folder-fake-widget-button')).toBeNull();
});
}));
it('should remove the folder via the remove button', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#folder-fake-widget')).not.toBeNull();
expect(element.querySelector('#folder-fake-widget-button')).toBeNull();
});
it('should remove the folder via the remove button', async () => {
spyOn(nodeService, 'getNode').and.returnValue(of(fakeMinimalNode));
expect(widget).not.toBeNull();
widget.field = new FormFieldModel(new FormModel(), {
@@ -145,13 +149,17 @@ describe('AttachFolderWidgetComponent', () => {
id: 'fake-widget',
value: 'fake-pippo-baudo-id'
});
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#folder-fake-widget')).not.toBeNull();
expect(element.querySelector('#folder-fake-widget-button')).toBeNull();
fixture.debugElement.query(By.css('#folder-fake-widget-remove')).nativeElement.click();
fixture.detectChanges();
expect(element.querySelector('#folder-fake-widget')).toBeNull();
});
}));
await fixture.whenStable();
expect(element.querySelector('#folder-fake-widget')).not.toBeNull();
expect(element.querySelector('#folder-fake-widget-button')).toBeNull();
fixture.debugElement.query(By.css('#folder-fake-widget-remove')).nativeElement.click();
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#folder-fake-widget')).toBeNull();
});
});

View File

@@ -18,7 +18,7 @@
import { CUSTOM_ELEMENTS_SCHEMA, SimpleChange } from '@angular/core';
import { of } from 'rxjs';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { formDefinitionDropdownField, formDefinitionTwoTextFields,
@@ -55,7 +55,6 @@ describe('FormComponent UI and visibility', () => {
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
describe('Validation icon', () => {
@@ -116,37 +115,37 @@ describe('FormComponent UI and visibility', () => {
expect(lastNameEl).toBeDefined();
});
it('should display dropdown field', async(() => {
it('should display dropdown field', async () => {
spyOn(service, 'getTask').and.returnValue(of({}));
spyOn(service, 'getTaskForm').and.returnValue(of(formDefinitionDropdownField));
const change = new SimpleChange(null, 1, true);
component.ngOnChanges({ 'taskId': change });
fixture.detectChanges();
await fixture.whenStable();
openSelect();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const options = fixture.debugElement.queryAll(By.css('.mat-option-text'));
const options = fixture.debugElement.queryAll(By.css('.mat-option-text'));
const optOne = options[1];
const optTwo = options[2];
const optThree = options[3];
const optOne = options[1];
const optTwo = options[2];
const optThree = options[3];
expect(optOne.nativeElement.innerText.trim()).toEqual('united kingdom');
expect(optTwo.nativeElement.innerText.trim()).toEqual('italy');
expect(optThree.nativeElement.innerText.trim()).toEqual('france');
expect(optOne.nativeElement.innerText.trim()).toEqual('united kingdom');
expect(optTwo.nativeElement.innerText.trim()).toEqual('italy');
expect(optThree.nativeElement.innerText.trim()).toEqual('france');
optTwo.nativeElement.click();
optTwo.nativeElement.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
const dropdown = fixture.debugElement.queryAll(By.css('#country'));
expect(dropdown[0].nativeElement.innerText.trim()).toEqual('italy');
});
});
}));
fixture.detectChanges();
await fixture.whenStable();
const dropdown = fixture.debugElement.queryAll(By.css('#country'));
expect(dropdown[0].nativeElement.innerText.trim()).toEqual('italy');
});
describe('Visibility conditions', () => {
@@ -209,7 +208,7 @@ describe('FormComponent UI and visibility', () => {
});
describe('Readonly Form', () => {
it('should display two text fields readonly', async(() => {
it('should display two text fields readonly', async () => {
spyOn(service, 'getTask').and.returnValue(of({}));
spyOn(service, 'getTaskForm').and.returnValue(of(formReadonlyTwoTextFields));
@@ -217,14 +216,14 @@ describe('FormComponent UI and visibility', () => {
component.ngOnChanges({ 'taskId': change });
fixture.detectChanges();
fixture.whenStable().then(() => {
const firstNameEl = fixture.debugElement.query(By.css('#firstname'));
expect(firstNameEl.nativeElement.value).toEqual('fakeFirstName');
await fixture.whenStable();
const lastNameEl = fixture.debugElement.query(By.css('#lastname'));
expect(lastNameEl.nativeElement.value).toEqual('fakeLastName');
});
}));
const firstNameEl = fixture.debugElement.query(By.css('#firstname'));
expect(firstNameEl.nativeElement.value).toEqual('fakeFirstName');
const lastNameEl = fixture.debugElement.query(By.css('#lastname'));
expect(lastNameEl.nativeElement.value).toEqual('fakeLastName');
});
});
});
});

View File

@@ -16,7 +16,7 @@
*/
import { CUSTOM_ELEMENTS_SCHEMA, SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { of, throwError } from 'rxjs';
import {
startFormDateWidgetMock, startFormDropdownDefinitionMock,
@@ -306,59 +306,57 @@ describe('StartFormComponent', () => {
});
});
it('should display start form with fields ', async(() => {
it('should display start form with fields ', async () => {
getStartFormSpy.and.returnValue(of(startMockForm));
component.processDefinitionId = exampleId1;
component.showOutcomeButtons = true;
component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) });
fixture.whenStable().then(() => {
fixture.detectChanges();
const formFieldsWidget = fixture.debugElement.nativeElement.querySelector('form-field');
const inputElement = fixture.debugElement.nativeElement.querySelector('.adf-input');
const inputLabelElement = fixture.debugElement.nativeElement.querySelector('.mat-form-field-infix > .adf-label');
const dateElement = fixture.debugElement.nativeElement.querySelector('#billdate');
const dateLabelElement = fixture.debugElement.nativeElement.querySelector('#data-widget .mat-form-field-infix> .adf-label');
const selectElement = fixture.debugElement.nativeElement.querySelector('#claimtype');
const selectLabelElement = fixture.debugElement.nativeElement.querySelector('.adf-dropdown-widget > .adf-label');
expect(formFieldsWidget).toBeDefined();
expect(inputElement).toBeDefined();
expect(dateElement).toBeDefined();
expect(selectElement).toBeDefined();
translate.get(inputLabelElement.textContent).subscribe( (value) => {
expect(value).toBe('ClientName*');
});
translate.get(dateLabelElement.innerText).subscribe( (value) => {
expect(value).toBe('BillDate (D-M-YYYY)');
});
translate.get(selectLabelElement.innerText).subscribe( (value) => {
expect(value).toBe('ClaimType');
});
});
}));
it('should refresh start form on click of refresh button ', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const formFieldsWidget = fixture.debugElement.nativeElement.querySelector('form-field');
const inputElement = fixture.debugElement.nativeElement.querySelector('.adf-input');
const inputLabelElement = fixture.debugElement.nativeElement.querySelector('.mat-form-field-infix > .adf-label');
const dateElement = fixture.debugElement.nativeElement.querySelector('#billdate');
const dateLabelElement = fixture.debugElement.nativeElement.querySelector('#data-widget .mat-form-field-infix> .adf-label');
const selectElement = fixture.debugElement.nativeElement.querySelector('#claimtype');
const selectLabelElement = fixture.debugElement.nativeElement.querySelector('.adf-dropdown-widget > .adf-label');
expect(formFieldsWidget).toBeDefined();
expect(inputElement).toBeDefined();
expect(dateElement).toBeDefined();
expect(selectElement).toBeDefined();
expect(translate.instant(inputLabelElement.textContent)).toBe('ClientName*');
expect(translate.instant(dateLabelElement.innerText)).toBe('BillDate (D-M-YYYY)');
expect(translate.instant(selectLabelElement.innerText)).toBe('ClaimType');
});
it('should refresh start form on click of refresh button', async () => {
getStartFormSpy.and.returnValue(of(startMockForm));
component.processDefinitionId = exampleId1;
component.showOutcomeButtons = true;
component.showRefreshButton = true;
component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) });
fixture.detectChanges();
fixture.whenStable().then(() => {
const refreshElement = fixture.debugElement.nativeElement.querySelector('.mat-card-actions>button');
refreshElement.click();
fixture.detectChanges();
/* cspell:disable-next-line */
const selectElement = fixture.debugElement.nativeElement.querySelector('#claimtype');
const selectLabelElement = fixture.debugElement.nativeElement.querySelector('.adf-dropdown-widget > .adf-label');
expect(refreshElement).toBeDefined();
expect(selectElement).toBeDefined();
translate.get(selectLabelElement.innerText).subscribe( (value) => {
expect(value).toBe('ClaimType');
});
});
}));
await fixture.whenStable();
it('should define custom-tabs ', async(() => {
const refreshElement = fixture.debugElement.nativeElement.querySelector('.mat-card-actions>button');
refreshElement.click();
fixture.detectChanges();
await fixture.whenStable();
/* cspell:disable-next-line */
const selectElement = fixture.debugElement.nativeElement.querySelector('#claimtype');
const selectLabelElement = fixture.debugElement.nativeElement.querySelector('.adf-dropdown-widget > .adf-label');
expect(refreshElement).toBeDefined();
expect(selectElement).toBeDefined();
expect(translate.instant(selectLabelElement.innerText)).toBe('ClaimType');
});
it('should define custom-tabs ', fakeAsync(() => {
getStartFormSpy.and.returnValue(of(startMockFormWithTab));
component.processDefinitionId = exampleId1;
component.showOutcomeButtons = true;
@@ -376,7 +374,7 @@ describe('StartFormComponent', () => {
});
}));
it('should define title and [custom-action-buttons]', async(() => {
it('should define title and [custom-action-buttons]', fakeAsync(() => {
getStartFormSpy.and.returnValue(of(startMockFormWithTab));
component.processDefinitionId = exampleId1;
component.showOutcomeButtons = true;

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { LogService, setupTestBed, UserProcessModel } from '@alfresco/adf-core';
import { PeopleComponent } from './people.component';
import { ProcessTestingModule } from '../../../testing/process.testing.module';
@@ -23,14 +23,14 @@ import { TranslateModule } from '@ngx-translate/core';
declare let jasmine: any;
const fakeUser: UserProcessModel = new UserProcessModel({
const fakeUser = new UserProcessModel({
id: 'fake-id',
firstName: 'fake-name',
lastName: 'fake-last',
email: 'fake@mail.com'
});
const fakeSecondUser: UserProcessModel = new UserProcessModel({
const fakeSecondUser = new UserProcessModel({
id: 'fake-involve-id',
firstName: 'fake-involve-name',
lastName: 'fake-involve-last',
@@ -52,7 +52,7 @@ describe('PeopleComponent', () => {
]
});
beforeEach(async(() => {
beforeEach(() => {
logService = TestBed.inject(LogService);
fixture = TestBed.createComponent(PeopleComponent);
activitiPeopleComponent = fixture.componentInstance;
@@ -61,24 +61,26 @@ describe('PeopleComponent', () => {
activitiPeopleComponent.people = [];
activitiPeopleComponent.readOnly = true;
fixture.detectChanges();
}));
});
it('should show people component title', async(() => {
afterEach(() => fixture.destroy());
it('should show people component title', async () => {
activitiPeopleComponent.people = [...userArray];
fixture.detectChanges();
fixture.whenStable()
.then(() => {
expect(element.querySelector('#people-title')).toBeDefined();
expect(element.querySelector('#people-title')).not.toBeNull();
});
}));
it('should show no people involved message', () => {
fixture.whenStable()
.then(() => {
expect(element.querySelector('#no-people-label')).not.toBeNull();
expect(element.querySelector('#no-people-label').textContent).toContain('ADF_TASK_LIST.DETAILS.PEOPLE.NONE');
});
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#people-title')).toBeDefined();
expect(element.querySelector('#people-title')).not.toBeNull();
});
it('should show no people involved message', async () => {
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#no-people-label')).not.toBeNull();
expect(element.querySelector('#no-people-label').textContent).toContain('ADF_TASK_LIST.DETAILS.PEOPLE.NONE');
});
describe('when there are involved people', () => {
@@ -97,16 +99,16 @@ describe('PeopleComponent', () => {
jasmine.Ajax.uninstall();
});
it('should show people involved', async(() => {
fixture.whenStable()
.then(() => {
const gatewayElement: any = element.querySelector('#assignment-people-list .adf-datatable-body');
expect(gatewayElement).not.toBeNull();
expect(gatewayElement.children.length).toBe(2);
});
}));
it('should show people involved', async () => {
fixture.detectChanges();
await fixture.whenStable();
it('should remove people involved', async(() => {
const gatewayElement = element.querySelector('#assignment-people-list .adf-datatable-body');
expect(gatewayElement).not.toBeNull();
expect(gatewayElement.children.length).toBe(2);
});
it('should remove people involved', fakeAsync(() => {
activitiPeopleComponent.removeInvolvedUser(fakeUser);
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200
@@ -120,7 +122,7 @@ describe('PeopleComponent', () => {
});
}));
it('should involve people', async(() => {
it('should involve people', fakeAsync(() => {
activitiPeopleComponent.involveUser(fakeUser);
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200
@@ -189,7 +191,7 @@ describe('PeopleComponent', () => {
jasmine.Ajax.uninstall();
});
it('should log error message when search fails', async(() => {
it('should log error message when search fails', fakeAsync(() => {
activitiPeopleComponent.peopleSearch$.subscribe(() => {
expect(logService.error).toHaveBeenCalledWith('Could not load users');
});
@@ -199,7 +201,7 @@ describe('PeopleComponent', () => {
});
}));
it('should not remove user if remove involved user fail', async(() => {
it('should not remove user if remove involved user fail', fakeAsync(() => {
activitiPeopleComponent.removeInvolvedUser(fakeUser);
jasmine.Ajax.requests.mostRecent().respondWith({
status: 403
@@ -213,7 +215,7 @@ describe('PeopleComponent', () => {
});
}));
it('should not involve user if involve user fail', async(() => {
it('should not involve user if involve user fail', fakeAsync(() => {
activitiPeopleComponent.involveUser(fakeUser);
jasmine.Ajax.requests.mostRecent().respondWith({
status: 403

View File

@@ -16,7 +16,7 @@
*/
import { SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { of, throwError } from 'rxjs';
import { CommentProcessService, setupTestBed } from '@alfresco/adf-core';
@@ -72,64 +72,65 @@ describe('ProcessCommentsComponent', () => {
expect(getCommentsSpy).not.toHaveBeenCalled();
});
it('should display comments when the process has comments', async(() => {
it('should display comments when the process has comments', async () => {
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'processInstanceId': change });
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelectorAll('#comment-message').length).toBe(3);
expect(fixture.nativeElement.querySelector('#comment-message:empty')).toBeNull();
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('should display comments count when the process has comments', async(() => {
expect(fixture.nativeElement.querySelectorAll('#comment-message').length).toBe(3);
expect(fixture.nativeElement.querySelector('#comment-message:empty')).toBeNull();
});
it('should display comments count when the process has comments', async () => {
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'processInstanceId': change });
fixture.whenStable().then(() => {
fixture.detectChanges();
const element = fixture.nativeElement.querySelector('#comment-header');
expect(element.innerText).toBe('ADF_PROCESS_LIST.DETAILS.COMMENTS.HEADER');
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('should not display comments when the process has no comments', async(() => {
const element = fixture.nativeElement.querySelector('#comment-header');
expect(element.innerText).toBe('ADF_PROCESS_LIST.DETAILS.COMMENTS.HEADER');
});
it('should not display comments when the process has no comments', async () => {
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'processInstanceId': change });
getCommentsSpy.and.returnValue(of([]));
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('#comment-container')).toBeNull();
});
}));
it('should not display comments input by default', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(fixture.nativeElement.querySelector('#comment-container')).toBeNull();
});
it('should not display comments input by default', async () => {
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'processInstanceId': change });
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('#comment-input')).toBeNull();
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('should not display comments input when the process is readonly', async(() => {
expect(fixture.nativeElement.querySelector('#comment-input')).toBeNull();
});
it('should not display comments input when the process is readonly', async () => {
component.readOnly = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('#comment-input')).toBeNull();
});
}));
it('should display comments input when the process isn\'t readonly', async(() => {
component.readOnly = false;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('#comment-input')).not.toBeNull();
});
}));
await fixture.whenStable();
expect(fixture.nativeElement.querySelector('#comment-input')).toBeNull();
});
it('should display comments input when the process isn\'t readonly', async () => {
component.readOnly = false;
fixture.detectChanges();
await fixture.whenStable();
expect(fixture.nativeElement.querySelector('#comment-input')).not.toBeNull();
});
});

View File

@@ -16,7 +16,7 @@
*/
import { DebugElement, NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { of } from 'rxjs';
@@ -75,55 +75,59 @@ describe('ProcessInstanceDetailsComponent', () => {
expect(fixture.nativeElement.innerText).toBe('ADF_PROCESS_LIST.DETAILS.MESSAGES.NONE');
});
it('should display a header when the processInstanceId is provided', async(() => {
it('should display a header when the processInstanceId is provided', async () => {
fixture.detectChanges();
component.ngOnChanges({ 'processInstanceId': new SimpleChange(null, '123', true) });
fixture.whenStable().then(() => {
fixture.detectChanges();
const headerEl: DebugElement = fixture.debugElement.query(By.css('.mat-card-title '));
expect(headerEl).not.toBeNull();
expect(headerEl.nativeElement.innerText).toBe('Process 123');
});
}));
it('should display default details when the process instance has no name', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const headerEl: DebugElement = fixture.debugElement.query(By.css('.mat-card-title '));
expect(headerEl).not.toBeNull();
expect(headerEl.nativeElement.innerText).toBe('Process 123');
});
it('should display default details when the process instance has no name', async () => {
fixture.detectChanges();
getProcessSpy.and.returnValue(of(exampleProcessNoName));
fixture.detectChanges();
component.ngOnChanges({ 'processInstanceId': new SimpleChange(null, '123', true) });
fixture.whenStable().then(() => {
fixture.detectChanges();
const headerEl: DebugElement = fixture.debugElement.query(By.css('.mat-card-title '));
expect(headerEl).not.toBeNull();
expect(headerEl.nativeElement.innerText).toBe('My Process - Nov 10, 2016, 3:37:30 AM');
});
}));
it('should enable diagram button if the process is running', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const headerEl: DebugElement = fixture.debugElement.query(By.css('.mat-card-title '));
expect(headerEl).not.toBeNull();
expect(headerEl.nativeElement.innerText).toBe('My Process - Nov 10, 2016, 3:37:30 AM');
});
it('should enable diagram button if the process is running', async () => {
fixture.detectChanges();
getProcessSpy.and.returnValue(of(mockRunningProcess));
fixture.detectChanges();
component.ngOnChanges({ 'processInstanceId': new SimpleChange(null, '123', true) });
fixture.whenStable().then(() => {
fixture.detectChanges();
const diagramButton = fixture.debugElement.query(By.css('#show-diagram-button'));
expect(diagramButton).not.toBeNull();
expect(diagramButton.nativeElement.disabled).toBe(false);
});
}));
it('should disable diagram button if the process is running', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const diagramButton = fixture.debugElement.query(By.css('#show-diagram-button'));
expect(diagramButton).not.toBeNull();
expect(diagramButton.nativeElement.disabled).toBe(false);
});
it('should disable diagram button if the process is running', async () => {
fixture.detectChanges();
getProcessSpy.and.returnValue(of(processEnded));
fixture.detectChanges();
component.ngOnChanges({ 'processInstanceId': new SimpleChange(null, '123', true) });
fixture.whenStable().then(() => {
fixture.detectChanges();
const diagramButton = fixture.debugElement.query(By.css('#show-diagram-button'));
expect(diagramButton).not.toBeNull();
expect(diagramButton.nativeElement.disabled).toBe(true);
});
}));
fixture.detectChanges();
await fixture.whenStable();
const diagramButton = fixture.debugElement.query(By.css('#show-diagram-button'));
expect(diagramButton).not.toBeNull();
expect(diagramButton.nativeElement.disabled).toBe(true);
});
describe('change detection', () => {
@@ -136,46 +140,53 @@ describe('ProcessInstanceDetailsComponent', () => {
fixture.detectChanges();
});
it('should fetch new process details when processInstanceId changed', async(() => {
it('should fetch new process details when processInstanceId changed', async () => {
fixture.detectChanges();
component.ngOnChanges({ 'processInstanceId': change });
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(getProcessSpy).toHaveBeenCalledWith('456');
});
}));
it('should NOT fetch new process details when empty changeset made', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(getProcessSpy).toHaveBeenCalledWith('456');
});
it('should NOT fetch new process details when empty changeset made', async () => {
fixture.detectChanges();
component.ngOnChanges({});
fixture.whenStable().then(() => {
expect(getProcessSpy).not.toHaveBeenCalled();
});
}));
it('should NOT fetch new process details when processInstanceId changed to null', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(getProcessSpy).not.toHaveBeenCalled();
});
it('should NOT fetch new process details when processInstanceId changed to null', async () => {
fixture.detectChanges();
component.ngOnChanges({ 'processInstanceId': nullChange });
fixture.whenStable().then(() => {
expect(getProcessSpy).not.toHaveBeenCalled();
});
}));
it('should set a placeholder message when processInstanceId changed to null', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(getProcessSpy).not.toHaveBeenCalled();
});
it('should set a placeholder message when processInstanceId changed to null', async () => {
component.ngOnChanges({ 'processInstanceId': nullChange });
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.innerText).toBe('ADF_PROCESS_LIST.DETAILS.MESSAGES.NONE');
});
}));
it('should display cancel button if process is running', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(fixture.nativeElement.innerText).toBe('ADF_PROCESS_LIST.DETAILS.MESSAGES.NONE');
});
it('should display cancel button if process is running', async () => {
component.ngOnChanges({ 'processInstanceId': change });
fixture.whenStable().then(() => {
fixture.detectChanges();
const buttonEl = fixture.debugElement.query(By.css('[data-automation-id="header-status"] button'));
expect(buttonEl).not.toBeNull();
});
}));
fixture.detectChanges();
await fixture.whenStable();
const buttonEl = fixture.debugElement.query(By.css('[data-automation-id="header-status"] button'));
expect(buttonEl).not.toBeNull();
});
});
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppConfigService, setupTestBed } from '@alfresco/adf-core';
import { ProcessInstance } from '../models/process-instance.model';
import { exampleProcess } from '../../mock';
@@ -184,18 +184,18 @@ describe('ProcessInstanceHeaderComponent', () => {
expect(propertyList[1].innerText).toContain('ADF_PROCESS_LIST.PROPERTIES.END_DATE');
});
it('should show all the default properties if there is no configuration', async(() => {
it('should show all the default properties if there is no configuration', async () => {
appConfigService.config['adf-process-instance-header'] = {};
component.ngOnChanges();
fixture.detectChanges();
fixture.whenStable().then(() => {
const propertyList = fixture.nativeElement.querySelectorAll('.adf-property-list .adf-property');
expect(propertyList).toBeDefined();
expect(propertyList).not.toBeNull();
expect(propertyList.length).toBe(component.properties.length);
expect(propertyList[0].innerText).toContain('ADF_PROCESS_LIST.PROPERTIES.STATUS');
expect(propertyList[2].innerText).toContain('ADF_PROCESS_LIST.PROPERTIES.CATEGORY');
});
}));
await fixture.whenStable();
const propertyList = fixture.nativeElement.querySelectorAll('.adf-property-list .adf-property');
expect(propertyList).toBeDefined();
expect(propertyList).not.toBeNull();
expect(propertyList.length).toBe(component.properties.length);
expect(propertyList[0].innerText).toContain('ADF_PROCESS_LIST.PROPERTIES.STATUS');
expect(propertyList[2].innerText).toContain('ADF_PROCESS_LIST.PROPERTIES.CATEGORY');
});
});
});

View File

@@ -16,7 +16,7 @@
*/
import { SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { of } from 'rxjs';
@@ -59,23 +59,24 @@ describe('ProcessInstanceTasksComponent', () => {
fixture.destroy();
});
it('should initially render message about no active tasks if no process instance ID provided', async(() => {
it('should initially render message about no active tasks if no process instance ID provided', async () => {
component.processInstanceDetails = undefined;
fixture.detectChanges();
fixture.whenStable().then(() => {
const msgEl = fixture.debugElement.query(By.css('[data-automation-id="active-tasks-none"]'));
expect(msgEl).not.toBeNull();
});
}));
await fixture.whenStable();
it('should initially render message about no completed tasks if no process instance ID provided', async(() => {
const msgEl = fixture.debugElement.query(By.css('[data-automation-id="active-tasks-none"]'));
expect(msgEl).not.toBeNull();
});
it('should initially render message about no completed tasks if no process instance ID provided', async () => {
component.processInstanceDetails = undefined;
fixture.detectChanges();
fixture.whenStable().then(() => {
const msgEl = fixture.debugElement.query(By.css('[data-automation-id="completed-tasks-none"]'));
expect(msgEl).not.toBeNull();
});
}));
await fixture.whenStable();
const msgEl = fixture.debugElement.query(By.css('[data-automation-id="completed-tasks-none"]'));
expect(msgEl).not.toBeNull();
});
it('should not render active tasks list if no process instance ID provided', () => {
component.processInstanceDetails = undefined;
@@ -91,30 +92,32 @@ describe('ProcessInstanceTasksComponent', () => {
expect(listEl).toBeNull();
});
it('should display active tasks', async(() => {
it('should display active tasks', async () => {
const change = new SimpleChange(null, exampleProcessInstance, true);
fixture.detectChanges();
component.ngOnChanges({ 'processInstanceDetails': change });
fixture.whenStable().then(() => {
fixture.detectChanges();
component.ngOnChanges({ 'processInstanceDetails': change });
const listEl = fixture.debugElement.query(By.css('[data-automation-id="active-tasks"]'));
expect(listEl).not.toBeNull();
expect(listEl.queryAll(By.css('mat-list-item')).length).toBe(1);
});
}));
it('should display completed tasks', async(() => {
fixture.detectChanges();
await fixture.whenStable();
component.ngOnChanges({ 'processInstanceDetails': change });
const listEl = fixture.debugElement.query(By.css('[data-automation-id="active-tasks"]'));
expect(listEl).not.toBeNull();
expect(listEl.queryAll(By.css('mat-list-item')).length).toBe(1);
});
it('should display completed tasks', async () => {
const change = new SimpleChange(null, exampleProcessInstance, true);
fixture.detectChanges();
component.ngOnChanges({ 'processInstanceDetails': change });
fixture.whenStable().then(() => {
fixture.detectChanges();
const listEl = fixture.debugElement.query(By.css('[data-automation-id="completed-tasks"]'));
expect(listEl).not.toBeNull();
expect(listEl.queryAll(By.css('mat-list-item')).length).toBe(1);
});
}));
fixture.detectChanges();
await fixture.whenStable();
const listEl = fixture.debugElement.query(By.css('[data-automation-id="completed-tasks"]'));
expect(listEl).not.toBeNull();
expect(listEl.queryAll(By.css('mat-list-item')).length).toBe(1);
});
describe('task reloading', () => {
@@ -122,35 +125,37 @@ describe('ProcessInstanceTasksComponent', () => {
component.processInstanceDetails = exampleProcessInstance;
});
it('should render a refresh button by default', async(() => {
it('should render a refresh button by default', async () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(fixture.debugElement.query(By.css('.process-tasks-refresh'))).not.toBeNull();
});
}));
await fixture.whenStable();
it('should render a refresh button if configured to', async(() => {
expect(fixture.debugElement.query(By.css('.process-tasks-refresh'))).not.toBeNull();
});
it('should render a refresh button if configured to', async () => {
component.showRefreshButton = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(fixture.debugElement.query(By.css('.process-tasks-refresh'))).not.toBeNull();
});
}));
it('should NOT render a refresh button if configured not to', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(fixture.debugElement.query(By.css('.process-tasks-refresh'))).not.toBeNull();
});
it('should NOT render a refresh button if configured not to', async () => {
component.showRefreshButton = false;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(fixture.debugElement.query(By.css('.process-tasks-refresh'))).toBeNull();
});
}));
it('should call service to get tasks when reload button clicked', async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
component.onRefreshClicked();
expect(service.getProcessTasks).toHaveBeenCalled();
});
}));
await fixture.whenStable();
expect(fixture.debugElement.query(By.css('.process-tasks-refresh'))).toBeNull();
});
it('should call service to get tasks when reload button clicked', async () => {
fixture.detectChanges();
await fixture.whenStable();
component.onRefreshClicked();
expect(service.getProcessTasks).toHaveBeenCalled();
});
});
});

View File

@@ -16,7 +16,7 @@
*/
import { Component, SimpleChange, ViewChild, OnInit, Output, EventEmitter } from '@angular/core';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { of, throwError, Subject } from 'rxjs';
import { By } from '@angular/platform-browser';
import { ProcessInstanceListComponent } from './process-list.component';
@@ -57,7 +57,7 @@ describe('ProcessInstanceListComponent', () => {
]
});
beforeEach(async(() => {
beforeEach(() => {
fixture = TestBed.createComponent(ProcessInstanceListComponent);
component = fixture.componentInstance;
appConfig = TestBed.inject(AppConfigService);
@@ -67,7 +67,7 @@ describe('ProcessInstanceListComponent', () => {
appConfig.config['adf-process-list'] = {
'presets': fakeProcessColumnSchema
};
}));
});
it('should display loading spinner', () => {
component.isLoading = true;
@@ -128,7 +128,7 @@ describe('ProcessInstanceListComponent', () => {
expect(emitSpy).toHaveBeenCalledWith(jasmine.objectContaining(fakeProcessInstance));
}));
it('should return the process instances list in original order when datalist passed non-existent columns', async(() => {
it('should return the process instances list in original order when datalist passed non-existent columns', (done) => {
component.data = new ObjectDataTableAdapter(
[],
[
@@ -144,20 +144,22 @@ describe('ProcessInstanceListComponent', () => {
expect(component.rows.length).toEqual(2);
expect(component.rows[0]['name']).toEqual('Process 773443333');
expect(component.rows[1]['name']).toEqual('Process 382927392');
done();
});
fixture.detectChanges();
}));
});
it('should return a default name if no name is specified on the process', async(() => {
it('should return a default name if no name is specified on the process', (done) => {
getProcessInstancesSpy = getProcessInstancesSpy.and.returnValue(of(fakeProcessInstancesWithNoName));
component.appId = 1;
component.state = 'open';
component.success.subscribe(() => {
expect(component.rows[0]['name']).toEqual('Fake Process Name - Nov 9, 2017, 12:36:14 PM');
expect(component.rows[1]['name']).toEqual('Fake Process Name - Nov 9, 2017, 12:37:25 PM');
done();
});
fixture.detectChanges();
}));
});
it('should return a currentId null when the processList is empty', () => {
component.selectFirst();
@@ -263,7 +265,7 @@ describe('ProcessInstanceListComponent', () => {
component.onRowKeyUp(keyEvent);
});
it('should NOT emit row click event on every other key', async(() => {
it('should NOT emit row click event on every other key', async () => {
let triggered = false;
const keyEvent = new CustomEvent('Keyboard event', { detail: {
keyboardEvent: { key: 'Space' },
@@ -273,12 +275,13 @@ describe('ProcessInstanceListComponent', () => {
component.rowClick.subscribe(() => triggered = true);
component.onRowKeyUp(keyEvent);
fixture.whenStable().then(() => {
expect(triggered).toBeFalsy();
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('should show custom resolved value in the column', async(() => {
expect(triggered).toBeFalsy();
});
it('should show custom resolved value in the column', async () => {
appConfig.config['adf-process-list'] = {
'presets': {
'fakeProcessCustomSchema': [
@@ -294,13 +297,13 @@ describe('ProcessInstanceListComponent', () => {
component.resolverFn = resolverfn;
component.reload();
fixture.whenStable().then(() => {
fixture.detectChanges();
const customColumn = fixture.debugElement.queryAll(By.css('[title="Variables"] adf-datatable-cell'));
expect(customColumn[0].nativeElement.innerText).toEqual('initiator - fake-user-1');
expect(customColumn[1].nativeElement.innerText).toEqual('initiator - fake-user-2');
});
}));
fixture.detectChanges();
await fixture.whenStable();
const customColumn = fixture.debugElement.queryAll(By.css('[title="Variables"] adf-datatable-cell'));
expect(customColumn[0].nativeElement.innerText).toEqual('initiator - fake-user-1');
expect(customColumn[1].nativeElement.innerText).toEqual('initiator - fake-user-2');
});
describe('component changes', () => {

View File

@@ -16,7 +16,7 @@
*/
import { DebugElement, SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivitiContentService, AppConfigService, FormService, setupTestBed, AppsProcessService } from '@alfresco/adf-core';
import { of, throwError } from 'rxjs';
import { MatSelectChange } from '@angular/material/select';
@@ -105,49 +105,56 @@ describe('StartFormComponent', () => {
fixture.detectChanges();
});
it('should enable start button when name and process filled out', async(() => {
it('should enable start button when name and process filled out', async () => {
spyOn(component, 'loadProcessDefinitions').and.callThrough();
component.processNameInput.setValue('My Process');
component.processDefinitionInput.setValue(testProcessDef.name);
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn.disabled).toBe(false);
});
}));
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn.disabled).toBe(false);
});
it('should have start button disabled when name not filled out', async(() => {
it('should have start button disabled when name not filled out', async () => {
spyOn(component, 'loadProcessDefinitions').and.callThrough();
component.processNameInput.setValue('');
component.processDefinitionInput.setValue(testProcessDef.name);
fixture.detectChanges();
fixture.whenStable().then(() => {
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn.disabled).toBe(true);
});
}));
it('should have start button disabled when no process is selected', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn.disabled).toBe(true);
});
it('should have start button disabled when no process is selected', async () => {
component.selectedProcessDef = null;
fixture.detectChanges();
fixture.whenStable().then(() => {
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn.disabled).toBe(true);
});
}));
it('should have start button disabled process name has a space as the first or last character.', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn.disabled).toBe(true);
});
it('should have start button disabled process name has a space as the first or last character.', async () => {
component.processNameInput.setValue(' Space in the beginning');
component.processDefinitionInput.setValue(testProcessDef.name);
fixture.detectChanges();
await fixture.whenStable();
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn.disabled).toBe(true);
component.processNameInput.setValue('Space in the end ');
fixture.detectChanges();
await fixture.whenStable();
expect(startBtn.disabled).toBe(true);
}));
});
});
describe('with start form', () => {
@@ -159,60 +166,74 @@ describe('StartFormComponent', () => {
component.ngOnChanges({ 'appId': change });
});
it('should initialize start form', async(() => {
it('should initialize start form', async () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(component.startForm).toBeDefined();
expect(component.startForm).not.toBeNull();
});
}));
await fixture.whenStable();
it('should have labels for process name and type', async(() => {
expect(component.startForm).toBeDefined();
expect(component.startForm).not.toBeNull();
});
it('should have labels for process name and type', async () => {
component.processDefinitionInput.setValue('My Default Name');
component.processNameInput.setValue('claim');
fixture.detectChanges();
await fixture.whenStable();
const inputLabelsNodes = document.querySelectorAll('.adf-start-process .adf-process-input-container mat-label');
expect(inputLabelsNodes.length).toBe(2);
}));
});
it('should have floating labels for process name and type', async(() => {
it('should have floating labels for process name and type', async () => {
component.processDefinitionInput.setValue('My Default Name');
component.processNameInput.setValue('claim');
fixture.detectChanges();
await fixture.whenStable();
const inputLabelsNodes = document.querySelectorAll('.adf-start-process .adf-process-input-container');
inputLabelsNodes.forEach(labelNode => {
expect(labelNode.getAttribute('ng-reflect-float-label')).toBe('always');
});
}));
});
it('should load start form from service', async(() => {
it('should load start form from service', async () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(getStartFormDefinitionSpy).toHaveBeenCalled();
});
}));
await fixture.whenStable();
expect(getStartFormDefinitionSpy).toHaveBeenCalled();
});
it('should have start button disabled if the process is not selected', async(() => {
it('should have start button disabled if the process is not selected', async () => {
component.name = 'My new process';
fixture.detectChanges();
fixture.whenStable().then(() => {
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn).toBeNull();
});
}));
it('should emit cancel event on cancel Button', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn).toBeNull();
});
it('should emit cancel event on cancel Button', async () => {
fixture.detectChanges();
await fixture.whenStable();
const cancelButton = fixture.nativeElement.querySelector('#cancel_process');
const cancelSpy: jasmine.Spy = spyOn(component.cancel, 'emit');
cancelButton.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cancelSpy).toHaveBeenCalled();
});
}));
await fixture.whenStable();
expect(cancelSpy).toHaveBeenCalled();
});
it('should return true if startFrom defined', async () => {
component.name = 'my:process1';
fixture.detectChanges();
await fixture.whenStable();
expect(component.hasStartForm()).toBe(true);
});
});
@@ -233,7 +254,7 @@ describe('StartFormComponent', () => {
expect(component.alfrescoRepositoryName).toBe('alfresco-1-fake-repo-name');
});
it('if values in input is a node should be linked in the process service', async(() => {
it('if values in input is a node should be linked in the process service', async () => {
component.values = {};
component.values['file'] = {
isFile: true,
@@ -242,13 +263,14 @@ describe('StartFormComponent', () => {
component.moveNodeFromCStoPS();
fixture.whenStable().then(() => {
expect(component.movedNodeToPS.file[0].id).toBe(1234);
expect(applyAlfrescoNodeSpy).toHaveBeenCalled();
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('if values in input is a collection of nodes should be linked in the process service', async(() => {
expect(component.movedNodeToPS.file[0].id).toBe(1234);
expect(applyAlfrescoNodeSpy).toHaveBeenCalled();
});
it('if values in input is a collection of nodes should be linked in the process service', async () => {
component.values = {};
component.values['file'] = [
{
@@ -267,13 +289,14 @@ describe('StartFormComponent', () => {
component.moveNodeFromCStoPS();
fixture.whenStable().then(() => {
expect(component.movedNodeToPS.file.length).toBe(3);
expect(component.movedNodeToPS.file[0].id).toBe(1234);
expect(component.movedNodeToPS.file[1].id).toBe(1234);
expect(applyAlfrescoNodeSpy).toHaveBeenCalledTimes(3);
});
}));
fixture.detectChanges();
await fixture.whenStable();
expect(component.movedNodeToPS.file.length).toBe(3);
expect(component.movedNodeToPS.file[0].id).toBe(1234);
expect(component.movedNodeToPS.file[1].id).toBe(1234);
expect(applyAlfrescoNodeSpy).toHaveBeenCalledTimes(3);
});
});
});
@@ -314,94 +337,102 @@ describe('StartFormComponent', () => {
});
});
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([]));
component.appId = 123;
const change = new SimpleChange(null, 123, true);
component.ngOnChanges({ 'appId': change });
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const noProcessElement = fixture.nativeElement.querySelector('.adf-empty-content__title');
expect(noProcessElement).not.toBeNull('Expected no available process message to be present');
expect(noProcessElement.innerText.trim()).toBe('ADF_PROCESS_LIST.START_PROCESS.NO_PROCESS_DEFINITIONS');
});
}));
const noProcessElement = fixture.nativeElement.querySelector('.adf-empty-content__title');
expect(noProcessElement).not.toBeNull('Expected no available process message to be present');
expect(noProcessElement.innerText.trim()).toBe('ADF_PROCESS_LIST.START_PROCESS.NO_PROCESS_DEFINITIONS');
});
it('should select processDefinition based on processDefinition input', async(() => {
it('should select processDefinition based on processDefinition input', async () => {
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(testMultipleProcessDefs));
component.appId = 123;
component.processNameInput.setValue('My Process 2');
component.processDefinitionInput.setValue('My Process 2');
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(component.selectedProcessDef.name).toBe(JSON.parse(JSON.stringify(testMultipleProcessDefs[1])).name);
});
}));
it('should select automatically the processDefinition if the app contain only one', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(component.selectedProcessDef.name).toBe(JSON.parse(JSON.stringify(testMultipleProcessDefs[1])).name);
});
it('should select automatically the processDefinition if the app contain only one', async () => {
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(testProcessDefinitions));
component.appId = 123;
const change = new SimpleChange(null, 123, true);
component.ngOnChanges({ 'appId': change });
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(component.selectedProcessDef.name).toBe(JSON.parse(JSON.stringify(testProcessDefinitions[0])).name);
});
}));
it('should not select automatically any processDefinition if the app contain multiple process and does not have any processDefinition as input', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(component.selectedProcessDef.name).toBe(JSON.parse(JSON.stringify(testProcessDefinitions[0])).name);
});
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));
component.appId = 123;
const change = new SimpleChange(null, 123, true);
component.ngOnChanges({ 'appId': change });
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(component.selectedProcessDef.name).toBeNull();
});
}));
await fixture.whenStable();
expect(component.selectedProcessDef.name).toBeNull();
});
describe('dropdown', () => {
it('should hide the process dropdown button if showSelectProcessDropdown is false', async(() => {
it('should hide the process dropdown button if showSelectProcessDropdown is false', async () => {
fixture.detectChanges();
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of([testProcessDef]));
component.appId = 123;
component.showSelectProcessDropdown = false;
component.ngOnChanges({});
fixture.detectChanges();
fixture.whenStable().then(() => {
const selectElement = fixture.nativeElement.querySelector('button#adf-select-process-dropdown');
expect(selectElement).toBeNull();
});
}));
it('should show the process dropdown button if showSelectProcessDropdown is false', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const selectElement = fixture.nativeElement.querySelector('button#adf-select-process-dropdown');
expect(selectElement).toBeNull();
});
it('should show the process dropdown button if showSelectProcessDropdown is false', async () => {
fixture.detectChanges();
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(testMultipleProcessDefs));
component.appId = 123;
component.processDefinitionName = 'My Process 2';
component.showSelectProcessDropdown = true;
component.ngOnChanges({});
fixture.detectChanges();
fixture.whenStable().then(() => {
const selectElement = fixture.nativeElement.querySelector('button#adf-select-process-dropdown');
expect(selectElement).not.toBeNull();
});
}));
it('should show the process dropdown button by default', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const selectElement = fixture.nativeElement.querySelector('button#adf-select-process-dropdown');
expect(selectElement).not.toBeNull();
});
it('should show the process dropdown button by default', async () => {
fixture.detectChanges();
await fixture.whenStable();
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(testMultipleProcessDefs));
component.appId = 123;
component.processDefinitionName = 'My Process 2';
component.ngOnChanges({});
fixture.detectChanges();
fixture.whenStable().then(() => {
const selectElement = fixture.nativeElement.querySelector('button#adf-select-process-dropdown');
expect(selectElement).not.toBeNull();
});
}));
await fixture.whenStable();
const selectElement = fixture.nativeElement.querySelector('button#adf-select-process-dropdown');
expect(selectElement).not.toBeNull();
});
});
});
@@ -409,23 +440,20 @@ describe('StartFormComponent', () => {
const change = new SimpleChange(123, 456, true);
beforeEach(async(() => {
beforeEach(async () => {
component.appId = 123;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
getDefinitionsSpy.calls.reset();
});
}));
});
it('should reload processes when appId input changed', async(() => {
it('should reload processes when appId input changed', async () => {
component.appId = 456;
component.ngOnChanges({ appId: change });
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(getDefinitionsSpy).toHaveBeenCalledWith(456);
});
}));
await fixture.whenStable();
expect(getDefinitionsSpy).toHaveBeenCalledWith(456);
});
it('should get current processDef', () => {
component.appId = 456;
@@ -445,31 +473,37 @@ describe('StartFormComponent', () => {
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 () => {
component.processDefinitionSelectionChanged(testProcessDef);
component.startProcess();
fixture.whenStable().then(() => {
expect(startProcessSpy).toHaveBeenCalled();
});
}));
it('should avoid calling service to start process if required fields NOT provided', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(startProcessSpy).toHaveBeenCalled();
});
it('should avoid calling service to start process if required fields NOT provided', async () => {
component.name = '';
component.startProcess();
fixture.whenStable().then(() => {
expect(startProcessSpy).not.toHaveBeenCalled();
});
}));
it('should call service to start process with the correct parameters', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(startProcessSpy).not.toHaveBeenCalled();
});
it('should call service to start process with the correct parameters', async () => {
component.processDefinitionSelectionChanged(testProcessDef);
component.startProcess();
fixture.whenStable().then(() => {
expect(startProcessSpy).toHaveBeenCalledWith('my:process1', 'My new process', undefined, undefined, undefined);
});
}));
it('should call service to start process with the variables setted', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(startProcessSpy).toHaveBeenCalledWith('my:process1', 'My new process', undefined, undefined, undefined);
});
it('should call service to start process with the variables setted', async () => {
const inputProcessVariable: ProcessInstanceVariable[] = [];
const variable: ProcessInstanceVariable = {};
@@ -481,19 +515,23 @@ describe('StartFormComponent', () => {
component.variables = inputProcessVariable;
component.processDefinitionSelectionChanged(testProcessDef);
component.startProcess();
fixture.whenStable().then(() => {
expect(startProcessSpy).toHaveBeenCalledWith('my:process1', 'My new process', undefined, undefined, inputProcessVariable);
});
}));
it('should output start event when process started successfully', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(startProcessSpy).toHaveBeenCalledWith('my:process1', 'My new process', undefined, undefined, inputProcessVariable);
});
it('should output start event when process started successfully', async () => {
const emitSpy = spyOn(component.start, 'emit');
component.processDefinitionSelectionChanged(testProcessDef);
component.startProcess();
fixture.whenStable().then(() => {
expect(emitSpy).toHaveBeenCalledWith(newProcess);
});
}));
fixture.detectChanges();
await fixture.whenStable();
expect(emitSpy).toHaveBeenCalledWith(newProcess);
});
it('should emit start event when start select a process and add a name', (done) => {
const disposableStart = component.start.subscribe(() => {

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { mockError, fakeProcessFiltersResponse } from '../../mock';
import { FilterProcessRepresentationModel } from '../models/filter-process.model';
import { ProcessFilterService } from './process-filter.service';
@@ -96,14 +96,6 @@ describe('Process filter', () => {
);
});
it('should return the non-empty filter list that is returned by the API', async(() => {
service.getProcessFilters(null).subscribe(
(res) => {
expect(res.length).toBe(1);
}
);
}));
it('should return the default filters', (done) => {
service.createDefaultFilters(1234).subscribe((res: FilterProcessRepresentationModel []) => {
expect(res).toBeDefined();
@@ -185,16 +177,17 @@ describe('Process filter', () => {
});
});
it('should pass on any error that is returned by the API', async(() => {
it('should pass on any error that is returned by the API', (done) => {
getFilters = getFilters.and.returnValue(Promise.reject(mockError));
service.getProcessFilters(null).subscribe(
() => {},
(res) => {
expect(res).toBe(mockError);
done();
}
);
}));
});
});
@@ -213,32 +206,35 @@ describe('Process filter', () => {
expect(createFilter).toHaveBeenCalledWith(filter);
});
it('should return the created filter', async(() => {
service.addProcessFilter(filter).subscribe((createdFilter: FilterProcessRepresentationModel) => {
it('should return the created filter', (done) => {
service.addProcessFilter(filter).subscribe((createdFilter) => {
expect(createdFilter).toBe(filter);
done();
});
}));
});
it('should pass on any error that is returned by the API', async(() => {
it('should pass on any error that is returned by the API', (done) => {
createFilter = createFilter.and.returnValue(Promise.reject(mockError));
service.addProcessFilter(filter).subscribe(
() => {},
(res) => {
expect(res).toBe(mockError);
done();
}
);
}));
});
it('should return a default error if no data is returned by the API', async(() => {
it('should return a default error if no data is returned by the API', (done) => {
createFilter = createFilter.and.returnValue(Promise.reject(null));
service.addProcessFilter(filter).subscribe(
() => {},
(res) => {
expect(res).toBe('Server error');
done();
}
);
}));
});
});
});

View File

@@ -15,8 +15,8 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { exampleProcess, fakeProcessInstances, mockError, fakeProcessDef, fakeTasksList } from '../../mock';
import { TestBed } from '@angular/core/testing';
import { exampleProcess, mockError, fakeProcessDef, fakeTasksList } from '../../mock';
import { ProcessFilterParamRepresentationModel } from '../models/filter-process.model';
import { ProcessInstanceVariable } from '../models/process-instance-variable.model';
import { ProcessService } from './process.service';
@@ -45,9 +45,6 @@ describe('ProcessService', () => {
});
describe('process instances', () => {
let getProcessInstances: jasmine.Spy;
const filter = new ProcessFilterParamRepresentationModel({
processDefinitionId: '1',
appDefinitionId: '1',
@@ -57,118 +54,47 @@ describe('ProcessService', () => {
});
beforeEach(() => {
getProcessInstances = spyOn(alfrescoApi.activiti.processApi, 'getProcessInstances')
spyOn(alfrescoApi.activiti.processApi, 'getProcessInstances')
.and
.returnValue(Promise.resolve({ data: [ exampleProcess ] }));
});
it('should return the correct number of instances', async(() => {
it('should return the correct number of instances', (done) => {
service.getProcessInstances(filter).subscribe((instances) => {
expect(instances.data.length).toBe(1);
done();
});
}));
});
it('should return the correct instance data', async(() => {
it('should return the correct instance data', (done) => {
service.getProcessInstances(filter).subscribe((instances) => {
const instance = instances.data[0];
expect(instance.id).toBe(exampleProcess.id);
expect(instance.name).toBe(exampleProcess.name);
expect(instance.started).toBe(exampleProcess.started);
done();
});
}));
it('should filter by processDefinitionKey', async(() => {
getProcessInstances = getProcessInstances.and.returnValue(Promise.resolve(fakeProcessInstances));
service.getProcessInstances(filter, 'fakeProcessDefinitionKey1').subscribe((instances) => {
expect(instances.data.length).toBe(1);
const instance = instances.data[0];
expect(instance.id).toBe('340124');
/* cspell:disable-next-line */
expect(instance.name).toBe('James Franklin EMEA Onboarding');
expect(instance.started).toEqual(new Date('2017-10-09T12:19:44.560+0000'));
});
}));
it('should call service to fetch process instances', () => {
service.getProcessInstances(filter);
expect(getProcessInstances).toHaveBeenCalled();
});
it('should call service with supplied parameters', () => {
service.getProcessInstances(filter);
expect(getProcessInstances).toHaveBeenCalledWith(filter);
});
it('should pass on any error that is returned by the API', async(() => {
getProcessInstances = getProcessInstances.and.returnValue(Promise.reject(mockError));
service.getProcessInstances(null).subscribe(
() => {},
(res) => {
expect(res).toBe(mockError);
}
);
}));
it('should return a default error if no data is returned by the API', async(() => {
getProcessInstances = getProcessInstances.and.returnValue(Promise.reject(null));
service.getProcessInstances(null).subscribe(
() => {},
(res) => {
expect(res).toBe('Server error');
}
);
}));
});
describe('process instance', () => {
const processId = 'test';
let getProcessInstance: jasmine.Spy;
beforeEach(() => {
getProcessInstance = spyOn(alfrescoApi.activiti.processApi, 'getProcessInstance')
spyOn(alfrescoApi.activiti.processApi, 'getProcessInstance')
.and
.returnValue(Promise.resolve(exampleProcess));
});
it('should return the correct instance data', async(() => {
it('should return the correct instance data', (done) => {
service.getProcess(processId).subscribe((instance) => {
expect(instance.id).toBe(exampleProcess.id);
expect(instance.name).toBe(exampleProcess.name);
expect(instance.started).toBe(exampleProcess.started);
done();
});
}));
it('should call service to fetch process instances', () => {
service.getProcess(processId);
expect(getProcessInstance).toHaveBeenCalled();
});
it('should call service with supplied process ID', () => {
service.getProcess(processId);
expect(getProcessInstance).toHaveBeenCalledWith(processId);
});
it('should pass on any error that is returned by the API', async(() => {
getProcessInstance = getProcessInstance.and.returnValue(Promise.reject(mockError));
service.getProcess(null).subscribe(
() => {},
(res) => {
expect(res).toBe(mockError);
}
);
}));
it('should return a default error if no data is returned by the API', async(() => {
getProcessInstance = getProcessInstance.and.returnValue(Promise.reject(null));
service.getProcess(null).subscribe(
() => {},
(res) => {
expect(res).toBe('Server error');
}
);
}));
});
describe('start process instance', () => {
@@ -203,35 +129,38 @@ describe('ProcessService', () => {
});
});
it('should return the created process instance', async(() => {
it('should return the created process instance', (done) => {
service.startProcess(processDefId, processName).subscribe((createdProcess) => {
expect(createdProcess.id).toBe(exampleProcess.id);
expect(createdProcess.name).toBe(exampleProcess.name);
expect(createdProcess.started).toBe(exampleProcess.started);
expect(createdProcess.startedBy.id).toBe(exampleProcess.startedBy.id);
done();
});
}));
});
it('should pass on any error that is returned by the API', async(() => {
it('should pass on any error that is returned by the API', (done) => {
startNewProcessInstance = startNewProcessInstance.and.returnValue(Promise.reject(mockError));
service.startProcess(processDefId, processName).subscribe(
() => {},
(res) => {
expect(res).toBe(mockError);
done();
}
);
}));
});
it('should return a default error if no data is returned by the API', async(() => {
it('should return a default error if no data is returned by the API', (done) => {
startNewProcessInstance = startNewProcessInstance.and.returnValue(Promise.reject(null));
service.startProcess(processDefId, processName).subscribe(
() => {},
(res) => {
expect(res).toBe('Server error');
done();
}
);
}));
});
});
describe('cancel process instance', () => {
@@ -261,25 +190,27 @@ describe('ProcessService', () => {
});
});
it('should pass on any error that is returned by the API', async(() => {
it('should pass on any error that is returned by the API', (done) => {
deleteProcessInstance = deleteProcessInstance.and.returnValue(Promise.reject(mockError));
service.cancelProcess(null).subscribe(
() => {},
(res) => {
expect(res).toBe(mockError);
done();
}
);
}));
});
it('should return a default error if no data is returned by the API', async(() => {
it('should return a default error if no data is returned by the API', (done) => {
deleteProcessInstance = deleteProcessInstance.and.returnValue(Promise.reject(null));
service.cancelProcess(null).subscribe(
() => {},
(res) => {
expect(res).toBe('Server error');
done();
}
);
}));
});
});
describe('process definitions', () => {
@@ -292,24 +223,19 @@ describe('ProcessService', () => {
.returnValue(Promise.resolve({ data: [ fakeProcessDef, fakeProcessDef ] }));
});
it('should return the correct number of process defs', async(() => {
it('should return the correct number of process defs', (done) => {
service.getProcessDefinitions().subscribe((defs) => {
expect(defs.length).toBe(2);
done();
});
}));
});
it('should return the correct process def data', async(() => {
it('should return the correct process def data', (done) => {
service.getProcessDefinitions().subscribe((defs) => {
expect(defs[0].id).toBe(fakeProcessDef.id);
expect(defs[0].key).toBe(fakeProcessDef.key);
expect(defs[0].name).toBe(fakeProcessDef.name);
});
}));
it('should call API with correct parameters when no appId provided', () => {
service.getProcessDefinitions();
expect(getProcessDefinitions).toHaveBeenCalledWith({
latest: true
done();
});
});
@@ -322,25 +248,27 @@ describe('ProcessService', () => {
});
});
it('should pass on any error that is returned by the API', async(() => {
it('should pass on any error that is returned by the API', (done) => {
getProcessDefinitions = getProcessDefinitions.and.returnValue(Promise.reject(mockError));
service.getProcessDefinitions().subscribe(
() => {},
(res) => {
expect(res).toBe(mockError);
done();
}
);
}));
});
it('should return a default error if no data is returned by the API', async(() => {
it('should return a default error if no data is returned by the API', (done) => {
getProcessDefinitions = getProcessDefinitions.and.returnValue(Promise.reject(null));
service.getProcessDefinitions().subscribe(
() => {},
(res) => {
expect(res).toBe('Server error');
done();
}
);
}));
});
});
describe('process instance tasks', () => {
@@ -354,21 +282,23 @@ describe('ProcessService', () => {
.returnValue(Promise.resolve(fakeTasksList));
});
it('should return the correct number of tasks', async(() => {
it('should return the correct number of tasks', (done) => {
service.getProcessTasks(processId).subscribe((tasks) => {
expect(tasks.length).toBe(2);
done();
});
}));
});
it('should return the correct task data', async(() => {
it('should return the correct task data', (done) => {
const fakeTasks = fakeTasksList.data;
service.getProcessTasks(processId).subscribe((tasks) => {
const task = tasks[0];
expect(task.id).toBe(fakeTasks[0].id);
expect(task.name).toBe(fakeTasks[0].name);
expect(task.created).toEqual(moment(new Date('2016-11-10T00:00:00+00:00'), 'YYYY-MM-DD').format());
done();
});
}));
});
it('should call service to fetch process instance tasks', () => {
service.getProcessTasks(processId);
@@ -390,25 +320,27 @@ describe('ProcessService', () => {
});
});
it('should pass on any error that is returned by the API', async(() => {
it('should pass on any error that is returned by the API', (done) => {
listTasks = listTasks.and.returnValue(Promise.reject(mockError));
service.getProcessTasks(processId).subscribe(
() => {},
(res) => {
expect(res).toBe(mockError);
done();
}
);
}));
});
it('should return a default error if no data is returned by the API', async(() => {
it('should return a default error if no data is returned by the API', (done) => {
listTasks = listTasks.and.returnValue(Promise.reject(null));
service.getProcessTasks(processId).subscribe(
() => {},
(res) => {
expect(res).toBe('Server error');
done();
}
);
}));
});
});
describe('process variables', () => {
@@ -440,30 +372,30 @@ describe('ProcessService', () => {
expect(getVariablesSpy).toHaveBeenCalled();
});
it('should pass on any error that is returned by the API', async(() => {
it('should pass on any error that is returned by the API', (done) => {
getVariablesSpy = getVariablesSpy.and.returnValue(Promise.reject(mockError));
service.getProcessInstanceVariables(null).subscribe(
() => {},
(res) => {
expect(res).toBe(mockError);
done();
}
);
}));
});
it('should return a default error if no data is returned by the API', async(() => {
it('should return a default error if no data is returned by the API', (done) => {
getVariablesSpy = getVariablesSpy.and.returnValue(Promise.reject(null));
service.getProcessInstanceVariables(null).subscribe(
() => {},
(res) => {
expect(res).toBe('Server error');
done();
}
);
}));
});
});
describe('create or update variables', () => {
const updatedVariables = [new ProcessInstanceVariable({
name: 'var1',
value: 'Test1'
@@ -477,55 +409,51 @@ describe('ProcessService', () => {
expect(createOrUpdateProcessInstanceVariablesSpy).toHaveBeenCalled();
});
it('should pass on any error that is returned by the API', async(() => {
it('should pass on any error that is returned by the API', (done) => {
createOrUpdateProcessInstanceVariablesSpy = createOrUpdateProcessInstanceVariablesSpy.and.returnValue(Promise.reject(mockError));
service.createOrUpdateProcessInstanceVariables('123', updatedVariables).subscribe(
() => {},
(res) => {
expect(res).toBe(mockError);
done();
}
);
}));
});
it('should return a default error if no data is returned by the API', async(() => {
it('should return a default error if no data is returned by the API', (done) => {
createOrUpdateProcessInstanceVariablesSpy = createOrUpdateProcessInstanceVariablesSpy.and.returnValue(Promise.reject(null));
service.createOrUpdateProcessInstanceVariables('123', updatedVariables).subscribe(
() => {},
(res) => {
expect(res).toBe('Server error');
done();
}
);
}));
});
});
describe('delete variables', () => {
it('should call service to delete variables', () => {
service.deleteProcessInstanceVariable('123', 'myVar');
expect(deleteProcessInstanceVariableSpy).toHaveBeenCalled();
});
it('should pass on any error that is returned by the API', async(() => {
it('should pass on any error that is returned by the API', (done) => {
deleteProcessInstanceVariableSpy = deleteProcessInstanceVariableSpy.and.returnValue(Promise.reject(mockError));
service.deleteProcessInstanceVariable('123', 'myVar').subscribe(
() => {},
(res) => {
expect(res).toBe(mockError);
done();
}
);
}));
});
it('should return a default error if no data is returned by the API', async(() => {
it('should return a default error if no data is returned by the API', (done) => {
deleteProcessInstanceVariableSpy = deleteProcessInstanceVariableSpy.and.returnValue(Promise.reject(null));
service.deleteProcessInstanceVariable('123', 'myVar').subscribe(
() => {},
(res) => {
expect(res).toBe('Server error');
done();
}
);
}));
});
});
});
});

View File

@@ -16,7 +16,7 @@
*/
import { AttachFormComponent } from './attach-form.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { setupTestBed } from '@alfresco/adf-core';
import { ProcessTestingModule } from '../../testing/process.testing.module';
import { TaskListService } from './../services/tasklist.service';
@@ -37,119 +37,128 @@ describe('AttachFormComponent', () => {
]
});
beforeEach(async(() => {
beforeEach(() => {
fixture = TestBed.createComponent(AttachFormComponent);
component = fixture.componentInstance;
element = fixture.nativeElement;
taskService = TestBed.inject(TaskListService);
fixture.detectChanges();
}));
});
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should show the attach button disabled', async(() => {
it('should show the attach button disabled', async () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
const attachButton = fixture.debugElement.query(By.css('#adf-attach-form-attach-button'));
expect(attachButton.nativeElement.disabled).toBeTruthy();
});
}));
await fixture.whenStable();
it('should emit cancel event if clicked on Cancel Button ', async(() => {
const attachButton = fixture.debugElement.query(By.css('#adf-attach-form-attach-button'));
expect(attachButton.nativeElement.disabled).toBeTruthy();
});
it('should emit cancel event if clicked on Cancel Button ', async () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
const emitSpy = spyOn(component.cancelAttachForm, 'emit');
const el = fixture.nativeElement.querySelector('#adf-attach-form-cancel-button');
el.click();
expect(emitSpy).toHaveBeenCalled();
});
}));
await fixture.whenStable();
it('should call attachFormToATask if clicked on attach Button', async(() => {
const emitSpy = spyOn(component.cancelAttachForm, 'emit');
const el = fixture.nativeElement.querySelector('#adf-attach-form-cancel-button');
el.click();
expect(emitSpy).toHaveBeenCalled();
});
it('should call attachFormToATask if clicked on attach Button', async () => {
component.taskId = 1;
component.attachFormControl.setValue(2);
spyOn(taskService, 'attachFormToATask').and.returnValue(of(true));
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#adf-attach-form-attach-button')).toBeDefined();
const el = fixture.nativeElement.querySelector('#adf-attach-form-attach-button');
el.click();
expect(taskService.attachFormToATask).toHaveBeenCalledWith(1, 2);
});
}));
it('should render the attachForm enabled if the user select the different formId', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#adf-attach-form-attach-button')).toBeDefined();
const el = fixture.nativeElement.querySelector('#adf-attach-form-attach-button');
el.click();
expect(taskService.attachFormToATask).toHaveBeenCalledWith(1, 2);
});
it('should render the attachForm enabled if the user select the different formId', async () => {
component.taskId = 1;
component.formId = 2;
component.attachFormControl.setValue(3);
fixture.detectChanges();
spyOn(taskService, 'attachFormToATask').and.returnValue(of(true));
fixture.detectChanges();
fixture.whenStable().then(() => {
const attachButton = fixture.debugElement.query(By.css('#adf-attach-form-attach-button'));
expect(attachButton.nativeElement.disabled).toBeFalsy();
});
}));
it('should render a disabled attachForm button if the user select the original formId', async(() => {
fixture.detectChanges();
await fixture.whenStable();
spyOn(taskService, 'attachFormToATask').and.returnValue(of(true));
fixture.detectChanges();
await fixture.whenStable();
const attachButton = fixture.debugElement.query(By.css('#adf-attach-form-attach-button'));
expect(attachButton.nativeElement.disabled).toBeFalsy();
});
it('should render a disabled attachForm button if the user select the original formId', async () => {
component.taskId = 1;
component.formId = 2;
component.attachFormControl.setValue(3);
fixture.detectChanges();
spyOn(taskService, 'attachFormToATask').and.returnValue(of(true));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
component.attachFormControl.setValue(2);
fixture.detectChanges();
const attachButton = fixture.debugElement.query(By.css('#adf-attach-form-attach-button'));
expect(attachButton.nativeElement.disabled).toBeTruthy();
});
}));
it('should show the adf-form of the selected form', async(() => {
fixture.detectChanges();
await fixture.whenStable();
spyOn(taskService, 'attachFormToATask').and.returnValue(of(true));
fixture.detectChanges();
await fixture.whenStable();
component.attachFormControl.setValue(2);
fixture.detectChanges();
await fixture.whenStable();
const attachButton = fixture.debugElement.query(By.css('#adf-attach-form-attach-button'));
expect(attachButton.nativeElement.disabled).toBeTruthy();
});
it('should show the adf-form of the selected form', async () => {
component.taskId = 1;
component.selectedFormId = 12;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const formContainer = fixture.debugElement.nativeElement.querySelector('adf-form');
expect(formContainer).toBeDefined();
expect(formContainer).not.toBeNull();
});
}));
it('should show the formPreview of the selected form', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const formContainer = fixture.debugElement.nativeElement.querySelector('adf-form');
expect(formContainer).toBeDefined();
expect(formContainer).not.toBeNull();
});
it('should show the formPreview of the selected form', async () => {
component.formKey = 12;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const formContainer = fixture.debugElement.nativeElement.querySelector('.adf-form-container');
expect(formContainer).toBeDefined();
expect(formContainer).toBeNull();
});
}));
it('should remove form if it is present', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const formContainer = fixture.debugElement.nativeElement.querySelector('.adf-form-container');
expect(formContainer).toBeDefined();
expect(formContainer).toBeNull();
});
it('should remove form if it is present', async () => {
component.taskId = 1;
component.attachFormControl.setValue(10);
component.formKey = 12;
spyOn(taskService, 'deleteForm').and.returnValue(of(null));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#adf-attach-form-remove-button')).toBeDefined();
const el = fixture.nativeElement.querySelector('#adf-attach-form-remove-button');
el.click();
expect(component.formId).toBeNull();
});
}));
await fixture.whenStable();
it('should emit success when a form is attached', async(() => {
expect(element.querySelector('#adf-attach-form-remove-button')).toBeDefined();
const el = fixture.nativeElement.querySelector('#adf-attach-form-remove-button');
el.click();
expect(component.formId).toBeNull();
});
it('should emit success when a form is attached', async () => {
component.taskId = 1;
component.attachFormControl.setValue(10);
@@ -163,11 +172,11 @@ describe('AttachFormComponent', () => {
));
fixture.detectChanges();
fixture.whenStable().then(() => {
const emitSpy = spyOn(component.success, 'emit');
const el = fixture.nativeElement.querySelector('#adf-attach-form-attach-button');
el.click();
expect(emitSpy).toHaveBeenCalled();
});
}));
await fixture.whenStable();
const emitSpy = spyOn(component.success, 'emit');
const el = fixture.nativeElement.querySelector('#adf-attach-form-attach-button');
el.click();
expect(emitSpy).toHaveBeenCalled();
});
});

View File

@@ -16,7 +16,7 @@
*/
import { SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TaskDetailsModel } from '../models/task-details.model';
import { ChecklistComponent } from './checklist.component';
import { setupTestBed } from '@alfresco/adf-core';
@@ -40,7 +40,7 @@ describe('ChecklistComponent', () => {
]
});
beforeEach(async(() => {
beforeEach(() => {
service = TestBed.inject(TaskListService);
spyOn(service, 'getTaskChecklist').and.returnValue(of([new TaskDetailsModel({
id: 'fake-check-changed-id',
@@ -52,7 +52,7 @@ describe('ChecklistComponent', () => {
element = fixture.nativeElement;
fixture.detectChanges();
}));
});
it('should show checklist component title', () => {
expect(element.querySelector('[data-automation-id=checklist-label]')).toBeDefined();
@@ -176,7 +176,7 @@ describe('ChecklistComponent', () => {
expect(element.querySelector('#remove-fake-completed-id')).toBeNull();
});
it('should add checklist', async(() => {
it('should add checklist', async () => {
spyOn(service, 'addTask').and.returnValue(of(new TaskDetailsModel({
id: 'fake-check-added-id', name: 'fake-check-added-name'
})));
@@ -185,14 +185,14 @@ describe('ChecklistComponent', () => {
const addButtonDialog = <HTMLElement> window.document.querySelector('#add-check');
addButtonDialog.click();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#check-fake-check-added-id')).not.toBeNull();
expect(element.querySelector('#check-fake-check-added-id').textContent).toContain('fake-check-added-name');
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('should remove a checklist element', async(() => {
expect(element.querySelector('#check-fake-check-added-id')).not.toBeNull();
expect(element.querySelector('#check-fake-check-added-id').textContent).toContain('fake-check-added-name');
});
it('should remove a checklist element', async () => {
spyOn(service, 'deleteTask').and.returnValue(of(null));
checklistComponent.taskId = 'new-fake-task-id';
@@ -200,19 +200,22 @@ describe('ChecklistComponent', () => {
id: 'fake-check-id',
name: 'fake-check-name'
}));
fixture.detectChanges();
await fixture.whenStable();
const checklistElementRemove = <HTMLElement> element.querySelector('#remove-fake-check-id');
expect(checklistElementRemove).toBeDefined();
expect(checklistElementRemove).not.toBeNull();
checklistElementRemove.click();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#fake-check-id')).toBeNull();
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('should send an event when the checklist is deleted', async(() => {
expect(element.querySelector('#fake-check-id')).toBeNull();
});
it('should send an event when the checklist is deleted', async () => {
spyOn(service, 'deleteTask').and.returnValue(of(null));
checklistComponent.taskId = 'new-fake-task-id';
checklistComponent.checklist.push(new TaskDetailsModel({
@@ -221,20 +224,18 @@ describe('ChecklistComponent', () => {
}));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(checklistComponent.checklist.length).toBe(1);
const checklistElementRemove = <HTMLElement> element.querySelector('#remove-fake-check-id');
expect(checklistElementRemove).toBeDefined();
expect(checklistElementRemove).not.toBeNull();
checklistElementRemove.click();
await fixture.whenStable();
expect(checklistComponent.checklist.length).toBe(0);
});
}));
expect(checklistComponent.checklist.length).toBe(1);
const checklistElementRemove = <HTMLElement> element.querySelector('#remove-fake-check-id');
expect(checklistElementRemove).toBeDefined();
expect(checklistElementRemove).not.toBeNull();
checklistElementRemove.click();
it('should show load task checklist on change', async(() => {
expect(checklistComponent.checklist.length).toBe(0);
});
it('should show load task checklist on change', async () => {
checklistComponent.taskId = 'new-fake-task-id';
checklistComponent.checklist.push(new TaskDetailsModel({
id: 'fake-check-id',
@@ -246,31 +247,35 @@ describe('ChecklistComponent', () => {
taskId: change
});
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#check-fake-check-changed-id')).not.toBeNull();
expect(element.querySelector('#check-fake-check-changed-id').textContent).toContain('fake-check-changed-name');
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('should show empty checklist when task id is null', async(() => {
expect(element.querySelector('#check-fake-check-changed-id')).not.toBeNull();
expect(element.querySelector('#check-fake-check-changed-id').textContent).toContain('fake-check-changed-name');
});
it('should show empty checklist when task id is null', async () => {
checklistComponent.taskId = 'new-fake-task-id';
checklistComponent.checklist.push(new TaskDetailsModel({
id: 'fake-check-id',
name: 'fake-check-name'
}));
fixture.detectChanges();
await fixture.whenStable();
checklistComponent.taskId = null;
const change = new SimpleChange(null, 'new-fake-task-id', true);
checklistComponent.ngOnChanges({
taskId: change
});
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#checklist-none-message')).not.toBeNull();
expect(element.querySelector('#checklist-none-message').textContent).toContain('ADF_TASK_LIST.DETAILS.CHECKLIST.NONE');
});
}));
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#checklist-none-message')).not.toBeNull();
expect(element.querySelector('#checklist-none-message').textContent).toContain('ADF_TASK_LIST.DETAILS.CHECKLIST.NONE');
});
it('should emit checklist task created event when the checklist is successfully added', (done) => {
spyOn(service, 'addTask').and.returnValue(of(new TaskDetailsModel({ id: 'fake-check-added-id', name: 'fake-check-added-name' })));

View File

@@ -16,7 +16,7 @@
*/
import { NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { of, throwError } from 'rxjs';
import {
@@ -130,14 +130,15 @@ describe('TaskDetailsComponent', () => {
expect(getTaskDetailsSpy).not.toHaveBeenCalled();
});
it('should send a claim task event when a task is claimed', async(() => {
it('should send a claim task event when a task is claimed', (done) => {
component.claimedTask.subscribe((taskId) => {
expect(taskId).toBe('FAKE-TASK-CLAIM');
done();
});
component.onClaimAction('FAKE-TASK-CLAIM');
}));
});
it('should send a unclaim task event when a task is unclaimed', async(() => {
it('should send a unclaim task event when a task is unclaimed', fakeAsync(() => {
component.claimedTask.subscribe((taskId) => {
expect(taskId).toBe('FAKE-TASK-UNCLAIM');
});
@@ -149,13 +150,13 @@ describe('TaskDetailsComponent', () => {
expect(fixture.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.MESSAGES.NONE');
});
it('should display a form when the task has an associated form', async(() => {
it('should display a form when the task has an associated form', fakeAsync(() => {
component.taskId = '123';
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('adf-form'))).not.toBeNull();
}));
it('should display a form in readonly when the task has an associated form and readOnlyForm is true', async(() => {
it('should display a form in readonly when the task has an associated form and readOnlyForm is true', fakeAsync(() => {
component.readOnlyForm = true;
component.taskId = '123';
fixture.detectChanges();
@@ -163,7 +164,7 @@ describe('TaskDetailsComponent', () => {
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', async(() => {
it('should not display a form when the task does not have an associated form', fakeAsync(() => {
component.taskId = '123';
taskDetailsMock.formKey = undefined;
fixture.detectChanges();
@@ -173,7 +174,7 @@ describe('TaskDetailsComponent', () => {
});
}));
it('should display the claim message when the task is not assigned', async(() => {
it('should display the claim message when the task is not assigned', fakeAsync(() => {
component.taskDetails = taskDetailsWithOutAssigneeMock;
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -183,7 +184,7 @@ describe('TaskDetailsComponent', () => {
});
}));
it('should not display the claim message when the task is assigned', async(() => {
it('should not display the claim message when the task is assigned', fakeAsync(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
const claimMessage = fixture.nativeElement.querySelector('#claim-message-id');
@@ -201,20 +202,17 @@ describe('TaskDetailsComponent', () => {
nullChange = new SimpleChange('123', null, true);
});
beforeEach(async(() => {
beforeEach(() => {
component.taskId = '123';
fixture.detectChanges();
fixture.whenStable().then(() => {
getTaskDetailsSpy.calls.reset();
});
}));
});
it('should fetch new task details when taskId changed', () => {
component.ngOnChanges({ 'taskId': change });
expect(getTaskDetailsSpy).toHaveBeenCalledWith('456');
});
it('should NOT fetch new task details when empty changeset made', async(() => {
it('should NOT fetch new task details when empty changeset made', fakeAsync(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
component.ngOnChanges({});
@@ -222,7 +220,7 @@ describe('TaskDetailsComponent', () => {
});
}));
it('should NOT fetch new task details when taskId changed to null', async(() => {
it('should NOT fetch new task details when taskId changed to null', fakeAsync(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
component.ngOnChanges({ 'taskId': nullChange });
@@ -239,11 +237,10 @@ describe('TaskDetailsComponent', () => {
describe('Form events', () => {
beforeEach(async(() => {
beforeEach(() => {
component.taskId = '123';
fixture.detectChanges();
fixture.whenStable();
}));
});
afterEach(() => {
const overlayContainers = <any> window.document.querySelectorAll('.cdk-overlay-container');
@@ -451,7 +448,7 @@ describe('TaskDetailsComponent', () => {
component.searchUser('fake-search-word');
});
it('should log error message when search fails', async(() => {
it('should log error message when search fails', fakeAsync(() => {
spyOn(peopleProcessService, 'getWorkflowUsers').and.returnValue(throwError(''));
component.peopleSearch.subscribe(() => {

View File

@@ -16,7 +16,7 @@
*/
import { SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppConfigService, AppsProcessService, setupTestBed } from '@alfresco/adf-core';
import { from, of } from 'rxjs';
import { FilterParamsModel, FilterRepresentationModel } from '../models/filter.model';
@@ -303,7 +303,7 @@ describe('TaskFiltersComponent', () => {
expect(component.getFiltersByAppId).toHaveBeenCalled();
});
it('should not change the current filter if no filter with taskid is found', async(() => {
it('should not change the current filter if no filter with taskid is found', () => {
const filter = new FilterRepresentationModel({
name: 'FakeMyTasks',
filter: { state: 'open', assignment: 'fake-assignee' }
@@ -314,7 +314,7 @@ describe('TaskFiltersComponent', () => {
component.selectFilterWithTask('111');
expect(component.currentFilter).toBe(filter);
}));
});
it('should attach specific icon for each filter if showIcon is true', (done) => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters));

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AppConfigService, setupTestBed, BpmUserService, BpmUserModel } from '@alfresco/adf-core';
import { of } from 'rxjs';
@@ -73,183 +73,184 @@ describe('TaskHeaderComponent', () => {
appConfigService = TestBed.inject(AppConfigService);
});
it('should render empty component if no task details provided', async(() => {
it('should render empty component if no task details provided', async () => {
component.taskDetails = undefined;
fixture.detectChanges();
await fixture.whenStable();
expect(fixture.debugElement.children.length).toBe(0);
}));
});
it('should display assignee', async(() => {
it('should display assignee', async () => {
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="header-assignee"] .adf-textitem-clickable-value'));
expect(formNameEl.nativeElement.value).toBe('Wilbur Adams');
});
}));
const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="header-assignee"] .adf-textitem-clickable-value'));
expect(formNameEl.nativeElement.value).toBe('Wilbur Adams');
});
it('should display placeholder if no assignee', async(() => {
it('should display placeholder if no assignee', async () => {
component.taskDetails.assignee = null;
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-assignee"] .adf-textitem-clickable-value'));
expect(valueEl.nativeElement.value).toBe('ADF_TASK_LIST.PROPERTIES.ASSIGNEE_DEFAULT');
});
const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-assignee"] .adf-textitem-clickable-value'));
expect(valueEl.nativeElement.value).toBe('ADF_TASK_LIST.PROPERTIES.ASSIGNEE_DEFAULT');
});
}));
it('should display priority', async(() => {
it('should display priority', async () => {
component.taskDetails.priority = 27;
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-priority"]'));
expect(formNameEl.nativeElement.value).toBe('27');
});
}));
const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-priority"]'));
expect(formNameEl.nativeElement.value).toBe('27');
});
it('should set editable to false if the task has already completed', async(() => {
it('should set editable to false if the task has already completed', async () => {
component.taskDetails.endDate = new Date('05/05/2002');
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const datePicker = fixture.debugElement.query(By.css(`[data-automation-id="datepicker-dueDate"]`));
expect(datePicker).toBeNull('Datepicker should NOT be in DOM');
});
}));
const datePicker = fixture.debugElement.query(By.css(`[data-automation-id="datepicker-dueDate"]`));
expect(datePicker).toBeNull('Datepicker should NOT be in DOM');
});
it('should set editable to true if the task has not completed yet', async(() => {
it('should set editable to true if the task has not completed yet', async () => {
component.taskDetails.endDate = undefined;
component.refreshData();
fixture.detectChanges();
fixture.whenStable().then(() => {
const datePicker = fixture.debugElement.query(By.css(`[data-automation-id="datepicker-dueDate"]`));
expect(datePicker).not.toBeNull('Datepicker should be in DOM');
});
}));
fixture.detectChanges();
await fixture.whenStable();
const datePicker = fixture.debugElement.query(By.css(`[data-automation-id="datepicker-dueDate"]`));
expect(datePicker).not.toBeNull('Datepicker should be in DOM');
});
describe('Claiming', () => {
it('should be able display the claim/release button if showClaimRelease set to true', async(() => {
it('should be able display the claim/release button if showClaimRelease set to true', async () => {
component.taskDetails = new TaskDetailsModel(claimableTaskDetailsMock);
component.showClaimRelease = true;
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
expect(claimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.CLAIM');
});
}));
const claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
expect(claimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.CLAIM');
});
it('should not be able display the claim/release button if showClaimRelease set to false', async(() => {
it('should not be able display the claim/release button if showClaimRelease set to false', async () => {
component.taskDetails = new TaskDetailsModel(claimableTaskDetailsMock);
component.showClaimRelease = false;
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
const claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
expect(claimButton).toBeNull();
});
it('should display the claim button if no assignee', async () => {
component.taskDetails = new TaskDetailsModel(claimableTaskDetailsMock);
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
expect(claimButton).toBeNull();
});
}));
it('should display the claim button if no assignee', async(() => {
component.taskDetails = new TaskDetailsModel(claimableTaskDetailsMock);
component.refreshData();
fixture.detectChanges();
fixture.whenStable().then(() => {
const claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
expect(claimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.CLAIM');
});
}));
it('should display the claim button if the task is claimable', async(() => {
component.taskDetails = new TaskDetailsModel(claimableTaskDetailsMock);
component.refreshData();
fixture.detectChanges();
fixture.whenStable().then(() => {
const claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
expect(component.isTaskClaimable()).toBeTruthy();
expect(claimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.CLAIM');
});
}));
it('should not display the claim/requeue button if the task is not claimable ', async(() => {
component.taskDetails = new TaskDetailsModel(taskDetailsWithOutCandidateGroup);
component.refreshData();
fixture.detectChanges();
fixture.whenStable().then(() => {
const claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
const unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
expect(component.isTaskClaimable()).toBeFalsy();
expect(component.isTaskClaimedByCandidateMember()).toBeFalsy();
expect(unclaimButton).toBeNull();
expect(claimButton).toBeNull();
});
}));
});
it('should display the requeue button if task is claimed by the current logged-in user', async(() => {
component.taskDetails = new TaskDetailsModel(claimedTaskDetailsMock);
component.refreshData();
fixture.detectChanges();
fixture.whenStable().then(() => {
const unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
expect(component.isTaskClaimedByCandidateMember()).toBeTruthy();
expect(unclaimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.UNCLAIM');
});
}));
it('should not display the requeue button to logged in user if task is claimed by other candidate member', async(() => {
component.taskDetails = new TaskDetailsModel(claimedByGroupMemberMock);
component.refreshData();
fixture.detectChanges();
fixture.whenStable().then(() => {
const unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
expect(component.isTaskClaimedByCandidateMember()).toBeFalsy();
expect(unclaimButton).toBeNull();
});
}));
it('should display the claim button if the task is claimable by candidates members', async(() => {
component.taskDetails = new TaskDetailsModel(claimableTaskDetailsMock);
component.refreshData();
fixture.detectChanges();
fixture.whenStable().then(() => {
const claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
expect(component.isTaskClaimable()).toBeTruthy();
expect(component.isTaskClaimedByCandidateMember()).toBeFalsy();
expect(claimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.CLAIM');
});
}));
it('should not display the requeue button if the task is completed', async(() => {
component.taskDetails = new TaskDetailsModel(completedTaskDetailsMock);
component.refreshData();
fixture.detectChanges();
it('should display the claim button if the task is claimable', async () => {
component.taskDetails = new TaskDetailsModel(claimableTaskDetailsMock);
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
const claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
expect(component.isTaskClaimable()).toBeTruthy();
expect(claimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.CLAIM');
});
it('should not display the claim/requeue button if the task is not claimable ', async () => {
component.taskDetails = new TaskDetailsModel(taskDetailsWithOutCandidateGroup);
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
const unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
expect(claimButton).toBeNull();
expect(component.isTaskClaimable()).toBeFalsy();
expect(component.isTaskClaimedByCandidateMember()).toBeFalsy();
expect(unclaimButton).toBeNull();
expect(claimButton).toBeNull();
});
}));
});
it('should display the requeue button if task is claimed by the current logged-in user', async () => {
component.taskDetails = new TaskDetailsModel(claimedTaskDetailsMock);
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
const unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
expect(component.isTaskClaimedByCandidateMember()).toBeTruthy();
expect(unclaimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.UNCLAIM');
});
it('should not display the requeue button to logged in user if task is claimed by other candidate member', async () => {
component.taskDetails = new TaskDetailsModel(claimedByGroupMemberMock);
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
const unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
expect(component.isTaskClaimedByCandidateMember()).toBeFalsy();
expect(unclaimButton).toBeNull();
});
it('should display the claim button if the task is claimable by candidates members', async () => {
component.taskDetails = new TaskDetailsModel(claimableTaskDetailsMock);
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
const claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
expect(component.isTaskClaimable()).toBeTruthy();
expect(component.isTaskClaimedByCandidateMember()).toBeFalsy();
expect(claimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.CLAIM');
});
it('should not display the requeue button if the task is completed', async () => {
component.taskDetails = new TaskDetailsModel(completedTaskDetailsMock);
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
const claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
const unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
expect(claimButton).toBeNull();
expect(unclaimButton).toBeNull();
});
it('should emit claim event when task is claimed', (done) => {
spyOn(service, 'claimTask').and.returnValue(of(null));
@@ -283,121 +284,122 @@ describe('TaskHeaderComponent', () => {
unclaimBtn.nativeElement.click();
});
it('should display due date', async(() => {
it('should display due date', async () => {
component.taskDetails.dueDate = new Date('2016-11-03');
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-dueDate"] .adf-property-value'));
expect(valueEl.nativeElement.innerText.trim()).toBe('Nov 3, 2016');
});
}));
const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-dueDate"] .adf-property-value'));
expect(valueEl.nativeElement.innerText.trim()).toBe('Nov 3, 2016');
});
it('should display placeholder if no due date', async(() => {
it('should display placeholder if no due date', async () => {
component.taskDetails.dueDate = null;
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-dueDate"] .adf-property-value'));
expect(valueEl.nativeElement.innerText.trim()).toBe('ADF_TASK_LIST.PROPERTIES.DUE_DATE_DEFAULT');
});
}));
const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-dueDate"] .adf-property-value'));
expect(valueEl.nativeElement.innerText.trim()).toBe('ADF_TASK_LIST.PROPERTIES.DUE_DATE_DEFAULT');
});
it('should display form name', async(() => {
it('should display form name', async () => {
component.formName = 'test form';
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-formName"] .adf-textitem-clickable-value'));
expect(valueEl.nativeElement.value).toBe('test form');
});
}));
const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-formName"] .adf-textitem-clickable-value'));
expect(valueEl.nativeElement.value).toBe('test form');
});
it('should set clickable to false if the task has already completed', async(() => {
it('should set clickable to false if the task has already completed', async () => {
component.taskDetails.endDate = new Date('05/05/2002');
component.formName = 'test form';
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const clickableForm = fixture.debugElement.query(By.css('[data-automation-id="header-formName"] .adf-textitem-clickable-value'));
expect(clickableForm).toBeNull();
const clickableForm = fixture.debugElement.query(By.css('[data-automation-id="header-formName"] .adf-textitem-clickable-value'));
expect(clickableForm).toBeNull();
const readOnlyForm = fixture.debugElement.query(By.css('[data-automation-id="header-formName"] input'));
expect(readOnlyForm.nativeElement.value).toBe('test form');
});
}));
const readOnlyForm = fixture.debugElement.query(By.css('[data-automation-id="header-formName"] input'));
expect(readOnlyForm.nativeElement.value).toBe('test form');
});
it('should display the default parent value if is undefined', async(() => {
it('should display the default parent value if is undefined', async () => {
component.taskDetails.processInstanceId = null;
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-parentName"] .adf-property-value'));
expect(valueEl.nativeElement.innerText.trim()).toEqual('ADF_TASK_LIST.PROPERTIES.PARENT_NAME_DEFAULT');
});
}));
const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-parentName"] .adf-property-value'));
expect(valueEl.nativeElement.innerText.trim()).toEqual('ADF_TASK_LIST.PROPERTIES.PARENT_NAME_DEFAULT');
});
it('should display the Parent name value', async(() => {
it('should display the Parent name value', async () => {
component.taskDetails.processInstanceId = '1';
component.taskDetails.processDefinitionName = 'Parent Name';
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-parentName"] .adf-property-value'));
expect(valueEl.nativeElement.innerText.trim()).toEqual('Parent Name');
});
}));
const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-parentName"] .adf-property-value'));
expect(valueEl.nativeElement.innerText.trim()).toEqual('Parent Name');
});
it('should not display form name if no form name provided', async(() => {
it('should not display form name if no form name provided', async () => {
component.refreshData();
fixture.detectChanges();
fixture.whenStable().then(() => {
const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-formName"] .adf-property-value'));
expect(valueEl.nativeElement.value).toBe('ADF_TASK_LIST.PROPERTIES.FORM_NAME_DEFAULT');
});
}));
fixture.detectChanges();
await fixture.whenStable();
const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-formName"] .adf-property-value'));
expect(valueEl.nativeElement.value).toBe('ADF_TASK_LIST.PROPERTIES.FORM_NAME_DEFAULT');
});
describe('Config Filtering', () => {
it('should show only the properties from the configuration file', async(() => {
it('should show only the properties from the configuration file', async () => {
spyOn(appConfigService, 'get').and.returnValue(['assignee', 'status']);
component.taskDetails.processInstanceId = '1';
component.taskDetails.processDefinitionName = 'Parent Name';
component.refreshData();
fixture.detectChanges();
await fixture.whenStable();
const propertyList = fixture.debugElement.queryAll(By.css('.adf-property-list .adf-property'));
fixture.whenStable().then(() => {
expect(propertyList).toBeDefined();
expect(propertyList).not.toBeNull();
expect(propertyList.length).toBe(2);
expect(propertyList[0].nativeElement.textContent).toContain('ADF_TASK_LIST.PROPERTIES.ASSIGNEE');
expect(propertyList[1].nativeElement.textContent).toContain('ADF_TASK_LIST.PROPERTIES.STATUS');
});
}));
expect(propertyList).toBeDefined();
expect(propertyList).not.toBeNull();
expect(propertyList.length).toBe(2);
expect(propertyList[0].nativeElement.textContent).toContain('ADF_TASK_LIST.PROPERTIES.ASSIGNEE');
expect(propertyList[1].nativeElement.textContent).toContain('ADF_TASK_LIST.PROPERTIES.STATUS');
});
it('should show all the default properties if there is no configuration', async(() => {
it('should show all the default properties if there is no configuration', async () => {
spyOn(appConfigService, 'get').and.returnValue(null);
component.taskDetails.processInstanceId = '1';
component.taskDetails.processDefinitionName = 'Parent Name';
component.refreshData();
fixture.detectChanges();
fixture.whenStable().then(() => {
const propertyList = fixture.debugElement.queryAll(By.css('.adf-property-list .adf-property'));
expect(propertyList).toBeDefined();
expect(propertyList).not.toBeNull();
expect(propertyList.length).toBe(component.properties.length);
expect(propertyList[0].nativeElement.textContent).toContain('ADF_TASK_LIST.PROPERTIES.ASSIGNEE');
expect(propertyList[1].nativeElement.textContent).toContain('ADF_TASK_LIST.PROPERTIES.STATUS');
});
}));
fixture.detectChanges();
await fixture.whenStable();
const propertyList = fixture.debugElement.queryAll(By.css('.adf-property-list .adf-property'));
expect(propertyList).toBeDefined();
expect(propertyList).not.toBeNull();
expect(propertyList.length).toBe(component.properties.length);
expect(propertyList[0].nativeElement.textContent).toContain('ADF_TASK_LIST.PROPERTIES.ASSIGNEE');
expect(propertyList[1].nativeElement.textContent).toContain('ADF_TASK_LIST.PROPERTIES.STATUS');
});
});
});

View File

@@ -16,7 +16,7 @@
*/
import { Component, SimpleChange, ViewChild, OnInit, Output, EventEmitter } from '@angular/core';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AppConfigService, setupTestBed, DataRowEvent, ObjectDataRow, DataCellEvent, ObjectDataColumn } from '@alfresco/adf-core';
import { TaskListService } from '../services/tasklist.service';
@@ -79,21 +79,22 @@ describe('TaskListComponent', () => {
expect(spinner).toBeDefined();
});
it('should hide loading spinner upon loading complete', async(() => {
it('should hide loading spinner upon loading complete', async () => {
component.isLoading = true;
fixture.detectChanges();
await fixture.whenStable();
let spinner = fixture.debugElement.query(By.css('.mat-progress-spinner'));
expect(spinner).toBeDefined();
component.isLoading = false;
fixture.detectChanges();
fixture.whenStable().then(() => {
spinner = fixture.debugElement.query(By.css('.mat-progress-spinner'));
expect(spinner).toBeNull();
});
}));
fixture.detectChanges();
await fixture.whenStable();
spinner = fixture.debugElement.query(By.css('.mat-progress-spinner'));
expect(spinner).toBeNull();
});
it('should use the default schemaColumn as default', () => {
component.ngAfterContentInit();
@@ -555,126 +556,140 @@ describe('TaskListComponent', () => {
expect(component.columns[1]).toEqual(expectedColumn2);
});
it('should show the updated list when pagination changes', async(() => {
it('should show the updated list when pagination changes', async () => {
spyOn(taskListService, 'findTasksByState').and.returnValues(of(fakeGlobalTask), of(paginatedTask));
const state = new SimpleChange(null, 'open', true);
const processDefinitionKey = new SimpleChange(null, null, true);
const assignment = new SimpleChange(null, 'fake-assignee', true);
component.ngAfterContentInit();
component.ngOnChanges({ 'state': state, 'processDefinitionKey': processDefinitionKey, 'assignment': assignment });
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
let rows = Array.from(fixture.debugElement.nativeElement.querySelectorAll('.adf-datatable-body adf-datatable-row'));
expect(rows.length).toEqual(2);
component.updatePagination({ skipCount: 0, maxItems: 5 });
fixture.detectChanges();
rows = Array.from(fixture.debugElement.nativeElement.querySelectorAll('.adf-datatable-body adf-datatable-row'));
expect(rows.length).toEqual(5);
expect(taskListService.findTasksByState).toHaveBeenCalledTimes(2);
});
let rows = Array.from(fixture.debugElement.nativeElement.querySelectorAll('.adf-datatable-body adf-datatable-row'));
expect(rows.length).toEqual(2);
component.updatePagination({ skipCount: 0, maxItems: 5 });
}));
fixture.detectChanges();
await fixture.whenStable();
it('should be able to select all tasks when multi-selection is enabled', async(() => {
rows = Array.from(fixture.debugElement.nativeElement.querySelectorAll('.adf-datatable-body adf-datatable-row'));
expect(rows.length).toEqual(5);
expect(taskListService.findTasksByState).toHaveBeenCalledTimes(2);
});
it('should be able to select all tasks when multi-selection is enabled', async () => {
spyOn(taskListService, 'findTasksByState').and.returnValues(of(fakeGlobalTask));
const state = new SimpleChange(null, 'open', true);
component.multiselect = true;
component.ngOnChanges({ 'sort': state });
fixture.detectChanges();
await fixture.whenStable();
const selectAllCheckbox = fixture.nativeElement.querySelector('div[class*="adf-datatable-cell-header adf-datatable-checkbox"] .mat-checkbox-inner-container');
selectAllCheckbox.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(component.selectedInstances.length).toBe(2);
expect(component.selectedInstances[0].obj.name).toBe('nameFake1');
expect(component.selectedInstances[1].obj.description).toBe('descriptionFake2');
await fixture.whenStable();
selectAllCheckbox.click();
fixture.detectChanges();
expect(component.selectedInstances.length).toBe(2);
expect(component.selectedInstances[0].obj.name).toBe('nameFake1');
expect(component.selectedInstances[1].obj.description).toBe('descriptionFake2');
expect(component.selectedInstances.length).toBe(0);
});
}));
selectAllCheckbox.click();
it('should be able to unselect a selected tasks using the checkbox', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(component.selectedInstances.length).toBe(0);
});
it('should be able to unselect a selected tasks using the checkbox', async () => {
spyOn(taskListService, 'findTasksByState').and.returnValues(of(fakeGlobalTask));
const state = new SimpleChange(null, 'open', true);
component.multiselect = true;
component.ngOnChanges({ 'sort': state });
fixture.detectChanges();
await fixture.whenStable();
const selectTask1 = fixture.nativeElement.querySelector('[data-automation-id="datatable-row-0"] .mat-checkbox-inner-container');
const selectTask2 = fixture.nativeElement.querySelector('[data-automation-id="datatable-row-1"] .mat-checkbox-inner-container');
selectTask1.click();
selectTask1.click();
selectTask2.click();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
let selectRow1 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-0"]');
let selectRow2 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-1"]');
expect(selectRow1).toBeDefined();
expect(selectRow2).toBeDefined();
expect(component.selectedInstances.length).toBe(2);
let selectRow1 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-0"]');
let selectRow2 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-1"]');
expect(selectRow1).toBeDefined();
expect(selectRow2).toBeDefined();
expect(component.selectedInstances.length).toBe(2);
selectTask2.click();
fixture.detectChanges();
selectTask2.click();
expect(component.selectedInstances.length).toBe(1);
selectRow1 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-0"]');
selectRow2 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-1"]');
expect(selectRow1).toBeDefined();
expect(selectRow2).toBeNull();
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('should not be able to select different row when selection mode is set to NONE and multiselection is enabled', async(() => {
expect(component.selectedInstances.length).toBe(1);
selectRow1 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-0"]');
selectRow2 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-1"]');
expect(selectRow1).toBeDefined();
expect(selectRow2).toBeNull();
});
it('should not be able to select different row when selection mode is set to NONE and multiselection is enabled', async () => {
spyOn(taskListService, 'findTasksByState').and.returnValues(of(fakeGlobalTask));
const state = new SimpleChange(null, 'open', true);
component.multiselect = true;
component.selectionMode = 'none';
component.ngOnChanges({ 'sort': state });
fixture.detectChanges();
await fixture.whenStable();
const selectTask1 = fixture.nativeElement.querySelector('[data-automation-id="datatable-row-0"] .mat-checkbox-inner-container');
const selectTask2 = fixture.nativeElement.querySelector('[data-automation-id="datatable-row-1"] .mat-checkbox-inner-container');
selectTask1.click();
selectTask1.click();
selectTask2.click();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
let selectRow1 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-0"]');
let selectRow2 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-1"]');
expect(selectRow1).toBeDefined();
expect(selectRow2).toBeDefined();
expect(component.selectedInstances.length).toBe(2);
let selectRow1 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-0"]');
let selectRow2 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-1"]');
expect(selectRow1).toBeDefined();
expect(selectRow2).toBeDefined();
expect(component.selectedInstances.length).toBe(2);
selectTask2.click();
fixture.detectChanges();
selectTask2.click();
fixture.detectChanges();
await fixture.whenStable();
expect(component.selectedInstances.length).toBe(1);
selectRow1 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-0"]');
selectRow2 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-1"]');
expect(selectRow1).toBeDefined();
expect(selectRow2).toBeNull();
expect(component.selectedInstances.length).toBe(1);
selectRow1 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-0"]');
selectRow2 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-1"]');
expect(selectRow1).toBeDefined();
expect(selectRow2).toBeNull();
const selectTask2Row = fixture.nativeElement.querySelector('[data-automation-id="text_No name"]');
selectTask2Row.click();
const selectTask2Row = fixture.nativeElement.querySelector('[data-automation-id="text_No name"]');
selectTask2Row.click();
selectRow1 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-0"]');
selectRow2 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-1"]');
expect(selectRow1).toBeDefined();
expect(selectRow2).toBeNull();
});
}));
selectRow1 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-0"]');
selectRow2 = fixture.nativeElement.querySelector('[class*="adf-is-selected"][data-automation-id="datatable-row-1"]');
expect(selectRow1).toBeDefined();
expect(selectRow2).toBeNull();
});
it('should select only one row when selection mode is set to SINGLE and multiselection is enabled', async(() => {
it('should select only one row when selection mode is set to SINGLE and multiselection is enabled', fakeAsync(() => {
spyOn(taskListService, 'findTasksByState').and.returnValues(of(fakeGlobalTask));
const state = new SimpleChange(null, 'open', true);
component.multiselect = true;
@@ -707,28 +722,29 @@ describe('TaskListComponent', () => {
});
}));
it('should change selected row after clicking on different row', async(() => {
it('should change selected row after clicking on different row', async () => {
spyOn(taskListService, 'findTasksByState').and.returnValues(of(fakeGlobalTask));
const state = new SimpleChange(null, 'open', true);
component.ngOnChanges({ 'sort': state });
fixture.detectChanges();
await fixture.whenStable();
const selectTask1 = fixture.nativeElement.querySelector('[data-automation-id="text_nameFake1"]');
const selectTask2 = fixture.nativeElement.querySelector('[data-automation-id="text_No name"]');
selectTask1.click();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
expect(component.currentInstanceId.toString()).toBe('14');
expect(component.currentInstanceId.toString()).toBe('14');
selectTask2.click();
selectTask2.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(component.currentInstanceId.toString()).toBe('2');
});
});
}));
fixture.detectChanges();
await fixture.whenStable();
expect(component.currentInstanceId.toString()).toBe('2');
});
});
@Component({

View File

@@ -16,7 +16,7 @@
*/
import { TaskStandaloneComponent } from './task-standalone.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { setupTestBed } from '@alfresco/adf-core';
import { ProcessTestingModule } from '../../testing/process.testing.module';
import { TranslateModule } from '@ngx-translate/core';
@@ -44,95 +44,103 @@ describe('TaskStandaloneComponent', () => {
fixture.destroy();
});
it('should show Completed message if isCompleted is true', async(() => {
it('should show Completed message if isCompleted is true', async () => {
component.isCompleted = true;
fixture.detectChanges();
const completedFormElement = fixture.debugElement.nativeElement.querySelector('#adf-completed-form-message');
const completedFormSubElement = fixture.debugElement.nativeElement.querySelector('.adf-no-form-submessage');
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#adf-no-form-message')).toBeNull();
expect(completedFormElement).toBeDefined();
expect(completedFormElement.innerText.trim()).toBe('ADF_TASK_LIST.STANDALONE_TASK.COMPLETE_TASK_MESSAGE');
expect(completedFormSubElement).toBeDefined();
expect(completedFormSubElement.innerText).toBe('ADF_TASK_LIST.STANDALONE_TASK.COMPLETE_TASK_SUB_MESSAGE');
expect(element.querySelector('.adf-no-form-mat-card-actions')).toBeDefined();
});
}));
it('should show No form message if isCompleted is false', async(() => {
await fixture.whenStable();
expect(element.querySelector('#adf-no-form-message')).toBeNull();
expect(completedFormElement).toBeDefined();
expect(completedFormElement.innerText.trim()).toBe('ADF_TASK_LIST.STANDALONE_TASK.COMPLETE_TASK_MESSAGE');
expect(completedFormSubElement).toBeDefined();
expect(completedFormSubElement.innerText).toBe('ADF_TASK_LIST.STANDALONE_TASK.COMPLETE_TASK_SUB_MESSAGE');
expect(element.querySelector('.adf-no-form-mat-card-actions')).toBeDefined();
});
it('should show No form message if isCompleted is false', async () => {
component.isCompleted = false;
fixture.detectChanges();
const noFormElement = fixture.debugElement.nativeElement.querySelector('#adf-no-form-message');
fixture.whenStable().then(() => {
expect(noFormElement).toBeDefined();
expect(noFormElement.innerText).toBe('ADF_TASK_LIST.STANDALONE_TASK.NO_FORM_MESSAGE');
expect(element.querySelector('#adf-completed-form-message')).toBeNull();
expect(element.querySelector('.adf-no-form-submessage')).toBeNull();
});
}));
it('should hide Cancel button by default', async(() => {
await fixture.whenStable();
expect(noFormElement).toBeDefined();
expect(noFormElement.innerText).toBe('ADF_TASK_LIST.STANDALONE_TASK.NO_FORM_MESSAGE');
expect(element.querySelector('#adf-completed-form-message')).toBeNull();
expect(element.querySelector('.adf-no-form-submessage')).toBeNull();
});
it('should hide Cancel button by default', async () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#adf-no-form-cancel-button')).toBeNull();
});
}));
await fixture.whenStable();
it('should emit cancel event if clicked on Cancel Button ', async(() => {
expect(element.querySelector('#adf-no-form-cancel-button')).toBeNull();
});
it('should emit cancel event if clicked on Cancel Button ', async () => {
component.hideCancelButton = false;
component.isCompleted = false;
fixture.detectChanges();
fixture.whenStable().then(() => {
const emitSpy = spyOn(component.cancel, 'emit');
const el = fixture.nativeElement.querySelector('#adf-no-form-cancel-button');
el.click();
expect(emitSpy).toHaveBeenCalled();
});
}));
it('should hide Cancel button if hideCancelButton is true', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const emitSpy = spyOn(component.cancel, 'emit');
const el = fixture.nativeElement.querySelector('#adf-no-form-cancel-button');
el.click();
expect(emitSpy).toHaveBeenCalled();
});
it('should hide Cancel button if hideCancelButton is true', async () => {
component.hideCancelButton = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#adf-no-form-cancel-button')).toBeNull();
});
}));
it('should hide Cancel button if isCompleted is true', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#adf-no-form-cancel-button')).toBeNull();
});
it('should hide Cancel button if isCompleted is true', async () => {
component.isCompleted = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#adf-no-form-cancel-button')).toBeNull();
});
}));
it('should emit complete event if clicked on Complete Button', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#adf-no-form-cancel-button')).toBeNull();
});
it('should emit complete event if clicked on Complete Button', async () => {
component.hasCompletePermission = true;
component.isCompleted = false;
fixture.detectChanges();
fixture.whenStable().then(() => {
const emitSpy = spyOn(component.complete, 'emit');
expect(element.querySelector('#adf-no-form-complete-button')).toBeDefined();
const el = fixture.nativeElement.querySelector('#adf-no-form-complete-button');
el.click();
expect(emitSpy).toHaveBeenCalled();
});
}));
it('should hide Complete button if isCompleted is true', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const emitSpy = spyOn(component.complete, 'emit');
expect(element.querySelector('#adf-no-form-complete-button')).toBeDefined();
const el = fixture.nativeElement.querySelector('#adf-no-form-complete-button');
el.click();
expect(emitSpy).toHaveBeenCalled();
});
it('should hide Complete button if isCompleted is true', async () => {
component.isCompleted = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#adf-no-form-complete-button')).toBeNull();
});
}));
it('should hide Complete button if hasCompletePermission is false', async(() => {
component.hasCompletePermission = false;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#adf-no-form-complete-button')).toBeNull();
});
}));
await fixture.whenStable();
expect(element.querySelector('#adf-no-form-complete-button')).toBeNull();
});
it('should hide Complete button if hasCompletePermission is false', async () => {
component.hasCompletePermission = false;
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#adf-no-form-complete-button')).toBeNull();
});
});