diff --git a/lib/content-services/src/lib/aspect-list/aspect-list-dialog.component.spec.ts b/lib/content-services/src/lib/aspect-list/aspect-list-dialog.component.spec.ts index 53e58195e4..787e60ed81 100644 --- a/lib/content-services/src/lib/aspect-list/aspect-list-dialog.component.spec.ts +++ b/lib/content-services/src/lib/aspect-list/aspect-list-dialog.component.spec.ts @@ -305,17 +305,23 @@ describe('AspectListDialogComponent', () => { }); it('Should apply button be disabled by default', async () => { - await fixture.detectChanges(); + fixture.detectChanges(); + await fixture.whenStable(); + const applyButton = fixture.nativeElement.querySelector('#aspect-list-dialog-actions-apply'); expect(applyButton.disabled).toBe(true); }); it('Should apply button get enabled when the aspect list gets updated', async () => { - await fixture.detectChanges(); + fixture.detectChanges(); + await fixture.whenStable(); + const applyButton = fixture.nativeElement.querySelector('#aspect-list-dialog-actions-apply'); fixture.nativeElement.querySelector('#aspect-list-dialog-actions-clear').click(); - await fixture.detectChanges(); + + fixture.detectChanges(); + await fixture.whenStable(); expect(applyButton.disabled).toBe(false); }); diff --git a/lib/content-services/src/lib/aspect-list/aspect-list.service.spec.ts b/lib/content-services/src/lib/aspect-list/aspect-list.service.spec.ts index 051f115233..5f5451af03 100644 --- a/lib/content-services/src/lib/aspect-list/aspect-list.service.spec.ts +++ b/lib/content-services/src/lib/aspect-list/aspect-list.service.spec.ts @@ -16,7 +16,7 @@ */ import { AspectEntry, AspectPaging } from '@alfresco/js-api'; -import { async, TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { MatDialog, MatDialogModule } from '@angular/material/dialog'; import { TranslateModule } from '@ngx-translate/core'; import { AlfrescoApiService, AppConfigService, LogService, setupTestBed } from 'core'; @@ -163,34 +163,37 @@ describe('AspectListService', () => { service = TestBed.inject(AspectListService); }); - it('should get the list of only available aspects', async(() => { + it('should get the list of only available aspects', (done) => { aspectTypesApi.listAspects.and.returnValues(of(listAspectResp), of(customListAspectResp)); service.getAspects().subscribe((list) => { expect(list.length).toBe(2); expect(list[0].entry.id).toBe('frs:AspectOne'); expect(list[1].entry.id).toBe('frs:AspectCustom'); + done(); }); - })); + }); - it('should return a value when the standard aspect call fails', async(() => { + it('should return a value when the standard aspect call fails', (done) => { spyOn(logService, 'error').and.stub(); aspectTypesApi.listAspects.and.returnValues(throwError('Insert Coin'), of(customListAspectResp)); service.getAspects().subscribe((list) => { expect(list.length).toBe(1); expect(list[0].entry.id).toBe('frs:AspectCustom'); expect(logService.error).toHaveBeenCalled(); + done(); }); - })); + }); - it('should return a value when the custom aspect call fails', async(() => { + it('should return a value when the custom aspect call fails', (done) => { spyOn(logService, 'error').and.stub(); aspectTypesApi.listAspects.and.returnValues(of(listAspectResp), throwError('Insert Coin')); service.getAspects().subscribe((list) => { expect(list.length).toBe(1); expect(list[0].entry.id).toBe('frs:AspectOne'); expect(logService.error).toHaveBeenCalled(); + done(); }); - })); + }); }); }); diff --git a/lib/content-services/src/lib/breadcrumb/dropdown-breadcrumb.component.spec.ts b/lib/content-services/src/lib/breadcrumb/dropdown-breadcrumb.component.spec.ts index f7349bc697..e3a5bf3c51 100644 --- a/lib/content-services/src/lib/breadcrumb/dropdown-breadcrumb.component.spec.ts +++ b/lib/content-services/src/lib/breadcrumb/dropdown-breadcrumb.component.spec.ts @@ -16,7 +16,7 @@ */ import { 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 { setupTestBed } from '@alfresco/adf-core'; import { fakeNodeWithCreatePermission } from '../mock'; @@ -42,16 +42,16 @@ describe('DropdownBreadcrumb', () => { providers: [{ provide: DocumentListService, useValue: documentListService }] }); - beforeEach(async(() => { + beforeEach(() => { fixture = TestBed.createComponent(DropdownBreadcrumbComponent); component = fixture.componentInstance; documentList = TestBed.createComponent(DocumentListComponent).componentInstance; documentListService = TestBed.inject(DocumentListService); - })); + }); - afterEach(async(() => { + afterEach(() => { fixture.destroy(); - })); + }); function openSelect() { const folderIcon = fixture.debugElement.nativeElement.querySelector('[data-automation-id="dropdown-breadcrumb-trigger"]'); diff --git a/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.spec.ts b/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.spec.ts index 0c4da5162c..b03c8990dd 100644 --- a/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.spec.ts +++ b/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed, tick, fakeAsync } from '@angular/core/testing'; +import { ComponentFixture, TestBed, tick, fakeAsync } from '@angular/core/testing'; import { SimpleChange } from '@angular/core'; import { By } from '@angular/platform-browser'; import { MinimalNode, Node } from '@alfresco/js-api'; @@ -98,17 +98,18 @@ describe('ContentMetadataComponent', () => { }); describe('Folder', () => { - it('should show the folder node', () => { + it('should show the folder node', (done) => { component.expanded = false; fixture.detectChanges(); - component.ngOnChanges({ node: new SimpleChange(node, folderNode, false) }); - component.basicProperties$.subscribe(() => { fixture.detectChanges(); const basicPropertiesComponent = fixture.debugElement.query(By.directive(CardViewComponent)).componentInstance; expect(basicPropertiesComponent.properties).toBeDefined(); + done(); }); + + component.ngOnChanges({ node: new SimpleChange(node, folderNode, false) }); }); }); @@ -138,10 +139,8 @@ describe('ContentMetadataComponent', () => { it('should save changedProperties on save click', fakeAsync(async () => { component.editable = true; const property = { key: 'properties.property-key', value: 'original-value' }; - const expectedNode = Object.assign({}, node, { name: 'some-modified-value' }); - spyOn(nodesApiService, 'updateNode').and.callFake(() => { - return of(expectedNode); - }); + const expectedNode = { ...node, name: 'some-modified-value' }; + spyOn(nodesApiService, 'updateNode').and.returnValue(of(expectedNode)); updateService.update(property, 'updated-value'); tick(600); @@ -156,7 +155,7 @@ describe('ContentMetadataComponent', () => { expect(nodesApiService.updateNode).toHaveBeenCalled(); })); - it('should throw error on unsuccessful save', fakeAsync(async (done) => { + it('should throw error on unsuccessful save', fakeAsync((done) => { const logService: LogService = TestBed.inject(LogService); component.editable = true; const property = { key: 'properties.property-key', value: 'original-value' }; @@ -171,25 +170,22 @@ describe('ContentMetadataComponent', () => { done(); }); - spyOn(nodesApiService, 'updateNode').and.callFake(() => { - return throwError(new Error('My bad')); - }); + spyOn(nodesApiService, 'updateNode').and.returnValue(throwError(new Error('My bad'))); fixture.detectChanges(); - await fixture.whenStable(); - const saveButton = fixture.debugElement.query(By.css('[data-automation-id="save-metadata"]')); - saveButton.nativeElement.click(); - fixture.detectChanges(); + fixture.whenStable().then(() => { + const saveButton = fixture.debugElement.query(By.css('[data-automation-id="save-metadata"]')); + saveButton.nativeElement.click(); + fixture.detectChanges(); + }); })); it('should open the confirm dialog when content type is changed', fakeAsync(() => { component.editable = true; const property = { key: 'nodeType', value: 'ft:sbiruli' }; - const expectedNode = Object.assign({}, node, { nodeType: 'ft:sbiruli' }); + const expectedNode = { ...node, nodeType: 'ft:sbiruli' }; spyOn(contentMetadataService, 'openConfirmDialog').and.returnValue(of(true)); - spyOn(nodesApiService, 'updateNode').and.callFake(() => { - return of(expectedNode); - }); + spyOn(nodesApiService, 'updateNode').and.returnValue(of(expectedNode)); updateService.update(property, 'ft:poppoli'); tick(600); @@ -211,9 +207,7 @@ describe('ContentMetadataComponent', () => { const expectedNode = Object.assign({}, node, { nodeType: 'ft:sbiruli' }); spyOn(contentMetadataService, 'openConfirmDialog').and.returnValue(of(true)); spyOn(updateService, 'updateNodeAspect'); - spyOn(nodesApiService, 'updateNode').and.callFake(() => { - return of(expectedNode); - }); + spyOn(nodesApiService, 'updateNode').and.returnValue(of(expectedNode)); updateService.update(property, 'ft:poppoli'); tick(600); @@ -235,9 +229,7 @@ describe('ContentMetadataComponent', () => { component.hasMetadataChanged = true; component.editable = true; const expectedNode = Object.assign({}, node, { name: 'some-modified-value' }); - spyOn(nodesApiService, 'updateNode').and.callFake(() => { - return of(expectedNode); - }); + spyOn(nodesApiService, 'updateNode').and.returnValue(of(expectedNode)); fixture.detectChanges(); await fixture.whenStable(); @@ -251,10 +243,10 @@ describe('ContentMetadataComponent', () => { }); describe('Properties loading', () => { - let expectedNode; + let expectedNode: MinimalNode; beforeEach(() => { - expectedNode = Object.assign({}, node, { name: 'some-modified-value' }); + expectedNode = { ...node, name: 'some-modified-value' }; fixture.detectChanges(); }); @@ -267,36 +259,37 @@ describe('ContentMetadataComponent', () => { expect(contentMetadataService.getBasicProperties).toHaveBeenCalledWith(expectedNode); }); - it('should pass through the loaded basic properties to the card view', async(() => { + it('should pass through the loaded basic properties to the card view', async () => { const expectedProperties = []; component.expanded = false; - fixture.detectChanges(); - spyOn(contentMetadataService, 'getBasicProperties').and.callFake(() => { - return of(expectedProperties); - }); + + spyOn(contentMetadataService, 'getBasicProperties').and.returnValue(of(expectedProperties)); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); - component.basicProperties$.subscribe(() => { - fixture.detectChanges(); - const basicPropertiesComponent = fixture.debugElement.query(By.directive(CardViewComponent)).componentInstance; - expect(basicPropertiesComponent.properties.length).toBe(expectedProperties.length); - }); - })); - - it('should pass through the displayEmpty to the card view of basic properties', async(() => { - component.displayEmpty = false; fixture.detectChanges(); + await fixture.whenStable(); + + const basicPropertiesComponent = fixture.debugElement.query(By.directive(CardViewComponent)).componentInstance; + expect(basicPropertiesComponent.properties.length).toBe(expectedProperties.length); + }); + + it('should pass through the displayEmpty to the card view of basic properties', async () => { + component.displayEmpty = false; + + fixture.detectChanges(); + await fixture.whenStable(); + spyOn(contentMetadataService, 'getBasicProperties').and.returnValue(of([])); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); - component.basicProperties$.subscribe(() => { - fixture.detectChanges(); - const basicPropertiesComponent = fixture.debugElement.query(By.directive(CardViewComponent)).componentInstance; - expect(basicPropertiesComponent.displayEmpty).toBe(false); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); + + const basicPropertiesComponent = fixture.debugElement.query(By.directive(CardViewComponent)).componentInstance; + expect(basicPropertiesComponent.displayEmpty).toBe(false); + }); it('should load the group properties on node change', () => { spyOn(contentMetadataService, 'getGroupedProperties'); @@ -306,55 +299,55 @@ describe('ContentMetadataComponent', () => { expect(contentMetadataService.getGroupedProperties).toHaveBeenCalledWith(expectedNode, 'custom-preset'); }); - it('should pass through the loaded group properties to the card view', async(() => { + it('should pass through the loaded group properties to the card view', async () => { const expectedProperties = []; component.expanded = true; - fixture.detectChanges(); + spyOn(contentMetadataService, 'getGroupedProperties').and.returnValue(of([{ properties: expectedProperties } as any])); spyOn(component, 'showGroup').and.returnValue(true); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); - component.basicProperties$.subscribe(() => { - fixture.detectChanges(); - const firstGroupedPropertiesComponent = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container adf-card-view')).componentInstance; - expect(firstGroupedPropertiesComponent.properties).toBe(expectedProperties); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); - it('should pass through the displayEmpty to the card view of grouped properties', async(() => { + const firstGroupedPropertiesComponent = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container adf-card-view')).componentInstance; + expect(firstGroupedPropertiesComponent.properties).toBe(expectedProperties); + }); + + it('should pass through the displayEmpty to the card view of grouped properties', async () => { component.expanded = true; component.displayEmpty = false; - fixture.detectChanges(); + spyOn(contentMetadataService, 'getGroupedProperties').and.returnValue(of([{ properties: [] } as any])); spyOn(component, 'showGroup').and.returnValue(true); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); - component.basicProperties$.subscribe(() => { - fixture.detectChanges(); - const basicPropertiesComponent = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container adf-card-view')).componentInstance; - expect(basicPropertiesComponent.displayEmpty).toBe(false); - }); - })); - - it('should hide card views group when the grouped properties are empty', async(() => { - component.expanded = true; fixture.detectChanges(); + await fixture.whenStable(); + + const basicPropertiesComponent = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container adf-card-view')).componentInstance; + expect(basicPropertiesComponent.displayEmpty).toBe(false); + }); + + it('should hide card views group when the grouped properties are empty', async () => { + component.expanded = true; + spyOn(contentMetadataService, 'getGroupedProperties').and.returnValue(of([{ properties: [] } as any])); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); - component.basicProperties$.subscribe(() => { - fixture.detectChanges(); - const basicPropertiesGroup = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container mat-expansion-panel')); - expect(basicPropertiesGroup).toBeNull(); - }); - })); - - it('should display card views group when there is at least one property that is not empty', async(() => { - component.expanded = true; fixture.detectChanges(); + await fixture.whenStable(); + + const basicPropertiesGroup = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container mat-expansion-panel')); + expect(basicPropertiesGroup).toBeNull(); + }); + + it('should display card views group when there is at least one property that is not empty', async () => { + component.expanded = true; + const cardViewGroup = { title: 'Group 1', properties: [{ data: null, @@ -369,12 +362,12 @@ describe('ContentMetadataComponent', () => { component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); - component.basicProperties$.subscribe(() => { - fixture.detectChanges(); - const basicPropertiesGroup = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container mat-expansion-panel')); - expect(basicPropertiesGroup).toBeDefined(); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); + + const basicPropertiesGroup = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container mat-expansion-panel')); + expect(basicPropertiesGroup).toBeDefined(); + }); }); describe('Properties displaying', () => { @@ -400,20 +393,22 @@ describe('ContentMetadataComponent', () => { }); describe('Expand the panel', () => { - let expectedNode; + let expectedNode: MinimalNode; beforeEach(() => { - expectedNode = Object.assign({}, node, { name: 'some-modified-value' }); + expectedNode = { ...node, name: 'some-modified-value' }; spyOn(contentMetadataService, 'getGroupedProperties').and.returnValue(of(mockGroupProperties)); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); }); - it('should open and update drawer with expand section dynamically', async(() => { + it('should open and update drawer with expand section dynamically', async () => { component.displayAspect = 'EXIF'; component.expanded = true; component.displayEmpty = true; fixture.detectChanges(); + await fixture.whenStable() + let defaultProp = queryDom(fixture); let exifProp = queryDom(fixture, 'EXIF'); let customProp = queryDom(fixture, 'CUSTOM'); @@ -422,7 +417,10 @@ describe('ContentMetadataComponent', () => { expect(customProp.componentInstance.expanded).toBeFalsy(); component.displayAspect = 'CUSTOM'; + fixture.detectChanges(); + await fixture.whenStable() + defaultProp = queryDom(fixture); exifProp = queryDom(fixture, 'EXIF'); customProp = queryDom(fixture, 'CUSTOM'); @@ -431,29 +429,33 @@ describe('ContentMetadataComponent', () => { expect(customProp.componentInstance.expanded).toBeTruthy(); component.displayAspect = 'Properties'; + fixture.detectChanges(); + await fixture.whenStable() + defaultProp = queryDom(fixture); exifProp = queryDom(fixture, 'EXIF'); customProp = queryDom(fixture, 'CUSTOM'); expect(defaultProp.componentInstance.expanded).toBeTruthy(); expect(exifProp.componentInstance.expanded).toBeFalsy(); expect(customProp.componentInstance.expanded).toBeFalsy(); - })); + }); - it('should not expand anything if input is wrong', async(() => { + it('should not expand anything if input is wrong', async () => { component.displayAspect = 'XXXX'; component.expanded = true; component.displayEmpty = true; fixture.detectChanges(); + await fixture.whenStable(); + const defaultProp = queryDom(fixture); const exifProp = queryDom(fixture, 'EXIF'); const customProp = queryDom(fixture, 'CUSTOM'); expect(defaultProp.componentInstance.expanded).toBeFalsy(); expect(exifProp.componentInstance.expanded).toBeFalsy(); expect(customProp.componentInstance.expanded).toBeFalsy(); - - })); + }); }); describe('events', () => { diff --git a/lib/content-services/src/lib/content-metadata/services/config/content-metadata-config.factory.spec.ts b/lib/content-services/src/lib/content-metadata/services/config/content-metadata-config.factory.spec.ts index 9ee4bf830b..690c834a73 100644 --- a/lib/content-services/src/lib/content-metadata/services/config/content-metadata-config.factory.spec.ts +++ b/lib/content-services/src/lib/content-metadata/services/config/content-metadata-config.factory.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { AppConfigService, LogService, setupTestBed } from '@alfresco/adf-core'; import { IndifferentConfigService } from './indifferent-config.service'; import { AspectOrientedConfigService } from './aspect-oriented-config.service'; @@ -43,55 +43,51 @@ describe('ContentMetadataConfigFactory', () => { ] }); - beforeEach(async(() => { + beforeEach(() => { factory = TestBed.inject(ContentMetadataConfigFactory); appConfig = TestBed.inject(AppConfigService); - })); + }); describe('get', () => { let logService: LogService; - beforeEach(async(() => { + beforeEach(() => { logService = TestBed.inject(LogService); spyOn(logService, 'error').and.stub(); - })); - - afterEach(() => { - TestBed.resetTestingModule(); }); describe('get', () => { - it('should get back to default preset if no preset is provided as parameter', async(() => { + it('should get back to default preset if no preset is provided as parameter', () => { config = factory.get(); expect(config).toEqual(jasmine.any(IndifferentConfigService)); - })); + }); - it('should get back to default preset if no preset is set', async(() => { + it('should get back to default preset if no preset is set', () => { config = factory.get('default'); expect(config).toEqual(jasmine.any(IndifferentConfigService)); expect(logService.error).not.toHaveBeenCalled(); - })); + }); - it('should get back to the default preset if the requested preset does not exist', async(() => { + it('should get back to the default preset if the requested preset does not exist', () => { config = factory.get('not-existing-preset'); expect(config).toEqual(jasmine.any(IndifferentConfigService)); - })); + }); - it('should log an error message if the requested preset does not exist', async(() => { + it('should log an error message if the requested preset does not exist', () => { config = factory.get('not-existing-preset'); expect(logService.error).toHaveBeenCalledWith('No content-metadata preset for: not-existing-preset'); - })); + }); }); describe('set', () => { - function setConfig(presetName, presetConfig) { + function setConfig(presetName: string, presetConfig: any) { appConfig.config['content-metadata'] = { presets: { [presetName]: presetConfig @@ -99,29 +95,29 @@ describe('ContentMetadataConfigFactory', () => { }; } - it('should get back the IndifferentConfigService preset if the preset config is indifferent', async(() => { + it('should get back the IndifferentConfigService preset if the preset config is indifferent', () => { setConfig('default', '*'); config = factory.get('default'); expect(config).toEqual(jasmine.any(IndifferentConfigService)); - })); + }); - it('should get back the AspectOrientedConfigService preset if the preset config is aspect oriented', async(() => { + it('should get back the AspectOrientedConfigService preset if the preset config is aspect oriented', () => { setConfig('default', { 'exif:exif': '*' }); config = factory.get('default'); expect(config).toEqual(jasmine.any(AspectOrientedConfigService)); - })); + }); - it('should get back the LayoutOrientedConfigService preset if the preset config is layout oriented', async(() => { + it('should get back the LayoutOrientedConfigService preset if the preset config is layout oriented', () => { setConfig('default', []); config = factory.get('default'); expect(config).toEqual(jasmine.any(LayoutOrientedConfigService)); - })); + }); }); }); }); diff --git a/lib/content-services/src/lib/dialogs/folder.dialog.spec.ts b/lib/content-services/src/lib/dialogs/folder.dialog.spec.ts index b1b278169a..f7eea48f70 100644 --- a/lib/content-services/src/lib/dialogs/folder.dialog.spec.ts +++ b/lib/content-services/src/lib/dialogs/folder.dialog.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { TestBed, async, ComponentFixture } from '@angular/core/testing'; +import { TestBed, ComponentFixture } from '@angular/core/testing'; import { MatDialogRef } from '@angular/material/dialog'; import { NodesApiService, setupTestBed } from '@alfresco/adf-core'; import { FolderDialogComponent } from './folder.dialog'; @@ -25,7 +25,6 @@ import { By } from '@angular/platform-browser'; import { TranslateModule } from '@ngx-translate/core'; describe('FolderDialogComponent', () => { - let fixture: ComponentFixture; let component: FolderDialogComponent; let nodesApi: NodesApiService; @@ -77,10 +76,10 @@ describe('FolderDialogComponent', () => { }); it('should have the proper title', () => { - const title = fixture.debugElement.query(By.css('[mat-dialog-title]')); - expect(title === null).toBe(false); - expect(title.nativeElement.innerText.trim()).toBe('CORE.FOLDER_DIALOG.EDIT_FOLDER_TITLE'); - }); + const title = fixture.debugElement.query(By.css('[mat-dialog-title]')); + expect(title === null).toBe(false); + expect(title.nativeElement.innerText.trim()).toBe('CORE.FOLDER_DIALOG.EDIT_FOLDER_TITLE'); + }); it('should update form input', () => { component.form.controls['name'].setValue('folder-name-update'); @@ -125,19 +124,20 @@ describe('FolderDialogComponent', () => { expect(dialogRef.close).toHaveBeenCalledWith(folder); }); - it('should emit success output event with folder when submit is successful', async(() => { - const folder: any = { data: 'folder-data' }; - let expectedNode = null; + it('should emit success output event with folder when submit is successful', async () => { + const folder: any = { data: 'folder-data' }; + let expectedNode = null; - spyOn(nodesApi, 'updateNode').and.returnValue(of(folder)); + spyOn(nodesApi, 'updateNode').and.returnValue(of(folder)); - component.success.subscribe((node) => { expectedNode = node; }); - component.submit(); + component.success.subscribe((node) => { expectedNode = node; }); + component.submit(); - fixture.whenStable().then(() => { - expect(expectedNode).toBe(folder); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(expectedNode).toBe(folder); + }); it('should not submit if form is invalid', () => { spyOn(nodesApi, 'updateNode'); @@ -213,27 +213,27 @@ describe('FolderDialogComponent', () => { }); it('should submit updated values if form is valid (with custom nodeType)', () => { - spyOn(nodesApi, 'createFolder').and.returnValue(of(null)); + spyOn(nodesApi, 'createFolder').and.returnValue(of(null)); - component.form.controls['name'].setValue('folder-name-update'); - component.form.controls['title'].setValue('folder-title-update'); - component.form.controls['description'].setValue('folder-description-update'); - component.nodeType = 'cm:sushi'; + component.form.controls['name'].setValue('folder-name-update'); + component.form.controls['title'].setValue('folder-title-update'); + component.form.controls['description'].setValue('folder-description-update'); + component.nodeType = 'cm:sushi'; - component.submit(); + component.submit(); - expect(nodesApi.createFolder).toHaveBeenCalledWith( - 'parentNodeId', - { - name: 'folder-name-update', - properties: { - 'cm:title': 'folder-title-update', - 'cm:description': 'folder-description-update' - }, - nodeType: 'cm:sushi' - } - ); - }); + expect(nodesApi.createFolder).toHaveBeenCalledWith( + 'parentNodeId', + { + name: 'folder-name-update', + properties: { + 'cm:title': 'folder-title-update', + 'cm:description': 'folder-description-update' + }, + nodeType: 'cm:sushi' + } + ); + }); it('should call dialog to close with form data when submit is successfully', () => { const folder: any = { diff --git a/lib/content-services/src/lib/document-list/components/content-action/content-action.component.spec.ts b/lib/content-services/src/lib/document-list/components/content-action/content-action.component.spec.ts index 4fee219aa7..3567199c19 100644 --- a/lib/content-services/src/lib/document-list/components/content-action/content-action.component.spec.ts +++ b/lib/content-services/src/lib/document-list/components/content-action/content-action.component.spec.ts @@ -16,10 +16,10 @@ */ import { CUSTOM_ELEMENTS_SCHEMA, SimpleChange, EventEmitter } from '@angular/core'; -import { async, TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { ContentService, setupTestBed } from '@alfresco/adf-core'; import { FileNode } from '../../../mock'; -import { ContentActionHandler, ContentActionModel } from './../../models/content-action.model'; +import { ContentActionModel } from './../../models/content-action.model'; import { DocumentActionsService } from './../../services/document-actions.service'; import { FolderActionsService } from './../../services/folder-actions.service'; import { NodeActionsService } from './../../services/node-actions.service'; @@ -30,7 +30,6 @@ import { ContentTestingModule } from '../../../testing/content.testing.module'; import { TranslateModule } from '@ngx-translate/core'; describe('ContentAction', () => { - let documentList: DocumentListComponent; let actionList: ContentActionListComponent; let documentActions: DocumentActionsService; @@ -229,16 +228,14 @@ describe('ContentAction', () => { }); it('should find document action handler via service', () => { - const handler = function () { - }; + const handler = () => {}; const action = new ContentActionComponent(actionList, documentActions, null); spyOn(documentActions, 'getHandler').and.returnValue(handler); expect(action.getSystemHandler('document', 'name')).toBe(handler); }); it('should find folder action handler via service', () => { - const handler = function () { - }; + const handler = () => {}; const action = new ContentActionComponent(actionList, null, folderActions); spyOn(folderActions, 'getHandler').and.returnValue(handler); expect(action.getSystemHandler('folder', 'name')).toBe(handler); @@ -255,20 +252,21 @@ describe('ContentAction', () => { expect(documentActions.getHandler).not.toHaveBeenCalled(); }); - it('should wire model with custom event handler', async(() => { + it('should wire model with custom event handler', (done) => { const action = new ContentActionComponent(actionList, documentActions, folderActions); const file = new FileNode(); const handler = new EventEmitter(); handler.subscribe((e) => { expect(e.value).toBe(file); + done(); }); action.execute = handler; action.ngOnInit(); documentList.actions[0].execute(file); - })); + }); it('should allow registering model without handler', () => { const action = new ContentActionComponent(actionList, documentActions, folderActions); diff --git a/lib/content-services/src/lib/document-list/services/document-list.service.ts b/lib/content-services/src/lib/document-list/services/document-list.service.ts index dd1193d14e..6c0ab6f5ad 100644 --- a/lib/content-services/src/lib/document-list/services/document-list.service.ts +++ b/lib/content-services/src/lib/document-list/services/document-list.service.ts @@ -56,7 +56,7 @@ export class DocumentListService implements DocumentListLoader { * @param targetParentId The id of the folder where the node will be copied * @returns NodeEntry for the copied node */ - copyNode(nodeId: string, targetParentId: string) { + copyNode(nodeId: string, targetParentId: string): Observable { return from(this.apiService.getInstance().nodes.copyNode(nodeId, { targetParentId })).pipe( catchError((err) => this.handleError(err)) ); diff --git a/lib/content-services/src/lib/document-list/services/node-actions.service.spec.ts b/lib/content-services/src/lib/document-list/services/node-actions.service.spec.ts index f34e62f1ea..711dceda8a 100644 --- a/lib/content-services/src/lib/document-list/services/node-actions.service.spec.ts +++ b/lib/content-services/src/lib/document-list/services/node-actions.service.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, TestBed } from '@angular/core/testing'; +import { fakeAsync, TestBed } from '@angular/core/testing'; import { Node, NodeEntry } from '@alfresco/js-api'; import { AppConfigService, setupTestBed } from '@alfresco/adf-core'; import { DocumentListService } from './document-list.service'; @@ -58,7 +58,7 @@ describe('NodeActionsService', () => { contentDialogService = TestBed.inject(ContentNodeDialogService); }); - it('should be able to copy content', async(() => { + it('should be able to copy content', fakeAsync(() => { spyOn(documentListService, 'copyNode').and.returnValue(of(new NodeEntry())); spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode])); @@ -67,7 +67,7 @@ describe('NodeActionsService', () => { }); })); - it('should be able to move content', async(() => { + it('should be able to move content', fakeAsync(() => { spyOn(documentListService, 'moveNode').and.returnValue(of(new NodeEntry())); spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode])); @@ -76,7 +76,7 @@ describe('NodeActionsService', () => { }); })); - it('should be able to move folder', async(() => { + it('should be able to move folder', fakeAsync(() => { spyOn(documentListService, 'moveNode').and.returnValue(of(new NodeEntry())); spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode])); @@ -85,7 +85,7 @@ describe('NodeActionsService', () => { }); })); - it('should be able to copy folder', async(() => { + it('should be able to copy folder', fakeAsync(() => { spyOn(documentListService, 'copyNode').and.returnValue(of(new NodeEntry())); spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode])); @@ -94,7 +94,7 @@ describe('NodeActionsService', () => { }); })); - it('should be able to propagate the dialog error', async(() => { + it('should be able to propagate the dialog error', fakeAsync(() => { spyOn(documentListService, 'copyNode').and.returnValue(throwError('FAKE-KO')); spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode])); diff --git a/lib/content-services/src/lib/folder-directive/folder-create.directive.spec.ts b/lib/content-services/src/lib/folder-directive/folder-create.directive.spec.ts index dee7eb8be3..daafa113ef 100644 --- a/lib/content-services/src/lib/folder-directive/folder-create.directive.spec.ts +++ b/lib/content-services/src/lib/folder-directive/folder-create.directive.spec.ts @@ -16,7 +16,7 @@ */ import { Component } from '@angular/core'; -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { MatDialog } from '@angular/material/dialog'; import { By } from '@angular/platform-browser'; import { Subject, of } from 'rxjs'; @@ -112,19 +112,19 @@ describe('FolderCreateDirective', () => { }); }); - it('should emit success event with node if the folder creation was successful', async(() => { + it('should emit success event with node if the folder creation was successful', async () => { const testNode = {}; - fixture.detectChanges(); element.triggerEventHandler('click', event); dialogRefMock.componentInstance.success.next(testNode); - fixture.whenStable().then(() => { - expect(fixture.componentInstance.successParameter).toBe(testNode); - }); - })); + fixture.whenStable(); + await fixture.whenStable(); - it('should open the dialog with the proper title and nodeType', async(() => { + expect(fixture.componentInstance.successParameter).toBe(testNode); + }); + + it('should open the dialog with the proper title and nodeType', () => { fixture.detectChanges(); element.triggerEventHandler('click', event); @@ -136,7 +136,7 @@ describe('FolderCreateDirective', () => { }, width: jasmine.any(String) }); - })); + }); }); describe('Without overrides', () => { @@ -149,7 +149,7 @@ describe('FolderCreateDirective', () => { spyOn(dialog, 'open').and.returnValue(dialogRefMock); }); - it('should open the dialog with the default title and nodeType', async(() => { + it('should open the dialog with the default title and nodeType', () => { fixture.detectChanges(); element.triggerEventHandler('click', event); @@ -161,6 +161,6 @@ describe('FolderCreateDirective', () => { }, width: jasmine.any(String) }); - })); + }); }); }); diff --git a/lib/content-services/src/lib/folder-directive/folder-edit.directive.spec.ts b/lib/content-services/src/lib/folder-directive/folder-edit.directive.spec.ts index 842c6fafd8..f736b49904 100644 --- a/lib/content-services/src/lib/folder-directive/folder-edit.directive.spec.ts +++ b/lib/content-services/src/lib/folder-directive/folder-edit.directive.spec.ts @@ -16,7 +16,7 @@ */ import { Component } from '@angular/core'; -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { MatDialog } from '@angular/material/dialog'; import { By } from '@angular/platform-browser'; import { Subject, of } from 'rxjs'; @@ -80,34 +80,35 @@ describe('FolderEditDirective', () => { spyOn(dialog, 'open').and.returnValue(dialogRefMock); }); - it('should not emit folderEdit event when input value is undefined', () => { + it('should not emit folderEdit event when input value is undefined', async () => { spyOn(dialogRefMock, 'afterClosed').and.returnValue(of(null)); spyOn(contentService.folderEdit, 'next'); fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - element.nativeElement.click(); - expect(contentService.folderEdit.next).not.toHaveBeenCalled(); - }); + element.nativeElement.click(); + expect(contentService.folderEdit.next).not.toHaveBeenCalled(); }); - it('should emit success event with node if the folder creation was successful', async(() => { - const testNode = {}; + it('should emit success event with node if the folder creation was successful', async () => { fixture.detectChanges(); + const testNode = {}; element.triggerEventHandler('click', event); dialogRefMock.componentInstance.success.next(testNode); - fixture.whenStable().then(() => { - expect(fixture.componentInstance.successParameter).toBe(testNode); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); + expect(fixture.componentInstance.successParameter).toBe(testNode); + }); - it('should open the dialog with the proper title', async(() => { + it('should open the dialog with the proper title', async () => { fixture.detectChanges(); element.triggerEventHandler('click', event); + await fixture.whenStable(); + expect(dialog.open).toHaveBeenCalledWith(jasmine.any(Function), { data: { folder: jasmine.any(Object), @@ -115,5 +116,5 @@ describe('FolderEditDirective', () => { }, width: jasmine.any(String) }); - })); + }); }); diff --git a/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-dialog.component.spec.ts b/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-dialog.component.spec.ts index 3919af4275..c4cfc165ec 100644 --- a/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-dialog.component.spec.ts +++ b/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-dialog.component.spec.ts @@ -89,37 +89,45 @@ describe('AddPermissionDialog', () => { }); it('should close the dialog when close button is clicked', () => { - const closeButton: HTMLButtonElement = element.querySelector('[data-automation-id="add-permission-dialog-close-button"]'); + const closeButton = element.querySelector('[data-automation-id="add-permission-dialog-close-button"]'); expect(closeButton).not.toBeNull(); closeButton.click(); expect(dialogRef.close).toHaveBeenCalled(); }); it('should disable the confirm button when no selection is applied', () => { - const confirmButton: HTMLButtonElement = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); + const confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); expect(confirmButton.disabled).toBeTruthy(); }); it('should enable the button when a selection is done', async() => { const addPermissionPanelComponent: AddPermissionPanelComponent = fixture.debugElement.query(By.directive(AddPermissionPanelComponent)).componentInstance; addPermissionPanelComponent.select.emit(fakeAuthorityResults); - let confirmButton: HTMLButtonElement = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); + let confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); expect(confirmButton.disabled).toBeTruthy(); - await fixture.detectChanges(); - confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); + + fixture.detectChanges(); + await fixture.whenStable(); + + confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); expect(confirmButton.disabled).toBe(false); }); it('should update the role after selection', async (done) => { spyOn(component, 'onMemberUpdate').and.callThrough(); const addPermissionPanelComponent: AddPermissionPanelComponent = fixture.debugElement.query(By.directive(AddPermissionPanelComponent)).componentInstance; - let confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); + let confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); expect(confirmButton.disabled).toBe(true); addPermissionPanelComponent.select.emit([fakeAuthorityResults[0]]); - await fixture.detectChanges(); + + fixture.detectChanges(); + await fixture.whenStable(); + expect(confirmButton.disabled).toBe(false); confirmButton.click(); - await fixture.detectChanges(); + + fixture.detectChanges(); + await fixture.whenStable(); const selectBox = fixture.debugElement.query(By.css(('[id="adf-select-role-permission"] .mat-select-trigger'))); selectBox.triggerEventHandler('click', null); @@ -129,7 +137,10 @@ describe('AddPermissionDialog', () => { expect(options).not.toBeNull(); expect(options.length).toBe(2); options[0].triggerEventHandler('click', {}); - await fixture.detectChanges(); + + fixture.detectChanges(); + await fixture.whenStable(); + expect(component.onMemberUpdate).toHaveBeenCalled(); data.confirm.subscribe((selection) => { @@ -137,7 +148,7 @@ describe('AddPermissionDialog', () => { done(); }); - confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); + confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); expect(confirmButton.disabled).toBe(false); confirmButton.click(); }); @@ -145,30 +156,40 @@ describe('AddPermissionDialog', () => { it('should update all the user role on header column update', async () => { spyOn(component, 'onBulkUpdate').and.callThrough(); const addPermissionPanelComponent: AddPermissionPanelComponent = fixture.debugElement.query(By.directive(AddPermissionPanelComponent)).componentInstance; - let confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); + let confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); expect(confirmButton.disabled).toBe(true); addPermissionPanelComponent.select.emit(fakeAuthorityResults); - await fixture.detectChanges(); + + fixture.detectChanges(); + await fixture.whenStable(); + expect(confirmButton.disabled).toBe(false); confirmButton.click(); - await fixture.detectChanges(); + + fixture.detectChanges(); + await fixture.whenStable(); const selectBox = fixture.debugElement.query(By.css(('[id="adf-bulk-select-role-permission"] .mat-select-trigger'))); selectBox.triggerEventHandler('click', null); + fixture.detectChanges(); + await fixture.whenStable(); const options = fixture.debugElement.queryAll(By.css('mat-option')); expect(options).not.toBeNull(); expect(options.length).toBe(2); options[0].triggerEventHandler('click', {}); - await fixture.detectChanges(); + + fixture.detectChanges(); + await fixture.whenStable(); + expect(component.onBulkUpdate).toHaveBeenCalled(); data.confirm.subscribe((selection) => { expect(selection.length).toBe(3); }); - confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); + confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); expect(confirmButton.disabled).toBe(false); confirmButton.click(); }); @@ -177,31 +198,42 @@ describe('AddPermissionDialog', () => { spyOn(component, 'onMemberUpdate').and.callThrough(); spyOn(component, 'onMemberDelete').and.callThrough(); const addPermissionPanelComponent: AddPermissionPanelComponent = fixture.debugElement.query(By.directive(AddPermissionPanelComponent)).componentInstance; - let confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); + let confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); expect(confirmButton.disabled).toBe(true); addPermissionPanelComponent.select.emit(fakeAuthorityResults); - await fixture.detectChanges(); + + fixture.detectChanges(); + await fixture.whenStable(); + expect(confirmButton.disabled).toBe(false); confirmButton.click(); - await fixture.detectChanges(); + + fixture.detectChanges(); + await fixture.whenStable(); const selectBox = fixture.debugElement.query(By.css(('[id="adf-select-role-permission"] .mat-select-trigger'))); selectBox.triggerEventHandler('click', null); + fixture.detectChanges(); + await fixture.whenStable(); const options = fixture.debugElement.queryAll(By.css('mat-option')); expect(options).not.toBeNull(); expect(options.length).toBe(2); options[0].triggerEventHandler('click', {}); - await fixture.detectChanges(); + fixture.detectChanges(); + await fixture.whenStable(); + expect(component.onMemberUpdate).toHaveBeenCalled(); - confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); + confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); expect(confirmButton.disabled).toBe(true); const deleteButton = element.querySelectorAll('[data-automation-id="adf-delete-permission-button"]') as any; deleteButton[1].click(); deleteButton[2].click(); - await fixture.detectChanges(); + + fixture.detectChanges(); + await fixture.whenStable(); expect(confirmButton.disabled).toBe(false); expect(component.onMemberDelete).toHaveBeenCalled(); @@ -220,8 +252,9 @@ describe('AddPermissionDialog', () => { expect(fakeAuthorityResults[0].entry.id).toBe(selection[0].authorityId); }); - await fixture.detectChanges(); - const confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); + fixture.detectChanges(); + await fixture.whenStable(); + const confirmButton = element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]'); confirmButton.click(); }); }); diff --git a/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.spec.ts b/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.spec.ts index 700033551c..619a1945b9 100644 --- a/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.spec.ts +++ b/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission-panel.component.spec.ts @@ -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 { AddPermissionPanelComponent } from './add-permission-panel.component'; import { By } from '@angular/platform-browser'; import { SearchService, setupTestBed } from '@alfresco/adf-core'; @@ -42,9 +42,12 @@ describe('AddPermissionPanelComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(AddPermissionPanelComponent); + searchApiService = fixture.componentRef.injector.get(SearchService); + debugElement = fixture.debugElement; element = fixture.nativeElement; component = fixture.componentInstance; + fixture.detectChanges(); }); @@ -64,8 +67,7 @@ describe('AddPermissionPanelComponent', () => { expect(element.querySelector('#searchInput')).not.toBeNull(); }); - it('should show search results when user types something', async(() => { - searchApiService = fixture.componentRef.injector.get(SearchService); + it('should show search results when user types something', fakeAsync(() => { spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult)); expect(element.querySelector('#adf-add-permission-type-search')).not.toBeNull(); expect(element.querySelector('#searchInput')).not.toBeNull(); @@ -78,8 +80,7 @@ describe('AddPermissionPanelComponent', () => { }); })); - it('should emit a select event with the selected items when an item is clicked', async(() => { - searchApiService = fixture.componentRef.injector.get(SearchService); + it('should emit a select event with the selected items when an item is clicked', fakeAsync(() => { spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult)); component.select.subscribe((items) => { expect(items).not.toBeNull(); @@ -98,8 +99,7 @@ describe('AddPermissionPanelComponent', () => { }); })); - it('should show the icon related on the nodeType', async(() => { - searchApiService = fixture.componentRef.injector.get(SearchService); + it('should show the icon related on the nodeType', fakeAsync(() => { spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult)); expect(element.querySelector('#adf-add-permission-type-search')).not.toBeNull(); expect(element.querySelector('#searchInput')).not.toBeNull(); @@ -115,8 +115,7 @@ describe('AddPermissionPanelComponent', () => { }); })); - it('should clear the search when user delete the search input field', async(() => { - searchApiService = fixture.componentRef.injector.get(SearchService); + it('should clear the search when user delete the search input field', fakeAsync(() => { spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult)); expect(element.querySelector('#adf-add-permission-type-search')).not.toBeNull(); expect(element.querySelector('#searchInput')).not.toBeNull(); @@ -136,8 +135,7 @@ describe('AddPermissionPanelComponent', () => { }); })); - it('should remove element from selection when is clicked and already selected', async(() => { - searchApiService = fixture.componentRef.injector.get(SearchService); + it('should remove element from selection when is clicked and already selected', fakeAsync(() => { spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult)); component.selectedItems.push(fakeAuthorityListResult.list.entries[0]); component.select.subscribe((items) => { @@ -156,8 +154,7 @@ describe('AddPermissionPanelComponent', () => { }); })); - it('should always show as extra result the everyone group', async(() => { - searchApiService = fixture.componentRef.injector.get(SearchService); + it('should always show as extra result the everyone group', fakeAsync(() => { spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult)); component.selectedItems.push(fakeAuthorityListResult.list.entries[0]); @@ -175,8 +172,7 @@ describe('AddPermissionPanelComponent', () => { }); })); - it('should show everyone group when search return no result', async(() => { - searchApiService = fixture.componentRef.injector.get(SearchService); + it('should show everyone group when search return no result', fakeAsync(() => { spyOn(searchApiService, 'search').and.returnValue(of({ list: { entries: [] } })); component.selectedItems.push(fakeAuthorityListResult.list.entries[0]); @@ -190,8 +186,7 @@ describe('AddPermissionPanelComponent', () => { }); })); - it('should show first and last name of users', async(() => { - searchApiService = fixture.componentRef.injector.get(SearchService); + it('should show first and last name of users', fakeAsync(() => { spyOn(searchApiService, 'search').and.returnValue(of(fakeNameListResult)); component.selectedItems.push(fakeNameListResult.list.entries[0]); component.selectedItems.push(fakeNameListResult.list.entries[1]); @@ -208,8 +203,7 @@ describe('AddPermissionPanelComponent', () => { }); })); - it('should emit unique element in between multiple search', async(() => { - searchApiService = fixture.componentRef.injector.get(SearchService); + it('should emit unique element in between multiple search', fakeAsync(() => { spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult)); let searchAttempt = 0; diff --git a/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission.component.spec.ts b/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission.component.spec.ts index 3474ec0735..8fdaad287d 100644 --- a/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission.component.spec.ts +++ b/lib/content-services/src/lib/permission-manager/components/add-permission/add-permission.component.spec.ts @@ -17,7 +17,7 @@ import { setupTestBed } from '@alfresco/adf-core'; import { Node } from '@alfresco/js-api'; -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { AddPermissionComponent } from './add-permission.component'; import { AddPermissionPanelComponent } from './add-permission-panel.component'; import { By } from '@angular/platform-browser'; @@ -61,27 +61,28 @@ describe('AddPermissionComponent', () => { expect(addButton.disabled).toBeTruthy(); }); - it('should enable the ADD button when a selection is sent', async(() => { + it('should enable the ADD button when a selection is sent', async () => { const addPermissionPanelComponent: AddPermissionPanelComponent = fixture.debugElement.query(By.directive(AddPermissionPanelComponent)).componentInstance; addPermissionPanelComponent.select.emit(fakeAuthorityResults); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const addButton: HTMLButtonElement = element.querySelector('#adf-add-permission-action-button'); - expect(addButton.disabled).toBeFalsy(); - }); - })); - it('should NOT enable the ADD button when a selection is sent but the user does not have the permissions', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const addButton = element.querySelector('#adf-add-permission-action-button'); + expect(addButton.disabled).toBeFalsy(); + }); + + it('should NOT enable the ADD button when a selection is sent but the user does not have the permissions', async () => { const addPermissionPanelComponent: AddPermissionPanelComponent = fixture.debugElement.query(By.directive(AddPermissionPanelComponent)).componentInstance; addPermissionPanelComponent.select.emit(fakeAuthorityResults); fixture.componentInstance.currentNode = new Node({id: 'fake-node-id'}); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const addButton: HTMLButtonElement = element.querySelector('#adf-add-permission-action-button'); - expect(addButton.disabled).toBeTruthy(); - }); - })); + + fixture.detectChanges(); + await fixture.whenStable(); + + const addButton = element.querySelector('#adf-add-permission-action-button'); + expect(addButton.disabled).toBeTruthy(); + }); it('should emit a success event when the node is updated', async (done) => { fixture.componentInstance.selectedItems = fakeAuthorityResults; @@ -92,8 +93,10 @@ describe('AddPermissionComponent', () => { done(); }); - await fixture.detectChanges(); - const addButton: HTMLButtonElement = element.querySelector('#adf-add-permission-action-button'); + fixture.detectChanges(); + await fixture.whenStable(); + + const addButton = element.querySelector('#adf-add-permission-action-button'); addButton.click(); }); @@ -116,8 +119,10 @@ describe('AddPermissionComponent', () => { done(); }); - await fixture.detectChanges(); - const addButton: HTMLButtonElement = element.querySelector('#adf-add-permission-action-button'); + fixture.detectChanges(); + await fixture.whenStable(); + + const addButton = element.querySelector('#adf-add-permission-action-button'); addButton.click(); }); }); diff --git a/lib/content-services/src/lib/permission-manager/components/inherited-button.directive.spec.ts b/lib/content-services/src/lib/permission-manager/components/inherited-button.directive.spec.ts index 37ab567826..e4209a4f8a 100644 --- a/lib/content-services/src/lib/permission-manager/components/inherited-button.directive.spec.ts +++ b/lib/content-services/src/lib/permission-manager/components/inherited-button.directive.spec.ts @@ -16,7 +16,7 @@ */ import { SimpleInheritedPermissionTestComponent } from '../../mock/inherited-permission.component.mock'; -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { NodesApiService, setupTestBed } from '@alfresco/adf-core'; import { of } from 'rxjs'; import { ContentTestingModule } from '../../testing/content.testing.module'; @@ -43,20 +43,22 @@ describe('InheritPermissionDirective', () => { ] }); - beforeEach(async(() => { + beforeEach(() => { fixture = TestBed.createComponent(SimpleInheritedPermissionTestComponent); component = fixture.componentInstance; element = fixture.nativeElement; nodeService = TestBed.inject(NodesApiService); - })); + }); - it('should be able to render the simple component', async(() => { + it('should be able to render the simple component', async () => { fixture.detectChanges(); + await fixture.whenStable(); + expect(element.querySelector('#sample-button-permission')).not.toBeNull(); expect(element.querySelector('#update-notification')).toBeNull(); - })); + }); - it('should be able to add inherited permission', async(() => { + it('should be able to add inherited permission', async () => { spyOn(nodeService, 'getNode').and.returnValue(of(fakeNodeNoInherit)); spyOn(nodeService, 'updateNode').and.callFake((_, nodeBody) => { if (nodeBody.permissions?.isInheritanceEnabled) { @@ -66,17 +68,20 @@ describe('InheritPermissionDirective', () => { } }); fixture.detectChanges(); + await fixture.whenStable(); + const buttonPermission: HTMLButtonElement = element.querySelector('#sample-button-permission'); expect(buttonPermission).not.toBeNull(); expect(element.querySelector('#update-notification')).toBeNull(); buttonPermission.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelector('#update-notification')).not.toBeNull(); - }); - })); - it('should be able to remove inherited permission', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.querySelector('#update-notification')).not.toBeNull(); + }); + + it('should be able to remove inherited permission', async () => { spyOn(nodeService, 'getNode').and.returnValue(of(fakeNodeWithInherit)); spyOn(nodeService, 'updateNode').and.callFake((_, nodeBody) => { if (nodeBody.permissions?.isInheritanceEnabled) { @@ -86,29 +91,37 @@ describe('InheritPermissionDirective', () => { } }); component.updatedNode = true; + fixture.detectChanges(); + await fixture.whenStable(); + const buttonPermission: HTMLButtonElement = element.querySelector('#sample-button-permission'); expect(buttonPermission).not.toBeNull(); expect(element.querySelector('#update-notification')).not.toBeNull(); buttonPermission.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelector('#update-notification')).toBeNull(); - }); - })); - it('should not update the node when node has no permission', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.querySelector('#update-notification')).toBeNull(); + }); + + it('should not update the node when node has no permission', async () => { spyOn(nodeService, 'getNode').and.returnValue(of(fakeNodeWithInheritNoPermission)); const spyUpdateNode = spyOn(nodeService, 'updateNode'); component.updatedNode = true; + fixture.detectChanges(); + await fixture.whenStable(); + const buttonPermission: HTMLButtonElement = element.querySelector('#sample-button-permission'); expect(buttonPermission).not.toBeNull(); expect(element.querySelector('#update-notification')).not.toBeNull(); buttonPermission.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(spyUpdateNode).not.toHaveBeenCalled(); - }); - })); + await fixture.whenStable(); + + expect(spyUpdateNode).not.toHaveBeenCalled(); + }); }); diff --git a/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.spec.ts b/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.spec.ts index 52cd89d617..a4d6129d1e 100644 --- a/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.spec.ts +++ b/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.spec.ts @@ -16,7 +16,7 @@ */ import { NodesApiService, SearchService, setupTestBed } from '@alfresco/adf-core'; -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { TranslateModule } from '@ngx-translate/core'; import { of, throwError } from 'rxjs'; @@ -78,7 +78,10 @@ describe('PermissionListComponent', () => { component.nodeId = 'fake-node-id'; getNodeSpy.and.returnValue(of(fakeNodeWithoutPermissions)); component.ngOnInit(); - await fixture.detectChanges(); + + fixture.detectChanges(); + await fixture.whenStable(); + expect(element.querySelector('.adf-permission-container')).not.toBeNull(); expect(element.querySelector('[data-automation-id="adf-locally-set-permission"]')).not.toBeNull(); }); @@ -87,7 +90,9 @@ describe('PermissionListComponent', () => { component.nodeId = 'fake-node-id'; getNodeSpy.and.returnValue(throwError(null)); component.ngOnInit(); - await fixture.detectChanges(); + + fixture.detectChanges(); + await fixture.whenStable(); expect(element.querySelector('.adf-no-permission__template')).not.toBeNull(); expect(element.querySelector('.adf-no-permission__template p').textContent).toContain('PERMISSION_MANAGER.ERROR.NOT-FOUND'); @@ -101,7 +106,7 @@ describe('PermissionListComponent', () => { expect(element.querySelectorAll('[data-automation-id="adf-locally-set-permission"] .adf-datatable-row').length).toBe(2); - const showButton: HTMLButtonElement = element.querySelector('[data-automation-id="permission-info-button"]'); + const showButton = element.querySelector('[data-automation-id="permission-info-button"]'); showButton.click(); fixture.detectChanges(); @@ -112,7 +117,9 @@ describe('PermissionListComponent', () => { it('should show inherited details', async() => { getNodeSpy.and.returnValue(of(fakeNodeInheritedOnly)); component.ngOnInit(); - await fixture.detectChanges(); + + fixture.detectChanges(); + await fixture.whenStable(); expect(element.querySelector('.adf-inherit-container .mat-checked')).toBeDefined(); expect(element.querySelector('.adf-inherit-container h3').textContent.trim()) @@ -121,10 +128,11 @@ describe('PermissionListComponent', () => { .toBe('PERMISSION_MANAGER.LABELS.INHERITED-SUBTITLE'); }); - it('should toggle the inherited button', async() => { + it('should toggle the inherited button', fakeAsync(() => { getNodeSpy.and.returnValue(of(fakeNodeInheritedOnly)); component.ngOnInit(); - await fixture.detectChanges(); + + fixture.detectChanges(); expect(element.querySelector('.adf-inherit-container .mat-checked')).toBeDefined(); expect(element.querySelector('.adf-inherit-container h3').textContent.trim()) @@ -136,19 +144,22 @@ describe('PermissionListComponent', () => { const slider = fixture.debugElement.query(By.css('mat-slide-toggle')); slider.triggerEventHandler('change', { source: { checked: false } }); - await fixture.detectChanges(); + + fixture.detectChanges(); expect(element.querySelector('.adf-inherit-container .mat-checked')).toBe(null); expect(element.querySelector('.adf-inherit-container h3').textContent.trim()) .toBe('PERMISSION_MANAGER.LABELS.INHERITED-PERMISSIONS PERMISSION_MANAGER.LABELS.OFF'); expect(element.querySelector('span[title="total"]').textContent.trim()) .toBe('PERMISSION_MANAGER.LABELS.INHERITED-SUBTITLE'); - }); + })); it('should not toggle inherited button for read only users', async () => { getNodeSpy.and.returnValue(of(fakeReadOnlyNodeInherited)); component.ngOnInit(); - await fixture.detectChanges(); + + fixture.detectChanges(); + await fixture.whenStable(); expect(element.querySelector('.adf-inherit-container .mat-checked')).toBeDefined(); expect(element.querySelector('.adf-inherit-container h3').textContent.trim()) @@ -160,7 +171,9 @@ describe('PermissionListComponent', () => { const slider = fixture.debugElement.query(By.css('mat-slide-toggle')); slider.triggerEventHandler('change', { source: { checked: false } }); - await fixture.detectChanges(); + + fixture.detectChanges(); + await fixture.whenStable(); expect(element.querySelector('.adf-inherit-container .mat-checked')).toBeDefined(); expect(element.querySelector('.adf-inherit-container h3').textContent.trim()) @@ -182,7 +195,9 @@ describe('PermissionListComponent', () => { searchQuerySpy.and.returnValue(of(fakeSiteNodeResponse)); component.ngOnInit(); - await fixture.detectChanges(); + fixture.detectChanges(); + await fixture.whenStable(); + expect(element.querySelector('adf-user-name-column').textContent).toContain('GROUP_EVERYONE'); expect(element.querySelector('#adf-select-role-permission').textContent).toContain('Contributor'); }); @@ -191,7 +206,9 @@ describe('PermissionListComponent', () => { searchQuerySpy.and.returnValue(of(fakeSiteNodeResponse)); component.ngOnInit(); - await fixture.detectChanges(); + fixture.detectChanges(); + await fixture.whenStable(); + expect(element.querySelector('adf-user-name-column').textContent).toContain('GROUP_EVERYONE'); expect(element.querySelector('#adf-select-role-permission').textContent).toContain('Contributor'); @@ -199,7 +216,7 @@ describe('PermissionListComponent', () => { selectBox.triggerEventHandler('click', null); fixture.detectChanges(); - const options: any = fixture.debugElement.queryAll(By.css('mat-option')); + const options = fixture.debugElement.queryAll(By.css('mat-option')); expect(options).not.toBeNull(); expect(options.length).toBe(4); expect(options[0].nativeElement.innerText).toContain('ADF.ROLES.SITECOLLABORATOR'); @@ -212,12 +229,14 @@ describe('PermissionListComponent', () => { getNodeSpy.and.returnValue(of(fakeNodeLocalSiteManager)); component.ngOnInit(); - await fixture.detectChanges(); + fixture.detectChanges(); + await fixture.whenStable(); + expect(element.querySelector('adf-user-name-column').textContent).toContain('GROUP_site_testsite_SiteManager'); expect(element.querySelector('#adf-select-role-permission').textContent).toContain('ADF.ROLES.SITEMANAGER'); - const deleteButton: HTMLButtonElement = element.querySelector('[data-automation-id="adf-delete-permission-button-GROUP_site_testsite_SiteManager"]'); + const deleteButton = element.querySelector('[data-automation-id="adf-delete-permission-button-GROUP_site_testsite_SiteManager"]'); expect(deleteButton.disabled).toBe(true); - const otherDeleteButton: HTMLButtonElement = element.querySelector('[data-automation-id="adf-delete-permission-button-superadminuser"]'); + const otherDeleteButton = element.querySelector('[data-automation-id="adf-delete-permission-button-superadminuser"]'); expect(otherDeleteButton.disabled).toBe(false); }); @@ -226,7 +245,8 @@ describe('PermissionListComponent', () => { searchQuerySpy.and.returnValue(of(fakeEmptyResponse)); component.ngOnInit(); - await fixture.detectChanges(); + fixture.detectChanges(); + await fixture.whenStable(); expect(element.querySelector('adf-user-name-column').textContent).toContain('GROUP_EVERYONE'); expect(element.querySelector('#adf-select-role-permission').textContent).toContain('Contributor'); @@ -234,7 +254,7 @@ describe('PermissionListComponent', () => { const selectBox = fixture.debugElement.query(By.css(('[id="adf-select-role-permission"] .mat-select-trigger'))); selectBox.triggerEventHandler('click', null); fixture.detectChanges(); - const options: any = fixture.debugElement.queryAll(By.css('mat-option')); + const options = fixture.debugElement.queryAll(By.css('mat-option')); expect(options).not.toBeNull(); expect(options.length).toBe(5); options[3].triggerEventHandler('click', {}); @@ -246,12 +266,14 @@ describe('PermissionListComponent', () => { spyOn(nodeService, 'updateNode').and.returnValue(of(new MinimalNode({id: 'fake-uwpdated-node'}))); searchQuerySpy.and.returnValue(of(fakeEmptyResponse)); component.ngOnInit(); - await fixture.detectChanges(); + + fixture.detectChanges(); + await fixture.whenStable(); expect(element.querySelector('adf-user-name-column').textContent).toContain('GROUP_EVERYONE'); expect(element.querySelector('#adf-select-role-permission').textContent).toContain('Contributor'); - const deleteButton: HTMLButtonElement = element.querySelector('[data-automation-id="adf-delete-permission-button-GROUP_EVERYONE"]'); + const deleteButton = element.querySelector('[data-automation-id="adf-delete-permission-button-GROUP_EVERYONE"]'); deleteButton.click(); fixture.detectChanges(); diff --git a/lib/content-services/src/lib/permission-manager/services/node-permission.service.spec.ts b/lib/content-services/src/lib/permission-manager/services/node-permission.service.spec.ts index 0555a991d9..7df421f229 100644 --- a/lib/content-services/src/lib/permission-manager/services/node-permission.service.spec.ts +++ b/lib/content-services/src/lib/permission-manager/services/node-permission.service.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { NodePermissionService } from './node-permission.service'; import { SearchService, NodesApiService, setupTestBed } from '@alfresco/adf-core'; import { Node, PermissionElement } from '@alfresco/js-api'; @@ -62,18 +62,14 @@ describe('NodePermissionService', () => { nodeService = TestBed.inject(NodesApiService); }); - afterEach(() => { - TestBed.resetTestingModule(); - }); - - function returnUpdatedNode(_, nodeBody) { - const fakeNode: Node = new Node({}); - fakeNode.id = 'fake-updated-node'; - fakeNode.permissions = nodeBody.permissions; - return of(fakeNode); + function returnUpdatedNode(nodeBody: Node) { + return of(new Node({ + id: 'fake-updated-node', + permissions: nodeBody.permissions + })); } - it('should return a list of roles taken from the site groups', async(() => { + it('should return a list of roles taken from the site groups', (done) => { spyOn(searchApiService, 'searchByQueryBody').and.returnValue(of(fakeSiteNodeResponse)); spyOn(service, 'getGroupMemberByGroupName').and.returnValue(of(fakeSiteRoles)); @@ -81,20 +77,22 @@ describe('NodePermissionService', () => { expect(roleArray).not.toBeNull(); expect(roleArray.length).toBe(4); expect(roleArray[0]).toBe('SiteCollaborator'); + done(); }); - })); + }); - it('should return a list of settable if node has no site', async(() => { + it('should return a list of settable if node has no site', (done) => { spyOn(searchApiService, 'searchByQueryBody').and.returnValue(of(fakeEmptyResponse)); service.getNodeRoles(fakeNodeWithOnlyLocally).subscribe((roleArray: string[]) => { expect(roleArray).not.toBeNull(); expect(roleArray.length).toBe(5); expect(roleArray[0]).toBe('Contributor'); + done(); }); - })); + }); - it('should be able to update a locally set permission role', async(() => { + it('should be able to update a locally set permission role', (done) => { const fakeAccessStatus: any = 'DENIED'; const fakePermission: PermissionElement = { 'authorityId': 'GROUP_EVERYONE', @@ -102,7 +100,7 @@ describe('NodePermissionService', () => { 'accessStatus' : fakeAccessStatus }; - spyOn(nodeService, 'updateNode').and.callFake((nodeId, permissionBody) => returnUpdatedNode(nodeId, permissionBody)); + spyOn(nodeService, 'updateNode').and.callFake((_, permissionBody) => returnUpdatedNode(permissionBody)); service.updatePermissionRole(JSON.parse(JSON.stringify(fakeNodeWithOnlyLocally)), fakePermission).subscribe((node: Node) => { expect(node).not.toBeNull(); @@ -111,16 +109,17 @@ describe('NodePermissionService', () => { expect(node.permissions.locallySet[0].authorityId).toBe(fakePermission.authorityId); expect(node.permissions.locallySet[0].name).toBe(fakePermission.name); expect(node.permissions.locallySet[0].accessStatus).toBe(fakePermission.accessStatus); + done(); }); - })); + }); - it('should be able to remove a locally set permission', async(() => { - const fakePermission: PermissionElement = { + it('should be able to remove a locally set permission', (done) => { + const fakePermission = { 'authorityId': 'FAKE_PERSON_1', 'name': 'Contributor', 'accessStatus' : 'ALLOWED' }; - spyOn(nodeService, 'updateNode').and.callFake((nodeId, permissionBody) => returnUpdatedNode(nodeId, permissionBody)); + spyOn(nodeService, 'updateNode').and.callFake((_, permissionBody) => returnUpdatedNode(permissionBody)); const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeToRemovePermission)); service.removePermission(fakeNodeCopy, fakePermission).subscribe((node: Node) => { @@ -129,13 +128,14 @@ describe('NodePermissionService', () => { expect(node.permissions.locallySet.length).toBe(2); expect(node.permissions.locallySet[0].authorityId).not.toBe(fakePermission.authorityId); expect(node.permissions.locallySet[1].authorityId).not.toBe(fakePermission.authorityId); + done(); }); - })); + }); - it('should be able to update locally set permissions on the node by node id', async(() => { + it('should be able to update locally set permissions on the node by node id', (done) => { const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeWithOnlyLocally)); spyOn(nodeService, 'getNode').and.returnValue(of(fakeNodeCopy)); - spyOn(nodeService, 'updateNode').and.callFake((nodeId, permissionBody) => returnUpdatedNode(nodeId, permissionBody)); + spyOn(nodeService, 'updateNode').and.callFake((_, permissionBody) => returnUpdatedNode(permissionBody)); service.updateNodePermissions('fake-node-id', fakePermissionElements).subscribe((node: Node) => { expect(node).not.toBeNull(); @@ -144,12 +144,13 @@ describe('NodePermissionService', () => { expect(node.permissions.locallySet[3].authorityId).not.toBe(fakeAuthorityResults[0].entry['cm:userName']); expect(node.permissions.locallySet[2].authorityId).not.toBe(fakeAuthorityResults[1].entry['cm:userName']); expect(node.permissions.locallySet[1].authorityId).not.toBe(fakeAuthorityResults[2].entry['cm:userName']); + done(); }); - })); + }); - it('should be able to update locally permissions on the node', async(() => { + it('should be able to update locally permissions on the node', (done) => { const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeWithOnlyLocally)); - spyOn(nodeService, 'updateNode').and.callFake((nodeId, permissionBody) => returnUpdatedNode(nodeId, permissionBody)); + spyOn(nodeService, 'updateNode').and.callFake((_, permissionBody) => returnUpdatedNode(permissionBody)); service.updateLocallySetPermissions(fakeNodeCopy, fakePermissionElements).subscribe((node: Node) => { expect(node).not.toBeNull(); @@ -158,13 +159,14 @@ describe('NodePermissionService', () => { expect(node.permissions.locallySet[3].authorityId).not.toBe(fakeAuthorityResults[0].entry['cm:userName']); expect(node.permissions.locallySet[2].authorityId).not.toBe(fakeAuthorityResults[1].entry['cm:userName']); expect(node.permissions.locallySet[1].authorityId).not.toBe(fakeAuthorityResults[2].entry['cm:userName']); + done(); }); - })); + }); - it('should be able to update locally permissions on the node without locally set permissions', async(() => { + it('should be able to update locally permissions on the node without locally set permissions', (done) => { const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeWithoutPermissions)); fakeNodeCopy.permissions.locallySet = undefined; - spyOn(nodeService, 'updateNode').and.callFake((nodeId, permissionBody) => returnUpdatedNode(nodeId, permissionBody)); + spyOn(nodeService, 'updateNode').and.callFake((_, permissionBody) => returnUpdatedNode(permissionBody)); service.updateLocallySetPermissions(fakeNodeCopy, fakePermissionElements).subscribe((node: Node) => { expect(node).not.toBeNull(); expect(node.id).toBe('fake-updated-node'); @@ -172,10 +174,11 @@ describe('NodePermissionService', () => { expect(node.permissions.locallySet[2].authorityId).not.toBe(fakeAuthorityResults[0].entry['cm:userName']); expect(node.permissions.locallySet[1].authorityId).not.toBe(fakeAuthorityResults[1].entry['cm:userName']); expect(node.permissions.locallySet[0].authorityId).not.toBe(fakeAuthorityResults[2].entry['cm:userName']); + done(); }); - })); + }); - it('should fail when user select the same authority and role to add', async(() => { + it('should fail when user select the same authority and role to add', (done) => { const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeWithOnlyLocally)); const fakeDuplicateAuthority: PermissionElement [] = [{ @@ -185,32 +188,35 @@ describe('NodePermissionService', () => { }]; service.updateLocallySetPermissions(fakeNodeCopy, fakeDuplicateAuthority) - .subscribe(() => { - fail('should throw exception'); - }, (errorMessage) => { - expect(errorMessage).not.toBeNull(); - expect(errorMessage).toBeDefined(); - expect(errorMessage).toBe('PERMISSION_MANAGER.ERROR.DUPLICATE-PERMISSION'); - }); - })); + .subscribe( + () => { fail('should throw exception'); }, + (errorMessage) => { + expect(errorMessage).not.toBeNull(); + expect(errorMessage).toBeDefined(); + expect(errorMessage).toBe('PERMISSION_MANAGER.ERROR.DUPLICATE-PERMISSION'); + done(); + } + ); + }); - it('should be able to remove the locallyset permission', async(() => { + it('should be able to remove the locallyset permission', (done) => { const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeWithoutPermissions)); fakeNodeCopy.permissions.locallySet = [...fakePermissionElements]; - spyOn(nodeService, 'updateNode').and.callFake((nodeId, permissionBody) => returnUpdatedNode(nodeId, permissionBody)); - service.removePermissions(fakeNodeCopy, [fakePermissionElements[2]]).subscribe((node: Node) => { + spyOn(nodeService, 'updateNode').and.callFake((_, permissionBody) => returnUpdatedNode(permissionBody)); + service.removePermissions(fakeNodeCopy, [fakePermissionElements[2]]).subscribe((node) => { expect(node).not.toBeNull(); expect(node.id).toBe('fake-updated-node'); expect(node.permissions.locallySet.length).toBe(2); expect(node.permissions.locallySet[0].authorityId).toBe(fakePermissionElements[0].authorityId); expect(node.permissions.locallySet[1].authorityId).toBe(fakePermissionElements[1].authorityId); + done(); }); - })); + }); - it('should be able to replace the locally set', async(() => { + it('should be able to replace the locally set', (done) => { const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeWithOnlyLocally)); fakeNodeCopy.permissions.locallySet = []; - spyOn(nodeService, 'updateNode').and.callFake((nodeId, permissionBody) => returnUpdatedNode(nodeId, permissionBody)); + spyOn(nodeService, 'updateNode').and.callFake((_, permissionBody) => returnUpdatedNode(permissionBody)); service.updatePermissions(fakeNodeCopy, fakePermissionElements).subscribe((node: Node) => { expect(node).not.toBeNull(); expect(node.id).toBe('fake-updated-node'); @@ -218,10 +224,11 @@ describe('NodePermissionService', () => { expect(node.permissions.locallySet[0].authorityId).toBe(fakePermissionElements[0].authorityId); expect(node.permissions.locallySet[1].authorityId).toBe(fakePermissionElements[1].authorityId); expect(node.permissions.locallySet[2].authorityId).toBe(fakePermissionElements[2].authorityId); + done(); }); - })); + }); - it('should be able to get node and it\'s roles', async(() => { + it('should be able to get node and its roles', (done) => { const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeWithOnlyLocally)); spyOn(nodeService, 'getNode').and.returnValue(of(fakeNodeCopy)); spyOn(searchApiService, 'searchByQueryBody').and.returnValue(of(fakeSiteNodeResponse)); @@ -230,10 +237,11 @@ describe('NodePermissionService', () => { expect(node).toBe(fakeNodeCopy); expect(roles.length).toBe(4); expect(roles[0].role).toBe('SiteCollaborator'); + done(); }); - })); + }); - it('should provide node and default role if search API failed', async(() => { + it('should provide node and default role if search API failed', (done) => { const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeWithOnlyLocally)); spyOn(nodeService, 'getNode').and.returnValue(of(fakeNodeCopy)); spyOn(searchApiService, 'searchByQueryBody').and.returnValue(throwError('search service down')); @@ -241,6 +249,7 @@ describe('NodePermissionService', () => { expect(node).toBe(fakeNodeCopy); expect(roles.length).toBe(5); expect(roles[0].role).toBe('Contributor'); + done(); }); - })); + }); }); diff --git a/lib/content-services/src/lib/search/components/search-control.component.spec.ts b/lib/content-services/src/lib/search/components/search-control.component.spec.ts index d1c6ad6edf..84531a89f0 100644 --- a/lib/content-services/src/lib/search/components/search-control.component.spec.ts +++ b/lib/content-services/src/lib/search/components/search-control.component.spec.ts @@ -16,7 +16,7 @@ */ import { Component, DebugElement, ViewChild } 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 { AuthenticationService, @@ -90,7 +90,6 @@ describe('SearchControlComponent', () => { afterEach(() => { fixture.destroy(); - TestBed.resetTestingModule(); }); function typeWordIntoSearchInput(word: string): void { @@ -151,18 +150,22 @@ describe('SearchControlComponent', () => { describe('component rendering', () => { - it('should display a text input field by default', async(() => { + it('should display a text input field by default', async () => { fixture.detectChanges(); + await fixture.whenStable(); + expect(element.querySelectorAll('#adf-control-input').length).toBe(1); expect(element.querySelector('#adf-control-input')).toBeDefined(); expect(element.querySelector('#adf-control-input')).not.toBeNull(); - })); + }); - it('should set browser autocomplete to off by default', async(() => { + it('should set browser autocomplete to off by default', async () => { fixture.detectChanges(); + await fixture.whenStable(); + const attr = element.querySelector('#adf-control-input').getAttribute('autocomplete'); expect(attr).toBe('off'); - })); + }); }); describe('autocomplete list', () => { diff --git a/lib/content-services/src/lib/search/components/search-date-range/search-date-range.component.spec.ts b/lib/content-services/src/lib/search/components/search-date-range/search-date-range.component.spec.ts index 6058ee1d68..8ad693a930 100644 --- a/lib/content-services/src/lib/search/components/search-date-range/search-date-range.component.spec.ts +++ b/lib/content-services/src/lib/search/components/search-date-range/search-date-range.component.spec.ts @@ -18,7 +18,7 @@ import { SearchDateRangeComponent } from './search-date-range.component'; import { MomentDateAdapter, setupTestBed } from '@alfresco/adf-core'; import { DateAdapter } from '@angular/material/core'; -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ContentTestingModule } from '../../../testing/content.testing.module'; import { TranslateModule } from '@ngx-translate/core'; @@ -195,11 +195,12 @@ describe('SearchDateRangeComponent', () => { expect(component.getFromValidationMessage()).toEqual(''); }); - it('should have no maximum date by default', async(() => { + it('should have no maximum date by default', async () => { fixture.detectChanges(); + await fixture.whenStable(); expect(fixture.debugElement.nativeElement.querySelector('input[ng-reflect-max]')).toBeNull(); - })); + }); it('should be able to set a fixed maximum date', async () => { component.settings = { field: 'cm:created', dateFormat: dateFormatFixture, maxDate: maxDate }; diff --git a/lib/content-services/src/lib/search/components/search-datetime-range/search-datetime-range.component.spec.ts b/lib/content-services/src/lib/search/components/search-datetime-range/search-datetime-range.component.spec.ts index eb4bb1d1d1..a8debdedc2 100644 --- a/lib/content-services/src/lib/search/components/search-datetime-range/search-datetime-range.component.spec.ts +++ b/lib/content-services/src/lib/search/components/search-datetime-range/search-datetime-range.component.spec.ts @@ -17,7 +17,7 @@ import { SearchDatetimeRangeComponent } from './search-datetime-range.component'; import { setupTestBed } from '@alfresco/adf-core'; -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ContentTestingModule } from '../../../testing/content.testing.module'; import { TranslateModule } from '@ngx-translate/core'; @@ -45,17 +45,20 @@ describe('SearchDatetimeRangeComponent', () => { afterEach(() => fixture.destroy()); - it('should setup form elements on init', () => { + it('should setup form elements on init', async () => { fixture.detectChanges(); + await fixture.whenStable(); expect(component.from).toBeDefined(); expect(component.to).toBeDefined(); expect(component.form).toBeDefined(); }); - it('should setup form control with formatted valid datetime on change', () => { + it('should setup form control with formatted valid datetime on change', async () => { component.settings = { field: 'cm:created', datetimeFormat: datetimeFormatFixture }; + fixture.detectChanges(); + await fixture.whenStable(); const inputString = '20-feb-18 20:00'; const momentFromInput = moment(inputString, datetimeFormatFixture); @@ -67,9 +70,11 @@ describe('SearchDatetimeRangeComponent', () => { expect(component.from.value.toString()).toEqual(momentFromInput.toString()); }); - it('should NOT setup form control with invalid datetime on change', () => { + it('should NOT setup form control with invalid datetime on change', async () => { component.settings = { field: 'cm:created', datetimeFormat: datetimeFormatFixture }; + fixture.detectChanges(); + await fixture.whenStable(); const inputString = '2017-10-16 20:f:00'; const momentFromInput = moment(inputString, datetimeFormatFixture); @@ -81,8 +86,10 @@ describe('SearchDatetimeRangeComponent', () => { expect(component.from.value.toString()).not.toEqual(momentFromInput.toString()); }); - it('should reset form', () => { + it('should reset form', async () => { fixture.detectChanges(); + await fixture.whenStable(); + component.form.setValue({ from: fromDatetime, to: toDatetime }); expect(component.from.value).toEqual(fromDatetime); @@ -95,15 +102,17 @@ describe('SearchDatetimeRangeComponent', () => { expect(component.form.value).toEqual({ from: '', to: '' }); }); - it('should reset fromMaxDatetime on reset', () => { + it('should reset fromMaxDatetime on reset', async () => { fixture.detectChanges(); + await fixture.whenStable(); + component.fromMaxDatetime = fromDatetime; component.reset(); expect(component.fromMaxDatetime).toEqual(undefined); }); - it('should update query builder on reset', () => { + it('should update query builder on reset', async () => { const context: any = { queryFragments: { createdDatetimeRange: 'query' @@ -118,13 +127,15 @@ describe('SearchDatetimeRangeComponent', () => { spyOn(context, 'update').and.stub(); fixture.detectChanges(); + await fixture.whenStable(); + component.reset(); expect(context.queryFragments.createdDatetimeRange).toEqual(''); expect(context.update).toHaveBeenCalled(); }); - it('should update the query in UTC format when values change', () => { + it('should update the query in UTC format when values change', async () => { const context: any = { queryFragments: {}, update() { @@ -138,6 +149,8 @@ describe('SearchDatetimeRangeComponent', () => { spyOn(context, 'update').and.stub(); fixture.detectChanges(); + await fixture.whenStable(); + component.apply({ from: fromDatetime, to: toDatetime @@ -149,7 +162,7 @@ describe('SearchDatetimeRangeComponent', () => { expect(context.update).toHaveBeenCalled(); }); - it('should be able to update the query in UTC format from a GMT format', () => { + it('should be able to update the query in UTC format from a GMT format', async () => { const context: any = { queryFragments: {}, update() { @@ -165,6 +178,8 @@ describe('SearchDatetimeRangeComponent', () => { spyOn(context, 'update').and.stub(); fixture.detectChanges(); + await fixture.whenStable(); + component.apply({ from: fromInGmt, to: toInGmt @@ -178,6 +193,8 @@ describe('SearchDatetimeRangeComponent', () => { it('should show datetime-format error when an invalid datetime is set', async () => { fixture.detectChanges(); + await fixture.whenStable(); + component.onChangedHandler({ value: '10/14/2020 10:00:00 PM' }, component.from); fixture.detectChanges(); @@ -188,6 +205,8 @@ describe('SearchDatetimeRangeComponent', () => { it('should not show datetime-format error when valid found', async () => { fixture.detectChanges(); + await fixture.whenStable(); + const input = fixture.debugElement.nativeElement.querySelector('[data-automation-id="datetime-range-from-input"]'); input.value = '10/16/2017 9:00 PM'; input.dispatchEvent(new Event('input')); @@ -198,15 +217,18 @@ describe('SearchDatetimeRangeComponent', () => { expect(component.getFromValidationMessage()).toEqual(''); }); - it('should have no maximum datetime by default', async(() => { + it('should have no maximum datetime by default', async () => { fixture.detectChanges(); + await fixture.whenStable(); expect(fixture.debugElement.nativeElement.querySelector('input[ng-reflect-max]')).toBeNull(); - })); + }); it('should be able to set a fixed maximum datetime', async () => { component.settings = { field: 'cm:created', datetimeFormat: datetimeFormatFixture, maxDatetime: maxDatetime }; + fixture.detectChanges(); + await fixture.whenStable(); const inputs = fixture.debugElement.nativeElement.querySelectorAll('input[ng-reflect-max="Tue Mar 10 2020 20:00:00 GMT+0"]'); diff --git a/lib/content-services/src/lib/search/components/search-filter/search-filter.component.spec.ts b/lib/content-services/src/lib/search/components/search-filter/search-filter.component.spec.ts index f87f4ab3bb..b2c14f42c8 100644 --- a/lib/content-services/src/lib/search/components/search-filter/search-filter.component.spec.ts +++ b/lib/content-services/src/lib/search/components/search-filter/search-filter.component.spec.ts @@ -22,7 +22,7 @@ import { Subject } from 'rxjs'; import { FacetFieldBucket } from '../../models/facet-field-bucket.interface'; import { FacetField } from '../../models/facet-field.interface'; import { SearchFilterList } from '../../models/search-filter-list.model'; -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { ContentTestingModule } from '../../../testing/content.testing.module'; import { @@ -714,74 +714,85 @@ describe('SearchFilterComponent', () => { describe('widgets', () => { - it('should have expandable categories', async(() => { + it('should have expandable categories', async () => { fixture.detectChanges(); + await fixture.whenStable(); + queryBuilder.categories = expandableCategories; fixture.detectChanges(); - fixture.whenStable().then(() => { - const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel')); - expect(panels.length).toBe(1); + await fixture.whenStable(); - const element: HTMLElement = panels[0].nativeElement; + const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel')); + expect(panels.length).toBe(1); - (element.childNodes[0] as HTMLElement).click(); - fixture.detectChanges(); - expect(element.classList.contains('mat-expanded')).toBeTruthy(); + const element: HTMLElement = panels[0].nativeElement; - (element.childNodes[0] as HTMLElement).click(); - fixture.detectChanges(); - expect(element.classList.contains('mat-expanded')).toEqual(false); - }); - })); + (element.childNodes[0] as HTMLElement).click(); - it('should not show the disabled widget', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.classList.contains('mat-expanded')).toBeTruthy(); + + (element.childNodes[0] as HTMLElement).click(); + + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.classList.contains('mat-expanded')).toEqual(false); + }); + + it('should not show the disabled widget', async () => { appConfigService.config.search = { categories: disabledCategories }; queryBuilder.resetToDefaults(); fixture.detectChanges(); - fixture.whenStable().then(() => { - const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel')); - expect(panels.length).toBe(0); - }); - })); + await fixture.whenStable(); - it('should show the widget in expanded mode', async(() => { + const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel')); + expect(panels.length).toBe(0); + }); + + it('should show the widget in expanded mode', async () => { appConfigService.config.search = { categories: expandedCategories }; queryBuilder.resetToDefaults(); fixture.detectChanges(); - fixture.whenStable().then(() => { - const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel')); - expect(panels.length).toBe(1); + await fixture.whenStable(); - const title = fixture.debugElement.query(By.css('.mat-expansion-panel-header-title')); - expect(title.nativeElement.innerText.trim()).toBe('Type'); + const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel')); + expect(panels.length).toBe(1); - const element: HTMLElement = panels[0].nativeElement; - expect(element.classList.contains('mat-expanded')).toBeTruthy(); + const title = fixture.debugElement.query(By.css('.mat-expansion-panel-header-title')); + expect(title.nativeElement.innerText.trim()).toBe('Type'); - (element.childNodes[0] as HTMLElement).click(); - fixture.detectChanges(); - expect(element.classList.contains('mat-expanded')).toEqual(false); - }); - })); + const element: HTMLElement = panels[0].nativeElement; + expect(element.classList.contains('mat-expanded')).toBeTruthy(); - it('should show the widgets only if configured', async(() => { + (element.childNodes[0] as HTMLElement).click(); + + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.classList.contains('mat-expanded')).toEqual(false); + }); + + it('should show the widgets only if configured', async () => { appConfigService.config.search = { categories: simpleCategories }; queryBuilder.resetToDefaults(); fixture.detectChanges(); - fixture.whenStable().then(() => { - const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel')); - expect(panels.length).toBe(2); + await fixture.whenStable(); - const titleElements = fixture.debugElement.queryAll(By.css('.mat-expansion-panel-header-title')); - expect(titleElements.map(title => title.nativeElement.innerText.trim())).toEqual(['Name', 'Type']); - }); - })); + const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel')); + expect(panels.length).toBe(2); - it('should be update the search query when name changed', async( async () => { + const titleElements = fixture.debugElement.queryAll(By.css('.mat-expansion-panel-header-title')); + expect(titleElements.map(title => title.nativeElement.innerText.trim())).toEqual(['Name', 'Type']); + }); + + it('should be update the search query when name changed', async () => { spyOn(queryBuilder, 'update').and.stub(); appConfigService.config.search = searchFilter; queryBuilder.resetToDefaults(); @@ -800,7 +811,7 @@ describe('SearchFilterComponent', () => { panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel')); expect(panels.length).toBe(8); - })); + }); it('should add a panel only for the response buckets that are present in the response', async () => { appConfigService.config.search = searchFilter; diff --git a/lib/content-services/src/lib/search/components/search-text/search-text.component.spec.ts b/lib/content-services/src/lib/search/components/search-text/search-text.component.spec.ts index 39f4dc7013..4bc32071ff 100644 --- a/lib/content-services/src/lib/search/components/search-text/search-text.component.spec.ts +++ b/lib/content-services/src/lib/search/components/search-text/search-text.component.spec.ts @@ -18,7 +18,7 @@ import { SearchTextComponent } from './search-text.component'; import { setupTestBed } from '@alfresco/adf-core'; import { ContentTestingModule } from '../../../testing/content.testing.module'; -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { TranslateModule } from '@ngx-translate/core'; describe('SearchTextComponent', () => { @@ -97,24 +97,22 @@ describe('SearchTextComponent', () => { expect(component.context.queryFragments[component.id]).toBe(''); }); - it('should show the custom/default name', async(() => { + it('should show the custom/default name', async () => { component.context.queryFragments[component.id] = "cm:name:'secret.pdf'"; fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(component.value).toEqual('secret.pdf'); - const input = fixture.debugElement.nativeElement.querySelector('.mat-form-field-infix input'); - expect(input.value).toEqual('secret.pdf'); - }); - })); + await fixture.whenStable(); + expect(component.value).toEqual('secret.pdf'); + const input = fixture.debugElement.nativeElement.querySelector('.mat-form-field-infix input'); + expect(input.value).toEqual('secret.pdf'); + }); - it('should be able to reset by clicking clear button', async(() => { + it('should be able to reset by clicking clear button', async () => { component.context.queryFragments[component.id] = "cm:name:'secret.pdf'"; fixture.detectChanges(); - fixture.whenStable().then(() => { - const clearElement = fixture.debugElement.nativeElement.querySelector('button'); - clearElement.click(); - expect(component.value).toBe(''); - expect(component.context.queryFragments[component.id]).toBe(''); - }); - })); + await fixture.whenStable(); + const clearElement = fixture.debugElement.nativeElement.querySelector('button'); + clearElement.click(); + expect(component.value).toBe(''); + expect(component.context.queryFragments[component.id]).toBe(''); + }); }); diff --git a/lib/content-services/src/lib/site-dropdown/sites-dropdown.component.spec.ts b/lib/content-services/src/lib/site-dropdown/sites-dropdown.component.spec.ts index d245a7a644..1b180ce64e 100644 --- a/lib/content-services/src/lib/site-dropdown/sites-dropdown.component.spec.ts +++ b/lib/content-services/src/lib/site-dropdown/sites-dropdown.component.spec.ts @@ -16,7 +16,7 @@ */ import { DebugElement } from '@angular/core'; -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { DropdownSitesComponent, Relations } from './sites-dropdown.component'; import { SitesService, setupTestBed } from '@alfresco/adf-core'; @@ -68,36 +68,35 @@ describe('DropdownSitesComponent', () => { describe('Infinite Loading', () => { - beforeEach(async(() => { + beforeEach(() => { siteService = TestBed.inject(SitesService); fixture = TestBed.createComponent(DropdownSitesComponent); debug = fixture.debugElement; element = fixture.nativeElement; component = fixture.componentInstance; spyOn(siteService, 'getSites').and.returnValue(of(getFakeSitePaging())); - })); + }); - it('Should show loading item if there are more itemes', async(() => { + it('Should show loading item if there are more itemes', async () => { fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(element.querySelector('[data-automation-id="site-loading"]')).toBeDefined(); - }); - })); + await fixture.whenStable(); - it('Should not show loading item if there are more itemes', async(() => { + expect(element.querySelector('[data-automation-id="site-loading"]')).toBeDefined(); + }); + + it('Should not show loading item if there are more itemes', async () => { fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(element.querySelector('[data-automation-id="site-loading"]')).toBeNull(); - }); - })); + await fixture.whenStable(); + + fixture.detectChanges(); + expect(element.querySelector('[data-automation-id="site-loading"]')).toBeNull(); + }); }); describe('Sites', () => { - beforeEach(async(() => { + beforeEach(() => { siteService = TestBed.inject(SitesService); spyOn(siteService, 'getSites').and.returnValue(of(getFakeSitePagingNoMoreItems())); @@ -105,108 +104,113 @@ describe('DropdownSitesComponent', () => { debug = fixture.debugElement; element = fixture.nativeElement; component = fixture.componentInstance; - })); + }); function openSelectBox() { const selectBox = debug.query(By.css(('[data-automation-id="site-my-files-option"] .mat-select-trigger'))); selectBox.triggerEventHandler('click', null); } - it('Dropdown sites should be rendered', async(() => { + it('Dropdown sites should be rendered', async () => { fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(element.querySelector('#site-dropdown-container')).toBeDefined(); - expect(element.querySelector('#site-dropdown')).toBeDefined(); - expect(element.querySelector('#site-dropdown-container')).not.toBeNull(); - expect(element.querySelector('#site-dropdown')).not.toBeNull(); - }); - })); + await fixture.whenStable(); - it('should show the "My files" option by default', async(() => { + expect(element.querySelector('#site-dropdown-container')).toBeDefined(); + expect(element.querySelector('#site-dropdown')).toBeDefined(); + expect(element.querySelector('#site-dropdown-container')).not.toBeNull(); + expect(element.querySelector('#site-dropdown')).not.toBeNull(); + }); + + it('should show the "My files" option by default', async () => { component.hideMyFiles = false; + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null); - fixture.detectChanges(); - const options: any = debug.queryAll(By.css('mat-option')); - expect(options[0].nativeElement.innerText).toContain('DROPDOWN.MY_FILES_OPTION'); - }); - })); + debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null); - it('should hide the "My files" option if the developer desires that way', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const options: any = debug.queryAll(By.css('mat-option')); + expect(options[0].nativeElement.innerText).toContain('DROPDOWN.MY_FILES_OPTION'); + }); + + it('should hide the "My files" option if the developer desires that way', async () => { component.hideMyFiles = true; - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null); - fixture.detectChanges(); - const options: any = debug.queryAll(By.css('mat-option')); - expect(options[0].nativeElement.innerText).not.toContain('DROPDOWN.MY_FILES_OPTION'); - }); - })); - - it('should show the default placeholder label by default', async(() => { fixture.detectChanges(); + await fixture.whenStable(); + + debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null); + + fixture.detectChanges(); + await fixture.whenStable(); + + const options: any = debug.queryAll(By.css('mat-option')); + expect(options[0].nativeElement.innerText).not.toContain('DROPDOWN.MY_FILES_OPTION'); + }); + + it('should show the default placeholder label by default', async () => { + fixture.detectChanges(); + await fixture.whenStable(); openSelectBox(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(fixture.nativeElement.innerText.trim()).toContain('DROPDOWN.PLACEHOLDER_LABEL'); - }); - })); - - it('should show custom placeholder label when the \'placeholder\' input property is given a value', async(() => { fixture.detectChanges(); + await fixture.whenStable(); + expect(fixture.nativeElement.innerText.trim()).toContain('DROPDOWN.PLACEHOLDER_LABEL'); + }); + + it('should show custom placeholder label when the "placeholder" input property is given a value', async () => { component.placeholder = 'NODE_SELECTOR.SELECT_LOCATION'; + fixture.detectChanges(); + await fixture.whenStable(); openSelectBox(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(fixture.nativeElement.innerText.trim()).toContain('NODE_SELECTOR.SELECT_LOCATION'); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); - it('should load custom sites when the \'siteList\' input property is given a value', async(() => { + expect(fixture.nativeElement.innerText.trim()).toContain('NODE_SELECTOR.SELECT_LOCATION'); + }); + + it('should load custom sites when the "siteList" input property is given a value', async () => { component.siteList = customSiteList; fixture.detectChanges(); + await fixture.whenStable(); openSelectBox(); - let options: any = []; - fixture.whenStable().then(() => { - fixture.detectChanges(); - options = debug.queryAll(By.css('mat-option')); - options[0].triggerEventHandler('click', null); - fixture.detectChanges(); - }); - - component.change.subscribe(() => { - expect(options[0].nativeElement.innerText).toContain('PERSONAL_FILES'); - expect(options[1].nativeElement.innerText).toContain('FILE_LIBRARIES'); - }); - })); - - it('should load sites by default', async(() => { fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null); - fixture.detectChanges(); - const options: any = debug.queryAll(By.css('mat-option')); - expect(options[1].nativeElement.innerText).toContain('fake-test-site'); - expect(options[2].nativeElement.innerText).toContain('fake-test-2'); - }); - })); + let options = debug.queryAll(By.css('mat-option')); + options[0].triggerEventHandler('click', null); + + fixture.detectChanges(); + await fixture.whenStable(); + + expect(options[0].nativeElement.innerText).toContain('PERSONAL_FILES'); + expect(options[1].nativeElement.innerText).toContain('FILE_LIBRARIES'); + }); + + it('should load sites by default', async () => { + fixture.detectChanges(); + await fixture.whenStable(); + + debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null); + + fixture.detectChanges(); + await fixture.whenStable(); + + const options: any = debug.queryAll(By.css('mat-option')); + expect(options[1].nativeElement.innerText).toContain('fake-test-site'); + expect(options[2].nativeElement.innerText).toContain('fake-test-2'); + }); it('should raise an event when a site is selected', (done) => { fixture.detectChanges(); @@ -226,26 +230,25 @@ describe('DropdownSitesComponent', () => { }); }); - it('should be possible to select the default value', (done) => { + it('should be possible to select the default value', async () => { component.value = 'swsdp'; - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(component.selected.entry.title).toBe('fake-test-2'); - done(); - }); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.selected.entry.title).toBe('fake-test-2'); }); }); describe('Default value', () => { - beforeEach(async(() => { + beforeEach(() => { siteService = TestBed.inject(SitesService); spyOn(siteService, 'getSites').and.returnValues(of(getFakeSitePagingFirstPage()), of(getFakeSitePagingLastPage())); fixture = TestBed.createComponent(DropdownSitesComponent); component = fixture.componentInstance; - })); + }); it('should load new sites if default value is not in the first page', (done) => { component.value = 'fake-test-4'; @@ -271,7 +274,7 @@ describe('DropdownSitesComponent', () => { describe('Sites with members', () => { - beforeEach(async(() => { + beforeEach(() => { siteService = TestBed.inject(SitesService); spyOn(siteService, 'getSites').and.returnValue(of(getFakeSitePagingWithMembers())); @@ -279,18 +282,17 @@ describe('DropdownSitesComponent', () => { debug = fixture.debugElement; element = fixture.nativeElement; component = fixture.componentInstance; - })); + }); - afterEach(async(() => { + afterEach(() => { fixture.destroy(); - TestBed.resetTestingModule(); - })); + }); describe('No relations', () => { - beforeEach(async(() => { + beforeEach(() => { component.relations = Relations.Members; - })); + }); it('should show only sites which logged user is member of when member relation is set', (done) => { spyOn(siteService, 'getEcmCurrentLoggedUserName').and.returnValue('test'); @@ -312,9 +314,9 @@ describe('DropdownSitesComponent', () => { }); describe('No relations', () => { - beforeEach(async(() => { + beforeEach(() => { component.relations = []; - })); + }); it('should show all the sites if no relation is set', (done) => { spyOn(siteService, 'getEcmCurrentLoggedUserName').and.returnValue('test'); diff --git a/lib/content-services/src/lib/social/like.component.spec.ts b/lib/content-services/src/lib/social/like.component.spec.ts index 0fee22063e..08262625d8 100644 --- a/lib/content-services/src/lib/social/like.component.spec.ts +++ b/lib/content-services/src/lib/social/like.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { LikeComponent } from './like.component'; import { setupTestBed } from '@alfresco/adf-core'; @@ -38,7 +38,7 @@ describe('Like component', () => { ] }); - beforeEach(async(() => { + beforeEach(() => { service = TestBed.inject(RatingService); spyOn(service, 'getRating').and.returnValue(of({ @@ -54,17 +54,16 @@ describe('Like component', () => { component.nodeId = 'test-id'; component.ngOnChanges(); fixture.detectChanges(); - })); + }); - it('should load the likes by default on onChanges', async(() => { + it('should load the likes by default on onChanges', async () => { + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(element.querySelector('#adf-like-counter').innerHTML).toBe('2'); - }); - })); + expect(element.querySelector('#adf-like-counter').innerHTML).toBe('2'); + }); - it('should increase the number of likes when clicked', async(() => { + it('should increase the number of likes when clicked', async () => { spyOn(service, 'postRating').and.returnValue(of({ entry: { id: 'likes', @@ -75,13 +74,13 @@ describe('Like component', () => { const likeButton: any = element.querySelector('#adf-like-test-id'); likeButton.click(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(element.querySelector('#adf-like-counter').innerHTML).toBe('3'); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); - it('should decrease the number of likes when clicked and is already liked', async(() => { + expect(element.querySelector('#adf-like-counter').innerHTML).toBe('3'); + }); + + it('should decrease the number of likes when clicked and is already liked', async () => { spyOn(service, 'deleteRating').and.returnValue(of('')); component.isLike = true; @@ -89,10 +88,9 @@ describe('Like component', () => { const likeButton: any = element.querySelector('#adf-like-test-id'); likeButton.click(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(element.querySelector('#adf-like-counter').innerHTML).toBe('1'); - }); + fixture.detectChanges(); + await fixture.whenStable(); - })); + expect(element.querySelector('#adf-like-counter').innerHTML).toBe('1'); + }); }); diff --git a/lib/content-services/src/lib/tree-view/components/tree-view.component.spec.ts b/lib/content-services/src/lib/tree-view/components/tree-view.component.spec.ts index dd2846d6e9..cc5702567b 100644 --- a/lib/content-services/src/lib/tree-view/components/tree-view.component.spec.ts +++ b/lib/content-services/src/lib/tree-view/components/tree-view.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { setupTestBed } from '@alfresco/adf-core'; import { TreeViewComponent } from './tree-view.component'; import { ContentTestingModule } from '../../testing/content.testing.module'; @@ -76,13 +76,12 @@ describe('TreeViewComponent', () => { imports: [ TranslateModule.forRoot(), ContentTestingModule - ], - declarations: [] + ] }); describe('When there is a nodeId', () => { - beforeEach(async(() => { + beforeEach(() => { treeService = TestBed.inject(TreeViewService); fixture = TestBed.createComponent(TreeViewComponent); element = fixture.nativeElement; @@ -92,44 +91,50 @@ describe('TreeViewComponent', () => { const changeNodeId = new SimpleChange(null, '9999999', true); component.ngOnChanges({ 'nodeId': changeNodeId }); fixture.detectChanges(); - })); + }); afterEach(() => { fixture.destroy(); }); - it('should show the folder', async(() => { - expect(element.querySelector('#fake-node-name-tree-child-node')).not.toBeNull(); - })); + it('should show the folder', async () => { + fixture.detectChanges(); + await fixture.whenStable(); - it('should show the subfolders when the folder is clicked', async(() => { - const rootFolderButton: HTMLButtonElement = element.querySelector('#button-fake-node-name'); + expect(element.querySelector('#fake-node-name-tree-child-node')).not.toBeNull(); + }); + + it('should show the subfolders when the folder is clicked', async () => { + const rootFolderButton = element.querySelector('#button-fake-node-name'); expect(rootFolderButton).not.toBeNull(); rootFolderButton.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull(); - expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull(); - }); - })); - it('should show only the correct subfolders when the nodeId is changed', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull(); + expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull(); + }); + + it('should show only the correct subfolders when the nodeId is changed', async () => { component.nodeId = 'fake-second-id'; const changeNodeId = new SimpleChange('9999999', 'fake-second-id', true); component.ngOnChanges({ 'nodeId': changeNodeId }); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const rootFolderButton: HTMLButtonElement = element.querySelector('#button-fake-next-child-name'); - expect(rootFolderButton).not.toBeNull(); - rootFolderButton.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull(); - expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull(); - expect(element.querySelectorAll('mat-tree-node').length).toBe(4); - }); - }); - })); + await fixture.whenStable(); + + const rootFolderButton = element.querySelector('#button-fake-next-child-name'); + expect(rootFolderButton).not.toBeNull(); + rootFolderButton.click(); + + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull(); + expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull(); + expect(element.querySelectorAll('mat-tree-node').length).toBe(4); + }); it('should throw a nodeClicked event when a node is clicked', (done) => { component.nodeClicked.subscribe((nodeClicked: NodeEntry) => { @@ -139,100 +144,105 @@ describe('TreeViewComponent', () => { expect(nodeClicked.entry.id).toBe('fake-node-id'); done(); }); - const rootFolderButton: HTMLButtonElement = element.querySelector('#button-fake-node-name'); + const rootFolderButton = element.querySelector('#button-fake-node-name'); expect(rootFolderButton).not.toBeNull(); rootFolderButton.click(); }); - it('should change the icon of the opened folders', async(() => { - const rootFolderButton: HTMLButtonElement = element.querySelector('#button-fake-node-name'); + it('should change the icon of the opened folders', async () => { + const rootFolderButton = element.querySelector('#button-fake-node-name'); expect(rootFolderButton).not.toBeNull(); expect(element.querySelector('#button-fake-node-name .mat-icon').textContent.trim()).toBe('folder'); rootFolderButton.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelector('#button-fake-node-name .mat-icon').textContent.trim()).toBe('folder_open'); - }); - })); - it('should show the subfolders of a subfolder if there are any', async(() => { - const rootFolderButton: HTMLButtonElement = element.querySelector('#button-fake-node-name'); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.querySelector('#button-fake-node-name .mat-icon').textContent.trim()).toBe('folder_open'); + }); + + it('should show the subfolders of a subfolder if there are any', async () => { + const rootFolderButton = element.querySelector('#button-fake-node-name'); expect(rootFolderButton).not.toBeNull(); rootFolderButton.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull(); - const childButton: HTMLButtonElement = element.querySelector('#button-fake-second-name'); - expect(childButton).not.toBeNull(); - childButton.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelector('#fake-next-child-name-tree-child-node')).not.toBeNull(); - expect(element.querySelector('#fake-next-second-name-tree-child-node')).not.toBeNull(); - }); - }); - })); - it('should hide the subfolders when clicked again', async(() => { - const rootFolderButton: HTMLButtonElement = element.querySelector('#button-fake-node-name'); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull(); + const childButton = element.querySelector('#button-fake-second-name'); + expect(childButton).not.toBeNull(); + childButton.click(); + + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.querySelector('#fake-next-child-name-tree-child-node')).not.toBeNull(); + expect(element.querySelector('#fake-next-second-name-tree-child-node')).not.toBeNull(); + }); + + it('should hide the subfolders when clicked again', async () => { + const rootFolderButton = element.querySelector('#button-fake-node-name'); expect(rootFolderButton).not.toBeNull(); rootFolderButton.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull(); - expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull(); - rootFolderButton.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelector('#button-fake-node-name .mat-icon').textContent.trim()).toBe('folder'); - expect(element.querySelector('#fake-child-name-tree-child-node')).toBeNull(); - expect(element.querySelector('#fake-second-name-tree-child-node')).toBeNull(); - }); - }); - })); - it('should show the subfolders when the label is clicked', async(() => { - const rootLabel: HTMLButtonElement = element.querySelector('.adf-tree-view-label'); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull(); + expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull(); + rootFolderButton.click(); + + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.querySelector('#button-fake-node-name .mat-icon').textContent.trim()).toBe('folder'); + expect(element.querySelector('#fake-child-name-tree-child-node')).toBeNull(); + expect(element.querySelector('#fake-second-name-tree-child-node')).toBeNull(); + }); + + it('should show the subfolders when the label is clicked', async () => { + const rootLabel = element.querySelector('.adf-tree-view-label'); rootLabel.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull(); - expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull(); - }); - })); + await fixture.whenStable(); + + expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull(); + expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull(); + }); }); describe('When no nodeId is given', () => { let emptyElement: HTMLElement; - beforeEach(async(() => { + beforeEach(() => { fixture = TestBed.createComponent(TreeViewComponent); emptyElement = fixture.nativeElement; - })); + }); afterEach(() => { fixture.destroy(); }); - it('should show an error message when no nodeId is provided', async(() => { + it('should show an error message when no nodeId is provided', async () => { fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(emptyElement.querySelector('#adf-tree-view-missing-node')).toBeDefined(); - expect(emptyElement.querySelector('#adf-tree-view-missing-node')).not.toBeNull(); - }); - })); + await fixture.whenStable(); + + expect(emptyElement.querySelector('#adf-tree-view-missing-node')).toBeDefined(); + expect(emptyElement.querySelector('#adf-tree-view-missing-node')).not.toBeNull(); + }); }); describe('When invalid nodeId is given', () => { - beforeEach(async(() => { + beforeEach(() => { fixture = TestBed.createComponent(TreeViewComponent); treeService = TestBed.inject(TreeViewService); - spyOn(treeService, 'getTreeNodes').and.callFake(() => throwError('Invalid Node Id')); + spyOn(treeService, 'getTreeNodes').and.returnValue(throwError('Invalid Node Id')); fixture.componentInstance.nodeId = 'Poopoovic'; - })); + }); afterEach(() => { fixture.destroy(); diff --git a/lib/content-services/src/lib/upload/components/upload-drag-area.component.spec.ts b/lib/content-services/src/lib/upload/components/upload-drag-area.component.spec.ts index 60596bdced..e1d9e6db66 100644 --- a/lib/content-services/src/lib/upload/components/upload-drag-area.component.spec.ts +++ b/lib/content-services/src/lib/upload/components/upload-drag-area.component.spec.ts @@ -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 { FileModel, UploadService, setupTestBed } from '@alfresco/adf-core'; import { UploadDragAreaComponent } from './upload-drag-area.component'; import { ContentTestingModule } from '../../testing/content.testing.module'; @@ -197,13 +197,13 @@ describe('UploadDragAreaComponent', () => { }); describe('Upload Files', () => { - let addToQueueSpy; + let addToQueueSpy: jasmine.Spy; - beforeEach(async(() => { + beforeEach(() => { addToQueueSpy = spyOn(uploadService, 'addToQueue'); - })); + }); - it('should upload the list of files dropped', async(() => { + it('should upload the list of files dropped', (done) => { component.success = null; spyOn(uploadService, 'uploadFilesInTheQueue'); fixture.detectChanges(); @@ -215,12 +215,13 @@ describe('UploadDragAreaComponent', () => { fixture.whenStable().then(() => { addToQueueSpy.and.callFake((f: FileModel) => { expect(f.file).toBe(file); + done(); }); component.onFilesDropped(filesList); }); - })); + }); - it('should only upload those files whose fileTypes are in acceptedFilesType', async(() => { + it('should only upload those files whose fileTypes are in acceptedFilesType', async () => { spyOn(uploadService, 'uploadFilesInTheQueue'); component.success = null; component.error = null; @@ -232,27 +233,28 @@ describe('UploadDragAreaComponent', () => { { name: 'ganymede.bmp' } ]; component.onFilesDropped(files); - fixture.whenStable().then(() => { - expect(uploadService.uploadFilesInTheQueue).toHaveBeenCalledWith(null, null); - const filesCalledWith = addToQueueSpy.calls.mostRecent().args; - expect(filesCalledWith.length).toBe(2, 'Files should contain two elements'); - expect(filesCalledWith[0].name).toBe('phobos.jpg'); - expect(filesCalledWith[1].name).toBe('deimos.pdf'); - }); - })); - it('should upload a file if fileType is in acceptedFilesType', async(() => { + await fixture.whenStable(); + + expect(uploadService.uploadFilesInTheQueue).toHaveBeenCalledWith(null, null); + const filesCalledWith = addToQueueSpy.calls.mostRecent().args; + expect(filesCalledWith.length).toBe(2, 'Files should contain two elements'); + expect(filesCalledWith[0].name).toBe('phobos.jpg'); + expect(filesCalledWith[1].name).toBe('deimos.pdf'); + }); + + it('should upload a file if fileType is in acceptedFilesType', async () => { spyOn(uploadService, 'uploadFilesInTheQueue'); component.success = null; component.error = null; component.acceptedFilesType = '.png'; - fixture.detectChanges(); - fixture.whenStable().then(() => { - component.onFilesDropped([new File(['fakefake'], 'file-fake.png', { type: 'image/png' })]); - expect(uploadService.uploadFilesInTheQueue).toHaveBeenCalledWith(null, null); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); + + component.onFilesDropped([new File(['fakefake'], 'file-fake.png', { type: 'image/png' })]); + expect(uploadService.uploadFilesInTheQueue).toHaveBeenCalledWith(null, null); + }); it('should NOT upload the file if it is dropped on another file', () => { const fakeItem = { @@ -282,30 +284,34 @@ describe('UploadDragAreaComponent', () => { component.onUploadFiles(fakeCustomEvent); }); - it('should not upload a file if fileType is not in acceptedFilesType', async(() => { + it('should not upload a file if fileType is not in acceptedFilesType', async () => { component.success = null; component.error = null; component.acceptedFilesType = '.pdf'; - fixture.detectChanges(); + spyOn(uploadService, 'uploadFilesInTheQueue'); - fixture.whenStable().then(() => { - component.onFilesDropped([new File(['fakefake'], 'file-fake.png', { type: 'image/png' })]); - expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalledWith(null, null); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); - it('should upload a file with a custom root folder ID when dropped', async(() => { + component.onFilesDropped([new File(['fakefake'], 'file-fake.png', { type: 'image/png' })]); + expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalledWith(null, null); + }); + + it('should upload a file with a custom root folder ID when dropped', async () => { component.success = null; component.error = null; - fixture.detectChanges(); + spyOn(uploadService, 'uploadFilesInTheQueue'); + fixture.detectChanges(); + await fixture.whenStable(); + component.onFilesDropped([new File(['fakefake'], 'file-fake.png', { type: 'image/png' })]); expect(uploadService.uploadFilesInTheQueue).toHaveBeenCalledWith(null, null); - })); + }); - it('should upload a file when user has create permission on target folder', async(() => { + it('should upload a file when user has create permission on target folder', () => { const fakeItem = { fullPath: '/folder-fake/file-fake.png', isDirectory: false, @@ -327,10 +333,9 @@ describe('UploadDragAreaComponent', () => { component.onUploadFiles(fakeCustomEvent); expect(uploadService.addToQueue).toHaveBeenCalled(); - })); - - it('should upload a file to a specific target folder when dropped onto one', async(() => { + }); + it('should upload a file to a specific target folder when dropped onto one', (done) => { const fakeItem = { fullPath: '/folder-fake/file-fake.png', isDirectory: false, @@ -346,6 +351,7 @@ describe('UploadDragAreaComponent', () => { addToQueueSpy.and.callFake((fileList) => { expect(fileList.name).toBe('file'); expect(fileList.options.path).toBe('pippo/'); + done(); }); const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', { @@ -356,10 +362,9 @@ describe('UploadDragAreaComponent', () => { }); component.onUploadFiles(fakeCustomEvent); - })); - - it('should upload a folder to a specific target folder when dropped onto one', async(() => { + }); + it('should upload a folder to a specific target folder when dropped onto one', (done) => { const fakeItem = { fullPath: '/folder-fake/file-fake.png', isDirectory: false, @@ -375,6 +380,7 @@ describe('UploadDragAreaComponent', () => { addToQueueSpy.and.callFake((fileList) => { expect(fileList.name).toBe('file'); expect(fileList.options.path).toBe('pippo/super'); + done(); }); const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', { @@ -385,9 +391,9 @@ describe('UploadDragAreaComponent', () => { }); component.onUploadFiles(fakeCustomEvent); - })); + }); - it('should trigger updating the file version when we drop a file over another file', async(() => { + it('should trigger updating the file version when we drop a file over another file', fakeAsync((done) => { spyOn(component.updateFileVersion, 'emit'); const fakeItem = { fullPath: '/folder-fake/file-fake.png', @@ -404,6 +410,7 @@ describe('UploadDragAreaComponent', () => { addToQueueSpy.and.callFake((fileList) => { expect(fileList.name).toBe('file'); expect(fileList.options.path).toBe('/'); + done(); }); const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', { @@ -414,6 +421,8 @@ describe('UploadDragAreaComponent', () => { }); component.onUploadFiles(fakeCustomEvent); + fixture.detectChanges(); + expect(component.updateFileVersion.emit).toHaveBeenCalledWith(fakeCustomEvent); })); }); diff --git a/lib/content-services/src/lib/version-manager/version-manager.component.spec.ts b/lib/content-services/src/lib/version-manager/version-manager.component.spec.ts index a7820a6520..a539dad183 100644 --- a/lib/content-services/src/lib/version-manager/version-manager.component.spec.ts +++ b/lib/content-services/src/lib/version-manager/version-manager.component.spec.ts @@ -16,7 +16,7 @@ */ import { CUSTOM_ELEMENTS_SCHEMA } 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 { AlfrescoApiService, setupTestBed } from '@alfresco/adf-core'; import { Node, VersionPaging } from '@alfresco/js-api'; @@ -80,7 +80,7 @@ describe('VersionManagerComponent', () => { expect(component.viewVersion.emit).toHaveBeenCalledWith('1.0'); }); - it('should display comments for versions when not configured otherwise', async(() => { + it('should display comments for versions when not configured otherwise', fakeAsync(() => { fixture.detectChanges(); fixture.whenStable().then(() => { fixture.detectChanges(); @@ -91,27 +91,26 @@ describe('VersionManagerComponent', () => { }); })); - it('should not display comments for versions when configured not to show them', async(() => { + it('should not display comments for versions when configured not to show them', async () => { component.showComments = false; + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const versionCommentEl = fixture.debugElement.query(By.css('.adf-version-list-item-comment')); + const versionCommentEl = fixture.debugElement.query(By.css('.adf-version-list-item-comment')); + expect(versionCommentEl).toBeNull(); + }); - expect(versionCommentEl).toBeNull(); - }); - })); - - it('should emit success event upon successful upload of a new version', async(() => { + it('should emit success event upon successful upload of a new version', (done) => { fixture.detectChanges(); const emittedData = { value: { entry: node }}; component.uploadSuccess.subscribe((event) => { expect(event).toBe(node); + done(); }); component.onUploadSuccess(emittedData); - })); + }); it('should emit nodeUpdated event upon successful upload of a new version', (done) => { fixture.detectChanges(); diff --git a/lib/core/app-config/app-config.service.spec.ts b/lib/core/app-config/app-config.service.spec.ts index 9b3e4d3d42..095a13308f 100644 --- a/lib/core/app-config/app-config.service.spec.ts +++ b/lib/core/app-config/app-config.service.spec.ts @@ -16,7 +16,7 @@ */ import { HttpClient, HttpClientModule } from '@angular/common/http'; -import { async, TestBed } from '@angular/core/testing'; +import { fakeAsync, TestBed } from '@angular/core/testing'; import { AppConfigService } from './app-config.service'; import { AppConfigModule } from './app-config.module'; import { ExtensionConfig, ExtensionService } from '@alfresco/adf-extensions'; @@ -111,14 +111,14 @@ describe('AppConfigService', () => { done(); }); - it('should stream only the selected attribute changes when using select', async(() => { + it('should stream only the selected attribute changes when using select', fakeAsync(() => { appConfigService.config.testProp = true; appConfigService.select('testProp').subscribe((property) => { expect(property).toBeTruthy(); }); })); - it('should stream the page size value when is set', async(() => { + it('should stream the page size value when is set', fakeAsync(() => { appConfigService.config.testProp = true; appConfigService.onLoad.subscribe((config) => { expect(config.testProp).toBeTruthy(); diff --git a/lib/core/buttons-menu/buttons-menu.component.spec.ts b/lib/core/buttons-menu/buttons-menu.component.spec.ts index 4899ff5ea5..85d0e0ed97 100644 --- a/lib/core/buttons-menu/buttons-menu.component.spec.ts +++ b/lib/core/buttons-menu/buttons-menu.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { TestBed, async } from '@angular/core/testing'; +import { TestBed, ComponentFixture } from '@angular/core/testing'; import { MaterialModule } from '../material.module'; import { CoreTestingModule } from '../testing/core.testing.module'; import { setupTestBed } from '../testing/setup-test-bed'; @@ -55,7 +55,7 @@ describe('ButtonsMenuComponent', () => { describe('When Buttons are injected', () => { - let fixture; + let fixture: ComponentFixture; let component: CustomContainerComponent; let element: HTMLElement; @@ -81,31 +81,34 @@ describe('ButtonsMenuComponent', () => { afterEach(() => { fixture.destroy(); - TestBed.resetTestingModule(); }); - it('should render buttons menu when at least one button is declared', async(() => { + it('should render buttons menu when at least one button is declared', async () => { fixture.detectChanges(); - fixture.whenStable().then(() => { - const buttonsMenuElement = element.querySelector('#adf-buttons-menu'); - expect(buttonsMenuElement).toBeDefined(); - }); - })); + await fixture.whenStable(); - it('should trigger event when a specific button is clicked', async(() => { + const buttonsMenuElement = element.querySelector('#adf-buttons-menu'); + expect(buttonsMenuElement).toBeDefined(); + }); + + it('should trigger event when a specific button is clicked', async () => { expect(component.value).toBeUndefined(); + fixture.detectChanges(); + await fixture.whenStable(); + const button = element.querySelector('button'); button.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(component.value).toBe(1); - }); - })); + await fixture.whenStable(); + + expect(component.value).toBe(1); + }); }); describe('When no buttons are injected', () => { - let fixture; + let fixture: ComponentFixture; let element: HTMLElement; setupTestBed({ @@ -132,12 +135,12 @@ describe('ButtonsMenuComponent', () => { TestBed.resetTestingModule(); }); - it('should hide buttons menu if buttons input is empty', async(() => { + it('should hide buttons menu if buttons input is empty', async () => { fixture.detectChanges(); - fixture.whenStable().then(() => { - const buttonsMenuElement = element.querySelector('#adf-buttons-menu'); - expect(buttonsMenuElement).toBeNull(); - }); - })); + await fixture.whenStable(); + + const buttonsMenuElement = element.querySelector('#adf-buttons-menu'); + expect(buttonsMenuElement).toBeNull(); + }); }); }); diff --git a/lib/core/card-view/components/card-view-boolitem/card-view-boolitem.component.spec.ts b/lib/core/card-view/components/card-view-boolitem/card-view-boolitem.component.spec.ts index 9c25238d30..f873ae9ed8 100644 --- a/lib/core/card-view/components/card-view-boolitem/card-view-boolitem.component.spec.ts +++ b/lib/core/card-view/components/card-view-boolitem/card-view-boolitem.component.spec.ts @@ -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 { MatCheckbox, MatCheckboxChange } from '@angular/material/checkbox'; import { setupTestBed } from '../../../testing/setup-test-bed'; @@ -68,7 +68,7 @@ describe('CardViewBoolItemComponent', () => { expect(value).not.toBeNull(); }); - it('should NOT render the label and value if the property is NOT editable and doesn\'t have a proper boolean value set', () => { + it('should NOT render the label and value if the property is NOT editable and has no proper boolean value set', () => { component.editable = true; component.property.value = undefined; component.property.editable = false; @@ -189,15 +189,16 @@ describe('CardViewBoolItemComponent', () => { expect(cardViewUpdateService.update).toHaveBeenCalledWith(property, true); }); - it('should update the property value after a changed', async(() => { + it('should update the property value after a changed', async () => { component.property.value = true; component.changed( { checked: false }); - fixture.whenStable().then(() => { - expect(component.property.value).toBe(false); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.property.value).toBe(false); + }); it('should trigger an update event on the CardViewUpdateService [integration]', (done) => { const cardViewUpdateService = TestBed.inject(CardViewUpdateService); diff --git a/lib/core/card-view/components/card-view-dateitem/card-view-dateitem.component.spec.ts b/lib/core/card-view/components/card-view-dateitem/card-view-dateitem.component.spec.ts index aaf4e474c9..e1e2e6bd32 100644 --- a/lib/core/card-view/components/card-view-dateitem/card-view-dateitem.component.spec.ts +++ b/lib/core/card-view/components/card-view-dateitem/card-view-dateitem.component.spec.ts @@ -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 { By } from '@angular/platform-browser'; import { setupTestBed } from '../../../testing/setup-test-bed'; import moment from 'moment-es6'; @@ -209,7 +209,7 @@ describe('CardViewDateItemComponent', () => { component.onDateChanged({ value: expectedDate }); }); - it('should update the property value after a successful update attempt', async(() => { + it('should update the property value after a successful update attempt', fakeAsync(() => { component.editable = true; component.property.editable = true; component.property.value = null; @@ -271,7 +271,7 @@ describe('CardViewDateItemComponent', () => { expect(datePickerClearToggle).toBeNull('Clean Icon should not be in DOM'); }); - it('should remove the property value after a successful clear attempt', async(() => { + it('should remove the property value after a successful clear attempt', fakeAsync(() => { component.editable = true; component.property.editable = true; component.property.value = 'Jul 10 2017'; @@ -286,7 +286,7 @@ describe('CardViewDateItemComponent', () => { ); })); - it('should remove the property default value after a successful clear attempt', async(() => { + it('should remove the property default value after a successful clear attempt', fakeAsync(() => { component.editable = true; component.property.editable = true; component.property.default = 'Jul 10 2017'; @@ -301,7 +301,7 @@ describe('CardViewDateItemComponent', () => { ); })); - it('should remove actual and default value after a successful clear attempt', async(() => { + it('should remove actual and default value after a successful clear attempt', fakeAsync(() => { component.editable = true; component.property.editable = true; component.property.default = 'Jul 10 2017'; diff --git a/lib/core/card-view/components/card-view-keyvaluepairsitem/card-view-keyvaluepairsitem.component.spec.ts b/lib/core/card-view/components/card-view-keyvaluepairsitem/card-view-keyvaluepairsitem.component.spec.ts index e9e3a3e972..1b2e5db4e8 100644 --- a/lib/core/card-view/components/card-view-keyvaluepairsitem/card-view-keyvaluepairsitem.component.spec.ts +++ b/lib/core/card-view/components/card-view-keyvaluepairsitem/card-view-keyvaluepairsitem.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { CardViewKeyValuePairsItemModel } from '../../models/card-view-keyvaluepairs.model'; import { CardViewKeyValuePairsItemComponent } from './card-view-keyvaluepairsitem.component'; @@ -28,7 +28,7 @@ describe('CardViewKeyValuePairsItemComponent', () => { let fixture: ComponentFixture; let component: CardViewKeyValuePairsItemComponent; - let cardViewUpdateService; + let cardViewUpdateService: CardViewUpdateService; const mockEmptyData = [{ name: '', value: '' }]; const mockData = [{ name: 'test-name', value: 'test-value' }]; @@ -125,7 +125,7 @@ describe('CardViewKeyValuePairsItemComponent', () => { expect(component.property.value.length).toBe(0); }); - it('should update property on input blur', async(() => { + it('should update property on input blur', fakeAsync(() => { spyOn(cardViewUpdateService, 'update'); component.ngOnChanges(); fixture.detectChanges(); @@ -153,7 +153,7 @@ describe('CardViewKeyValuePairsItemComponent', () => { }); })); - it('should not update property if at least one input is empty on blur', async(() => { + it('should not update property if at least one input is empty on blur', fakeAsync(() => { spyOn(cardViewUpdateService, 'update'); component.ngOnChanges(); fixture.detectChanges(); diff --git a/lib/core/card-view/components/card-view-selectitem/select-filter-input/select-filter-input.component.spec.ts b/lib/core/card-view/components/card-view-selectitem/select-filter-input/select-filter-input.component.spec.ts index 6bc39f01c1..c110dcb939 100644 --- a/lib/core/card-view/components/card-view-selectitem/select-filter-input/select-filter-input.component.spec.ts +++ b/lib/core/card-view/components/card-view-selectitem/select-filter-input/select-filter-input.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { setupTestBed } from '../../../../testing/setup-test-bed'; import { CoreTestingModule } from '../../../../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; @@ -46,29 +46,33 @@ describe('SelectFilterInputComponent', () => { fixture.detectChanges(); }); - it('should focus input on initialization', async(() => { + it('should focus input on initialization', async () => { spyOn(component.selectFilterInput.nativeElement, 'focus'); matSelect.openedChange.next(true); + fixture.detectChanges(); + await fixture.whenStable(); expect(component.selectFilterInput.nativeElement.focus).toHaveBeenCalled(); - })); + }); - it('should clear search term on close', async(() => { + it('should clear search term on close', async () => { component.onModelChange('some-search-term'); expect(component.term).toBe('some-search-term'); matSelect.openedChange.next(false); fixture.detectChanges(); - expect(component.term).toBe(''); - })); + await fixture.whenStable(); - it('should emit event when value changes', async(() => { + expect(component.term).toBe(''); + }); + + it('should emit event when value changes', async () => { spyOn(component.change, 'next'); component.onModelChange('some-search-term'); expect(component.change.next).toHaveBeenCalledWith('some-search-term'); - })); + }); it('should reset value on reset() event', () => { component.onModelChange('some-search-term'); diff --git a/lib/core/card-view/components/card-view/card-view.component.spec.ts b/lib/core/card-view/components/card-view/card-view.component.spec.ts index 111ddb3784..8950dcd393 100644 --- a/lib/core/card-view/components/card-view/card-view.component.spec.ts +++ b/lib/core/card-view/components/card-view/card-view.component.spec.ts @@ -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 { setupTestBed } from '../../../testing/setup-test-bed'; import { CardViewDateItemModel } from '../../models/card-view-dateitem.model'; @@ -45,21 +45,20 @@ describe('CardViewComponent', () => { fixture.destroy(); }); - it('should render the label and value', async(() => { + it('should render the label and value', async () => { component.properties = [new CardViewTextItemModel({ label: 'My label', value: 'My value', key: 'some key' })]; + fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); + await fixture.whenStable(); - const labelValue = fixture.debugElement.query(By.css('.adf-property-label')); - expect(labelValue).not.toBeNull(); - expect(labelValue.nativeElement.innerText).toBe('My label'); + const labelValue = fixture.debugElement.query(By.css('.adf-property-label')); + expect(labelValue).not.toBeNull(); + expect(labelValue.nativeElement.innerText).toBe('My label'); - const value = fixture.debugElement.query(By.css('.adf-property-value')); - expect(value).not.toBeNull(); - expect(value.nativeElement.value).toBe('My value'); - }); - })); + const value = fixture.debugElement.query(By.css('.adf-property-value')); + expect(value).not.toBeNull(); + expect(value.nativeElement.value).toBe('My value'); + }); it('should pass through editable property to the items', () => { component.editable = true; @@ -76,28 +75,27 @@ describe('CardViewComponent', () => { expect(datePicker).not.toBeNull('Datepicker should be in DOM'); }); - it('should render the date in the correct format', async(() => { + it('should render the date in the correct format', async () => { component.properties = [new CardViewDateItemModel({ label: 'My date label', value: '2017-06-14', key: 'some key', format: 'short' })]; + fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); + await fixture.whenStable(); - const labelValue = fixture.debugElement.query(By.css('.adf-property-label')); - expect(labelValue).not.toBeNull(); - expect(labelValue.nativeElement.innerText).toBe('My date label'); + const labelValue = fixture.debugElement.query(By.css('.adf-property-label')); + expect(labelValue).not.toBeNull(); + expect(labelValue.nativeElement.innerText).toBe('My date label'); - const value = fixture.debugElement.query(By.css('.adf-property-value')); - expect(value).not.toBeNull(); - expect(value.nativeElement.innerText).toBe('6/14/17, 12:00 AM'); - }); - })); + const value = fixture.debugElement.query(By.css('.adf-property-value')); + expect(value).not.toBeNull(); + expect(value.nativeElement.innerText).toBe('6/14/17, 12:00 AM'); + }); - it('should render the default value if the value is empty, not editable and displayEmpty is true', async(() => { + it('should render the default value if the value is empty, not editable and displayEmpty is true', async () => { component.properties = [new CardViewTextItemModel({ label: 'My default label', value: null, @@ -107,22 +105,20 @@ describe('CardViewComponent', () => { })]; component.editable = true; component.displayEmpty = true; + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - fixture.detectChanges(); + const labelValue = fixture.debugElement.query(By.css('.adf-property-label')); + expect(labelValue).not.toBeNull(); + expect(labelValue.nativeElement.innerText).toBe('My default label'); - const labelValue = fixture.debugElement.query(By.css('.adf-property-label')); - expect(labelValue).not.toBeNull(); - expect(labelValue.nativeElement.innerText).toBe('My default label'); + const value = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-some-key"]')); + expect(value).not.toBeNull(); + expect(value.nativeElement.value).toBe('default value'); + }); - const value = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-some-key"]')); - expect(value).not.toBeNull(); - expect(value.nativeElement.value).toBe('default value'); - }); - })); - - it('should render the default value if the value is empty and is editable', async(() => { + it('should render the default value if the value is empty and is editable', async () => { component.properties = [new CardViewTextItemModel({ label: 'My default label', value: null, @@ -132,18 +128,16 @@ describe('CardViewComponent', () => { })]; component.editable = true; component.displayEmpty = false; + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - fixture.detectChanges(); + const labelValue = fixture.debugElement.query(By.css('.adf-property-label')); + expect(labelValue).not.toBeNull(); + expect(labelValue.nativeElement.innerText).toBe('My default label'); - const labelValue = fixture.debugElement.query(By.css('.adf-property-label')); - expect(labelValue).not.toBeNull(); - expect(labelValue.nativeElement.innerText).toBe('My default label'); - - const value = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-some-key"]')); - expect(value).not.toBeNull(); - expect(value.nativeElement.value).toBe('default value'); - }); - })); + const value = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-some-key"]')); + expect(value).not.toBeNull(); + expect(value.nativeElement.value).toBe('default value'); + }); }); diff --git a/lib/core/card-view/models/card-view-selectitem.model.spec.ts b/lib/core/card-view/models/card-view-selectitem.model.spec.ts index 61222d5de3..272dd805d5 100644 --- a/lib/core/card-view/models/card-view-selectitem.model.spec.ts +++ b/lib/core/card-view/models/card-view-selectitem.model.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async } from '@angular/core/testing'; +import { fakeAsync } from '@angular/core/testing'; import { CardViewSelectItemModel } from './card-view-selectitem.model'; import { CardViewSelectItemProperties } from '../interfaces/card-view.interfaces'; import { of } from 'rxjs'; @@ -35,7 +35,7 @@ describe('CardViewSelectItemModel', () => { }); describe('displayValue', () => { - it('should return the value if it is present', async(() => { + it('should return the value if it is present', fakeAsync(() => { const itemModel = new CardViewSelectItemModel(properties); itemModel.displayValue.subscribe((value) => { diff --git a/lib/core/card-view/services/card-view-update.service.spec.ts b/lib/core/card-view/services/card-view-update.service.spec.ts index b0c368f5da..e1755224bf 100644 --- a/lib/core/card-view/services/card-view-update.service.spec.ts +++ b/lib/core/card-view/services/card-view-update.service.spec.ts @@ -16,7 +16,7 @@ */ import { MinimalNode } from '@alfresco/js-api'; -import { async, TestBed } from '@angular/core/testing'; +import { fakeAsync, TestBed } from '@angular/core/testing'; import { CardViewBaseItemModel } from '../models/card-view-baseitem.model'; import { CardViewUpdateService, transformKeyToObject } from './card-view-update.service'; @@ -63,7 +63,7 @@ describe('CardViewUpdateService', () => { cardViewUpdateService = TestBed.inject(CardViewUpdateService); }); - it('should send updated message with proper parameters', async(() => { + it('should send updated message with proper parameters', fakeAsync(() => { cardViewUpdateService.itemUpdated$.subscribe( ( { target, changed } ) => { @@ -74,7 +74,7 @@ describe('CardViewUpdateService', () => { cardViewUpdateService.update(property, 'changed-property-value'); })); - it('should send clicked message with proper parameters', async(() => { + it('should send clicked message with proper parameters', fakeAsync(() => { cardViewUpdateService.itemClicked$.subscribe( ( { target } ) => { @@ -84,7 +84,7 @@ describe('CardViewUpdateService', () => { cardViewUpdateService.clicked(property); })); - it('should send updated node when aspect changed', async(() => { + it('should send updated node when aspect changed', fakeAsync(() => { const fakeNode: MinimalNode = { id: 'Bigfoot'}; cardViewUpdateService.updatedAspect$.subscribe((node: MinimalNode) => { expect(node.id).toBe('Bigfoot'); diff --git a/lib/core/comments/comment-list.component.spec.ts b/lib/core/comments/comment-list.component.spec.ts index 895ed05547..11693dfdd7 100644 --- a/lib/core/comments/comment-list.component.spec.ts +++ b/lib/core/comments/comment-list.component.spec.ts @@ -16,7 +16,7 @@ */ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing'; import { CommentModel, UserProcessModel } from '../models'; import { CommentListComponent } from './comment-list.component'; import { By } from '@angular/platform-browser'; @@ -26,28 +26,28 @@ import { setupTestBed } from '../testing/setup-test-bed'; import { CoreTestingModule } from '../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; -const testUser: UserProcessModel = new UserProcessModel({ +const testUser = new UserProcessModel({ id: '1', firstName: 'Test', lastName: 'User', email: 'tu@domain.com' }); -const processCommentOne: CommentModel = new CommentModel({ +const processCommentOne = new CommentModel({ id: 1, message: 'Test Comment', created: new Date(), createdBy: testUser }); -const processCommentTwo: CommentModel = new CommentModel({ +const processCommentTwo = new CommentModel({ id: 2, message: '2nd Test Comment', created: new Date(), createdBy: testUser }); -const contentCommentUserPictureDefined: CommentModel = new CommentModel({ +const contentCommentUserPictureDefined = new CommentModel({ id: 2, message: '2nd Test Comment', created: new Date(), @@ -63,7 +63,7 @@ const contentCommentUserPictureDefined: CommentModel = new CommentModel({ } }); -const processCommentUserPictureDefined: CommentModel = new CommentModel({ +const processCommentUserPictureDefined = new CommentModel({ id: 2, message: '2nd Test Comment', created: new Date(), @@ -76,7 +76,7 @@ const processCommentUserPictureDefined: CommentModel = new CommentModel({ } }); -const contentCommentUserNoPictureDefined: CommentModel = new CommentModel({ +const contentCommentUserNoPictureDefined = new CommentModel({ id: 2, message: '2nd Test Comment', created: new Date(), @@ -91,7 +91,7 @@ const contentCommentUserNoPictureDefined: CommentModel = new CommentModel({ } }); -const processCommentUserNoPictureDefined: CommentModel = new CommentModel({ +const processCommentUserNoPictureDefined = new CommentModel({ id: 2, message: '2nd Test Comment', created: new Date(), @@ -119,7 +119,7 @@ describe('CommentListComponent', () => { schemas: [CUSTOM_ELEMENTS_SCHEMA] }); - beforeEach(async(() => { + beforeEach(() => { ecmUserService = TestBed.inject(EcmUserService); spyOn(ecmUserService, 'getUserProfileImage').and.returnValue('alfresco-logo.svg'); @@ -130,16 +130,16 @@ describe('CommentListComponent', () => { commentList = fixture.componentInstance; element = fixture.nativeElement; fixture.detectChanges(); - })); + }); afterEach(() => { fixture.destroy(); }); - it('should emit row click event', async(() => { + it('should emit row click event', fakeAsync(() => { commentList.comments = [Object.assign({}, processCommentOne)]; - commentList.clickRow.subscribe((selectedComment) => { + commentList.clickRow.subscribe((selectedComment: CommentModel) => { expect(selectedComment.id).toEqual(1); expect(selectedComment.message).toEqual('Test Comment'); expect(selectedComment.createdBy).toEqual(testUser); @@ -153,7 +153,7 @@ describe('CommentListComponent', () => { }); })); - it('should deselect the previous selected comment when a new one is clicked', async(() => { + it('should deselect the previous selected comment when a new one is clicked', fakeAsync(() => { processCommentOne.isSelected = true; const commentOne = Object.assign({}, processCommentOne); const commentTwo = Object.assign({}, processCommentTwo); @@ -174,127 +174,126 @@ describe('CommentListComponent', () => { }); })); - it('should not show comment list if no input is given', async(() => { + it('should not show comment list if no input is given', async () => { fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - expect(fixture.nativeElement.querySelector('adf-datatable')).toBeNull(); - }); - })); + expect(fixture.nativeElement.querySelector('adf-datatable')).toBeNull(); + }); - it('should show comment message when input is given', async(() => { + it('should show comment message when input is given', async () => { commentList.comments = [Object.assign({}, processCommentOne)]; + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const elements = fixture.nativeElement.querySelectorAll('#comment-message'); - expect(elements.length).toBe(1); - expect(elements[0].innerText).toBe(processCommentOne.message); - expect(fixture.nativeElement.querySelector('#comment-message:empty')).toBeNull(); - }); - })); + const elements = fixture.nativeElement.querySelectorAll('#comment-message'); + expect(elements.length).toBe(1); + expect(elements[0].innerText).toBe(processCommentOne.message); + expect(fixture.nativeElement.querySelector('#comment-message:empty')).toBeNull(); + }); - it('should show comment user when input is given', async(() => { + it('should show comment user when input is given', async () => { commentList.comments = [Object.assign({}, processCommentOne)]; + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const elements = fixture.nativeElement.querySelectorAll('#comment-user'); - expect(elements.length).toBe(1); - expect(elements[0].innerText).toBe(processCommentOne.createdBy.firstName + ' ' + processCommentOne.createdBy.lastName); - expect(fixture.nativeElement.querySelector('#comment-user:empty')).toBeNull(); - }); - })); + const elements = fixture.nativeElement.querySelectorAll('#comment-user'); + expect(elements.length).toBe(1); + expect(elements[0].innerText).toBe(processCommentOne.createdBy.firstName + ' ' + processCommentOne.createdBy.lastName); + expect(fixture.nativeElement.querySelector('#comment-user:empty')).toBeNull(); + }); - it('comment date time should start with few seconds ago when comment date is few seconds ago', async(() => { + it('comment date time should start with few seconds ago when comment date is few seconds ago', async () => { const commentFewSecond = Object.assign({}, processCommentOne); commentFewSecond.created = new Date(); commentList.comments = [commentFewSecond]; + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - element = fixture.nativeElement.querySelector('#comment-time'); - expect(element.innerText).toContain('a few seconds ago'); - }); - })); + element = fixture.nativeElement.querySelector('#comment-time'); + expect(element.innerText).toContain('a few seconds ago'); + }); - it('comment date time should start with Yesterday when comment date is yesterday', async(() => { + it('comment date time should start with Yesterday when comment date is yesterday', async () => { const commentOld = Object.assign({}, processCommentOne); commentOld.created = new Date((Date.now() - 24 * 3600 * 1000)); commentList.comments = [commentOld]; + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - element = fixture.nativeElement.querySelector('#comment-time'); - expect(element.innerText).toContain('a day ago'); - }); - })); + element = fixture.nativeElement.querySelector('#comment-time'); + expect(element.innerText).toContain('a day ago'); + }); - it('comment date time should not start with Today/Yesterday when comment date is before yesterday', async(() => { + it('comment date time should not start with Today/Yesterday when comment date is before yesterday', async () => { const commentOld = Object.assign({}, processCommentOne); commentOld.created = new Date((Date.now() - 24 * 3600 * 1000 * 2)); commentList.comments = [commentOld]; + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - element = fixture.nativeElement.querySelector('#comment-time'); - expect(element.innerText).not.toContain('Today'); - expect(element.innerText).not.toContain('Yesterday'); - }); - })); + element = fixture.nativeElement.querySelector('#comment-time'); + expect(element.innerText).not.toContain('Today'); + expect(element.innerText).not.toContain('Yesterday'); + }); - it('should show user icon when input is given', async(() => { + it('should show user icon when input is given', async () => { commentList.comments = [Object.assign({}, processCommentOne)]; + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const elements = fixture.nativeElement.querySelectorAll('#comment-user-icon'); - expect(elements.length).toBe(1); - expect(elements[0].innerText).toContain(commentList.getUserShortName(processCommentOne.createdBy)); - expect(fixture.nativeElement.querySelector('#comment-user-icon:empty')).toBeNull(); - }); - })); + const elements = fixture.nativeElement.querySelectorAll('#comment-user-icon'); + expect(elements.length).toBe(1); + expect(elements[0].innerText).toContain(commentList.getUserShortName(processCommentOne.createdBy)); + expect(fixture.nativeElement.querySelector('#comment-user-icon:empty')).toBeNull(); + }); - it('should return content picture when is a content user with a picture', async(() => { + it('should return content picture when is a content user with a picture', async () => { commentList.comments = [contentCommentUserPictureDefined]; + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const elements = fixture.nativeElement.querySelectorAll('.adf-people-img'); - expect(elements.length).toBe(1); - expect(fixture.nativeElement.getElementsByClassName('adf-people-img')[0].src).toContain('alfresco-logo.svg'); - }); - })); + const elements = fixture.nativeElement.querySelectorAll('.adf-people-img'); + expect(elements.length).toBe(1); + expect(fixture.nativeElement.getElementsByClassName('adf-people-img')[0].src).toContain('alfresco-logo.svg'); + }); - it('should return process picture when is a process user with a picture', async(() => { + it('should return process picture when is a process user with a picture', async () => { commentList.comments = [processCommentUserPictureDefined]; + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const elements = fixture.nativeElement.querySelectorAll('.adf-people-img'); - expect(elements.length).toBe(1); - expect(fixture.nativeElement.getElementsByClassName('adf-people-img')[0].src).toContain('alfresco-logo.svg'); - }); - })); + const elements = fixture.nativeElement.querySelectorAll('.adf-people-img'); + expect(elements.length).toBe(1); + expect(fixture.nativeElement.getElementsByClassName('adf-people-img')[0].src).toContain('alfresco-logo.svg'); + }); - it('should return content short name when is a content user without a picture', async(() => { + it('should return content short name when is a content user without a picture', async () => { commentList.comments = [contentCommentUserNoPictureDefined]; + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const elements = fixture.nativeElement.querySelectorAll('.adf-comment-user-icon'); - expect(elements.length).toBe(1); - }); - })); + const elements = fixture.nativeElement.querySelectorAll('.adf-comment-user-icon'); + expect(elements.length).toBe(1); + }); - it('should return process short name when is a process user without a picture', async(() => { + it('should return process short name when is a process user without a picture', async () => { commentList.comments = [processCommentUserNoPictureDefined]; - fixture.detectChanges(); - fixture.whenStable().then(() => { - const elements = fixture.nativeElement.querySelectorAll('.adf-comment-user-icon'); - expect(elements.length).toBe(1); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); + + const elements = fixture.nativeElement.querySelectorAll('.adf-comment-user-icon'); + expect(elements.length).toBe(1); + }); }); diff --git a/lib/core/comments/comments.component.spec.ts b/lib/core/comments/comments.component.spec.ts index 1bcca94002..8035a3cfe0 100644 --- a/lib/core/comments/comments.component.spec.ts +++ b/lib/core/comments/comments.component.spec.ts @@ -16,7 +16,7 @@ */ import { CUSTOM_ELEMENTS_SCHEMA, 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 } from '../services/comment-process.service'; import { CommentsComponent } from './comments.component'; @@ -27,7 +27,6 @@ import { TranslateModule } from '@ngx-translate/core'; import { CommentModel } from '../models/comment.model'; describe('CommentsComponent', () => { - let component: CommentsComponent; let fixture: ComponentFixture; let getProcessCommentsSpy: jasmine.Spy; @@ -109,66 +108,65 @@ describe('CommentsComponent', () => { expect(getProcessCommentsSpy).not.toHaveBeenCalled(); }); - it('should display comments when the task has comments', async(() => { + it('should display comments when the task has comments', async () => { const change = new SimpleChange(null, '123', true); component.ngOnChanges({'taskId': 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 task 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 task has comments', async () => { const change = new SimpleChange(null, '123', true); component.ngOnChanges({'taskId': change}); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const element = fixture.nativeElement.querySelector('#comment-header'); - expect(element.innerText).toBe('COMMENTS.HEADER'); - }); - })); - it('should not display comments when the task has no comments', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const element = fixture.nativeElement.querySelector('#comment-header'); + expect(element.innerText).toBe('COMMENTS.HEADER'); + }); + + it('should not display comments when the task has no comments', async () => { component.taskId = '123'; getProcessCommentsSpy.and.returnValue(of([])); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(fixture.nativeElement.querySelector('#comment-container')).toBeNull(); - }); - })); - it('should display comments input by default', async(() => { + fixture.detectChanges(); + await fixture.whenStable() + + expect(fixture.nativeElement.querySelector('#comment-container')).toBeNull(); + }); + + it('should display comments input by default', async () => { const change = new SimpleChange(null, '123', true); component.ngOnChanges({'taskId': change}); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(fixture.nativeElement.querySelector('#comment-input')).not.toBeNull(); - }); - })); - it('should not display comments input when the task is readonly', async(() => { - component.readOnly = true; fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(fixture.nativeElement.querySelector('#comment-input')).toBeNull(); - }); - })); + await fixture.whenStable() + + expect(fixture.nativeElement.querySelector('#comment-input')).not.toBeNull(); + }); + + it('should not display comments input when the task is readonly', async () => { + component.readOnly = true; + + fixture.detectChanges(); + await fixture.whenStable() + + expect(fixture.nativeElement.querySelector('#comment-input')).toBeNull(); + }); describe('change detection taskId', () => { - const change = new SimpleChange('123', '456', true); const nullChange = new SimpleChange('123', null, true); - beforeEach(async(() => { + beforeEach(() => { component.taskId = '123'; fixture.detectChanges(); - fixture.whenStable().then(() => { - getProcessCommentsSpy.calls.reset(); - }); - })); + }); it('should fetch new comments when taskId changed', () => { component.ngOnChanges({'taskId': change}); @@ -187,17 +185,13 @@ describe('CommentsComponent', () => { }); describe('change detection node', () => { - const change = new SimpleChange('123', '456', true); const nullChange = new SimpleChange('123', null, true); - beforeEach(async(() => { + beforeEach(() => { component.nodeId = '123'; fixture.detectChanges(); - fixture.whenStable().then(() => { - getContentCommentsSpy.calls.reset(); - }); - })); + }); it('should fetch new comments when nodeId changed', () => { component.ngOnChanges({'nodeId': change}); @@ -217,81 +211,81 @@ describe('CommentsComponent', () => { describe('Add comment task', () => { - beforeEach(async(() => { + beforeEach(() => { component.taskId = '123'; fixture.detectChanges(); fixture.whenStable(); - })); + }); - it('should sanitize comment when user input contains html elements', async(() => { + it('should sanitize comment when user input contains html elements', async () => { const element = fixture.nativeElement.querySelector('.adf-comments-input-add'); component.message = '
'; element.dispatchEvent(new Event('click')); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(addProcessCommentSpy).toHaveBeenCalledWith('123', 'action'); - }); - })); - it('should normalize comment when user input contains spaces sequence', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(addProcessCommentSpy).toHaveBeenCalledWith('123', 'action'); + }); + + it('should normalize comment when user input contains spaces sequence', async () => { const element = fixture.nativeElement.querySelector('.adf-comments-input-add'); component.message = 'test comment'; element.dispatchEvent(new Event('click')); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(addProcessCommentSpy).toHaveBeenCalledWith('123', 'test comment'); - }); - })); - it('should add break lines to comment when user input contains new line characters', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(addProcessCommentSpy).toHaveBeenCalledWith('123', 'test comment'); + }); + + it('should add break lines to comment when user input contains new line characters', async () => { const element = fixture.nativeElement.querySelector('.adf-comments-input-add'); component.message = 'these\nare\nparagraphs\n'; element.dispatchEvent(new Event('click')); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(addProcessCommentSpy).toHaveBeenCalledWith('123', 'these
are
paragraphs'); - }); - })); - it('should call service to add a comment when add button is pressed', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(addProcessCommentSpy).toHaveBeenCalledWith('123', 'these
are
paragraphs'); + }); + + it('should call service to add a comment when add button is pressed', async () => { const element = fixture.nativeElement.querySelector('.adf-comments-input-add'); component.message = 'Test Comment'; element.dispatchEvent(new Event('click')); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(addProcessCommentSpy).toHaveBeenCalled(); - const elements = fixture.nativeElement.querySelectorAll('#comment-message'); - expect(elements.length).toBe(1); - expect(elements[0].innerText).toBe('Test Comment'); - }); - })); - it('should not call service to add a comment when comment is empty', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(addProcessCommentSpy).toHaveBeenCalled(); + const elements = fixture.nativeElement.querySelectorAll('#comment-message'); + expect(elements.length).toBe(1); + expect(elements[0].innerText).toBe('Test Comment'); + }); + + it('should not call service to add a comment when comment is empty', async () => { const element = fixture.nativeElement.querySelector('.adf-comments-input-add'); component.message = ''; element.dispatchEvent(new Event('click')); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(addProcessCommentSpy).not.toHaveBeenCalled(); - }); - })); - it('should clear comment when escape key is pressed', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(addProcessCommentSpy).not.toHaveBeenCalled(); + }); + + it('should clear comment when escape key is pressed', async () => { const event = new KeyboardEvent('keydown', {'key': 'Escape'}); let element = fixture.nativeElement.querySelector('#comment-input'); element.dispatchEvent(event); + fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - element = fixture.nativeElement.querySelector('#comment-input'); - expect(element.value).toBe(''); - }); - })); + await fixture.whenStable(); + + element = fixture.nativeElement.querySelector('#comment-input'); + expect(element.value).toBe(''); + }); it('should emit an error when an error occurs adding the comment', () => { const emitSpy = spyOn(component.error, 'emit'); @@ -304,81 +298,81 @@ describe('CommentsComponent', () => { describe('Add comment node', () => { - beforeEach(async(() => { + beforeEach(() => { component.nodeId = '123'; fixture.detectChanges(); fixture.whenStable(); - })); + }); - it('should call service to add a comment when add button is pressed', async(() => { + it('should call service to add a comment when add button is pressed', async () => { const element = fixture.nativeElement.querySelector('.adf-comments-input-add'); component.message = 'Test Comment'; element.dispatchEvent(new Event('click')); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(addContentCommentSpy).toHaveBeenCalled(); - const elements = fixture.nativeElement.querySelectorAll('#comment-message'); - expect(elements.length).toBe(1); - expect(elements[0].innerText).toBe('Test Comment'); - }); - })); - it('should sanitize comment when user input contains html elements', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(addContentCommentSpy).toHaveBeenCalled(); + const elements = fixture.nativeElement.querySelectorAll('#comment-message'); + expect(elements.length).toBe(1); + expect(elements[0].innerText).toBe('Test Comment'); + }); + + it('should sanitize comment when user input contains html elements', async () => { const element = fixture.nativeElement.querySelector('.adf-comments-input-add'); component.message = '
'; element.dispatchEvent(new Event('click')); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(addContentCommentSpy).toHaveBeenCalledWith('123', 'action'); - }); - })); - it('should normalize comment when user input contains spaces sequence', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(addContentCommentSpy).toHaveBeenCalledWith('123', 'action'); + }); + + it('should normalize comment when user input contains spaces sequence', async () => { const element = fixture.nativeElement.querySelector('.adf-comments-input-add'); component.message = 'test comment'; element.dispatchEvent(new Event('click')); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(addContentCommentSpy).toHaveBeenCalledWith('123', 'test comment'); - }); - })); - it('should add break lines to comment when user input contains new line characters', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(addContentCommentSpy).toHaveBeenCalledWith('123', 'test comment'); + }); + + it('should add break lines to comment when user input contains new line characters', async () => { const element = fixture.nativeElement.querySelector('.adf-comments-input-add'); component.message = 'these\nare\nparagraphs\n'; element.dispatchEvent(new Event('click')); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(addContentCommentSpy).toHaveBeenCalledWith('123', 'these
are
paragraphs'); - }); - })); - it('should not call service to add a comment when comment is empty', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(addContentCommentSpy).toHaveBeenCalledWith('123', 'these
are
paragraphs'); + }); + + it('should not call service to add a comment when comment is empty', async () => { const element = fixture.nativeElement.querySelector('.adf-comments-input-add'); component.message = ''; element.dispatchEvent(new Event('click')); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(addContentCommentSpy).not.toHaveBeenCalled(); - }); - })); - it('should clear comment when escape key is pressed', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(addContentCommentSpy).not.toHaveBeenCalled(); + }); + + it('should clear comment when escape key is pressed', async () => { const event = new KeyboardEvent('keydown', {'key': 'Escape'}); let element = fixture.nativeElement.querySelector('#comment-input'); element.dispatchEvent(event); + fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - element = fixture.nativeElement.querySelector('#comment-input'); - expect(element.value).toBe(''); - }); - })); + await fixture.whenStable(); + + element = fixture.nativeElement.querySelector('#comment-input'); + expect(element.value).toBe(''); + }); it('should emit an error when an error occurs adding the comment', () => { const emitSpy = spyOn(component.error, 'emit'); diff --git a/lib/core/datatable/components/empty-list/empty-list.component.spec.ts b/lib/core/datatable/components/empty-list/empty-list.component.spec.ts index 5fc248fc64..80407a3558 100644 --- a/lib/core/datatable/components/empty-list/empty-list.component.spec.ts +++ b/lib/core/datatable/components/empty-list/empty-list.component.spec.ts @@ -15,14 +15,13 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { EmptyListComponent } from './empty-list.component'; import { setupTestBed } from '../../../testing/setup-test-bed'; import { CoreTestingModule } from '../../../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; describe('EmptyListComponentComponent', () => { - let component: EmptyListComponent; let fixture: ComponentFixture; setupTestBed({ @@ -34,22 +33,16 @@ describe('EmptyListComponentComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(EmptyListComponent); - component = fixture.componentInstance; }); afterEach(() => { fixture.destroy(); }); - it('should be defined', () => { - expect(component).toBeDefined(); - }); - - it('should render the input values', async(() => { + it('should render the input values', async () => { fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(fixture.nativeElement.querySelector('.adf-empty-list_template')).toBeDefined(); - }); - })); + await fixture.whenStable(); + + expect(fixture.nativeElement.querySelector('.adf-empty-list_template')).toBeDefined(); + }); }); diff --git a/lib/core/directives/infinite-select-scroll.directive.ts b/lib/core/directives/infinite-select-scroll.directive.ts index f34aa1e349..ae8f4d8d91 100644 --- a/lib/core/directives/infinite-select-scroll.directive.ts +++ b/lib/core/directives/infinite-select-scroll.directive.ts @@ -16,10 +16,12 @@ */ import { Inject, AfterViewInit, Directive, EventEmitter, OnDestroy, Output } from '@angular/core'; -import { MatSelect, SELECT_ITEM_HEIGHT_EM } from '@angular/material/select'; +import { MatSelect } from '@angular/material/select'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; +const SELECT_ITEM_HEIGHT_EM = 3; + @Directive({ selector: '[adf-infinite-select-scroll]' }) diff --git a/lib/core/form/components/form-list.component.spec.ts b/lib/core/form/components/form-list.component.spec.ts index 5cfbd384ba..7f442b6c0a 100644 --- a/lib/core/form/components/form-list.component.spec.ts +++ b/lib/core/form/components/form-list.component.spec.ts @@ -46,17 +46,17 @@ describe('TaskAttachmentList', () => { })); - it('should show the forms as a list', async(() => { + it('should show the forms as a list', async () => { spyOn(service, 'getForms').and.returnValue(of([ { name: 'FakeName-1', lastUpdatedByFullName: 'FakeUser-1', lastUpdated: '2017-01-02' }, { name: 'FakeName-2', lastUpdatedByFullName: 'FakeUser-2', lastUpdated: '2017-01-03' } ])); component.ngOnChanges(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelectorAll('.adf-datatable-body > .adf-datatable-row').length).toBe(2); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.querySelectorAll('.adf-datatable-body > .adf-datatable-row').length).toBe(2); + }); }); diff --git a/lib/core/form/components/widgets/amount/amount.widget.spec.ts b/lib/core/form/components/widgets/amount/amount.widget.spec.ts index 6d9a6ea76a..792d775d0d 100644 --- a/lib/core/form/components/widgets/amount/amount.widget.spec.ts +++ b/lib/core/form/components/widgets/amount/amount.widget.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { FormFieldModel } from './../core/form-field.model'; import { AmountWidgetComponent, ADF_AMOUNT_SETTINGS } from './amount.widget'; import { setupTestBed } from '../../../../testing/setup-test-bed'; @@ -147,7 +147,7 @@ describe('AmountWidgetComponent - rendering', () => { expect(errorWidget.textContent).toBe('FORM.FIELD.VALIDATOR.INVALID_NUMBER'); }); - it('should display tooltip when tooltip is set', async(() => { + it('should display tooltip when tooltip is set', async () => { widget.field = new FormFieldModel(new FormModel(), { id: 'TestAmount1', name: 'Test Amount', @@ -168,11 +168,13 @@ describe('AmountWidgetComponent - rendering', () => { }); fixture.detectChanges(); + await fixture.whenStable(); + const ammountElement: any = fixture.nativeElement.querySelector('#TestAmount1'); const tooltip = ammountElement.getAttribute('ng-reflect-message'); expect(tooltip).toEqual(widget.field.tooltip); - })); + }); }); describe('AmountWidgetComponent settings', () => { diff --git a/lib/core/form/components/widgets/checkbox/checkbox.widget.spec.ts b/lib/core/form/components/widgets/checkbox/checkbox.widget.spec.ts index 2568f6f8a8..5fea34247a 100644 --- a/lib/core/form/components/widgets/checkbox/checkbox.widget.spec.ts +++ b/lib/core/form/components/widgets/checkbox/checkbox.widget.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing'; import { FormFieldTypes } from '../core/form-field-types'; import { FormFieldModel } from '../core/form-field.model'; import { FormModel } from '../core/form.model'; @@ -54,6 +54,8 @@ describe('CheckboxWidgetComponent', () => { element = fixture.nativeElement; }); + afterEach(() => fixture.destroy()); + describe('when template is ready', () => { beforeEach(() => { @@ -67,14 +69,14 @@ describe('CheckboxWidgetComponent', () => { }); }); - it('should be marked as invalid when required', async(() => { + it('should be marked as invalid when required', async () => { fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelector('.adf-invalid')).not.toBeNull(); - }); - })); + await fixture.whenStable(); - it('should be checked if boolean true is passed', async(() => { + expect(element.querySelector('.adf-invalid')).not.toBeNull(); + }); + + it('should be checked if boolean true is passed', fakeAsync(() => { widget.field.value = true; fixture.detectChanges(); fixture.whenStable().then(() => { @@ -84,26 +86,26 @@ describe('CheckboxWidgetComponent', () => { }); })); - it('should not be checked if false is passed', async(() => { + it('should not be checked if false is passed', async () => { widget.field.value = false; - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const checkbox = fixture.debugElement.nativeElement.querySelector('mat-checkbox input'); - expect(checkbox.getAttribute('aria-checked')).toBe('false'); - }); - })); - it('should display tooltip when tooltip is set', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const checkbox = fixture.debugElement.nativeElement.querySelector('mat-checkbox input'); + expect(checkbox.getAttribute('aria-checked')).toBe('false'); + }); + + it('should display tooltip when tooltip is set', async () => { widget.field.tooltip = 'checkbox widget'; fixture.detectChanges(); - fixture.whenStable().then(() => { - const checkbox = fixture.debugElement.nativeElement.querySelector('#check-id'); - const tooltip = checkbox.getAttribute('ng-reflect-message'); + await fixture.whenStable(); - expect(tooltip).toEqual(widget.field.tooltip); - }); - })); + const checkbox = fixture.debugElement.nativeElement.querySelector('#check-id'); + const tooltip = checkbox.getAttribute('ng-reflect-message'); + + expect(tooltip).toEqual(widget.field.tooltip); + }); }); }); diff --git a/lib/core/form/components/widgets/date-time/date-time.widget.spec.ts b/lib/core/form/components/widgets/date-time/date-time.widget.spec.ts index dd40f6aef1..b451393f0a 100644 --- a/lib/core/form/components/widgets/date-time/date-time.widget.spec.ts +++ b/lib/core/form/components/widgets/date-time/date-time.widget.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import moment from 'moment-es6'; import { FormFieldModel } from './../core/form-field.model'; import { FormModel } from './../core/form.model'; @@ -109,7 +109,7 @@ describe('DateTimeWidgetComponent', () => { describe('template check', () => { - it('should show visible date widget', async(() => { + it('should show visible date widget', async () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -117,37 +117,36 @@ describe('DateTimeWidgetComponent', () => { type: 'datetime', readOnly: 'false' }); - fixture.detectChanges(); - fixture.whenStable() - .then(() => { - expect(element.querySelector('#date-field-id')).toBeDefined(); - expect(element.querySelector('#date-field-id')).not.toBeNull(); - const dateElement: any = element.querySelector('#date-field-id'); - expect(dateElement.value).toBe('30-11-9999 10:30 AM'); - }); - })); - it('should show the correct format type', async(() => { - widget.field = new FormFieldModel(new FormModel(), { - id: 'date-field-id', - name: 'date-name', - value: '12-30-9999 10:30 AM', - dateDisplayFormat: 'MM-DD-YYYY HH:mm A', - type: 'datetime', - readOnly: 'false' - }); - fixture.detectChanges(); - fixture.whenStable() - .then(() => { - fixture.detectChanges(); - expect(element.querySelector('#date-field-id')).toBeDefined(); - expect(element.querySelector('#date-field-id')).not.toBeNull(); - const dateElement: any = element.querySelector('#date-field-id'); - expect(dateElement.value).toContain('12-30-9999 10:30 AM'); - }); - })); - - it('should disable date button when is readonly', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.querySelector('#date-field-id')).toBeDefined(); + expect(element.querySelector('#date-field-id')).not.toBeNull(); + const dateElement: any = element.querySelector('#date-field-id'); + expect(dateElement.value).toBe('30-11-9999 10:30 AM'); + }); + + it('should show the correct format type', async () => { + widget.field = new FormFieldModel(new FormModel(), { + id: 'date-field-id', + name: 'date-name', + value: '12-30-9999 10:30 AM', + dateDisplayFormat: 'MM-DD-YYYY HH:mm A', + type: 'datetime', + readOnly: 'false' + }); + + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.querySelector('#date-field-id')).toBeDefined(); + expect(element.querySelector('#date-field-id')).not.toBeNull(); + const dateElement: any = element.querySelector('#date-field-id'); + expect(dateElement.value).toContain('12-30-9999 10:30 AM'); + }); + + it('should disable date button when is readonly', async () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -157,18 +156,20 @@ describe('DateTimeWidgetComponent', () => { readOnly: 'false' }); fixture.detectChanges(); + await fixture.whenStable(); let dateButton = element.querySelector('button'); expect(dateButton.disabled).toBeFalsy(); widget.field.readOnly = true; fixture.detectChanges(); + await fixture.whenStable(); dateButton = element.querySelector('button'); expect(dateButton.disabled).toBeTruthy(); - })); + }); - it('should display tooltip when tooltip is set', async(() => { + it('should display tooltip when tooltip is set', async () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -180,11 +181,13 @@ describe('DateTimeWidgetComponent', () => { }); fixture.detectChanges(); + await fixture.whenStable(); + const dateElement: any = element.querySelector('#date-field-id'); const tooltip = dateElement.getAttribute('ng-reflect-message'); expect(tooltip).toEqual(widget.field.tooltip); - })); + }); }); it('should display always the json value', () => { diff --git a/lib/core/form/components/widgets/date/date.widget.spec.ts b/lib/core/form/components/widgets/date/date.widget.spec.ts index 68c723a69f..6e69ea7eb1 100644 --- a/lib/core/form/components/widgets/date/date.widget.spec.ts +++ b/lib/core/form/components/widgets/date/date.widget.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import moment from 'moment-es6'; import { FormFieldModel } from './../core/form-field.model'; import { FormModel } from './../core/form.model'; @@ -105,7 +105,7 @@ describe('DateWidgetComponent', () => { TestBed.resetTestingModule(); }); - it('should show visible date widget', async(() => { + it('should show visible date widget', async () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -115,16 +115,17 @@ describe('DateWidgetComponent', () => { }); widget.field.isVisible = true; widget.ngOnInit(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelector('#date-field-id')).toBeDefined(); - expect(element.querySelector('#date-field-id')).not.toBeNull(); - const dateElement: any = element.querySelector('#date-field-id'); - expect(dateElement.value).toContain('9-9-9999'); - }); - })); - it('should show the correct format type', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.querySelector('#date-field-id')).toBeDefined(); + expect(element.querySelector('#date-field-id')).not.toBeNull(); + const dateElement: any = element.querySelector('#date-field-id'); + expect(dateElement.value).toContain('9-9-9999'); + }); + + it('should show the correct format type', async () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -135,17 +136,17 @@ describe('DateWidgetComponent', () => { widget.field.isVisible = true; widget.field.dateDisplayFormat = 'MM-DD-YYYY'; widget.ngOnInit(); - fixture.detectChanges(); - fixture.whenStable() - .then(() => { - expect(element.querySelector('#date-field-id')).toBeDefined(); - expect(element.querySelector('#date-field-id')).not.toBeNull(); - const dateElement: any = element.querySelector('#date-field-id'); - expect(dateElement.value).toContain('12-30-9999'); - }); - })); - it('should disable date button when is readonly', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.querySelector('#date-field-id')).toBeDefined(); + expect(element.querySelector('#date-field-id')).not.toBeNull(); + const dateElement: any = element.querySelector('#date-field-id'); + expect(dateElement.value).toContain('12-30-9999'); + }); + + it('should disable date button when is readonly', async () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -155,7 +156,9 @@ describe('DateWidgetComponent', () => { }); widget.field.isVisible = true; widget.field.readOnly = false; + fixture.detectChanges(); + await fixture.whenStable(); let dateButton = element.querySelector('button'); expect(dateButton.disabled).toBeFalsy(); @@ -165,9 +168,9 @@ describe('DateWidgetComponent', () => { dateButton = element.querySelector('button'); expect(dateButton.disabled).toBeTruthy(); - })); + }); - it('should set isValid to false when the value is not a correct date value', async(() => { + it('should set isValid to false when the value is not a correct date value', async () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -177,9 +180,11 @@ describe('DateWidgetComponent', () => { }); widget.field.isVisible = true; widget.field.readOnly = false; + fixture.detectChanges(); + await fixture.whenStable(); expect(widget.field.isValid).toBeFalsy(); - })); + }); }); }); diff --git a/lib/core/form/components/widgets/dropdown/dropdown.widget.spec.ts b/lib/core/form/components/widgets/dropdown/dropdown.widget.spec.ts index 08570b21af..3d1023d389 100644 --- a/lib/core/form/components/widgets/dropdown/dropdown.widget.spec.ts +++ b/lib/core/form/components/widgets/dropdown/dropdown.widget.spec.ts @@ -132,28 +132,33 @@ describe('DropdownWidgetComponent', () => { }); })); - it('should be able to display label with asterix', async(() => { + it('should be able to display label with asterix', async () => { const label = 'MyLabel123'; widget.field.name = label; + fixture.detectChanges(); + await fixture.whenStable(); expect(element.querySelector('label').innerText).toBe(label + '*'); - })); + }); - it('should be invalid if no default option', async(() => { + it('should be invalid if no default option', async () => { fixture.detectChanges(); + await fixture.whenStable(); expect(element.querySelector('.adf-invalid')).toBeDefined(); expect(element.querySelector('.adf-invalid')).not.toBeNull(); - })); + }); - it('should be valid if default option', async(() => { + it('should be valid if default option', async () => { widget.field.options = fakeOptionList; widget.field.value = fakeOptionList[0].id; + fixture.detectChanges(); + await fixture.whenStable(); expect(element.querySelector('.adf-invalid')).toBeNull(); - })); + }); }); describe('when template is ready', () => { @@ -177,7 +182,7 @@ describe('DropdownWidgetComponent', () => { fixture.detectChanges(); })); - it('should show visible dropdown widget', async(() => { + it('should show visible dropdown widget', async () => { expect(element.querySelector('#dropdown-id')).toBeDefined(); expect(element.querySelector('#dropdown-id')).not.toBeNull(); @@ -190,36 +195,35 @@ describe('DropdownWidgetComponent', () => { expect(optOne).not.toBeNull(); expect(optTwo).not.toBeNull(); expect(optThree).not.toBeNull(); - })); + }); - it('should select the default value when an option is chosen as default', async(() => { + it('should select the default value when an option is chosen as default', async () => { widget.field.value = 'option_2'; widget.ngOnInit(); - fixture.detectChanges(); - fixture.whenStable() - .then(() => { - const dropDownElement: any = element.querySelector('#dropdown-id'); - expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('option_2'); - expect(dropDownElement.attributes['ng-reflect-model'].textContent).toBe('option_2'); - }); - })); - it('should select the empty value when no default is chosen', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const dropDownElement: any = element.querySelector('#dropdown-id'); + expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('option_2'); + expect(dropDownElement.attributes['ng-reflect-model'].textContent).toBe('option_2'); + }); + + it('should select the empty value when no default is chosen', async () => { widget.field.value = 'empty'; widget.ngOnInit(); + fixture.detectChanges(); + await fixture.whenStable(); openSelect(); fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable() - .then(() => { - const dropDownElement: any = element.querySelector('#dropdown-id'); - expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('empty'); - }); - })); - + const dropDownElement: any = element.querySelector('#dropdown-id'); + expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('empty'); + }); }); describe('and dropdown is populated via processDefinitionId', () => { @@ -241,7 +245,7 @@ describe('DropdownWidgetComponent', () => { fixture.detectChanges(); })); - it('should show visible dropdown widget', async(() => { + it('should show visible dropdown widget', () => { expect(element.querySelector('#dropdown-id')).toBeDefined(); expect(element.querySelector('#dropdown-id')).not.toBeNull(); @@ -254,37 +258,37 @@ describe('DropdownWidgetComponent', () => { expect(optOne).not.toBeNull(); expect(optTwo).not.toBeNull(); expect(optThree).not.toBeNull(); - })); + }); - it('should select the default value when an option is chosen as default', async(() => { + it('should select the default value when an option is chosen as default', async () => { widget.field.value = 'option_2'; widget.ngOnInit(); - fixture.detectChanges(); - fixture.whenStable() - .then(() => { - const dropDownElement: any = element.querySelector('#dropdown-id'); - expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('option_2'); - expect(dropDownElement.attributes['ng-reflect-model'].textContent).toBe('option_2'); - }); - })); - it('should select the empty value when no default is chosen', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const dropDownElement: any = element.querySelector('#dropdown-id'); + expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('option_2'); + expect(dropDownElement.attributes['ng-reflect-model'].textContent).toBe('option_2'); + }); + + it('should select the empty value when no default is chosen', async () => { widget.field.value = 'empty'; widget.ngOnInit(); + fixture.detectChanges(); + await fixture.whenStable(); openSelect(); fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable() - .then(() => { - const dropDownElement: any = element.querySelector('#dropdown-id'); - expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('empty'); - }); - })); + const dropDownElement: any = element.querySelector('#dropdown-id'); + expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('empty'); + }); - it('should be disabled when the field is readonly', async(() => { + it('should be disabled when the field is readonly', async () => { widget.field = new FormFieldModel(new FormModel({ processDefinitionId: 'fake-process-id' }), { id: 'dropdown-id', name: 'date-name', @@ -294,15 +298,14 @@ describe('DropdownWidgetComponent', () => { }); fixture.detectChanges(); - fixture.whenStable() - .then(() => { - const dropDownElement: HTMLSelectElement = element.querySelector('#dropdown-id'); - expect(dropDownElement).not.toBeNull(); - expect(dropDownElement.getAttribute('aria-disabled')).toBe('true'); - }); - })); + await fixture.whenStable(); - it('should show the option value when the field is readonly', async(() => { + const dropDownElement: HTMLSelectElement = element.querySelector('#dropdown-id'); + expect(dropDownElement).not.toBeNull(); + expect(dropDownElement.getAttribute('aria-disabled')).toBe('true'); + }); + + it('should show the option value when the field is readonly', async () => { widget.field = new FormFieldModel(new FormModel({ processDefinitionId: 'fake-process-id' }), { id: 'dropdown-id', name: 'date-name', @@ -315,16 +318,14 @@ describe('DropdownWidgetComponent', () => { openSelect(); fixture.detectChanges(); - fixture.whenStable() - .then(() => { - fixture.detectChanges(); - const options = fixture.debugElement.queryAll(By.css('.mat-option-text')); - expect(options.length).toBe(1); + await fixture.whenStable(); - const option = options[0].nativeElement; - expect(option.innerText).toEqual('FakeValue'); - }); - })); + const options = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(options.length).toBe(1); + + const option = options[0].nativeElement; + expect(option.innerText).toEqual('FakeValue'); + }); }); }); }); diff --git a/lib/core/form/components/widgets/dynamic-table/dynamic-table.widget.spec.ts b/lib/core/form/components/widgets/dynamic-table/dynamic-table.widget.spec.ts index 55534572bd..81fa128f5e 100644 --- a/lib/core/form/components/widgets/dynamic-table/dynamic-table.widget.spec.ts +++ b/lib/core/form/components/widgets/dynamic-table/dynamic-table.widget.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { LogService } from '../../../../services'; import { FormService } from './../../../services/form.service'; import { FormFieldModel, FormFieldTypes, FormModel } from './../core/index'; @@ -338,7 +338,7 @@ describe('DynamicTableWidgetComponent', () => { TestBed.resetTestingModule(); }); - it('should select a row when press space bar', async(() => { + it('should select a row when press space bar', async () => { const rowElement = element.querySelector('#fake-dynamic-table-row-0'); expect(element.querySelector('#dynamic-table-fake-dynamic-table')).not.toBeNull(); @@ -348,15 +348,15 @@ describe('DynamicTableWidgetComponent', () => { const event: any = new Event('keyup'); event.keyCode = 32; rowElement.dispatchEvent(event); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const selectedRow = element.querySelector('#fake-dynamic-table-row-0'); - expect(selectedRow.className).toContain('adf-dynamic-table-widget__row-selected'); - }); - })); + const selectedRow = element.querySelector('#fake-dynamic-table-row-0'); + expect(selectedRow.className).toContain('adf-dynamic-table-widget__row-selected'); + }); - it('should focus on add button when a new row is saved', async(() => { + it('should focus on add button when a new row is saved', async () => { const addNewRowButton: HTMLButtonElement = element.querySelector('#fake-dynamic-table-add-row'); expect(element.querySelector('#dynamic-table-fake-dynamic-table')).not.toBeNull(); @@ -364,11 +364,11 @@ describe('DynamicTableWidgetComponent', () => { widget.addNewRow(); widget.onSaveChanges(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(document.activeElement.id).toBe('fake-dynamic-table-add-row'); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(document.activeElement.id).toBe('fake-dynamic-table-add-row'); + }); }); }); diff --git a/lib/core/form/components/widgets/dynamic-table/editors/dropdown/dropdown.editor.spec.ts b/lib/core/form/components/widgets/dynamic-table/editors/dropdown/dropdown.editor.spec.ts index a19bf16084..720bd9235f 100644 --- a/lib/core/form/components/widgets/dynamic-table/editors/dropdown/dropdown.editor.spec.ts +++ b/lib/core/form/components/widgets/dynamic-table/editors/dropdown/dropdown.editor.spec.ts @@ -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 { Observable, of, throwError } from 'rxjs'; import { FormService } from './../../../../../services/form.service'; @@ -195,11 +195,11 @@ describe('DropdownEditorComponent', () => { fixture.detectChanges(); } - beforeEach(async(() => { + beforeEach(() => { fixture = TestBed.createComponent(DropdownEditorComponent); dropDownEditorComponent = fixture.componentInstance; element = fixture.nativeElement; - })); + }); afterEach(() => { fixture.destroy(); @@ -207,7 +207,7 @@ describe('DropdownEditorComponent', () => { describe('and dropdown is populated via taskId', () => { - beforeEach(async(() => { + beforeEach(() => { stubFormService = fixture.debugElement.injector.get(FormService); spyOn(stubFormService, 'getRestFieldValuesColumn').and.returnValue(of(fakeOptionList)); row = {value: {dropdown: 'one'}}; @@ -235,9 +235,9 @@ describe('DropdownEditorComponent', () => { }); dropDownEditorComponent.table.field.isVisible = true; fixture.detectChanges(); - })); + }); - it('should show visible dropdown widget', async(() => { + it('should show visible dropdown widget', () => { expect(element.querySelector('#column-id')).toBeDefined(); expect(element.querySelector('#column-id')).not.toBeNull(); @@ -250,12 +250,12 @@ describe('DropdownEditorComponent', () => { expect(optOne).not.toBeNull(); expect(optTwo).not.toBeNull(); expect(optThree).not.toBeNull(); - })); + }); }); describe('and dropdown is populated via processDefinitionId', () => { - beforeEach(async(() => { + beforeEach(() => { stubFormService = fixture.debugElement.injector.get(FormService); spyOn(stubFormService, 'getRestFieldValuesColumnByProcessId').and.returnValue(of(fakeOptionList)); row = {value: {dropdown: 'one'}}; @@ -283,9 +283,9 @@ describe('DropdownEditorComponent', () => { }); dropDownEditorComponent.table.field.isVisible = true; fixture.detectChanges(); - })); + }); - it('should show visible dropdown widget', async(() => { + it('should show visible dropdown widget', () => { expect(element.querySelector('#column-id')).toBeDefined(); expect(element.querySelector('#column-id')).not.toBeNull(); @@ -298,8 +298,7 @@ describe('DropdownEditorComponent', () => { expect(optOne).not.toBeNull(); expect(optTwo).not.toBeNull(); expect(optThree).not.toBeNull(); - })); - + }); }); }); }); diff --git a/lib/core/form/components/widgets/people/people.widget.spec.ts b/lib/core/form/components/widgets/people/people.widget.spec.ts index 60520ad281..5ad02e5b20 100644 --- a/lib/core/form/components/widgets/people/people.widget.spec.ts +++ b/lib/core/form/components/widgets/people/people.widget.spec.ts @@ -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 { UserProcessModel } from '../../../../models'; import { Observable, of } from 'rxjs'; @@ -83,28 +83,23 @@ describe('PeopleWidgetComponent', () => { expect(widget.getDisplayName(model)).toBe('John'); }); - it('should init value from the field', async(() => { + it('should init value from the field', async () => { widget.field.value = new UserProcessModel({ id: 'people-id', firstName: 'John', lastName: 'Doe' }); - spyOn(formService, 'getWorkflowUsers').and.returnValue( - new Observable((observer) => { - observer.next(null); - observer.complete(); - }) - ); + spyOn(formService, 'getWorkflowUsers').and.returnValue(of(null)); widget.ngOnInit(); fixture.detectChanges(); - fixture.whenStable().then(() => { - expect((element.querySelector('input') as HTMLInputElement).value).toBe('John Doe'); - }); - })); + await fixture.whenStable(); - it('should show the readonly value when the form is readonly', async(() => { + expect((element.querySelector('input') as HTMLInputElement).value).toBe('John Doe'); + }); + + it('should show the readonly value when the form is readonly', async () => { widget.field.value = new UserProcessModel({ id: 'people-id', firstName: 'John', @@ -113,20 +108,15 @@ describe('PeopleWidgetComponent', () => { widget.field.readOnly = true; widget.field.form.readOnly = true; - spyOn(formService, 'getWorkflowUsers').and.returnValue( - new Observable((observer) => { - observer.next(null); - observer.complete(); - }) - ); + spyOn(formService, 'getWorkflowUsers').and.returnValue(of(null)); widget.ngOnInit(); fixture.detectChanges(); - fixture.whenStable().then(() => { - expect((element.querySelector('input') as HTMLInputElement).value).toBe('John Doe'); - expect((element.querySelector('input') as HTMLInputElement).disabled).toBeTruthy(); - }); - })); + await fixture.whenStable(); + + expect((element.querySelector('input') as HTMLInputElement).value).toBe('John Doe'); + expect((element.querySelector('input') as HTMLInputElement).disabled).toBeTruthy(); + }); it('should require form field to setup values on init', () => { widget.field.value = null; @@ -175,7 +165,7 @@ describe('PeopleWidgetComponent', () => { { id: 1001, firstName: 'Test01', lastName: 'Test01', email: 'test' }, { id: 1002, firstName: 'Test02', lastName: 'Test02', email: 'test2' }]; - beforeEach(async(() => { + beforeEach(() => { spyOn(formService, 'getWorkflowUsers').and.returnValue(new Observable((observer) => { observer.next(fakeUserResult); observer.complete(); @@ -188,7 +178,7 @@ describe('PeopleWidgetComponent', () => { }); fixture.detectChanges(); element = fixture.nativeElement; - })); + }); afterAll(() => { if (fixture) { @@ -201,32 +191,33 @@ describe('PeopleWidgetComponent', () => { expect(element.querySelector('#people-widget-content')).not.toBeNull(); }); - it('should show an error message if the user is invalid', async(() => { + it('should show an error message if the user is invalid', async () => { const peopleHTMLElement: HTMLInputElement = element.querySelector('input'); peopleHTMLElement.focus(); peopleHTMLElement.value = 'K'; peopleHTMLElement.dispatchEvent(new Event('keyup')); peopleHTMLElement.dispatchEvent(new Event('input')); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelector('.adf-error-text')).not.toBeNull(); - expect(element.querySelector('.adf-error-text').textContent).toContain('FORM.FIELD.VALIDATOR.INVALID_VALUE'); - }); - })); - it('should show the people if the typed result match', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.querySelector('.adf-error-text')).not.toBeNull(); + expect(element.querySelector('.adf-error-text').textContent).toContain('FORM.FIELD.VALIDATOR.INVALID_VALUE'); + }); + + it('should show the people if the typed result match', async () => { const peopleHTMLElement: HTMLInputElement = element.querySelector('input'); peopleHTMLElement.focus(); peopleHTMLElement.value = 'T'; peopleHTMLElement.dispatchEvent(new Event('keyup')); peopleHTMLElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(fixture.debugElement.query(By.css('#adf-people-widget-user-0'))).not.toBeNull(); - expect(fixture.debugElement.query(By.css('#adf-people-widget-user-1'))).not.toBeNull(); - }); - })); + await fixture.whenStable(); + + expect(fixture.debugElement.query(By.css('#adf-people-widget-user-0'))).not.toBeNull(); + expect(fixture.debugElement.query(By.css('#adf-people-widget-user-1'))).not.toBeNull(); + }); it('should hide result list if input is empty', () => { const peopleHTMLElement: HTMLInputElement = element.querySelector('input'); @@ -241,19 +232,22 @@ describe('PeopleWidgetComponent', () => { }); }); - it('should display two options if we tap one letter', async(() => { + it('should display two options if we tap one letter', async () => { + fixture.detectChanges(); + await fixture.whenStable(); + const peopleHTMLElement: HTMLInputElement = element.querySelector('input'); peopleHTMLElement.focus(); peopleHTMLElement.value = 'T'; peopleHTMLElement.dispatchEvent(new Event('keyup')); peopleHTMLElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(fixture.debugElement.query(By.css('#adf-people-widget-user-0'))).not.toBeNull(); - expect(fixture.debugElement.query(By.css('#adf-people-widget-user-1'))).not.toBeNull(); - }); - })); + await fixture.whenStable(); + + expect(fixture.debugElement.query(By.css('#adf-people-widget-user-0'))).not.toBeNull(); + expect(fixture.debugElement.query(By.css('#adf-people-widget-user-1'))).not.toBeNull(); + }); it('should emit peopleSelected if option is valid', async () => { const selectEmitSpy = spyOn(widget.peopleSelected, 'emit'); @@ -262,21 +256,23 @@ describe('PeopleWidgetComponent', () => { peopleHTMLElement.value = 'Test01 Test01'; peopleHTMLElement.dispatchEvent(new Event('keyup')); peopleHTMLElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(selectEmitSpy).toHaveBeenCalledWith(1001); - }); + await fixture.whenStable(); + + expect(selectEmitSpy).toHaveBeenCalledWith(1001); }); - it('should display tooltip when tooltip is set', async(() => { + it('should display tooltip when tooltip is set', async () => { widget.field.tooltip = 'people widget'; fixture.detectChanges(); + await fixture.whenStable(); + const radioButtonsElement: any = element.querySelector('#people-id'); const tooltip = radioButtonsElement.getAttribute('ng-reflect-message'); expect(tooltip).toEqual(widget.field.tooltip); - })); + }); }); }); diff --git a/lib/core/form/components/widgets/radio-buttons/radio-buttons.widget.spec.ts b/lib/core/form/components/widgets/radio-buttons/radio-buttons.widget.spec.ts index b7410ef678..bf12c912b1 100644 --- a/lib/core/form/components/widgets/radio-buttons/radio-buttons.widget.spec.ts +++ b/lib/core/form/components/widgets/radio-buttons/radio-buttons.widget.spec.ts @@ -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 { Observable, of } from 'rxjs'; import { FormService } from '../../../services/form.service'; import { ContainerModel } from '../core/container.model'; @@ -150,12 +150,12 @@ describe('RadioButtonsWidgetComponent', () => { name: 'opt-name-2' }]; - beforeEach(async(() => { + beforeEach(() => { fixture = TestBed.createComponent(RadioButtonsWidgetComponent); radioButtonWidget = fixture.componentInstance; element = fixture.nativeElement; stubFormService = fixture.debugElement.injector.get(FormService); - })); + }); it('should show radio buttons as text when is readonly', async () => { radioButtonWidget.field = new FormFieldModel(new FormModel({}), { @@ -230,7 +230,7 @@ describe('RadioButtonsWidgetComponent', () => { expect(radioButtonWidget.field.isValid).toBe(true); }); - it('should display tooltip when tooltip is set', async(() => { + it('should display tooltip when tooltip is set', async () => { radioButtonWidget.field = new FormFieldModel(new FormModel(), { id: 'radio-id', name: 'radio-name-label', @@ -244,15 +244,17 @@ describe('RadioButtonsWidgetComponent', () => { }); fixture.detectChanges(); + await fixture.whenStable(); + const radioButtonsElement: any = element.querySelector('#radio-id-opt-1'); const tooltip = radioButtonsElement.getAttribute('ng-reflect-message'); expect(tooltip).toEqual(radioButtonWidget.field.tooltip); - })); + }); describe('and radioButton is populated via taskId', () => { - beforeEach(async(() => { + beforeEach(() => { spyOn(stubFormService, 'getRestFieldValues').and.returnValue(of(restOption)); radioButtonWidget.field = new FormFieldModel(new FormModel({ taskId: 'task-id' }), { id: 'radio-id', @@ -264,17 +266,17 @@ describe('RadioButtonsWidgetComponent', () => { const fakeContainer = new ContainerModel(radioButtonWidget.field); radioButtonWidget.field.form.fields.push(fakeContainer); fixture.detectChanges(); - })); + }); - it('should show radio buttons', async(() => { + it('should show radio buttons', () => { expect(element.querySelector('#radio-id')).toBeDefined(); expect(element.querySelector('#radio-id-opt-1-input')).not.toBeNull(); expect(element.querySelector('#radio-id-opt-1')).not.toBeNull(); expect(element.querySelector('#radio-id-opt-2-input')).not.toBeNull(); expect(element.querySelector('#radio-id-opt-2')).not.toBeNull(); - })); + }); - it('should trigger field changed event on click', async(() => { + it('should trigger field changed event on click', fakeAsync(() => { const option: HTMLElement = element.querySelector('#radio-id-opt-1-input'); expect(element.querySelector('#radio-id')).not.toBeNull(); expect(option).not.toBeNull(); @@ -287,35 +289,35 @@ describe('RadioButtonsWidgetComponent', () => { describe('and radioButton is readonly', () => { - beforeEach(async(() => { + beforeEach(() => { radioButtonWidget.field.readOnly = true; fixture.detectChanges(); - })); + }); - it('should show radio buttons disabled', async(() => { + it('should show radio buttons disabled', () => { expect(element.querySelector('.mat-radio-disabled[ng-reflect-id="radio-id-opt-1"]')).toBeDefined(); expect(element.querySelector('.mat-radio-disabled[ng-reflect-id="radio-id-opt-1"]')).not.toBeNull(); expect(element.querySelector('.mat-radio-disabled[ng-reflect-id="radio-id-opt-2"]')).toBeDefined(); expect(element.querySelector('.mat-radio-disabled[ng-reflect-id="radio-id-opt-2"]')).not.toBeNull(); - })); + }); describe('and a value is selected', () => { - beforeEach(async(() => { + beforeEach(() => { radioButtonWidget.field.value = restOption[0].id; fixture.detectChanges(); - })); + }); - it('should check the selected value', async(() => { + it('should check the selected value', () => { expect(element.querySelector('.mat-radio-checked')).toBe(element.querySelector('mat-radio-button[ng-reflect-id="radio-id-opt-1"]')); - })); + }); }); }); }); describe('and radioButton is populated via processDefinitionId', () => { - beforeEach(async(() => { + beforeEach(() => { radioButtonWidget.field = new FormFieldModel(new FormModel({ processDefinitionId: 'proc-id' }), { id: 'radio-id', name: 'radio-name', @@ -325,15 +327,15 @@ describe('RadioButtonsWidgetComponent', () => { spyOn(stubFormService, 'getRestFieldValuesByProcessId').and.returnValue(of(restOption)); radioButtonWidget.field.isVisible = true; fixture.detectChanges(); - })); + }); - it('should show visible radio buttons', async(() => { + it('should show visible radio buttons', () => { expect(element.querySelector('#radio-id')).toBeDefined(); expect(element.querySelector('#radio-id-opt-1-input')).not.toBeNull(); expect(element.querySelector('#radio-id-opt-1')).not.toBeNull(); expect(element.querySelector('#radio-id-opt-2-input')).not.toBeNull(); expect(element.querySelector('#radio-id-opt-2')).not.toBeNull(); - })); + }); }); }); }); diff --git a/lib/core/form/components/widgets/text/text.widget.spec.ts b/lib/core/form/components/widgets/text/text.widget.spec.ts index 87db4e3c2c..686e3798ef 100644 --- a/lib/core/form/components/widgets/text/text.widget.spec.ts +++ b/lib/core/form/components/widgets/text/text.widget.spec.ts @@ -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 { FormFieldTypes } from '../core/form-field-types'; import { FormFieldModel } from '../core/form-field.model'; import { FormModel } from '../core/form.model'; @@ -203,7 +203,7 @@ describe('TextWidgetComponent', () => { expect(widget.field.isValid).toBe(false); }); - it('should display tooltip when tooltip is set', async(() => { + it('should display tooltip when tooltip is set', async () => { widget.field = new FormFieldModel(new FormModel(), { id: 'text-id', name: 'text-name', @@ -213,11 +213,13 @@ describe('TextWidgetComponent', () => { }); fixture.detectChanges(); + await fixture.whenStable(); + const textElement: any = element.querySelector('#text-id'); const tooltip = textElement.getAttribute('ng-reflect-message'); expect(tooltip).toEqual(widget.field.tooltip); - })); + }); }); describe('and no mask is configured on text element', () => { @@ -237,7 +239,7 @@ describe('TextWidgetComponent', () => { inputElement = element.querySelector('#text-id'); }); - it('should be disabled on readonly forms', async(() => { + it('should be disabled on readonly forms', fakeAsync(() => { fixture.whenStable().then(() => { fixture.detectChanges(); expect(inputElement).toBeDefined(); @@ -286,7 +288,7 @@ describe('TextWidgetComponent', () => { expect(label.innerText).toBe('simple placeholder'); }); - it('should prevent text to be written if is not allowed by the mask on keyUp event', async(() => { + it('should prevent text to be written if is not allowed by the mask on keyUp event', async () => { expect(element.querySelector('#text-id')).not.toBeNull(); inputElement.value = 'F'; @@ -294,31 +296,32 @@ describe('TextWidgetComponent', () => { const event: any = new Event('keyup'); event.keyCode = '70'; inputElement.dispatchEvent(event); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - inputElement = element.querySelector('#text-id'); - expect(inputElement.value).toBe(''); - }); - })); + inputElement = element.querySelector('#text-id'); + expect(inputElement.value).toBe(''); + }); - it('should prevent text to be written if is not allowed by the mask on input event', async(() => { + it('should prevent text to be written if is not allowed by the mask on input event', async () => { expect(element.querySelector('#text-id')).not.toBeNull(); inputElement.value = 'F'; widget.field.value = 'F'; inputElement.dispatchEvent(new Event('input')); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - inputElement = element.querySelector('#text-id'); - expect(inputElement.value).toBe(''); - }); - })); + inputElement = element.querySelector('#text-id'); + expect(inputElement.value).toBe(''); + }); + + it('should allow masked configured value on keyUp event', async () => { + fixture.detectChanges(); + await fixture.whenStable(); - it('should allow masked configured value on keyUp event', async(() => { expect(element.querySelector('#text-id')).not.toBeNull(); inputElement.value = '1'; @@ -327,14 +330,17 @@ describe('TextWidgetComponent', () => { event.keyCode = '49'; inputElement.dispatchEvent(event); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const textEle = element.querySelector('#text-id'); - expect(textEle.value).toBe('1'); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); + + const textEle = element.querySelector('#text-id'); + expect(textEle.value).toBe('1'); + }); + + it('should auto-fill masked configured value on keyUp event', async () => { + fixture.detectChanges(); + await fixture.whenStable(); - it('should auto-fill masked configured value on keyUp event', async(() => { expect(element.querySelector('#text-id')).not.toBeNull(); inputElement.value = '12345678'; @@ -343,12 +349,12 @@ describe('TextWidgetComponent', () => { event.keyCode = '49'; inputElement.dispatchEvent(event); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const textEle = element.querySelector('#text-id'); - expect(textEle.value).toBe('12-345,67%'); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); + + const textEle = element.querySelector('#text-id'); + expect(textEle.value).toBe('12-345,67%'); + }); }); describe('when the mask is reversed ', () => { @@ -374,7 +380,10 @@ describe('TextWidgetComponent', () => { TestBed.resetTestingModule(); }); - it('should be able to apply the mask reversed', async(() => { + it('should be able to apply the mask reversed', async () => { + fixture.detectChanges(); + await fixture.whenStable(); + expect(element.querySelector('#text-id')).not.toBeNull(); inputElement.value = '1234'; @@ -383,12 +392,12 @@ describe('TextWidgetComponent', () => { event.keyCode = '49'; inputElement.dispatchEvent(event); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const textEle = element.querySelector('#text-id'); - expect(textEle.value).toBe('12,34%'); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); + + const textEle = element.querySelector('#text-id'); + expect(textEle.value).toBe('12,34%'); + }); }); describe('and a mask placeholder is configured', () => { diff --git a/lib/core/form/components/widgets/typeahead/typeahead.widget.spec.ts b/lib/core/form/components/widgets/typeahead/typeahead.widget.spec.ts index 06c99180e9..ceaf1c79d6 100644 --- a/lib/core/form/components/widgets/typeahead/typeahead.widget.spec.ts +++ b/lib/core/form/components/widgets/typeahead/typeahead.widget.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { Observable, of, throwError } from 'rxjs'; import { By } from '@angular/platform-browser'; @@ -234,11 +234,11 @@ describe('TypeaheadWidgetComponent', () => { name: 'Fake Name 2' }, { id: '3', name: 'Fake Name 3' }]; - beforeEach(async(() => { + beforeEach(() => { fixture = TestBed.createComponent(TypeaheadWidgetComponent); typeaheadWidgetComponent = fixture.componentInstance; element = fixture.nativeElement; - })); + }); afterEach(() => { fixture.destroy(); @@ -247,7 +247,7 @@ describe('TypeaheadWidgetComponent', () => { describe ('and typeahead is in readonly mode', () => { - it('should show typeahead value with input disabled', async(() => { + it('should show typeahead value with input disabled', async () => { typeaheadWidgetComponent.field = new FormFieldModel( new FormModel({ processVariables: [{ name: 'typeahead-id_LABEL', value: 'FakeProcessValue' }] }), { id: 'typeahead-id', @@ -255,15 +255,15 @@ describe('TypeaheadWidgetComponent', () => { type: 'readonly', params: { field: { id: 'typeahead-id', name: 'typeahead-name', type: 'typeahead' } } }); + fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const readonlyInput: HTMLInputElement = element.querySelector('#typeahead-id'); - expect(readonlyInput.disabled).toBeTruthy(); - expect(readonlyInput).not.toBeNull(); - expect(readonlyInput.value).toBe('FakeProcessValue'); - }); - })); + await fixture.whenStable(); + + const readonlyInput = element.querySelector('#typeahead-id'); + expect(readonlyInput.disabled).toBeTruthy(); + expect(readonlyInput).not.toBeNull(); + expect(readonlyInput.value).toBe('FakeProcessValue'); + }); afterEach(() => { fixture.destroy(); @@ -273,7 +273,7 @@ describe('TypeaheadWidgetComponent', () => { describe('and typeahead is populated via taskId', () => { - beforeEach(async(() => { + beforeEach(() => { stubFormService = fixture.debugElement.injector.get(FormService); spyOn(stubFormService, 'getRestFieldValues').and.returnValue(of(fakeOptionList)); typeaheadWidgetComponent.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), { @@ -285,73 +285,73 @@ describe('TypeaheadWidgetComponent', () => { }); typeaheadWidgetComponent.field.isVisible = true; fixture.detectChanges(); - })); + }); - it('should show visible typeahead widget', async(() => { + it('should show visible typeahead widget', () => { expect(element.querySelector('#typeahead-id')).toBeDefined(); expect(element.querySelector('#typeahead-id')).not.toBeNull(); - })); + }); - it('should show typeahead options', async(() => { + it('should show typeahead options', async () => { const typeaheadElement = fixture.debugElement.query(By.css('#typeahead-id')); - const typeaheadHTMLElement: HTMLInputElement = typeaheadElement.nativeElement; + const typeaheadHTMLElement = typeaheadElement.nativeElement; typeaheadHTMLElement.focus(); typeaheadWidgetComponent.value = 'F'; typeaheadHTMLElement.value = 'F'; typeaheadHTMLElement.dispatchEvent(new Event('keyup')); typeaheadHTMLElement.dispatchEvent(new Event('input')); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-0"] span'))).not.toBeNull(); - expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-1"] span'))).not.toBeNull(); - expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-2"] span'))).not.toBeNull(); - }); - })); - it('should hide the option when the value is empty', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-0"] span'))).not.toBeNull(); + expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-1"] span'))).not.toBeNull(); + expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-2"] span'))).not.toBeNull(); + }); + + it('should hide the option when the value is empty', async () => { const typeaheadElement = fixture.debugElement.query(By.css('#typeahead-id')); - const typeaheadHTMLElement: HTMLInputElement = typeaheadElement.nativeElement; + const typeaheadHTMLElement = typeaheadElement.nativeElement; typeaheadHTMLElement.focus(); typeaheadWidgetComponent.value = 'F'; typeaheadHTMLElement.value = 'F'; typeaheadHTMLElement.dispatchEvent(new Event('keyup')); typeaheadHTMLElement.dispatchEvent(new Event('input')); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-0"] span'))).not.toBeNull(); - typeaheadHTMLElement.focus(); - typeaheadWidgetComponent.value = ''; - typeaheadHTMLElement.dispatchEvent(new Event('keyup')); - typeaheadHTMLElement.dispatchEvent(new Event('input')); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-0"] span'))).toBeNull(); - }); - }); - })); - it('should show error message when the value is not valid', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-0"] span'))).not.toBeNull(); + typeaheadHTMLElement.focus(); + typeaheadWidgetComponent.value = ''; + typeaheadHTMLElement.dispatchEvent(new Event('keyup')); + typeaheadHTMLElement.dispatchEvent(new Event('input')); + + fixture.detectChanges(); + await fixture.whenStable(); + + expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-0"] span'))).toBeNull(); + }); + + it('should show error message when the value is not valid', async () => { typeaheadWidgetComponent.value = 'Fake Name'; typeaheadWidgetComponent.field.value = 'Fake Name'; typeaheadWidgetComponent.field.options = fakeOptionList; expect(element.querySelector('.adf-error-text')).toBeNull(); const keyboardEvent = new KeyboardEvent('keypress'); typeaheadWidgetComponent.onKeyUp(keyboardEvent); + fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(element.querySelector('.adf-error-text')).not.toBeNull(); - expect(element.querySelector('.adf-error-text').textContent).toContain('FORM.FIELD.VALIDATOR.INVALID_VALUE'); - }); - })); + await fixture.whenStable(); + + expect(element.querySelector('.adf-error-text')).not.toBeNull(); + expect(element.querySelector('.adf-error-text').textContent).toContain('FORM.FIELD.VALIDATOR.INVALID_VALUE'); + }); }); describe('and typeahead is populated via processDefinitionId', () => { - beforeEach(async(() => { + beforeEach(() => { stubFormService = fixture.debugElement.injector.get(FormService); spyOn(stubFormService, 'getRestFieldValuesByProcessId').and.returnValue(of(fakeOptionList)); typeaheadWidgetComponent.field = new FormFieldModel(new FormModel({ processDefinitionId: 'fake-process-id' }), { @@ -363,24 +363,25 @@ describe('TypeaheadWidgetComponent', () => { typeaheadWidgetComponent.field.emptyOption = { id: 'empty', name: 'Choose one...' }; typeaheadWidgetComponent.field.isVisible = true; fixture.detectChanges(); - })); + }); - it('should show visible typeahead widget', async(() => { + it('should show visible typeahead widget', () => { expect(element.querySelector('#typeahead-id')).toBeDefined(); expect(element.querySelector('#typeahead-id')).not.toBeNull(); - })); + }); - it('should show typeahead options', async(() => { + it('should show typeahead options', async () => { const keyboardEvent = new KeyboardEvent('keypress'); typeaheadWidgetComponent.value = 'F'; typeaheadWidgetComponent.onKeyUp(keyboardEvent); + fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(fixture.debugElement.queryAll(By.css('[id="adf-typeahed-widget-user-0"] span'))).toBeDefined(); - expect(fixture.debugElement.queryAll(By.css('[id="adf-typeahed-widget-user-1"] span'))).toBeDefined(); - expect(fixture.debugElement.queryAll(By.css('[id="adf-typeahed-widget-user-2"] span'))).toBeDefined(); - }); - })); + await fixture.whenStable(); + + expect(fixture.debugElement.queryAll(By.css('[id="adf-typeahed-widget-user-0"] span'))).toBeDefined(); + expect(fixture.debugElement.queryAll(By.css('[id="adf-typeahed-widget-user-1"] span'))).toBeDefined(); + expect(fixture.debugElement.queryAll(By.css('[id="adf-typeahed-widget-user-2"] span'))).toBeDefined(); + }); }); }); }); diff --git a/lib/core/form/components/widgets/upload/upload.widget.spec.ts b/lib/core/form/components/widgets/upload/upload.widget.spec.ts index 623b0b2974..9b35927bee 100644 --- a/lib/core/form/components/widgets/upload/upload.widget.spec.ts +++ b/lib/core/form/components/widgets/upload/upload.widget.spec.ts @@ -16,7 +16,7 @@ */ import { DebugElement } 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'; import { FormService } from '../../../services/form.service'; @@ -60,7 +60,7 @@ const fakeJpgAnswer = { describe('UploadWidgetComponent', () => { - function fakeCreationFile (name, id) { + function fakeCreationFile (name: string, id: string | number) { return { 'id': id, 'name': name, @@ -96,13 +96,13 @@ describe('UploadWidgetComponent', () => { let inputElement: HTMLInputElement; let formServiceInstance: FormService; - beforeEach(async(() => { + beforeEach(() => { fixture = TestBed.createComponent(UploadWidgetComponent); uploadWidgetComponent = fixture.componentInstance; element = fixture.nativeElement; debugElement = fixture.debugElement; contentService = TestBed.inject(ProcessContentService); - })); + }); it('should setup with field data', () => { const fileName = 'hello world'; @@ -152,57 +152,60 @@ describe('UploadWidgetComponent', () => { uploadWidgetComponent.field.value = []; }); - it('should be not present in readonly forms', async(() => { + it('should be not present in readonly forms', async () => { uploadWidgetComponent.field.form.readOnly = true; fixture.detectChanges(); - inputElement = element.querySelector('#upload-id'); + inputElement = element.querySelector('#upload-id'); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(inputElement).toBeNull(); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); - it('should have the multiple attribute when is selected in parameters', async(() => { + expect(inputElement).toBeNull(); + }); + + it('should have the multiple attribute when is selected in parameters', async () => { uploadWidgetComponent.field.params.multiple = true; fixture.detectChanges(); - inputElement = element.querySelector('#upload-id'); + inputElement = element.querySelector('#upload-id'); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(inputElement).toBeDefined(); - expect(inputElement).not.toBeNull(); - expect(inputElement.getAttributeNode('multiple')).toBeTruthy(); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); - it('should not have the multiple attribute if multiple is false', async(() => { + expect(inputElement).toBeDefined(); + expect(inputElement).not.toBeNull(); + expect(inputElement.getAttributeNode('multiple')).toBeTruthy(); + }); + + it('should not have the multiple attribute if multiple is false', async () => { uploadWidgetComponent.field.params.multiple = false; fixture.detectChanges(); - inputElement = element.querySelector('#upload-id'); + inputElement = element.querySelector('#upload-id'); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(inputElement).toBeDefined(); - expect(inputElement).not.toBeNull(); - expect(inputElement.getAttributeNode('multiple')).toBeFalsy(); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); - it('should show the list file after upload a new content', async(() => { + expect(inputElement).toBeDefined(); + expect(inputElement).not.toBeNull(); + expect(inputElement.getAttributeNode('multiple')).toBeFalsy(); + }); + + it('should show the list file after upload a new content', async () => { spyOn(contentService, 'createTemporaryRawRelatedContent').and.returnValue(of(fakePngAnswer)); uploadWidgetComponent.field.params.multiple = false; + fixture.detectChanges(); + await fixture.whenStable(); + const inputDebugElement = fixture.debugElement.query(By.css('#upload-id')); inputDebugElement.triggerEventHandler('change', { target: { files: [filJpgFake] } }); const filesList = fixture.debugElement.query(By.css('#file-1156')); expect(filesList).toBeDefined(); - })); + }); - it('should update the form after deleted a file', async(() => { + it('should update the form after deleted a file', async () => { spyOn(contentService, 'createTemporaryRawRelatedContent').and.callFake((file: any) => { if (file.name === 'file-fake.png') { return of(fakePngAnswer); @@ -218,21 +221,23 @@ describe('UploadWidgetComponent', () => { uploadWidgetComponent.field.params.multiple = true; spyOn(uploadWidgetComponent.field, 'updateForm'); + fixture.detectChanges(); + await fixture.whenStable(); + const inputDebugElement = fixture.debugElement.query(By.css('#upload-id')); inputDebugElement.triggerEventHandler('change', { target: { files: [filePngFake, filJpgFake] } }); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const deleteButton = element.querySelector('#file-1155-remove'); - deleteButton.click(); + fixture.detectChanges(); + await fixture.whenStable(); - expect(uploadWidgetComponent.field.updateForm).toHaveBeenCalled(); - }); + const deleteButton = element.querySelector('#file-1155-remove'); + deleteButton.click(); - })); + expect(uploadWidgetComponent.field.updateForm).toHaveBeenCalled(); + }); - it('should set has field value all the files uploaded', async(() => { + it('should set has field value all the files uploaded', async () => { spyOn(contentService, 'createTemporaryRawRelatedContent').and.callFake((file: any) => { if (file.name === 'file-fake.png') { return of(fakePngAnswer); @@ -246,149 +251,141 @@ describe('UploadWidgetComponent', () => { }); uploadWidgetComponent.field.params.multiple = true; + fixture.detectChanges(); + await fixture.whenStable(); + const inputDebugElement = fixture.debugElement.query(By.css('#upload-id')); inputDebugElement.triggerEventHandler('change', { target: { files: [filePngFake, filJpgFake] } }); - fixture.whenStable().then(() => { - fixture.detectChanges(); - inputElement = element.querySelector('#upload-id'); - expect(inputElement).toBeDefined(); - expect(inputElement).not.toBeNull(); - expect(uploadWidgetComponent.field.value).not.toBeNull(); - expect(uploadWidgetComponent.field.value.length).toBe(2); - expect(uploadWidgetComponent.field.value[0].id).toBe(1155); - expect(uploadWidgetComponent.field.value[1].id).toBe(1156); - expect(uploadWidgetComponent.field.json.value.length).toBe(2); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); - it('should show all the file uploaded on multiple field', async(() => { + inputElement = element.querySelector('#upload-id'); + expect(inputElement).toBeDefined(); + expect(inputElement).not.toBeNull(); + expect(uploadWidgetComponent.field.value).not.toBeNull(); + expect(uploadWidgetComponent.field.value.length).toBe(2); + expect(uploadWidgetComponent.field.value[0].id).toBe(1155); + expect(uploadWidgetComponent.field.value[1].id).toBe(1156); + expect(uploadWidgetComponent.field.json.value.length).toBe(2); + }); + + it('should show all the file uploaded on multiple field', async () => { uploadWidgetComponent.field.params.multiple = true; uploadWidgetComponent.field.value.push(fakeJpgAnswer); uploadWidgetComponent.field.value.push(fakePngAnswer); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const jpegElement = element.querySelector('#file-1156'); - const pngElement = element.querySelector('#file-1155'); - expect(jpegElement).not.toBeNull(); - expect(pngElement).not.toBeNull(); - expect(jpegElement.textContent).toBe('a_jpg_file.jpg'); - expect(pngElement.textContent).toBe('a_png_file.png'); - }); - })); + const jpegElement = element.querySelector('#file-1156'); + const pngElement = element.querySelector('#file-1155'); + expect(jpegElement).not.toBeNull(); + expect(pngElement).not.toBeNull(); + expect(jpegElement.textContent).toBe('a_jpg_file.jpg'); + expect(pngElement.textContent).toBe('a_png_file.png'); + }); - it('should show correctly the file name when is formed with special characters', async(() => { + it('should show correctly the file name when is formed with special characters', async () => { uploadWidgetComponent.field.value.push(fakeCreationFile('±!@#$%^&*()_+{}:”|<>?§™£-=[];’\\,./.jpg', 10)); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const jpegElement = element.querySelector('#file-10'); - expect(jpegElement).not.toBeNull(); - expect(jpegElement.textContent).toBe(`±!@#$%^&*()_+{}:”|<>?§™£-=[];’\\,./.jpg`); - }); - })); + const jpegElement = element.querySelector('#file-10'); + expect(jpegElement).not.toBeNull(); + expect(jpegElement.textContent).toBe(`±!@#$%^&*()_+{}:”|<>?§™£-=[];’\\,./.jpg`); + }); - it('should show correctly the file name when is formed with Arabic characters', async(() => { + it('should show correctly the file name when is formed with Arabic characters', async () => { const name = 'غ ظ ض ذ خ ث ت ش ر ق ص ف ع س ن م ل ك ي ط ح ز و ه د ج ب ا.jpg'; uploadWidgetComponent.field.value.push(fakeCreationFile(name, 11)); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const jpegElement = element.querySelector('#file-11'); - expect(jpegElement).not.toBeNull(); - expect(jpegElement.textContent).toBe('غ ظ ض ذ خ ث ت ش ر ق ص ف ع س ن م ل ك ي ط ح ز و ه د ج ب ا.jpg'); - }); - })); + const jpegElement = element.querySelector('#file-11'); + expect(jpegElement).not.toBeNull(); + expect(jpegElement.textContent).toBe('غ ظ ض ذ خ ث ت ش ر ق ص ف ع س ن م ل ك ي ط ح ز و ه د ج ب ا.jpg'); + }); - it('should show correctly the file name when is formed with French characters', async(() => { + it('should show correctly the file name when is formed with French characters', async () => { // cspell: disable-next uploadWidgetComponent.field.value.push(fakeCreationFile('Àâæçéèêëïîôœùûüÿ.jpg', 12)); fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const jpegElement = element.querySelector('#file-12'); - expect(jpegElement).not.toBeNull(); - // cspell: disable-next - expect(jpegElement.textContent).toBe('Àâæçéèêëïîôœùûüÿ.jpg'); - }); - })); + const jpegElement = element.querySelector('#file-12'); + expect(jpegElement).not.toBeNull(); + // cspell: disable-next + expect(jpegElement.textContent).toBe('Àâæçéèêëïîôœùûüÿ.jpg'); + }); - it('should show correctly the file name when is formed with Greek characters', async(() => { + it('should show correctly the file name when is formed with Greek characters', async () => { // cspell: disable-next uploadWidgetComponent.field.value.push(fakeCreationFile('άέήίϊϊΐόύϋΰώθωερτψυιοπασδφγηςκλζχξωβνμ.jpg', 13)); fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const jpegElement = element.querySelector('#file-13'); - expect(jpegElement).not.toBeNull(); - // cspell: disable-next - expect(jpegElement.textContent).toBe('άέήίϊϊΐόύϋΰώθωερτψυιοπασδφγηςκλζχξωβνμ.jpg'); - }); - })); + const jpegElement = element.querySelector('#file-13'); + expect(jpegElement).not.toBeNull(); + // cspell: disable-next + expect(jpegElement.textContent).toBe('άέήίϊϊΐόύϋΰώθωερτψυιοπασδφγηςκλζχξωβνμ.jpg'); + }); - it('should show correctly the file name when is formed with Polish accented characters', async(() => { + it('should show correctly the file name when is formed with Polish accented characters', async () => { uploadWidgetComponent.field.value.push(fakeCreationFile('Ą Ć Ę Ł Ń Ó Ś Ź Żą ć ę ł ń ó ś ź ż.jpg', 14)); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const jpegElement = element.querySelector('#file-14'); - expect(jpegElement).not.toBeNull(); - expect(jpegElement.textContent).toBe('Ą Ć Ę Ł Ń Ó Ś Ź Żą ć ę ł ń ó ś ź ż.jpg'); - }); - })); + const jpegElement = element.querySelector('#file-14'); + expect(jpegElement).not.toBeNull(); + expect(jpegElement.textContent).toBe('Ą Ć Ę Ł Ń Ó Ś Ź Żą ć ę ł ń ó ś ź ż.jpg'); + }); - it('should show correctly the file name when is formed with Spanish accented characters', async(() => { + it('should show correctly the file name when is formed with Spanish accented characters', async () => { uploadWidgetComponent.field.value.push(fakeCreationFile('á, é, í, ó, ú, ñ, Ñ, ü, Ü, ¿, ¡. Á, É, Í, Ó, Ú.jpg', 15)); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const jpegElement = element.querySelector('#file-15'); - expect(jpegElement).not.toBeNull(); - expect(jpegElement.textContent).toBe('á, é, í, ó, ú, ñ, Ñ, ü, Ü, ¿, ¡. Á, É, Í, Ó, Ú.jpg'); - }); - })); + const jpegElement = element.querySelector('#file-15'); + expect(jpegElement).not.toBeNull(); + expect(jpegElement.textContent).toBe('á, é, í, ó, ú, ñ, Ñ, ü, Ü, ¿, ¡. Á, É, Í, Ó, Ú.jpg'); + }); - it('should show correctly the file name when is formed with Swedish characters', async(() => { + it('should show correctly the file name when is formed with Swedish characters', async () => { // cspell: disable-next uploadWidgetComponent.field.value.push(fakeCreationFile('Äåéö.jpg', 16)); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const jpegElement = element.querySelector('#file-16'); - expect(jpegElement).not.toBeNull(); - // cspell: disable-next - expect(jpegElement.textContent).toBe('Äåéö.jpg'); - }); - })); + const jpegElement = element.querySelector('#file-16'); + expect(jpegElement).not.toBeNull(); + // cspell: disable-next + expect(jpegElement.textContent).toBe('Äåéö.jpg'); + }); - it('should remove file from field value', async(() => { + it('should remove file from field value', async () => { uploadWidgetComponent.field.params.multiple = true; uploadWidgetComponent.field.value.push(fakeJpgAnswer); uploadWidgetComponent.field.value.push(fakePngAnswer); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const buttonElement = element.querySelector('#file-1156-remove'); - buttonElement.click(); - fixture.detectChanges(); - const jpegElement = element.querySelector('#file-1156'); - expect(jpegElement).toBeNull(); - expect(uploadWidgetComponent.field.value.length).toBe(1); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); + + const buttonElement = element.querySelector('#file-1156-remove'); + buttonElement.click(); + fixture.detectChanges(); + const jpegElement = element.querySelector('#file-1156'); + expect(jpegElement).toBeNull(); + expect(uploadWidgetComponent.field.value.length).toBe(1); + }); it('should emit form content clicked event on icon click', (done) => { spyOn(contentService, 'getContentPreview').and.returnValue(of(new Blob())); diff --git a/lib/core/login/components/login.component.spec.ts b/lib/core/login/components/login.component.spec.ts index e530666868..e55ff32d35 100644 --- a/lib/core/login/components/login.component.spec.ts +++ b/lib/core/login/components/login.component.spec.ts @@ -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 { Validators } from '@angular/forms'; import { Router } from '@angular/router'; @@ -67,7 +67,7 @@ describe('LoginComponent', () => { ] }); - beforeEach(async(() => { + beforeEach(fakeAsync(() => { fixture = TestBed.createComponent(LoginComponent); element = fixture.nativeElement; @@ -93,7 +93,7 @@ describe('LoginComponent', () => { fixture.destroy(); }); - function loginWithCredentials(username, password) { + function loginWithCredentials(username: string, password: string) { usernameInput.value = username; passwordInput.value = password; @@ -175,7 +175,7 @@ describe('LoginComponent', () => { expect(router.navigateByUrl).toHaveBeenCalledWith('some-route'); }); - it('should update user preferences upon login', async(() => { + it('should update user preferences upon login', fakeAsync(() => { spyOn(userPreferences, 'setStoragePrefix').and.callThrough(); spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.resolve()); @@ -465,7 +465,7 @@ describe('LoginComponent', () => { loginWithCredentials('fake-username-CORS-error', 'fake-password'); }); - it('should return CSRF error when server CSRF error occurs', async(() => { + it('should return CSRF error when server CSRF error occurs', fakeAsync(() => { spyOn(authService, 'login') .and.returnValue(throwError({ message: 'ERROR: Invalid CSRF-token', status: 403 })); @@ -480,7 +480,7 @@ describe('LoginComponent', () => { loginWithCredentials('fake-username-CSRF-error', 'fake-password'); })); - it('should return ECM read-only error when error occurs', async(() => { + it('should return ECM read-only error when error occurs', fakeAsync(() => { spyOn(authService, 'login') .and.returnValue( throwError( @@ -544,7 +544,7 @@ describe('LoginComponent', () => { loginWithCredentials('fake-username', 'fake-password'); }); - it('should emit success event after the login has succeeded and discard password', async(() => { + it('should emit success event after the login has succeeded and discard password', fakeAsync(() => { spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); component.success.subscribe((event) => { @@ -559,7 +559,7 @@ describe('LoginComponent', () => { loginWithCredentials('fake-username', 'fake-password'); })); - it('should emit error event after the login has failed', async(() => { + it('should emit error event after the login has failed', fakeAsync(() => { spyOn(authService, 'login').and.returnValue(throwError('Fake server error')); component.error.subscribe((error) => { @@ -596,7 +596,7 @@ describe('LoginComponent', () => { expect(element.querySelector('#password').type).toEqual('password'); }); - it('should emit only the username and not the password as part of the executeSubmit', async(() => { + it('should emit only the username and not the password as part of the executeSubmit', fakeAsync(() => { spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.resolve()); component.executeSubmit.subscribe((res) => { @@ -620,20 +620,18 @@ describe('LoginComponent', () => { alfrescoApiService.reset(); }); - it('should not show login username and password if SSO implicit flow is active', async(() => { + it('should not show login username and password if SSO implicit flow is active', fakeAsync(() => { spyOn(authService, 'isOauth').and.returnValue(true); component.ngOnInit(); fixture.detectChanges(); - fixture.detectChanges(); - fixture.whenStable().then(() => { expect(element.querySelector('#username')).toBeNull(); expect(element.querySelector('#password')).toBeNull(); }); })); - it('should not render the implicitFlow button in case silentLogin is enabled', async(() => { + it('should not render the implicitFlow button in case silentLogin is enabled', fakeAsync(() => { spyOn(authService, 'isOauth').and.returnValue(true); appConfigService.config.oauth2 = { implicitFlow: true, silentLogin: true }; @@ -649,7 +647,7 @@ describe('LoginComponent', () => { })); - it('should render the implicitFlow button in case silentLogin is disabled', async(() => { + it('should render the implicitFlow button in case silentLogin is disabled', fakeAsync(() => { spyOn(authService, 'isOauth').and.returnValue(true); component.ngOnInit(); @@ -661,7 +659,7 @@ describe('LoginComponent', () => { })); - it('should not show the login base auth button', async(() => { + it('should not show the login base auth button', fakeAsync(() => { spyOn(authService, 'isOauth').and.returnValue(true); component.ngOnInit(); @@ -672,7 +670,7 @@ describe('LoginComponent', () => { }); })); - it('should show the login SSO button', async(() => { + it('should show the login SSO button', fakeAsync(() => { spyOn(authService, 'isOauth').and.returnValue(true); component.ngOnInit(); diff --git a/lib/core/pipes/time-ago.pipe.spec.ts b/lib/core/pipes/time-ago.pipe.spec.ts index e815981eda..88e7a4cc9e 100644 --- a/lib/core/pipes/time-ago.pipe.spec.ts +++ b/lib/core/pipes/time-ago.pipe.spec.ts @@ -16,7 +16,7 @@ */ import { TimeAgoPipe } from './time-ago.pipe'; -import { async, TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { AppConfigService } from '../app-config/app-config.service'; import { UserPreferencesService } from '../services/user-preferences.service'; import { setupTestBed } from '../testing/setup-test-bed'; @@ -36,11 +36,11 @@ describe('TimeAgoPipe', () => { ] }); - beforeEach(async(() => { + beforeEach(() => { userPreferences = TestBed.inject(UserPreferencesService); spyOn(userPreferences, 'select').and.returnValue(of('')); pipe = new TimeAgoPipe(userPreferences, TestBed.inject(AppConfigService)); - })); + }); it('should return time difference for a given date', () => { const date = new Date(); @@ -59,11 +59,11 @@ describe('TimeAgoPipe', () => { describe('When a locale is given', () => { - it('should return a localised message', async(() => { + it('should return a localised message', () => { const date = new Date(); const transformedDate = pipe.transform(date, 'de'); /* cspell:disable-next-line */ expect(transformedDate).toBe('vor ein paar Sekunden'); - })); + }); }); }); diff --git a/lib/core/search-text/search-text-input.component.spec.ts b/lib/core/search-text/search-text-input.component.spec.ts index cb38e6dcb9..4a43d314f4 100644 --- a/lib/core/search-text/search-text-input.component.spec.ts +++ b/lib/core/search-text/search-text-input.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ComponentFixture, TestBed, discardPeriodicTasks, fakeAsync, tick, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed, discardPeriodicTasks, fakeAsync, tick } from '@angular/core/testing'; import { CoreTestingModule } from '../testing/core.testing.module'; import { SearchTextInputComponent } from './search-text-input.component'; import { DebugElement } from '@angular/core'; @@ -55,12 +55,17 @@ describe('SearchTextInputComponent', () => { describe('component rendering', () => { - it('should display a search input field when specified', async(() => { + it('should display a search input field when specified', async () => { fixture.detectChanges(); + await fixture.whenStable(); + component.inputType = 'search'; + fixture.detectChanges(); + await fixture.whenStable(); + expect(element.querySelectorAll('input[type="search"]').length).toBe(1); - })); + }); }); describe('expandable option false', () => { @@ -246,10 +251,13 @@ describe('SearchTextInputComponent', () => { discardPeriodicTasks(); })); - it('should set browser autocomplete to on when configured', async(() => { + it('should set browser autocomplete to on when configured', async () => { component.autocomplete = true; + fixture.detectChanges(); + await fixture.whenStable(); + expect(element.querySelector('#adf-control-input').getAttribute('autocomplete')).toBe('on'); - })); + }); }); }); diff --git a/lib/core/services/auth-guard-bpm.service.spec.ts b/lib/core/services/auth-guard-bpm.service.spec.ts index c57b293c06..1e98b49f20 100644 --- a/lib/core/services/auth-guard-bpm.service.spec.ts +++ b/lib/core/services/auth-guard-bpm.service.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { AppConfigService } from '../app-config/app-config.service'; import { AuthGuardBpm } from './auth-guard-bpm.service'; import { AuthenticationService } from './authentication.service'; @@ -51,7 +51,7 @@ describe('AuthGuardService BPM', () => { appConfigService.config.oauth2 = {}; }); - it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async(async () => { + it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async () => { spyOn(router, 'navigateByUrl').and.stub(); spyOn(authService, 'isBpmLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); @@ -72,33 +72,33 @@ describe('AuthGuardService BPM', () => { expect(await authGuard.canActivate(null, route)).toBeFalsy(); expect(authService.ssoImplicitLogin).toHaveBeenCalledTimes(1); - })); + }); - it('if the alfresco js api is logged in should canActivate be true', async(async () => { + it('if the alfresco js api is logged in should canActivate be true', async () => { spyOn(authService, 'isBpmLoggedIn').and.returnValue(true); - const route: RouterStateSnapshot = { url: 'some-url' }; + const route = { url: 'some-url' }; expect(await authGuard.canActivate(null, route)).toBeTruthy(); - })); + }); - it('if the alfresco js api is configured with withCredentials true should canActivate be true', async(async () => { + it('if the alfresco js api is configured with withCredentials true should canActivate be true', async () => { spyOn(authService, 'isBpmLoggedIn').and.returnValue(true); appConfigService.config.auth.withCredentials = true; - const route: RouterStateSnapshot = { url: 'some-url' }; + const route = { url: 'some-url' }; expect(await authGuard.canActivate(null, route)).toBeTruthy(); - })); + }); - it('if the alfresco js api is NOT logged in should canActivate be false', async(async () => { + it('if the alfresco js api is NOT logged in should canActivate be false', async () => { spyOn(authService, 'isBpmLoggedIn').and.returnValue(false); spyOn(router, 'navigateByUrl').and.stub(); const route: RouterStateSnapshot = { url: 'some-url' }; expect(await authGuard.canActivate(null, route)).toBeFalsy(); - })); + }); - it('if the alfresco js api is NOT logged in should trigger a redirect event', async(async () => { + it('if the alfresco js api is NOT logged in should trigger a redirect event', async () => { appConfigService.config.loginRoute = 'login'; spyOn(router, 'navigateByUrl'); @@ -107,31 +107,31 @@ describe('AuthGuardService BPM', () => { expect(await authGuard.canActivate(null, route)).toBeFalsy(); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url')); - })); + }); - it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async(async () => { + it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async () => { spyOn(router, 'navigateByUrl').and.stub(); spyOn(authService, 'isBpmLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); appConfigService.config.oauth2.silentLogin = false; - const route: RouterStateSnapshot = { url: 'some-url' }; + const route = { url: 'some-url' }; expect(await authGuard.canActivate(null, route)).toBeFalsy(); expect(router.navigateByUrl).toHaveBeenCalled(); - })); + }); - it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async(async () => { + it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async () => { spyOn(router, 'navigateByUrl').and.stub(); spyOn(authService, 'isBpmLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); appConfigService.config.oauth2.silentLogin = undefined; - const route: RouterStateSnapshot = { url: 'some-url' }; + const route = { url: 'some-url' }; expect(await authGuard.canActivate(null, route)).toBeFalsy(); expect(router.navigateByUrl).toHaveBeenCalled(); - })); + }); - it('should set redirect url', async(() => { + it('should set redirect url', () => { spyOn(authService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); const route: RouterStateSnapshot = { url: 'some-url' }; @@ -142,9 +142,9 @@ describe('AuthGuardService BPM', () => { provider: 'BPM', url: 'some-url' }); expect(authService.getRedirect()).toEqual('some-url'); - })); + }); - it('should set redirect navigation commands with query params', async(() => { + it('should set redirect navigation commands with query params', () => { spyOn(authService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); const route: RouterStateSnapshot = { url: 'some-url;q=123' }; @@ -155,9 +155,9 @@ describe('AuthGuardService BPM', () => { provider: 'BPM', url: 'some-url;q=123' }); expect(authService.getRedirect()).toEqual('some-url;q=123'); - })); + }); - it('should set redirect navigation commands with query params', async(() => { + it('should set redirect navigation commands with query params', () => { spyOn(authService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); const route: RouterStateSnapshot = { url: '/' }; @@ -168,9 +168,9 @@ describe('AuthGuardService BPM', () => { provider: 'BPM', url: '/' }); expect(authService.getRedirect()).toEqual('/'); - })); + }); - it('should get redirect url from config if there is one configured', async(() => { + it('should get redirect url from config if there is one configured', () => { appConfigService.config.loginRoute = 'fakeLoginRoute'; spyOn(authService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); @@ -182,7 +182,7 @@ describe('AuthGuardService BPM', () => { provider: 'BPM', url: 'some-url' }); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url')); - })); + }); it('should to close the material dialog if is redirect to the login', () => { const materialDialog = TestBed.inject(MatDialog); diff --git a/lib/core/services/auth-guard-ecm.service.spec.ts b/lib/core/services/auth-guard-ecm.service.spec.ts index 66381d892c..02b30c619e 100644 --- a/lib/core/services/auth-guard-ecm.service.spec.ts +++ b/lib/core/services/auth-guard-ecm.service.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { AppConfigService } from '../app-config/app-config.service'; import { AuthGuardEcm } from './auth-guard-ecm.service'; import { AuthenticationService } from './authentication.service'; @@ -51,31 +51,31 @@ describe('AuthGuardService ECM', () => { appConfigService.config.oauth2 = {}; }); - it('if the alfresco js api is logged in should canActivate be true', async(async() => { + it('if the alfresco js api is logged in should canActivate be true', async() => { spyOn(authService, 'isEcmLoggedIn').and.returnValue(true); const route: RouterStateSnapshot = {url : 'some-url'}; expect(await authGuard.canActivate(null, route)).toBeTruthy(); - })); + }); - it('if the alfresco js api is configured with withCredentials true should canActivate be true', async(async() => { + it('if the alfresco js api is configured with withCredentials true should canActivate be true', async() => { spyOn(authService, 'isBpmLoggedIn').and.returnValue(true); appConfigService.config.auth.withCredentials = true; const route: RouterStateSnapshot = {url : 'some-url'}; expect(await authGuard.canActivate(null, route)).toBeTruthy(); - })); + }); - it('if the alfresco js api is NOT logged in should canActivate be false', async(async() => { + it('if the alfresco js api is NOT logged in should canActivate be false', async() => { spyOn(authService, 'isEcmLoggedIn').and.returnValue(false); spyOn(router, 'navigateByUrl').and.stub(); const route: RouterStateSnapshot = { url: 'some-url' }; expect(await authGuard.canActivate(null, route)).toBeFalsy(); - })); + }); - it('if the alfresco js api is NOT logged in should trigger a redirect event', async(async() => { + it('if the alfresco js api is NOT logged in should trigger a redirect event', async() => { appConfigService.config.loginRoute = 'login'; spyOn(router, 'navigateByUrl'); @@ -84,9 +84,9 @@ describe('AuthGuardService ECM', () => { expect(await authGuard.canActivate(null, route)).toBeFalsy(); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url')); - })); + }); - it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async(async() => { + it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async() => { spyOn(router, 'navigateByUrl').and.stub(); spyOn(authService, 'isEcmLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); @@ -95,9 +95,9 @@ describe('AuthGuardService ECM', () => { expect(await authGuard.canActivate(null, route)).toBeFalsy(); expect(router.navigateByUrl).toHaveBeenCalled(); - })); + }); - it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async(async() => { + it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async() => { spyOn(authService, 'isEcmLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); spyOn(authService, 'isPublicUrl').and.returnValue(false); @@ -116,9 +116,9 @@ describe('AuthGuardService ECM', () => { expect(await authGuard.canActivate(null, route)).toBeFalsy(); expect(authService.ssoImplicitLogin).toHaveBeenCalledTimes(1); - })); + }); - it('should not redirect url if NOT logged in and isOAuth but no silentLogin configured', async(async() => { + it('should not redirect url if NOT logged in and isOAuth but no silentLogin configured', async() => { spyOn(router, 'navigateByUrl').and.stub(); spyOn(authService, 'isEcmLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); @@ -127,9 +127,9 @@ describe('AuthGuardService ECM', () => { expect(await authGuard.canActivate(null, route)).toBeFalsy(); expect(router.navigateByUrl).toHaveBeenCalled(); - })); + }); - it('should set redirect navigation commands', async(() => { + it('should set redirect navigation commands', () => { spyOn(authService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); const route: RouterStateSnapshot = { url: 'some-url' }; @@ -140,9 +140,9 @@ describe('AuthGuardService ECM', () => { provider: 'ECM', url: 'some-url' }); expect(authService.getRedirect()).toEqual('some-url'); - })); + }); - it('should set redirect navigation commands with query params', async(() => { + it('should set redirect navigation commands with query params', () => { spyOn(authService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); const route: RouterStateSnapshot = { url: 'some-url;q=123' }; @@ -153,9 +153,9 @@ describe('AuthGuardService ECM', () => { provider: 'ECM', url: 'some-url;q=123' }); expect(authService.getRedirect()).toEqual('some-url;q=123'); - })); + }); - it('should set redirect navigation commands with query params', async(() => { + it('should set redirect navigation commands with query params', () => { spyOn(authService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); const route: RouterStateSnapshot = { url: '/' }; @@ -166,9 +166,9 @@ describe('AuthGuardService ECM', () => { provider: 'ECM', url: '/' }); expect(authService.getRedirect()).toEqual('/'); - })); + }); - it('should get redirect url from config if there is one configured', async(() => { + it('should get redirect url from config if there is one configured', () => { appConfigService.config.loginRoute = 'fakeLoginRoute'; spyOn(authService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); @@ -180,7 +180,7 @@ describe('AuthGuardService ECM', () => { provider: 'ECM', url: 'some-url' }); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url')); - })); + }); it('should to close the material dialog if is redirect to the login', () => { const materialDialog = TestBed.inject(MatDialog); diff --git a/lib/core/services/comment-process.service.spec.ts b/lib/core/services/comment-process.service.spec.ts index 267d7554f3..3e24807647 100644 --- a/lib/core/services/comment-process.service.spec.ts +++ b/lib/core/services/comment-process.service.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { CommentModel } from '../models/comment.model'; import { fakeProcessComment, fakeTasksComment, fakeUser1 } from '../mock/comment-process-service.mock'; import { CommentProcessService } from './comment-process.service'; @@ -65,37 +65,40 @@ describe('Comment ProcessService Service', () => { .returnValue(Promise.resolve({data: [fakeProcessComment, fakeProcessComment]})); }); - it('should return the correct number of comments', async(() => { + it('should return the correct number of comments', (done) => { service.getProcessInstanceComments(processId).subscribe((tasks) => { expect(tasks.length).toBe(2); + done(); }); - })); + }); - it('should return the correct comment data', async(() => { + it('should return the correct comment data', (done) => { service.getProcessInstanceComments(processId).subscribe((comments) => { const comment: any = comments[0]; expect(comment.id).toBe(fakeProcessComment.id); expect(comment.created).toBe(fakeProcessComment.created); expect(comment.message).toBe(fakeProcessComment.message); expect(comment.createdBy.id).toBe(fakeProcessComment.createdBy.id); + done(); }); - })); + }); it('should call service to fetch process instance comments', () => { service.getProcessInstanceComments(processId); expect(getProcessInstanceComments).toHaveBeenCalledWith(processId); }); - 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) => { getProcessInstanceComments = getProcessInstanceComments.and.returnValue(Promise.reject(null)); service.getProcessInstanceComments(processId).subscribe( () => { }, (res) => { expect(res).toBe('Server error'); + done(); } ); - })); + }); }); @@ -117,25 +120,26 @@ describe('Comment ProcessService Service', () => { }, processId); }); - it('should return the created comment', async(() => { + it('should return the created comment', (done) => { service.addProcessInstanceComment(processId, message).subscribe((comment) => { expect(comment.id).toBe(fakeProcessComment.id); expect(comment.created).toBe(fakeProcessComment.created); expect(comment.message).toBe(fakeProcessComment.message); expect(comment.createdBy).toBe(fakeProcessComment.createdBy); + 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) => { addProcessInstanceComment = addProcessInstanceComment.and.returnValue(Promise.reject(null)); service.addProcessInstanceComment(processId, message).subscribe( - () => { - }, + () => {}, (res) => { expect(res).toBe('Server error'); + done(); } ); - })); + }); }); }); diff --git a/lib/core/services/upload.service.spec.ts b/lib/core/services/upload.service.spec.ts index fd98dfcd43..f197a9bb34 100644 --- a/lib/core/services/upload.service.spec.ts +++ b/lib/core/services/upload.service.spec.ts @@ -16,7 +16,7 @@ */ import { EventEmitter } from '@angular/core'; -import { async, TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { FileModel, FileUploadOptions, FileUploadStatus } from '../models/file.model'; import { AppConfigModule } from '../app-config/app-config.module'; import { UploadService } from './upload.service'; @@ -447,32 +447,32 @@ describe('UploadService', () => { expect(result[0]).toBe(file2); }); - it('should call onUploadDeleted if file was deleted', async(() => { + it('should call onUploadDeleted if file was deleted', () => { const file = ({ status: FileUploadStatus.Deleted }); spyOn(service.fileUploadDeleted, 'next'); service.cancelUpload(file); expect(service.fileUploadDeleted.next).toHaveBeenCalled(); - })); + }); - it('should call fileUploadError if file has error status', async(() => { + it('should call fileUploadError if file has error status', () => { const file = ({ status: FileUploadStatus.Error }); spyOn(service.fileUploadError, 'next'); service.cancelUpload(file); expect(service.fileUploadError.next).toHaveBeenCalled(); - })); + }); - it('should call fileUploadCancelled if file is in pending', async(() => { + it('should call fileUploadCancelled if file is in pending', () => { const file = ({ status: FileUploadStatus.Pending }); spyOn(service.fileUploadCancelled, 'next'); service.cancelUpload(file); expect(service.fileUploadCancelled.next).toHaveBeenCalled(); - })); + }); it('Should not pass rendition if it is disabled', () => { mockProductInfo.next({ status: { isThumbnailGenerationEnabled: false } } as EcmProductVersionModel); diff --git a/lib/core/services/user-preferences.service.spec.ts b/lib/core/services/user-preferences.service.spec.ts index e7bece60f1..734ea42345 100644 --- a/lib/core/services/user-preferences.service.spec.ts +++ b/lib/core/services/user-preferences.service.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { TestBed, async } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { TranslateService, TranslateModule } from '@ngx-translate/core'; import { AppConfigService } from '../app-config/app-config.service'; import { StorageService } from './storage.service'; @@ -177,7 +177,7 @@ describe('UserPreferencesService', () => { describe('with language config', () => { - it('should store default textOrientation based on language', async(() => { + it('should store default textOrientation based on language', () => { appConfig.config.languages = [ { key: 'fake-locale-config' @@ -187,9 +187,9 @@ describe('UserPreferencesService', () => { alfrescoApiService.initialize(); const textOrientation = preferences.getPropertyKey('textOrientation'); expect(storage.getItem(textOrientation)).toBe('ltr'); - })); + }); - it('should store textOrientation based on language config direction', async(() => { + it('should store textOrientation based on language config direction', () => { appConfig.config.languages = [ { key: 'fake-locale-config', @@ -200,9 +200,9 @@ describe('UserPreferencesService', () => { alfrescoApiService.initialize(); const textOrientation = preferences.getPropertyKey('textOrientation'); expect(storage.getItem(textOrientation)).toBe('rtl'); - })); + }); - it('should not store textOrientation based on language ', async(() => { + it('should not store textOrientation based on language ', () => { appConfig.config.languages = [ { key: 'fake-locale-browser' @@ -212,7 +212,7 @@ describe('UserPreferencesService', () => { const textOrientation = preferences.getPropertyKey('textOrientation'); expect(storage.getItem(textOrientation)).toBe(null); - })); + }); it('should default to browser locale for textOrientation when locale is not defined in configuration', (done) => { appConfig.config.languages = [ diff --git a/lib/core/templates/empty-content/empty-content.component.spec.ts b/lib/core/templates/empty-content/empty-content.component.spec.ts index 0864750d87..8452da96fe 100644 --- a/lib/core/templates/empty-content/empty-content.component.spec.ts +++ b/lib/core/templates/empty-content/empty-content.component.spec.ts @@ -16,7 +16,7 @@ */ import { Component } from '@angular/core'; -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { setupTestBed } from '@alfresco/adf-core'; import { TranslateService, TranslateModule } from '@ngx-translate/core'; @@ -58,16 +58,16 @@ describe('EmptyContentComponent', () => { translateService = TestBed.inject(TranslateService); }); - it('should render custom title', async(() => { + it('should render custom title', async () => { fixture.detectChanges(); - fixture.whenStable().then(() => { - const title = fixture.debugElement.query(By.css('.adf-empty-content__title')); - expect(title).toBeDefined('title element not found'); - expect(title.nativeElement.textContent).toContain('CUSTOM_TITLE', 'incorrect title value'); - }); - })); + await fixture.whenStable(); - it('should translate title and subtitle', async(() => { + const title = fixture.debugElement.query(By.css('.adf-empty-content__title')); + expect(title).toBeDefined('title element not found'); + expect(title.nativeElement.textContent).toContain('CUSTOM_TITLE', 'incorrect title value'); + }); + + it('should translate title and subtitle', async () => { spyOn(translateService, 'get').and.callFake((key: string) => { switch (key) { case 'CUSTOM_TITLE': @@ -80,17 +80,17 @@ describe('EmptyContentComponent', () => { }); fixture.detectChanges(); - fixture.whenStable().then(() => { - const title = fixture.debugElement.query(By.css('.adf-empty-content__title')); - const subtitle = fixture.debugElement.query(By.css('.adf-empty-content__subtitle')); + await fixture.whenStable(); - expect(title).toBeDefined('title element not found'); - expect(title.nativeElement.textContent).toContain('ENG_CUSTOM_TITLE', 'incorrect title value'); + const title = fixture.debugElement.query(By.css('.adf-empty-content__title')); + const subtitle = fixture.debugElement.query(By.css('.adf-empty-content__subtitle')); - expect(subtitle).toBeDefined('subtitle element not found'); - expect(subtitle.nativeElement.textContent).toContain('ENG_CUSTOM_SUBTITLE', 'incorrect subtitle value'); - }); - })); + expect(title).toBeDefined('title element not found'); + expect(title.nativeElement.textContent).toContain('ENG_CUSTOM_TITLE', 'incorrect title value'); + + expect(subtitle).toBeDefined('subtitle element not found'); + expect(subtitle.nativeElement.textContent).toContain('ENG_CUSTOM_SUBTITLE', 'incorrect subtitle value'); + }); it('should render multiple subtitle elements', () => { const subTitles = fixture.debugElement.queryAll(By.css('.adf-empty-content__text')); diff --git a/lib/core/templates/error-content/error-content.component.spec.ts b/lib/core/templates/error-content/error-content.component.spec.ts index b3c8241a80..514b07af27 100644 --- a/lib/core/templates/error-content/error-content.component.spec.ts +++ b/lib/core/templates/error-content/error-content.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { TestBed, async, ComponentFixture } from '@angular/core/testing'; +import { TestBed, ComponentFixture } from '@angular/core/testing'; import { CoreTestingModule } from '../../testing/core.testing.module'; import { ErrorContentComponent } from './error-content.component'; import { TranslationService } from '../../services/translation.service'; @@ -40,7 +40,6 @@ describe('ErrorContentComponent', () => { afterEach(() => { fixture.destroy(); - TestBed.resetTestingModule(); }); describe(' with an undefined error', () => { @@ -55,56 +54,57 @@ describe('ErrorContentComponent', () => { ] }); - it('should create error component', async(() => { + it('should render error code', async () => { fixture.detectChanges(); - expect(errorContentComponent).toBeTruthy(); - })); + await fixture.whenStable(); - it('should render error code', async(() => { - fixture.detectChanges(); const errorContentElement = element.querySelector('.adf-error-content-code'); expect(errorContentElement).not.toBeNull(); expect(errorContentElement).toBeDefined(); - })); + }); - it('should render error title', async(() => { + it('should render error title', async () => { fixture.detectChanges(); + await fixture.whenStable(); + const errorContentElement = element.querySelector('.adf-error-content-title'); expect(errorContentElement).not.toBeNull(); expect(errorContentElement).toBeDefined(); - })); + }); - it('should render error description', async(() => { + it('should render error description', async () => { fixture.detectChanges(); + await fixture.whenStable(); + const errorContentElement = element.querySelector('.adf-error-content-description'); expect(errorContentElement).not.toBeNull(); expect(errorContentElement).toBeDefined(); - })); + }); - it('should render error description', async(() => { + it('should render error description', async () => { fixture.detectChanges(); + await fixture.whenStable(); + const errorContentElement = element.querySelector('.adf-error-content-description'); expect(errorContentElement).not.toBeNull(); expect(errorContentElement).toBeDefined(); - })); + }); - it('should hide secondary button if this one has no value', async(() => { - spyOn(translateService, 'instant').and.callFake(() => { - return ''; - }); + it('should hide secondary button if this one has no value', async () => { + spyOn(translateService, 'instant').and.returnValue(''); fixture.detectChanges(); - fixture.whenStable().then(() => { - const errorContentElement = element.querySelector('.adf-error-content-description-link'); - expect(errorContentElement).toBeNull(); - }); - })); + await fixture.whenStable(); - it('should navigate to the default error UNKNOWN if it does not find the error', async(() => { + const errorContentElement = element.querySelector('.adf-error-content-description-link'); + expect(errorContentElement).toBeNull(); + }); + + it('should navigate to the default error UNKNOWN if it does not find the error', async () => { fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(errorContentComponent.errorCode).toBe('UNKNOWN'); - }); - })); + await fixture.whenStable(); + + expect(errorContentComponent.errorCode).toBe('UNKNOWN'); + }); }); describe(' with a specific error', () => { @@ -119,12 +119,12 @@ describe('ErrorContentComponent', () => { ] }); - it('should navigate to an error given by the route params', async(() => { + it('should navigate to an error given by the route params', async () => { spyOn(translateService, 'instant').and.returnValue(of('404')); fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(errorContentComponent.errorCodeTranslated).toBe('404'); - }); - })); + await fixture.whenStable(); + + expect(errorContentComponent.errorCodeTranslated).toBe('404'); + }); }); }); diff --git a/lib/core/viewer/components/viewer.component.spec.ts b/lib/core/viewer/components/viewer.component.spec.ts index dc9e65f063..ad705fa9e0 100644 --- a/lib/core/viewer/components/viewer.component.spec.ts +++ b/lib/core/viewer/components/viewer.component.spec.ts @@ -18,7 +18,7 @@ import { Location } from '@angular/common'; import { SpyLocation } from '@angular/common/testing'; import { Component } from '@angular/core'; -import { ComponentFixture, TestBed, fakeAsync, tick, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; import { AlfrescoApiService, RenditionsService } from '../../services'; import { throwError } from 'rxjs'; @@ -715,7 +715,7 @@ describe('ViewerComponent', () => { }); }); - it('should emit `showViewerChange` event on close', async(() => { + it('should emit `showViewerChange` event on close', async () => { spyOn(component.showViewerChange, 'emit'); @@ -723,11 +723,10 @@ describe('ViewerComponent', () => { button.click(); fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(component.showViewerChange.emit).toHaveBeenCalled(); - }); - })); + await fixture.whenStable(); + + expect(component.showViewerChange.emit).toHaveBeenCalled(); + }); it('should not render close viewer button if it is a shared link', (done) => { spyOn(alfrescoApiService.getInstance().core.sharedlinksApi, 'getSharedLink') diff --git a/lib/extensions/src/lib/services/extension-loader.service.spec.ts b/lib/extensions/src/lib/services/extension-loader.service.spec.ts index 37f3e3a76a..510c902da6 100644 --- a/lib/extensions/src/lib/services/extension-loader.service.spec.ts +++ b/lib/extensions/src/lib/services/extension-loader.service.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ExtensionConfig } from '../config/extension.config'; import { ExtensionLoaderService } from './extension-loader.service'; @@ -94,28 +94,31 @@ describe('ExtensionLoaderService', () => { }); }); - it('should load default registered app extensions when no custom $references defined', async(() => { + it('should load default registered app extensions when no custom $references defined', (done) => { extensionLoaderService.load('assets/app.extensions.json', 'assets/plugins', ['test.extension.1.json']).then((config: ExtensionConfig) => { const pluginsReference = config.$references.map((entry: ExtensionConfig) => entry.$name); expect(pluginsReference).toEqual(['test.extension.1']); + done(); }); - })); + }); - it('should ignore default registered app extension if defined in $ignoreReferenceList', async(() => { + it('should ignore default registered app extension if defined in $ignoreReferenceList', (done) => { appExtensionsConfig.$ignoreReferenceList = ['test.extension.1.json']; extensionLoaderService.load('assets/app.extensions.json', 'assets/plugins', ['test.extension.1.json']).then((config: ExtensionConfig) => { const pluginsReference = config.$references.map((entry: ExtensionConfig) => entry.$name); expect(pluginsReference).toEqual([]); + done(); }); - })); + }); - it('should load only extensions defined by $references', async(() => { + it('should load only extensions defined by $references', (done) => { appExtensionsConfig.$references = ['test.extension.1.json']; extensionLoaderService.load('assets/app.extensions.json', 'assets/plugins', ['test.extension.2.json, test.extension.3.json']).then((config: ExtensionConfig) => { const pluginsReference = config.$references.map((entry: ExtensionConfig) => entry.$name); expect(pluginsReference).toEqual(['test.extension.1']); + done(); }); - })); + }); }); diff --git a/lib/insights/src/lib/analytics-process/components/analytics-report-heat-map.component.spec.ts b/lib/insights/src/lib/analytics-process/components/analytics-report-heat-map.component.spec.ts index 40ba2dd204..95b536bfc9 100644 --- a/lib/insights/src/lib/analytics-process/components/analytics-report-heat-map.component.spec.ts +++ b/lib/insights/src/lib/analytics-process/components/analytics-report-heat-map.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { AnalyticsReportHeatMapComponent } from '../components/analytics-report-heat-map.component'; import { setupTestBed } from '@alfresco/adf-core'; import { InsightsTestingModule } from '../../testing/insights.testing.module'; @@ -69,50 +69,48 @@ describe('AnalyticsReportHeatMapComponent', () => { jasmine.Ajax.uninstall(); }); - it('should render the dropdown with the metric options', async(() => { + it('should render the dropdown with the metric options', async () => { component.report = { totalCountsPercentages: { 'sid-fake-id': 10, 'fake-start-event': 30 } }; - component.success.subscribe(() => { - fixture.whenStable().then(() => { - const dropDown: any = element.querySelector('#select-metrics'); - expect(dropDown).toBeDefined(); - expect(dropDown.length).toEqual(3); - expect(dropDown[0].innerHTML).toEqual('Number of times a step is executed'); - expect(dropDown[1].innerHTML).toEqual('Total time spent in a process step'); - expect(dropDown[2].innerHTML).toEqual('Average time spent in a process step'); - }); - }); fixture.detectChanges(); - })); + await fixture.whenStable(); - it('should return false when no metrics are defined in the report', async(() => { + const dropDown: any = element.querySelector('#select-metrics'); + expect(dropDown).toBeDefined(); + expect(dropDown.length).toEqual(3); + expect(dropDown[0].innerHTML).toEqual('Number of times a step is executed'); + expect(dropDown[1].innerHTML).toEqual('Total time spent in a process step'); + expect(dropDown[2].innerHTML).toEqual('Average time spent in a process step'); + }); + + it('should return false when no metrics are defined in the report', () => { component.report = {}; expect(component.hasMetric()).toBeFalsy(); - })); + }); - it('should return true when the metrics are defined in the report', async(() => { + it('should return true when the metrics are defined in the report', () => { expect(component.hasMetric()).toBeTruthy(); - })); + }); - it('should change the currentMetric width totalCount', async(() => { + it('should change the currentMetric width totalCount', () => { const field = { value: 'totalCount' }; component.onMetricChanges(field); expect(component.currentMetric).toEqual(totalCountValues); expect(component.currentMetricColors).toEqual(totalCountPercent); - })); + }); - it('should change the currentMetric width totalTime', async(() => { + it('should change the currentMetric width totalTime', () => { const field = { value: 'totalTime' }; component.onMetricChanges(field); expect(component.currentMetric).toEqual(totalTimeValues); expect(component.currentMetricColors).toEqual(totalTimePercent); - })); + }); - it('should change the currentMetric width avgTime', async(() => { + it('should change the currentMetric width avgTime', () => { const field = { value: 'avgTime' }; component.onMetricChanges(field); expect(component.currentMetric).toEqual(avgTimeValues); expect(component.currentMetricColors).toEqual(avgTimePercentages); - })); + }); }); }); diff --git a/lib/insights/src/lib/analytics-process/components/analytics-report-parameters.component.spec.ts b/lib/insights/src/lib/analytics-process/components/analytics-report-parameters.component.spec.ts index 9859c69333..b9ab6cde29 100644 --- a/lib/insights/src/lib/analytics-process/components/analytics-report-parameters.component.spec.ts +++ b/lib/insights/src/lib/analytics-process/components/analytics-report-parameters.component.spec.ts @@ -16,7 +16,7 @@ */ import { SimpleChange } from '@angular/core'; -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing'; import { ReportParametersModel } from '../../diagram/models/report/report-parameters.model'; import * as analyticParamsMock from '../../mock'; import { AnalyticsReportParametersComponent } from '../components/analytics-report-parameters.component'; @@ -408,7 +408,7 @@ describe('AnalyticsReportParametersComponent', () => { describe('When the form is rendered correctly', () => { - beforeEach(async(() => { + beforeEach(async () => { const reportId = 1; const change = new SimpleChange(null, reportId, true); component.ngOnChanges({'reportId': change}); @@ -420,20 +420,19 @@ describe('AnalyticsReportParametersComponent', () => { responseText: analyticParamsMock.reportDefParamStatus }); - fixture.whenStable().then(() => { - component.toggleParameters(); - fixture.detectChanges(); - }); - })); + await fixture.whenStable(); + component.toggleParameters(); + fixture.detectChanges(); + }); it('Should be able to change the report title', (done) => { spyOn(service, 'updateReport').and.returnValue(of(analyticParamsMock.reportDefParamStatus)); - const title: HTMLElement = element.querySelector('h4'); + const title = element.querySelector('h4'); title.click(); fixture.detectChanges(); - const reportName: HTMLInputElement = element.querySelector('#reportName'); + const reportName = element.querySelector('#reportName'); expect(reportName).not.toBeNull(); reportName.focus(); @@ -444,31 +443,31 @@ describe('AnalyticsReportParametersComponent', () => { fixture.detectChanges(); fixture.whenStable().then(() => { fixture.detectChanges(); - const titleChanged: HTMLElement = element.querySelector('h4'); + const titleChanged = element.querySelector('h4'); expect(titleChanged.textContent.trim()).toEqual('FAKE_TEST_NAME'); done(); }); }); - it('should render adf-buttons-menu component', async(() => { + it('should render adf-buttons-menu component', async () => { fixture.detectChanges(); - fixture.whenStable().then(() => { - const buttonsMenuComponent = element.querySelector('adf-buttons-action-menu'); - expect(buttonsMenuComponent).not.toBeNull(); - expect(buttonsMenuComponent).toBeDefined(); - }); - })); + await fixture.whenStable(); - it('should render delete button', async(() => { + const buttonsMenuComponent = element.querySelector('adf-buttons-action-menu'); + expect(buttonsMenuComponent).not.toBeNull(); + expect(buttonsMenuComponent).toBeDefined(); + }); + + it('should render delete button', async () => { fixture.detectChanges(); - fixture.whenStable().then(() => { - const buttonsMenuComponent = element.querySelector('#delete-button'); - expect(buttonsMenuComponent).not.toBeNull(); - expect(buttonsMenuComponent).toBeDefined(); - }); - })); + await fixture.whenStable(); - it('Should raise an event for report deleted', async(() => { + const buttonsMenuComponent = element.querySelector('#delete-button'); + expect(buttonsMenuComponent).not.toBeNull(); + expect(buttonsMenuComponent).toBeDefined(); + }); + + it('Should raise an event for report deleted', fakeAsync(() => { fixture.detectChanges(); spyOn(component, 'deleteReport'); const deleteButton = fixture.debugElement.nativeElement.querySelector('#delete-button'); @@ -481,7 +480,7 @@ describe('AnalyticsReportParametersComponent', () => { expect(component.deleteReport).toHaveBeenCalled(); })); - it('Should hide export button if the form is not valid', async(() => { + it('Should hide export button if the form is not valid', fakeAsync(() => { validForm = true; fixture.detectChanges(); fixture.whenStable().then(() => { @@ -501,7 +500,7 @@ describe('AnalyticsReportParametersComponent', () => { })); - it('Should hide save button if the form is not valid', async(() => { + it('Should hide save button if the form is not valid', fakeAsync(() => { validForm = true; fixture.detectChanges(); fixture.whenStable().then(() => { @@ -520,7 +519,7 @@ describe('AnalyticsReportParametersComponent', () => { }); })); - it('Should show export and save button when the form became valid', async(() => { + it('Should show export and save button when the form became valid', fakeAsync(() => { validForm = false; fixture.detectChanges(); let saveButton: HTMLButtonElement = element.querySelector('#save-button'); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.activities.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.activities.spec.ts index 8dfd94eaf1..bbc7e56462 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.activities.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.activities.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as diagramsActivitiesMock from '../../mock/diagram/diagram-activities.mock'; import { DiagramComponent } from './diagram.component'; @@ -69,7 +69,7 @@ describe('Diagrams activities', () => { describe('Diagrams component Activities: ', () => { - it('Should render the User Task', async(() => { + it('Should render the User Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -87,14 +87,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.userTask] }; ajaxReply(resp); - })); + }); - it('Should render the Manual Task', async(() => { + it('Should render the Manual Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -112,14 +113,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.manualTask] }; ajaxReply(resp); - })); + }); - it('Should render the Service Task', async(() => { + it('Should render the Service Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -135,14 +137,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.serviceTask] }; ajaxReply(resp); - })); + }); - it('Should render the Service Camel Task', async(() => { + it('Should render the Service Camel Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -160,14 +163,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.camelTask] }; ajaxReply(resp); - })); + }); - it('Should render the Service Mule Task', async(() => { + it('Should render the Service Mule Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -181,14 +185,15 @@ describe('Diagrams activities', () => { const iconTask: any = element.querySelector('diagram-mule-task > diagram-icon-mule-task > raphael-icon-mule'); expect(iconTask).not.toBeNull(); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.muleTask] }; ajaxReply(resp); - })); + }); - it('Should render the Service Alfresco Publish Task', async(() => { + it('Should render the Service Alfresco Publish Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -207,14 +212,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.alfrescoPublishTask] }; ajaxReply(resp); - })); + }); - it('Should render the Service Google Drive Publish Task', async(() => { + it('Should render the Service Google Drive Publish Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -233,14 +239,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.googleDrivePublishTask] }; ajaxReply(resp); - })); + }); - it('Should render the Rest Call Task', async(() => { + it('Should render the Rest Call Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -259,14 +266,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.restCallTask] }; ajaxReply(resp); - })); + }); - it('Should render the Service Box Publish Task', async(() => { + it('Should render the Service Box Publish Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -285,14 +293,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.boxPublishTask] }; ajaxReply(resp); - })); + }); - it('Should render the Receive Task', async(() => { + it('Should render the Receive Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -310,14 +319,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.receiveTask] }; ajaxReply(resp); - })); + }); - it('Should render the Script Task', async(() => { + it('Should render the Script Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -335,14 +345,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.scriptTask] }; ajaxReply(resp); - })); + }); - it('Should render the Business Rule Task', async(() => { + it('Should render the Business Rule Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -360,17 +371,18 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.businessRuleTask] }; ajaxReply(resp); - })); + }); }); describe('Diagrams component Activities with process instance id: ', () => { - it('Should render the User Task', async(() => { + it('Should render the User Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -388,14 +400,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.userTask] }; ajaxReply(resp); - })); + }); - it('Should render the Active User Task', async(() => { + it('Should render the Active User Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -413,14 +426,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.userTaskActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed User Task', async(() => { + it('Should render the Completed User Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -438,14 +452,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.userTaskCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Manual Task', async(() => { + it('Should render the Manual Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -463,14 +478,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.manualTask] }; ajaxReply(resp); - })); + }); - it('Should render the Active Manual Task', async(() => { + it('Should render the Active Manual Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -488,14 +504,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.manualTaskActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Manual Task', async(() => { + it('Should render the Completed Manual Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -513,14 +530,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.manualTaskCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Service Task', async(() => { + it('Should render the Service Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -538,14 +556,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.serviceTask] }; ajaxReply(resp); - })); + }); - it('Should render the Active Service Task', async(() => { + it('Should render the Active Service Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -563,14 +582,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.serviceTaskActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Service Task', async(() => { + it('Should render the Completed Service Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -588,14 +608,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.serviceTaskCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Service Camel Task', async(() => { + it('Should render the Service Camel Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -613,14 +634,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.camelTask] }; ajaxReply(resp); - })); + }); - it('Should render the Active Service Camel Task', async(() => { + it('Should render the Active Service Camel Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -638,14 +660,16 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.camelTaskActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Service Camel Task', async(() => { + it('Should render the Completed Service Camel Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -663,14 +687,16 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.camelTaskCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Service Mule Task', async(() => { + it('Should render the Service Mule Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -684,14 +710,15 @@ describe('Diagrams activities', () => { const iconTask: any = element.querySelector('diagram-mule-task > diagram-icon-mule-task > raphael-icon-mule'); expect(iconTask).not.toBeNull(); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.muleTask] }; ajaxReply(resp); - })); + }); - it('Should render the Active Service Mule Task', async(() => { + it('Should render the Active Service Mule Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -705,14 +732,15 @@ describe('Diagrams activities', () => { const iconTask: any = element.querySelector('diagram-mule-task > diagram-icon-mule-task > raphael-icon-mule'); expect(iconTask).not.toBeNull(); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.muleTaskActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Service Mule Task', async(() => { + it('Should render the Completed Service Mule Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -726,14 +754,15 @@ describe('Diagrams activities', () => { const iconTask: any = element.querySelector('diagram-mule-task > diagram-icon-mule-task > raphael-icon-mule'); expect(iconTask).not.toBeNull(); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.muleTaskCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Service Alfresco Publish Task', async(() => { + it('Should render the Service Alfresco Publish Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -752,14 +781,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.alfrescoPublishTask] }; ajaxReply(resp); - })); + }); - it('Should render the Active Service Alfresco Publish Task', async(() => { + it('Should render the Active Service Alfresco Publish Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -778,14 +808,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.alfrescoPublishTaskActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Service Alfresco Publish Task', async(() => { + it('Should render the Completed Service Alfresco Publish Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -804,14 +835,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.alfrescoPublishTaskCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Service Google Drive Publish Task', async(() => { + it('Should render the Service Google Drive Publish Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -830,14 +862,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.googleDrivePublishTask] }; ajaxReply(resp); - })); + }); - it('Should render the Active Service Google Drive Publish Task', async(() => { + it('Should render the Active Service Google Drive Publish Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -856,14 +889,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.googleDrivePublishTaskActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Service Google Drive Publish Task', async(() => { + it('Should render the Completed Service Google Drive Publish Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -882,14 +916,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.googleDrivePublishTaskCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Rest Call Task', async(() => { + it('Should render the Rest Call Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -908,14 +943,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.restCallTask] }; ajaxReply(resp); - })); + }); - it('Should render the Active Rest Call Task', async(() => { + it('Should render the Active Rest Call Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -934,14 +970,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.restCallTaskActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Rest Call Task', async(() => { + it('Should render the Completed Rest Call Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -960,14 +997,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.restCallTaskCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Service Box Publish Task', async(() => { + it('Should render the Service Box Publish Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -986,14 +1024,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.boxPublishTask] }; ajaxReply(resp); - })); + }); - it('Should render the Active Service Box Publish Task', async(() => { + it('Should render the Active Service Box Publish Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -1012,14 +1051,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.boxPublishTaskActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Service Box Publish Task', async(() => { + it('Should render the Completed Service Box Publish Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -1038,14 +1078,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.boxPublishTaskCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Receive Task', async(() => { + it('Should render the Receive Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -1063,14 +1104,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.receiveTask] }; ajaxReply(resp); - })); + }); - it('Should render the Active Receive Task', async(() => { + it('Should render the Active Receive Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -1088,14 +1130,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.receiveTaskActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Receive Task', async(() => { + it('Should render the Completed Receive Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -1113,14 +1156,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.receiveTaskCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Script Task', async(() => { + it('Should render the Script Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -1138,14 +1182,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.scriptTask] }; ajaxReply(resp); - })); + }); - it('Should render the Active Script Task', async(() => { + it('Should render the Active Script Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -1163,14 +1208,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.scriptTaskActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Script Task', async(() => { + it('Should render the Completed Script Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -1188,14 +1234,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.scriptTaskCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Business Rule Task', async(() => { + it('Should render the Business Rule Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -1213,14 +1260,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.businessRuleTask] }; ajaxReply(resp); - })); + }); - it('Should render the Active Business Rule Task', async(() => { + it('Should render the Active Business Rule Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -1238,14 +1286,15 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.businessRuleTaskActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Business Rule Task', async(() => { + it('Should render the Completed Business Rule Task', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -1263,11 +1312,12 @@ describe('Diagrams activities', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].name); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsActivitiesMock.businessRuleTaskCompleted] }; ajaxReply(resp); - })); + }); }); }); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.boundary.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.boundary.spec.ts index cafda5ae1a..9065399986 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.boundary.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.boundary.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as boundaryEventMock from '../../mock/diagram/diagram-boundary.mock'; import { DiagramComponent } from './diagram.component'; @@ -43,9 +43,7 @@ describe('Diagrams boundary', () => { component = fixture.componentInstance; element = fixture.nativeElement; fixture.detectChanges(); - }); - beforeEach(() => { jasmine.Ajax.install(); component.processInstanceId = '38399'; component.processDefinitionId = 'fakeprocess:24:38399'; @@ -53,7 +51,6 @@ describe('Diagrams boundary', () => { }); afterEach(() => { - component.success.unsubscribe(); fixture.destroy(); jasmine.Ajax.uninstall(); }); @@ -68,7 +65,7 @@ describe('Diagrams boundary', () => { describe('Diagrams component Boundary events with process instance id: ', () => { - it('Should render the Boundary time event', async(() => { + it('Should render the Boundary time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -90,14 +87,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundaryTimeEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Boundary time event', async(() => { + it('Should render the Active Boundary time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -123,14 +121,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundaryTimeEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Boundary time event', async(() => { + it('Should render the Completed Boundary time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -156,14 +155,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundaryTimeEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Boundary error event', async(() => { + it('Should render the Boundary error event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -185,14 +185,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundaryErrorEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Boundary error event', async(() => { + it('Should render the Active Boundary error event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -218,14 +219,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundaryErrorEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Boundary error event', async(() => { + it('Should render the Completed Boundary error event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -251,14 +253,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundaryErrorEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Boundary signal event', async(() => { + it('Should render the Boundary signal event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -280,14 +283,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundarySignalEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Boundary signal event', async(() => { + it('Should render the Active Boundary signal event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -313,14 +317,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundarySignalEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Boundary signal event', async(() => { + it('Should render the Completed Boundary signal event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -346,14 +351,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundarySignalEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Boundary signal message', async(() => { + it('Should render the Boundary signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -375,14 +381,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundaryMessageEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Boundary signal message', async(() => { + it('Should render the Active Boundary signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -408,14 +415,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundaryMessageEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Boundary signal message', async(() => { + it('Should render the Completed Boundary signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -441,14 +449,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundaryMessageEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Boundary signal message', async(() => { + it('Should render the Boundary signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -470,14 +479,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundaryMessageEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Boundary signal message', async(() => { + it('Should render the Active Boundary signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -503,14 +513,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundaryMessageEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Boundary signal message', async(() => { + it('Should render the Completed Boundary signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -536,17 +547,18 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundaryMessageEventCompleted] }; ajaxReply(resp); - })); + }); }); describe('Diagrams component Boundary events: ', () => { - it('Should render the Boundary time event', async(() => { + it('Should render the Boundary time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -568,14 +580,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundaryTimeEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Boundary error event', async(() => { + it('Should render the Boundary error event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -597,14 +610,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundaryErrorEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Boundary signal event', async(() => { + it('Should render the Boundary signal event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -626,14 +640,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundarySignalEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Boundary signal message', async(() => { + it('Should render the Boundary signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -655,14 +670,15 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundaryMessageEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Boundary signal message', async(() => { + it('Should render the Boundary signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -684,11 +700,12 @@ describe('Diagrams boundary', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [boundaryEventMock.boundaryMessageEvent] }; ajaxReply(resp); - })); + }); }); }); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.catching.events.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.catching.events.spec.ts index 2f3d5bc8c1..162b2dd69d 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.catching.events.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.catching.events.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as intermediateCatchingMock from '../../mock/diagram/diagram-intermediate.mock'; import { DiagramComponent } from './diagram.component'; @@ -68,7 +68,7 @@ describe('Diagrams Catching', () => { describe('Diagrams component Intermediate Catching events: ', () => { - it('Should render the Intermediate catching time event', async(() => { + it('Should render the Intermediate catching time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -90,14 +90,15 @@ describe('Diagrams Catching', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [intermediateCatchingMock.intermediateCatchingTimeEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Intermediate catching error event', async(() => { + it('Should render the Intermediate catching error event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -119,14 +120,15 @@ describe('Diagrams Catching', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [intermediateCatchingMock.intermediateCatchingErrorEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Intermediate catching signal event', async(() => { + it('Should render the Intermediate catching signal event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -148,14 +150,15 @@ describe('Diagrams Catching', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [intermediateCatchingMock.intermediateCatchingSignalEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Intermediate catching signal message', async(() => { + it('Should render the Intermediate catching signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -177,17 +180,18 @@ describe('Diagrams Catching', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [intermediateCatchingMock.intermediateCatchingMessageEvent] }; ajaxReply(resp); - })); + }); }); describe('Diagrams component Intermediate Catching events with process instance id: ', () => { - it('Should render the Intermediate catching time event', async(() => { + it('Should render the Intermediate catching time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -209,14 +213,15 @@ describe('Diagrams Catching', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [intermediateCatchingMock.intermediateCatchingTimeEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Intermediate catching time event', async(() => { + it('Should render the Active Intermediate catching time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -242,14 +247,15 @@ describe('Diagrams Catching', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [intermediateCatchingMock.intermediateCatchingTimeEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Intermediate catching time event', async(() => { + it('Should render the Completed Intermediate catching time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -275,14 +281,15 @@ describe('Diagrams Catching', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [intermediateCatchingMock.intermediateCatchingTimeEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Intermediate catching error event', async(() => { + it('Should render the Intermediate catching error event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -304,14 +311,15 @@ describe('Diagrams Catching', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [intermediateCatchingMock.intermediateCatchingErrorEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Intermediate catching error event', async(() => { + it('Should render the Active Intermediate catching error event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -337,14 +345,15 @@ describe('Diagrams Catching', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [intermediateCatchingMock.intermediateCatchingErrorEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Intermediate catching error event', async(() => { + it('Should render the Completed Intermediate catching error event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -370,14 +379,15 @@ describe('Diagrams Catching', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [intermediateCatchingMock.intermediateCatchingErrorEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Intermediate catching signal event', async(() => { + it('Should render the Intermediate catching signal event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -399,14 +409,15 @@ describe('Diagrams Catching', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [intermediateCatchingMock.intermediateCatchingSignalEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Intermediate Active catching signal event', async(() => { + it('Should render the Intermediate Active catching signal event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -432,14 +443,15 @@ describe('Diagrams Catching', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [intermediateCatchingMock.intermediateCatchingSignalEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Intermediate catching signal event', async(() => { + it('Should render the Completed Intermediate catching signal event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -465,14 +477,15 @@ describe('Diagrams Catching', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [intermediateCatchingMock.intermediateCatchingSignalEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Intermediate catching signal message', async(() => { + it('Should render the Intermediate catching signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -494,14 +507,15 @@ describe('Diagrams Catching', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [intermediateCatchingMock.intermediateCatchingMessageEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Intermediate catching signal message', async(() => { + it('Should render the Active Intermediate catching signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -527,14 +541,15 @@ describe('Diagrams Catching', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [intermediateCatchingMock.intermediateCatchingMessageEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Intermediate catching signal message', async(() => { + it('Should render the Completed Intermediate catching signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -560,11 +575,12 @@ describe('Diagrams Catching', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [intermediateCatchingMock.intermediateCatchingMessageEventCompleted] }; ajaxReply(resp); - })); + }); }); }); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.events.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.events.spec.ts index e72ebbf3aa..1a3ccc1a51 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.events.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.events.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as diagramsEventsMock from '../../mock/diagram/diagram-events.mock'; import { DiagramComponent } from './diagram.component'; @@ -68,7 +68,7 @@ describe('Diagrams events', () => { describe('Diagrams component Events: ', () => { - it('Should render the Start Event', async(() => { + it('Should render the Start Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -78,14 +78,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Start Timer Event', async(() => { + it('Should render the Start Timer Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -99,15 +100,16 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startTimeEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Start Signal Event', async(() => { + it('Should render the Start Signal Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -121,14 +123,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startSignalEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Start Message Event', async(() => { + it('Should render the Start Message Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -142,14 +145,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startMessageEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Start Error Event', async(() => { + it('Should render the Start Error Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -163,14 +167,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startErrorEvent] }; ajaxReply(resp); - })); + }); - it('Should render the End Event', async(() => { + it('Should render the End Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -180,14 +185,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.endEvent] }; ajaxReply(resp); - })); + }); - it('Should render the End Error Event', async(() => { + it('Should render the End Error Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -201,17 +207,18 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.endErrorEvent] }; ajaxReply(resp); - })); + }); }); describe('Diagrams component Events with process instance id: ', () => { - it('Should render the Start Event', async(() => { + it('Should render the Start Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -221,14 +228,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Start Event', async(() => { + it('Should render the Active Start Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -238,14 +246,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Start Event', async(() => { + it('Should render the Completed Start Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -255,14 +264,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Start Timer Event', async(() => { + it('Should render the Start Timer Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -276,15 +286,16 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startTimeEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Start Timer Event', async(() => { + it('Should render the Active Start Timer Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -298,15 +309,16 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startTimeEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Start Timer Event', async(() => { + it('Should render the Completed Start Timer Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -320,15 +332,16 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startTimeEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Start Signal Event', async(() => { + it('Should render the Start Signal Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -342,14 +355,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startSignalEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Start Signal Event', async(() => { + it('Should render the Active Start Signal Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -363,14 +377,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startSignalEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Start Signal Event', async(() => { + it('Should render the Completed Start Signal Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -384,14 +399,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startSignalEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Start Message Event', async(() => { + it('Should render the Start Message Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -405,14 +421,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startMessageEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Start Message Event', async(() => { + it('Should render the Active Start Message Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -426,14 +443,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startMessageEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Start Message Event', async(() => { + it('Should render the Completed Start Message Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -447,14 +465,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startMessageEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Start Error Event', async(() => { + it('Should render the Start Error Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -468,14 +487,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startErrorEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Start Error Event', async(() => { + it('Should render the Active Start Error Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -489,14 +509,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startErrorEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Start Error Event', async(() => { + it('Should render the Completed Start Error Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -510,14 +531,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.startErrorEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the End Event', async(() => { + it('Should render the End Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -527,14 +549,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.endEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active End Event', async(() => { + it('Should render the Active End Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -544,14 +567,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.endEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed End Event', async(() => { + it('Should render the Completed End Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -561,14 +585,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.endEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the End Error Event', async(() => { + it('Should render the End Error Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -582,14 +607,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.endErrorEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active End Error Event', async(() => { + it('Should render the Active End Error Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -603,14 +629,15 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.endErrorEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed End Error Event', async(() => { + it('Should render the Completed End Error Event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -624,11 +651,12 @@ describe('Diagrams events', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsEventsMock.endErrorEventCompleted] }; ajaxReply(resp); - })); + }); }); }); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.flows.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.flows.spec.ts index f9a0e03f80..3aaa91eb05 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.flows.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.flows.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as flowsMock from '../../mock/diagram/diagram-flows.mock'; import { DiagramComponent } from './diagram.component'; @@ -43,9 +43,7 @@ describe('Diagrams flows', () => { component = fixture.componentInstance; element = fixture.nativeElement; fixture.detectChanges(); - }); - beforeEach(() => { jasmine.Ajax.install(); component.processInstanceId = '38399'; component.processDefinitionId = 'fakeprocess:24:38399'; @@ -68,7 +66,7 @@ describe('Diagrams flows', () => { describe('Diagrams component Flows with process instance id: ', () => { - it('Should render the flow', async(() => { + it('Should render the flow', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -79,17 +77,18 @@ describe('Diagrams flows', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.flows[0].id); expect(tooltip.textContent).toContain(res.flows[0].type); + done(); }); }); component.ngOnChanges(); const resp = { flows: [flowsMock.flow] }; ajaxReply(resp); - })); + }); }); describe('Diagrams component Flows: ', () => { - it('Should render the flow', async(() => { + it('Should render the flow', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -100,11 +99,12 @@ describe('Diagrams flows', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.flows[0].id); expect(tooltip.textContent).toContain(res.flows[0].type); + done(); }); }); component.ngOnChanges(); const resp = { flows: [flowsMock.flow] }; ajaxReply(resp); - })); + }); }); }); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.gateways.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.gateways.spec.ts index 1edc39e1a9..5d1cb88b99 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.gateways.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.gateways.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as diagramsGatewaysMock from '../../mock/diagram/diagram-gateways.mock'; import { DiagramComponent } from './diagram.component'; @@ -68,7 +68,7 @@ describe('Diagrams gateways', () => { describe('Diagrams component Gateways: ', () => { - it('Should render the Exclusive Gateway', async(() => { + it('Should render the Exclusive Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -82,14 +82,15 @@ describe('Diagrams gateways', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsGatewaysMock.exclusiveGateway] }; ajaxReply(resp); - })); + }); - it('Should render the Inclusive Gateway', async(() => { + it('Should render the Inclusive Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -103,14 +104,15 @@ describe('Diagrams gateways', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsGatewaysMock.inclusiveGateway] }; ajaxReply(resp); - })); + }); - it('Should render the Parallel Gateway', async(() => { + it('Should render the Parallel Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -124,14 +126,15 @@ describe('Diagrams gateways', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsGatewaysMock.parallelGateway] }; ajaxReply(resp); - })); + }); - it('Should render the Event Gateway', async(() => { + it('Should render the Event Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -155,17 +158,18 @@ describe('Diagrams gateways', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsGatewaysMock.eventGateway] }; ajaxReply(resp); - })); + }); }); describe('Diagrams component Gateways with process instance id: ', () => { - it('Should render the Exclusive Gateway', async(() => { + it('Should render the Exclusive Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -179,14 +183,15 @@ describe('Diagrams gateways', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsGatewaysMock.exclusiveGateway] }; ajaxReply(resp); - })); + }); - it('Should render the Active Exclusive Gateway', async(() => { + it('Should render the Active Exclusive Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -200,14 +205,15 @@ describe('Diagrams gateways', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsGatewaysMock.exclusiveGatewayActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Exclusive Gateway', async(() => { + it('Should render the Completed Exclusive Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -221,14 +227,15 @@ describe('Diagrams gateways', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsGatewaysMock.exclusiveGatewayCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Inclusive Gateway', async(() => { + it('Should render the Inclusive Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -242,14 +249,15 @@ describe('Diagrams gateways', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsGatewaysMock.inclusiveGateway] }; ajaxReply(resp); - })); + }); - it('Should render the Active Inclusive Gateway', async(() => { + it('Should render the Active Inclusive Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -263,14 +271,15 @@ describe('Diagrams gateways', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsGatewaysMock.inclusiveGatewayActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Inclusive Gateway', async(() => { + it('Should render the Completed Inclusive Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -284,14 +293,15 @@ describe('Diagrams gateways', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsGatewaysMock.inclusiveGatewayCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Parallel Gateway', async(() => { + it('Should render the Parallel Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -305,14 +315,15 @@ describe('Diagrams gateways', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsGatewaysMock.parallelGateway] }; ajaxReply(resp); - })); + }); - it('Should render the Active Parallel Gateway', async(() => { + it('Should render the Active Parallel Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -326,14 +337,15 @@ describe('Diagrams gateways', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsGatewaysMock.parallelGatewayActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Parallel Gateway', async(() => { + it('Should render the Completed Parallel Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -347,14 +359,15 @@ describe('Diagrams gateways', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsGatewaysMock.parallelGatewayCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Event Gateway', async(() => { + it('Should render the Event Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -378,14 +391,15 @@ describe('Diagrams gateways', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsGatewaysMock.eventGateway] }; ajaxReply(resp); - })); + }); - it('Should render the Active Event Gateway', async(() => { + it('Should render the Active Event Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -409,14 +423,15 @@ describe('Diagrams gateways', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsGatewaysMock.eventGatewayActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Event Gateway', async(() => { + it('Should render the Completed Event Gateway', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -440,11 +455,12 @@ describe('Diagrams gateways', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [diagramsGatewaysMock.eventGatewayCompleted] }; ajaxReply(resp); - })); + }); }); }); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.structural.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.structural.spec.ts index 2f198571f4..5a0ae3e41d 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.structural.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.structural.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as structuralMock from '../../mock/diagram/diagram-structural.mock'; import { DiagramComponent } from './diagram.component'; @@ -68,7 +68,7 @@ describe('Diagrams structural', () => { describe('Diagrams component Structural: ', () => { - it('Should render the Subprocess', async(() => { + it('Should render the Subprocess', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -79,14 +79,15 @@ describe('Diagrams structural', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [structuralMock.subProcess] }; ajaxReply(resp); - })); + }); - it('Should render the Event Subprocess', async(() => { + it('Should render the Event Subprocess', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -97,17 +98,18 @@ describe('Diagrams structural', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [structuralMock.eventSubProcess] }; ajaxReply(resp); - })); + }); }); describe('Diagrams component Structural with process instance id: ', () => { - it('Should render the Subprocess', async(() => { + it('Should render the Subprocess', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -118,14 +120,15 @@ describe('Diagrams structural', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [structuralMock.subProcess] }; ajaxReply(resp); - })); + }); - it('Should render the Active Subprocess', async(() => { + it('Should render the Active Subprocess', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -136,14 +139,15 @@ describe('Diagrams structural', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [structuralMock.subProcessActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Subprocess', async(() => { + it('Should render the Completed Subprocess', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -154,14 +158,15 @@ describe('Diagrams structural', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [structuralMock.subProcessCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Event Subprocess', async(() => { + it('Should render the Event Subprocess', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -172,14 +177,15 @@ describe('Diagrams structural', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [structuralMock.eventSubProcess] }; ajaxReply(resp); - })); + }); - it('Should render the Active Event Subprocess', async(() => { + it('Should render the Active Event Subprocess', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -190,14 +196,15 @@ describe('Diagrams structural', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [structuralMock.eventSubProcessActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Event Subprocess', async(() => { + it('Should render the Completed Event Subprocess', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -208,11 +215,12 @@ describe('Diagrams structural', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [structuralMock.eventSubProcessCompleted] }; ajaxReply(resp); - })); + }); }); }); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.swim.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.swim.spec.ts index 31fa280487..c6278d655d 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.swim.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.swim.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as swimLanesMock from '../../mock/diagram/diagram-swimlanes.mock'; import { DiagramComponent } from './diagram.component'; @@ -68,7 +68,7 @@ describe('Diagrams swim', () => { describe('Diagrams component Swim lane: ', () => { - it('Should render the Pool', async(() => { + it('Should render the Pool', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -79,14 +79,15 @@ describe('Diagrams swim', () => { const shapeText: any = element.querySelector('diagram-pool > raphael-text'); expect(shapeText).not.toBeNull(); expect(shapeText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Activiti'); + done(); }); }); component.ngOnChanges(); const resp = { pools: [swimLanesMock.pool] }; ajaxReply(resp); - })); + }); - it('Should render the Pool with Lanes', async(() => { + it('Should render the Pool with Lanes', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -100,17 +101,18 @@ describe('Diagrams swim', () => { const shapeText: any = element.querySelector('diagram-lanes > div > div > diagram-lane > raphael-text'); expect(shapeText).not.toBeNull(); expect(shapeText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Backend'); + done(); }); }); component.ngOnChanges(); const resp = { pools: [swimLanesMock.poolLanes] }; ajaxReply(resp); - })); + }); }); describe('Diagrams component Swim lane with process instance id: ', () => { - it('Should render the Pool', async(() => { + it('Should render the Pool', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -121,14 +123,15 @@ describe('Diagrams swim', () => { const shapeText: any = element.querySelector('diagram-pool > raphael-text'); expect(shapeText).not.toBeNull(); expect(shapeText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Activiti'); + done(); }); }); component.ngOnChanges(); const resp = { pools: [swimLanesMock.pool] }; ajaxReply(resp); - })); + }); - it('Should render the Pool with Lanes', async(() => { + it('Should render the Pool with Lanes', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -142,11 +145,12 @@ describe('Diagrams swim', () => { const shapeText: any = element.querySelector('diagram-lanes > div > div > diagram-lane > raphael-text'); expect(shapeText).not.toBeNull(); expect(shapeText.attributes.getNamedItem('ng-reflect-text').value).toEqual('Backend'); + done(); }); }); component.ngOnChanges(); const resp = { pools: [swimLanesMock.poolLanes] }; ajaxReply(resp); - })); + }); }); }); diff --git a/lib/insights/src/lib/diagram/components/diagram.component.throw.spec.ts b/lib/insights/src/lib/diagram/components/diagram.component.throw.spec.ts index fb1a9f60ba..682691bd1c 100644 --- a/lib/insights/src/lib/diagram/components/diagram.component.throw.spec.ts +++ b/lib/insights/src/lib/diagram/components/diagram.component.throw.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import * as throwEventMock from '../../mock/diagram/diagram-throw.mock'; import { DiagramComponent } from './diagram.component'; @@ -38,7 +38,7 @@ describe('Diagrams throw', () => { ] }); - beforeEach(async(() => { + beforeEach(() => { jasmine.Ajax.install(); fixture = TestBed.createComponent(DiagramComponent); @@ -49,10 +49,9 @@ describe('Diagrams throw', () => { component.metricPercentages = { startEvent: 0 }; fixture.detectChanges(); - })); + }); afterEach(() => { - component.success.unsubscribe(); fixture.destroy(); jasmine.Ajax.uninstall(); }); @@ -67,7 +66,7 @@ describe('Diagrams throw', () => { describe('Diagrams component Throw events with process instance id: ', () => { - it('Should render the Throw time event', async(() => { + it('Should render the Throw time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -85,14 +84,15 @@ describe('Diagrams throw', () => { const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-timer'); expect(iconShape).not.toBeNull(); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwTimeEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Throw time event', async(() => { + it('Should render the Active Throw time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -114,14 +114,15 @@ describe('Diagrams throw', () => { const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-timer'); expect(iconShape).not.toBeNull(); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwTimeEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Throw time event', async(() => { + it('Should render the Completed Throw time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -143,14 +144,15 @@ describe('Diagrams throw', () => { const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-timer'); expect(iconShape).not.toBeNull(); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwTimeEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Throw error event', async(() => { + it('Should render the Throw error event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -172,14 +174,15 @@ describe('Diagrams throw', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwErrorEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Throw error event', async(() => { + it('Should render the Active Throw error event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -205,14 +208,15 @@ describe('Diagrams throw', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwErrorEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Throw error event', async(() => { + it('Should render the Completed Throw error event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -238,14 +242,15 @@ describe('Diagrams throw', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwErrorEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Throw signal event', async(() => { + it('Should render the Throw signal event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -267,14 +272,15 @@ describe('Diagrams throw', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwSignalEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Throw signal event', async(() => { + it('Should render the Active Throw signal event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -300,14 +306,15 @@ describe('Diagrams throw', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwSignalEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Throw signal event', async(() => { + it('Should render the Completed Throw signal event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -333,14 +340,15 @@ describe('Diagrams throw', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwSignalEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Throw signal message', async(() => { + it('Should render the Throw signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -362,14 +370,15 @@ describe('Diagrams throw', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwMessageEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Throw signal message', async(() => { + it('Should render the Active Throw signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -395,14 +404,15 @@ describe('Diagrams throw', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwMessageEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Throw signal message', async(() => { + it('Should render the Completed Throw signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -428,14 +438,15 @@ describe('Diagrams throw', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwMessageEventCompleted] }; ajaxReply(resp); - })); + }); - it('Should render the Throw signal message', async(() => { + it('Should render the Throw signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -457,14 +468,15 @@ describe('Diagrams throw', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwMessageEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Active Throw signal message', async(() => { + it('Should render the Active Throw signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -490,14 +502,15 @@ describe('Diagrams throw', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwMessageEventActive] }; ajaxReply(resp); - })); + }); - it('Should render the Completed Throw signal message', async(() => { + it('Should render the Completed Throw signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -523,17 +536,18 @@ describe('Diagrams throw', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwMessageEventCompleted] }; ajaxReply(resp); - })); + }); }); describe('Diagrams component Throw events: ', () => { - it('Should render the Throw time event', async(() => { + it('Should render the Throw time event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -551,14 +565,15 @@ describe('Diagrams throw', () => { const iconShape: any = element.querySelector('diagram-throw-event > diagram-container-icon-event >' + ' div > div > diagram-icon-timer'); expect(iconShape).not.toBeNull(); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwTimeEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Throw error event', async(() => { + it('Should render the Throw error event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -580,14 +595,15 @@ describe('Diagrams throw', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwErrorEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Throw signal event', async(() => { + it('Should render the Throw signal event', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -609,14 +625,15 @@ describe('Diagrams throw', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwSignalEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Throw signal message', async(() => { + it('Should render the Throw signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -638,14 +655,15 @@ describe('Diagrams throw', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwMessageEvent] }; ajaxReply(resp); - })); + }); - it('Should render the Throw signal message', async(() => { + it('Should render the Throw signal message', (done) => { component.success.subscribe((res) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -667,11 +685,12 @@ describe('Diagrams throw', () => { const tooltip: any = element.querySelector('diagram-tooltip > div'); expect(tooltip.textContent).toContain(res.elements[0].id); expect(tooltip.textContent).toContain(res.elements[0].type); + done(); }); }); component.ngOnChanges(); const resp = { elements: [throwEventMock.throwMessageEvent] }; ajaxReply(resp); - })); + }); }); }); diff --git a/lib/process-services-cloud/src/lib/app/components/app-list-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/app/components/app-list-cloud.component.spec.ts index 6e403d0dbc..57114dd030 100644 --- a/lib/process-services-cloud/src/lib/app/components/app-list-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/app/components/app-list-cloud.component.spec.ts @@ -16,7 +16,7 @@ */ import { Component } from '@angular/core'; -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { setupTestBed, AlfrescoApiService } from '@alfresco/adf-core'; import { of, throwError } from 'rxjs'; @@ -81,7 +81,7 @@ describe('AppListCloudComponent', () => { expect(component.isGrid()).toBe(true); }); - it('Should fetch deployed apps', async(() => { + it('Should fetch deployed apps', (done) => { fixture.detectChanges(); fixture.whenStable().then(() => { component.apps$.subscribe((response: any[]) => { @@ -95,10 +95,10 @@ describe('AppListCloudComponent', () => { expect(response[1].status).toEqual('Pending'); expect(response[1].icon).toEqual('favorite_border'); expect(response[1].theme).toEqual('theme-2'); + done(); }); }); - expect(getAppsSpy).toHaveBeenCalled(); - })); + }); it('should display default adf-empty-content template when response empty', () => { getAppsSpy.and.returnValue(of([])); @@ -115,7 +115,7 @@ describe('AppListCloudComponent', () => { expect(getAppsSpy).toHaveBeenCalled(); }); - it('should display default no permissions template when response returns exception', () => { + it('should display default no permissions template when response returns exception', (done) => { getAppsSpy.and.returnValue(throwError({})); fixture.detectChanges(); fixture.whenStable().then(() => { @@ -128,6 +128,7 @@ describe('AppListCloudComponent', () => { expect(errorTitle.innerText).toBe('ADF_CLOUD_TASK_LIST.APPS.ERROR.TITLE'); expect(errorSubtitle.innerText).toBe('ADF_CLOUD_TASK_LIST.APPS.ERROR.SUBTITLE'); expect(getAppsSpy).toHaveBeenCalled(); + done(); }); }); @@ -219,12 +220,12 @@ describe('AppListCloudComponent', () => { customFixture.destroy(); }); - it('should render the custom empty template', async(() => { + it('should render the custom empty template', async () => { customFixture.detectChanges(); - customFixture.whenStable().then(() => { - const title: any = customFixture.nativeElement.querySelector('#custom-id'); - expect(title.innerText).toBe('No Apps Found'); - }); - })); + await customFixture.whenStable(); + + const title: any = customFixture.nativeElement.querySelector('#custom-id'); + expect(title.innerText).toBe('No Apps Found'); + }); }); }); diff --git a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts index 3eed28edfb..9f65505362 100644 --- a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts @@ -1085,7 +1085,7 @@ describe('FormCloudWithCustomOutComesComponent', () => { fixture.destroy(); }); - it('should be able to inject custom outcomes and click on custom outcomes', async(() => { + it('should be able to inject custom outcomes and click on custom outcomes', async () => { fixture.detectChanges(); const onCustomButtonOneSpy = spyOn(customComponent, 'onCustomButtonOneClick').and.callThrough(); @@ -1096,11 +1096,12 @@ describe('FormCloudWithCustomOutComesComponent', () => { buttonOneBtn.nativeElement.click(); fixture.detectChanges(); + await fixture.whenStable(); expect(onCustomButtonOneSpy).toHaveBeenCalled(); expect(buttonOneBtn.nativeElement.innerText).toBe('CUSTOM-BUTTON-1'); expect(buttonTwoBtn.nativeElement.innerText).toBe('CUSTOM-BUTTON-2'); - })); + }); }); describe('retrieve metadata on submit', () => { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts index f727fefb0a..2d7fa19d74 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ContentCloudNodeSelectorService } from '../../../services/content-cloud-node-selector.service'; import { ProcessCloudContentService } from '../../../services/process-cloud-content.service'; @@ -114,7 +114,7 @@ describe('AttachFileCloudWidgetComponent', () => { schemas: [CUSTOM_ELEMENTS_SCHEMA] }); - beforeEach(async(() => { + beforeEach(() => { downloadService = TestBed.inject(DownloadService); fixture = TestBed.createComponent(AttachFileCloudWidgetComponent); widget = fixture.componentInstance; @@ -130,29 +130,28 @@ describe('AttachFileCloudWidgetComponent', () => { alfrescoApiService = TestBed.inject(AlfrescoApiService); contentNodeSelectorPanelService = TestBed.inject(ContentNodeSelectorPanelService); openUploadFileDialogSpy = spyOn(contentCloudNodeSelectorService, 'openUploadFileDialog').and.returnValue(of([fakeMinimalNode])); - })); + }); afterEach(() => { fixture.destroy(); }); - 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 () => { createUploadWidgetField(new FormModel(), 'simple-upload-button', [], allSourceParams); fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - expect(element.querySelector('#simple-upload-button')).not.toBeNull(); - }); - })); + expect(element.querySelector('#simple-upload-button')).not.toBeNull(); + }); - it('should show up as content upload when is configured with content', async(() => { + it('should show up as content upload when is configured with content', async () => { createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], contentSourceParam); fixture.detectChanges(); + await fixture.whenStable(); + + expect(element.querySelector('.adf-attach-widget__menu-upload')).not.toBeNull(); + }); - fixture.whenStable().then(() => { - expect(element.querySelector('.adf-attach-widget__menu-upload')).not.toBeNull(); - }); - })); it('should be able to attach files coming from content selector', async () => { createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], contentSourceParam); fixture.detectChanges(); @@ -183,14 +182,13 @@ describe('AttachFileCloudWidgetComponent', () => { expect(fileIcon).not.toBeNull(); }); - it('should display file list when field has value', async(() => { + it('should display file list when field has value', async () => { createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [fakeLocalPngResponse], onlyLocalParams); fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - expect(element.querySelector('#file-1155-icon')).not.toBeNull(); - }); - })); + expect(element.querySelector('#file-1155-icon')).not.toBeNull(); + }); it('should be able to set label property for Attach File widget', () => { createUploadWidgetField(new FormModel(), 'attach-file', [], onlyLocalParams, false, 'Label', true); @@ -469,56 +467,68 @@ describe('AttachFileCloudWidgetComponent', () => { expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-my-', 'single', false, true); }); - it('should display tooltip when tooltip is set', async(() => { + it('should display tooltip when tooltip is set', async () => { createUploadWidgetField(new FormModel(), 'attach-file-attach', [], onlyLocalParams); fixture.detectChanges(); - const attachElement: any = element.querySelector('#attach-file-attach'); + await fixture.whenStable(); + + const attachElement = element.querySelector('#attach-file-attach'); const tooltip = attachElement.getAttribute('ng-reflect-message'); expect(tooltip).toEqual(widget.field.tooltip); - })); + }); }); }); describe('when is readonly', () => { - it('should show empty list message when there are no file', async(() => { + it('should show empty list message when there are no file', async () => { createUploadWidgetField(new FormModel(), 'empty-test', [], onlyLocalParams, null, null, true); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelector('#adf-attach-empty-list-empty-test')).not.toBeNull(); - }); - })); - it('should not show empty list message when there are files', async(() => { - createUploadWidgetField(new FormModel(), 'fill-test', [fakeLocalPngResponse], onlyLocalParams, null, null, true); fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelector('#adf-attach-empty-list-fill-test')).toBeNull(); - }); - })); + await fixture.whenStable(); - it('should not show remove button when there are files attached', async(() => { + expect(element.querySelector('#adf-attach-empty-list-empty-test')).not.toBeNull(); + }); + + it('should not show empty list message when there are files', async () => { createUploadWidgetField(new FormModel(), 'fill-test', [fakeLocalPngResponse], onlyLocalParams, null, null, true); + fixture.detectChanges(); - const menuButton: HTMLButtonElement = ( + await fixture.whenStable(); + + expect(element.querySelector('#adf-attach-empty-list-fill-test')).toBeNull(); + }); + + it('should not show remove button when there are files attached', async () => { + createUploadWidgetField(new FormModel(), 'fill-test', [fakeLocalPngResponse], onlyLocalParams, null, null, true); + + fixture.detectChanges(); + await fixture.whenStable(); + + const menuButton = ( fixture.debugElement.query(By.css('#file-1155-option-menu')) .nativeElement ); menuButton.click(); + fixture.detectChanges(); + await fixture.whenStable(); expect(fixture.debugElement.query(By.css('#file-1155-remove'))).toBeNull(); - })); + }); - it('should not show any action when the attached file is a physical record', async(() => { + it('should not show any action when the attached file is a physical record', async () => { createUploadWidgetField(new FormModel(), 'fill-test', [fakeLocalPhysicalRecordResponse], onlyLocalParams, null, null, true); + fixture.detectChanges(); + await fixture.whenStable(); + const menuButton = fixture.debugElement.query(By.css('#file-1155-option-menu')); expect(menuButton).toBeNull(); - })); + }); }); describe('when a file is uploaded', () => { @@ -532,9 +542,12 @@ describe('AttachFileCloudWidgetComponent', () => { }); widget.field.id = 'attach-file-alfresco'; widget.field.params = menuTestSourceParam; + fixture.detectChanges(); await fixture.whenStable(); + clickOnAttachFileWidget('attach-file-alfresco'); + fixture.detectChanges(); await fixture.whenStable(); }); diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/date/date-cloud.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/date/date-cloud.widget.spec.ts index 2bf368f640..083df288d8 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/date/date-cloud.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/date/date-cloud.widget.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { DateCloudWidgetComponent } from './date-cloud.widget'; import { setupTestBed, FormFieldModel, FormModel } from '@alfresco/adf-core'; import moment from 'moment-es6'; @@ -36,11 +36,11 @@ describe('DateWidgetComponent', () => { ] }); - beforeEach(async(() => { + beforeEach(() => { fixture = TestBed.createComponent(DateCloudWidgetComponent); widget = fixture.componentInstance; element = fixture.nativeElement; - })); + }); it('should setup min value for date picker', () => { const minValue = '1982-03-13'; @@ -103,7 +103,7 @@ describe('DateWidgetComponent', () => { TestBed.resetTestingModule(); }); - it('should show visible date widget', async(() => { + it('should show visible date widget', async () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -114,15 +114,14 @@ describe('DateWidgetComponent', () => { widget.field.isVisible = true; widget.ngOnInit(); fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(element.querySelector('#date-field-id')).toBeDefined(); - expect(element.querySelector('#date-field-id')).not.toBeNull(); - const dateElement: any = element.querySelector('#date-field-id'); - expect(dateElement.value).toContain('9-9-9999'); - }); - })); + await fixture.whenStable(); + expect(element.querySelector('#date-field-id')).toBeDefined(); + expect(element.querySelector('#date-field-id')).not.toBeNull(); + const dateElement = element.querySelector('#date-field-id'); + expect(dateElement.value).toContain('9-9-9999'); + }); - it('should show the correct format type', async(() => { + it('should show the correct format type', async () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -134,16 +133,14 @@ describe('DateWidgetComponent', () => { widget.field.dateDisplayFormat = 'YYYY-DD-MM'; widget.ngOnInit(); fixture.detectChanges(); - fixture.whenStable() - .then(() => { - expect(element.querySelector('#date-field-id')).toBeDefined(); - expect(element.querySelector('#date-field-id')).not.toBeNull(); - const dateElement: any = element.querySelector('#date-field-id'); - expect(dateElement.value).toContain('9999-30-12'); - }); - })); + await fixture.whenStable(); + expect(element.querySelector('#date-field-id')).toBeDefined(); + expect(element.querySelector('#date-field-id')).not.toBeNull(); + const dateElement = element.querySelector('#date-field-id'); + expect(dateElement.value).toContain('9999-30-12'); + }); - it('should disable date button when is readonly', async(() => { + it('should disable date button when is readonly', async () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -154,18 +151,20 @@ describe('DateWidgetComponent', () => { widget.field.isVisible = true; widget.field.readOnly = false; fixture.detectChanges(); + await fixture.whenStable(); - let dateButton = element.querySelector('button'); + let dateButton = element.querySelector('button'); expect(dateButton.disabled).toBeFalsy(); widget.field.readOnly = true; fixture.detectChanges(); + await fixture.whenStable(); - dateButton = element.querySelector('button'); + dateButton = element.querySelector ('button'); expect(dateButton.disabled).toBeTruthy(); - })); + }); - it('should set isValid to false when the value is not a correct date value', async(() => { + it('should set isValid to false when the value is not a correct date value', async () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -175,12 +174,14 @@ describe('DateWidgetComponent', () => { }); widget.field.isVisible = true; widget.field.readOnly = false; + fixture.detectChanges(); + await fixture.whenStable(); expect(widget.field.isValid).toBeFalsy(); - })); + }); - it('should display tooltip when tooltip is set', async(() => { + it('should display tooltip when tooltip is set', async () => { widget.field = new FormFieldModel(new FormModel(), { id: 'date-field-id', name: 'date-name', @@ -191,11 +192,13 @@ describe('DateWidgetComponent', () => { }); fixture.detectChanges(); - const dateElement: any = element.querySelector('#date-field-id'); + await fixture.whenStable(); + + const dateElement = element.querySelector('#date-field-id'); const tooltip = dateElement.getAttribute('ng-reflect-message'); expect(tooltip).toEqual(widget.field.tooltip); - })); + }); }); it('should display always the json value', () => { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.spec.ts index 1a4b48c242..8e9da4d213 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.spec.ts @@ -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 { of } from 'rxjs'; import { DropdownCloudWidgetComponent } from './dropdown-cloud.widget'; @@ -58,7 +58,7 @@ describe('DropdownCloudWidgetComponent', () => { ] }); - beforeEach(async(() => { + beforeEach(() => { fixture = TestBed.createComponent(DropdownCloudWidgetComponent); widget = fixture.componentInstance; element = fixture.nativeElement; @@ -68,11 +68,11 @@ describe('DropdownCloudWidgetComponent', () => { formCloudService = TestBed.inject(FormCloudService); widget.field = new FormFieldModel(new FormModel()); - })); + }); afterEach(() => fixture.destroy()); - it('should require field with restUrl', async(() => { + it('should require field with restUrl', () => { spyOn(formService, 'getRestFieldValues').and.stub(); widget.field = null; @@ -82,13 +82,13 @@ describe('DropdownCloudWidgetComponent', () => { widget.field = new FormFieldModel(null, { restUrl: null }); widget.ngOnInit(); expect(formService.getRestFieldValues).not.toHaveBeenCalled(); - })); + }); describe('when template is ready', () => { describe('and dropdown is populated', () => { - beforeEach(async(() => { + beforeEach(() => { spyOn(visibilityService, 'refreshVisibility').and.stub(); spyOn(formService, 'getRestFieldValues').and.callFake(() => { return of(fakeOptionList); @@ -103,21 +103,21 @@ describe('DropdownCloudWidgetComponent', () => { widget.field.emptyOption = { id: 'empty', name: 'Choose one...' }; widget.field.isVisible = true; fixture.detectChanges(); - })); + }); - it('should select the default value when an option is chosen as default', async(() => { + it('should select the default value when an option is chosen as default', async () => { widget.field.value = 'option_2'; widget.ngOnInit(); - fixture.detectChanges(); - fixture.whenStable() - .then(() => { - const dropDownElement: any = element.querySelector('#dropdown-id'); - expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('option_2'); - expect(dropDownElement.attributes['ng-reflect-model'].textContent).toBe('option_2'); - }); - })); - it('should select the empty value when no default is chosen', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const dropDownElement: any = element.querySelector('#dropdown-id'); + expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('option_2'); + expect(dropDownElement.attributes['ng-reflect-model'].textContent).toBe('option_2'); + }); + + it('should select the empty value when no default is chosen', async () => { widget.field.value = 'empty'; widget.ngOnInit(); fixture.detectChanges(); @@ -125,26 +125,25 @@ describe('DropdownCloudWidgetComponent', () => { openSelect('#dropdown-id'); fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable() - .then(() => { - const dropDownElement: any = element.querySelector('#dropdown-id'); - expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('empty'); - }); - })); + const dropDownElement = element.querySelector('#dropdown-id'); + expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('empty'); + }); - it('should display tooltip when tooltip is set', async(() => { + it('should display tooltip when tooltip is set', async () => { widget.field.tooltip = 'dropdown widget'; widget.ngOnInit(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const dropDownElement: any = element.querySelector('#dropdown-id'); - const tooltip = dropDownElement.getAttribute('ng-reflect-message'); - expect(tooltip).toEqual(widget.field.tooltip); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); + + const dropDownElement: any = element.querySelector('#dropdown-id'); + const tooltip = dropDownElement.getAttribute('ng-reflect-message'); + + expect(tooltip).toEqual(widget.field.tooltip); + }); it('should load data from restUrl and populate options', async () => { const jsonDataSpy = spyOn(formCloudService, 'getDropDownJsonData').and.returnValue(of(fakeOptionList)); diff --git a/lib/process-services-cloud/src/lib/group/components/group-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/group/components/group-cloud.component.spec.ts index 77a6366d78..5010fe30e1 100644 --- a/lib/process-services-cloud/src/lib/group/components/group-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/group/components/group-cloud.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { of } from 'rxjs'; import { ProcessServiceCloudTestingModule } from './../../testing/process-service-cloud.testing.module'; @@ -74,24 +74,22 @@ describe('GroupCloudComponent', () => { spyOn(alfrescoApiService, 'getInstance').and.returnValue(mock); }); - it('should populate placeholder when title is present', async(() => { + it('should populate placeholder when title is present', async () => { component.title = 'TITLE_KEY'; + fixture.detectChanges(); + await fixture.whenStable(); - const matLabel: HTMLInputElement = element.querySelector('#adf-group-cloud-title-id'); - - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(matLabel.textContent).toEqual('TITLE_KEY'); - }); - })); + const matLabel = element.querySelector('#adf-group-cloud-title-id'); + expect(matLabel.textContent).toEqual('TITLE_KEY'); + }); describe('Search group', () => { - beforeEach(async(() => { + beforeEach(() => { fixture.detectChanges(); findGroupsByNameSpy = spyOn(identityGroupService, 'findGroupsByName').and.returnValue(of(mockIdentityGroups)); - })); + }); it('should list the groups as dropdown options if the search term has results', (done) => { const input = getElement('input'); @@ -228,7 +226,7 @@ describe('GroupCloudComponent', () => { let checkGroupHasAnyClientAppRoleSpy: jasmine.Spy; let checkGroupHasClientAppSpy: jasmine.Spy; - beforeEach(async(() => { + beforeEach(() => { findGroupsByNameSpy = spyOn(identityGroupService, 'findGroupsByName').and.returnValue(of(mockIdentityGroups)); checkGroupHasAnyClientAppRoleSpy = spyOn(identityGroupService, 'checkGroupHasAnyClientAppRole').and.returnValue(of(true)); checkGroupHasClientAppSpy = spyOn(identityGroupService, 'checkGroupHasClientApp').and.returnValue(of(true)); @@ -237,9 +235,9 @@ describe('GroupCloudComponent', () => { component.appName = 'mock-app-name'; fixture.detectChanges(); - })); + }); - it('should fetch the client ID if appName specified', async (() => { + it('should fetch the client ID if appName specified', async () => { const getClientIdByApplicationNameSpy = spyOn(identityGroupService, 'getClientIdByApplicationName').and.callThrough(); component.appName = 'mock-app-name'; @@ -247,11 +245,10 @@ describe('GroupCloudComponent', () => { component.ngOnChanges({ 'appName': change }); fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(getClientIdByApplicationNameSpy).toHaveBeenCalled(); - }); - })); + await fixture.whenStable(); + + expect(getClientIdByApplicationNameSpy).toHaveBeenCalled(); + }); it('should list groups who have access to the app when appName is specified', (done) => { const input = getElement('input'); @@ -423,12 +420,12 @@ describe('GroupCloudComponent', () => { describe('When roles defined', () => { let checkGroupHasRoleSpy: jasmine.Spy; - beforeEach(async(() => { + beforeEach(() => { component.roles = ['mock-role-1', 'mock-role-2']; spyOn(identityGroupService, 'findGroupsByName').and.returnValue(of(mockIdentityGroups)); checkGroupHasRoleSpy = spyOn(identityGroupService, 'checkGroupHasRole').and.returnValue(of(true)); fixture.detectChanges(); - })); + }); it('should filter if groups has any specified role', (done) => { fixture.detectChanges(); @@ -487,12 +484,12 @@ describe('GroupCloudComponent', () => { describe('Single Mode with pre-selected groups', () => { const changes = new SimpleChange(null, mockIdentityGroups, false); - beforeEach(async(() => { + beforeEach(() => { component.mode = 'single'; component.preSelectGroups = mockIdentityGroups; component.ngOnChanges({ 'preSelectGroups': changes }); fixture.detectChanges(); - })); + }); it('should show only one mat chip with the first preSelectedGroup', () => { const chips = fixture.debugElement.queryAll(By.css('mat-chip')); @@ -504,12 +501,12 @@ describe('GroupCloudComponent', () => { describe('Multiple Mode with pre-selected groups', () => { const change = new SimpleChange(null, mockIdentityGroups, false); - beforeEach(async(() => { + beforeEach(() => { component.mode = 'multiple'; component.preSelectGroups = mockIdentityGroups; component.ngOnChanges({ 'preSelectGroups': change }); fixture.detectChanges(); - })); + }); it('should render all preselected groups', () => { component.mode = 'multiple'; diff --git a/lib/process-services-cloud/src/lib/people/components/people-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/people/components/people-cloud.component.spec.ts index 009cd90c68..45432250d1 100644 --- a/lib/process-services-cloud/src/lib/people/components/people-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/people/components/people-cloud.component.spec.ts @@ -16,7 +16,7 @@ */ import { PeopleCloudComponent } from './people-cloud.component'; -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { IdentityUserService, AlfrescoApiService, @@ -78,36 +78,33 @@ describe('PeopleCloudComponent', () => { spyOn(alfrescoApiService, 'getInstance').and.returnValue(mock); }); - it('should populate placeholder when title is present', async(() => { + it('should populate placeholder when title is present', async () => { component.title = 'TITLE_KEY'; fixture.detectChanges(); const matLabel = getElement('#adf-people-cloud-title-id'); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(matLabel.textContent).toEqual('TITLE_KEY'); - }); - })); + await fixture.whenStable(); + expect(matLabel.textContent).toEqual('TITLE_KEY'); + }); - it('should not populate placeholder when title is not present', async(() => { + it('should not populate placeholder when title is not present', async () => { fixture.detectChanges(); const matLabel = getElement('#adf-people-cloud-title-id'); fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(matLabel.textContent).toEqual(''); - }); - })); + await fixture.whenStable(); + + expect(matLabel.textContent).toEqual(''); + }); describe('Search user', () => { - beforeEach(async(() => { + beforeEach(() => { fixture.detectChanges(); element = fixture.nativeElement; findUsersByNameSpy = spyOn(identityService, 'findUsersByName').and.returnValue(of(mockUsers)); - })); + }); it('should list the users as dropdown options if the search term has results', (done) => { const input = getElement('input'); @@ -337,7 +334,7 @@ describe('PeopleCloudComponent', () => { let checkUserHasAccessSpy: jasmine.Spy; let checkUserHasAnyClientAppRoleSpy: jasmine.Spy; - beforeEach(async(() => { + beforeEach(() => { findUsersByNameSpy = spyOn(identityService, 'findUsersByName').and.returnValue(of(mockUsers)); checkUserHasAccessSpy = spyOn(identityService, 'checkUserHasClientApp').and.returnValue(of(true)); checkUserHasAnyClientAppRoleSpy = spyOn(identityService, 'checkUserHasAnyClientAppRole').and.returnValue(of(true)); @@ -346,9 +343,9 @@ describe('PeopleCloudComponent', () => { component.appName = 'mock-app-name'; fixture.detectChanges(); element = fixture.nativeElement; - })); + }); - it('should fetch the client ID if appName specified', async (() => { + it('should fetch the client ID if appName specified', async () => { const getClientIdByApplicationNameSpy = spyOn(identityService, 'getClientIdByApplicationName').and.callThrough(); component.appName = 'mock-app-name'; @@ -356,11 +353,10 @@ describe('PeopleCloudComponent', () => { component.ngOnChanges({ 'appName': change }); fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(getClientIdByApplicationNameSpy).toHaveBeenCalled(); - }); - })); + await fixture.whenStable(); + + expect(getClientIdByApplicationNameSpy).toHaveBeenCalled(); + }); it('should list users who have access to the app when appName is specified', (done) => { const input = getElement('input'); @@ -529,13 +525,13 @@ describe('PeopleCloudComponent', () => { describe('When roles defined', () => { let checkUserHasRoleSpy: jasmine.Spy; - beforeEach(async(() => { + beforeEach(() => { component.roles = ['mock-role-1', 'mock-role-2']; spyOn(identityService, 'findUsersByName').and.returnValue(of(mockUsers)); checkUserHasRoleSpy = spyOn(identityService, 'checkUserHasRole').and.returnValue(of(true)); fixture.detectChanges(); element = fixture.nativeElement; - })); + }); it('should filter users if users has any specified role', (done) => { fixture.detectChanges(); @@ -594,14 +590,14 @@ describe('PeopleCloudComponent', () => { describe('Single Mode with Pre-selected users', () => { const changes = new SimpleChange(null, mockPreselectedUsers, false); - beforeEach(async(() => { + beforeEach(() => { component.mode = 'single'; component.preSelectUsers = mockPreselectedUsers; component.ngOnChanges({ 'preSelectUsers': changes }); fixture.detectChanges(); element = fixture.nativeElement; - })); + }); it('should show only one mat chip with the first preSelectedUser', (done) => { fixture.whenStable().then(() => { diff --git a/lib/process-services-cloud/src/lib/process/process-filters/components/edit-process-filter-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/process-filters/components/edit-process-filter-cloud.component.spec.ts index 4fdd8b2f70..1da0257a69 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/components/edit-process-filter-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/components/edit-process-filter-cloud.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { SimpleChange } from '@angular/core'; import { By } from '@angular/platform-browser'; @@ -126,78 +126,79 @@ describe('EditProcessFilterCloudComponent', () => { expect(count).toBe(1); }); - it('should fetch process instance filter by id', async(() => { + it('should fetch process instance filter by id', async () => { const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); component.ngOnChanges({ 'id': processFilterIdChange }); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(getProcessFilterByIdSpy).toHaveBeenCalled(); - expect(component.processFilter.name).toEqual('FakeRunningProcess'); - expect(component.processFilter.icon).toEqual('adjust'); - expect(component.processFilter.status).toEqual('RUNNING'); - expect(component.processFilter.order).toEqual('ASC'); - expect(component.processFilter.sort).toEqual('id'); - }); - })); - it('should display filter name as title', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(getProcessFilterByIdSpy).toHaveBeenCalled(); + expect(component.processFilter.name).toEqual('FakeRunningProcess'); + expect(component.processFilter.icon).toEqual('adjust'); + expect(component.processFilter.status).toEqual('RUNNING'); + expect(component.processFilter.order).toEqual('ASC'); + expect(component.processFilter.sort).toEqual('id'); + }); + + it('should display filter name as title', async () => { const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); component.showProcessFilterName = true; component.ngOnChanges({ 'id': processFilterIdChange }); + fixture.detectChanges(); + await fixture.whenStable(); + const title = fixture.debugElement.nativeElement.querySelector('#adf-edit-process-filter-title-id'); const subTitle = fixture.debugElement.nativeElement.querySelector('#adf-edit-process-filter-sub-title-id'); - fixture.whenStable().then(() => { - expect(title).toBeDefined(); - expect(subTitle).toBeDefined(); - expect(title.innerText).toEqual('FakeRunningProcess'); - expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_PROCESS_FILTER.TITLE'); - }); - })); + expect(title).toBeDefined(); + expect(subTitle).toBeDefined(); + expect(title.innerText).toEqual('FakeRunningProcess'); + expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_PROCESS_FILTER.TITLE'); + }); - it('should not display filter name as title if the flag is false', async(() => { + it('should not display filter name as title if the flag is false', async () => { const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); component.showProcessFilterName = false; component.ngOnChanges({ 'id': processFilterIdChange }); + fixture.detectChanges(); + await fixture.whenStable(); + const title = fixture.debugElement.nativeElement.querySelector('#adf-edit-process-filter-title-id'); + expect(title).toBeNull(); + }); - fixture.whenStable().then(() => { - expect(title).toBeNull(); - }); - })); - - it('should not display mat-spinner if isloading set to false', async(() => { + it('should not display mat-spinner if isloading set to false', async () => { const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); component.ngOnChanges({ 'id': processFilterIdChange }); + fixture.detectChanges(); + await fixture.whenStable(); + const title = fixture.debugElement.nativeElement.querySelector('#adf-edit-process-filter-title-id'); const subTitle = fixture.debugElement.nativeElement.querySelector('#adf-edit-process-filter-sub-title-id'); const matSpinnerElement = fixture.debugElement.nativeElement.querySelector('.adf-cloud-edit-process-filter-loading-margin'); - fixture.whenStable().then(() => { - expect(matSpinnerElement).toBeNull(); - expect(title).toBeDefined(); - expect(subTitle).toBeDefined(); - expect(title.innerText).toEqual('FakeRunningProcess'); - expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_PROCESS_FILTER.TITLE'); - }); - })); + expect(matSpinnerElement).toBeNull(); + expect(title).toBeDefined(); + expect(subTitle).toBeDefined(); + expect(title.innerText).toEqual('FakeRunningProcess'); + expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_PROCESS_FILTER.TITLE'); + }); - it('should display mat-spinner if isloading set to true', async(() => { + it('should display mat-spinner if isloading set to true', async () => { component.isLoading = true; const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); component.ngOnChanges({ 'id': processFilterIdChange }); + fixture.detectChanges(); + await fixture.whenStable(); const matSpinnerElement = fixture.debugElement.nativeElement.querySelector('.adf-cloud-edit-process-filter-loading-margin'); - - fixture.whenStable().then(() => { - expect(matSpinnerElement).toBeDefined(); - }); - })); + expect(matSpinnerElement).toBeDefined(); + }); describe('EditProcessFilter form', () => { @@ -207,38 +208,36 @@ describe('EditProcessFilterCloudComponent', () => { fixture.detectChanges(); }); - it('should defined editProcessFilter form', () => { + it('should create editProcessFilter form', async () => { + fixture.detectChanges(); + await fixture.whenStable(); + + const stateController = component.editProcessFilterForm.get('status'); + const sortController = component.editProcessFilterForm.get('sort'); + const orderController = component.editProcessFilterForm.get('order'); + expect(component.editProcessFilterForm).toBeDefined(); + expect(stateController).toBeDefined(); + expect(sortController).toBeDefined(); + expect(orderController).toBeDefined(); + + expect(stateController.value).toEqual('RUNNING'); + expect(sortController.value).toEqual('id'); + expect(orderController.value).toEqual('ASC'); }); - it('should create editProcessFilter form', async(() => { - fixture.detectChanges(); - fixture.whenStable().then(() => { - const stateController = component.editProcessFilterForm.get('status'); - const sortController = component.editProcessFilterForm.get('sort'); - const orderController = component.editProcessFilterForm.get('order'); - expect(component.editProcessFilterForm).toBeDefined(); - expect(stateController).toBeDefined(); - expect(sortController).toBeDefined(); - expect(orderController).toBeDefined(); - - expect(stateController.value).toEqual('RUNNING'); - expect(sortController.value).toEqual('id'); - expect(orderController.value).toEqual('ASC'); - }); - })); - describe('Save & Delete buttons', () => { - it('should enable delete button for custom process filters', async(() => { + it('should enable delete button for custom process filters', async () => { component.toggleFilterActions = true; const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); - expect(deleteButton.disabled).toEqual(false); - }); - })); + await fixture.whenStable(); + + const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); + expect(deleteButton.disabled).toEqual(false); + }); }); describe('SaveAs Button', () => { @@ -303,26 +302,30 @@ describe('EditProcessFilterCloudComponent', () => { }); }); - it('should display current process filter details', async(() => { + it('should display current process filter details', async () => { fixture.detectChanges(); - fixture.whenStable().then(() => { - const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); - expansionPanel.click(); - fixture.detectChanges(); - const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-process-property-status"]'); - const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-process-property-sort"]'); - const orderElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-process-property-order"]'); - expect(stateElement).toBeDefined(); - expect(sortElement).toBeDefined(); - expect(orderElement).toBeDefined(); - expect(stateElement.innerText.trim()).toEqual('ADF_CLOUD_PROCESS_FILTERS.STATUS.RUNNING'); - expect(sortElement.innerText.trim()).toEqual('ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.ID'); - expect(orderElement.innerText.trim()).toEqual('ADF_CLOUD_PROCESS_FILTERS.DIRECTION.ASCENDING'); - }); - })); + await fixture.whenStable(); + + const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); + expansionPanel.click(); - it('should display state drop down', async(() => { fixture.detectChanges(); + await fixture.whenStable(); + + const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-process-property-status"]'); + const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-process-property-sort"]'); + const orderElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-process-property-order"]'); + expect(stateElement).toBeDefined(); + expect(sortElement).toBeDefined(); + expect(orderElement).toBeDefined(); + expect(stateElement.innerText.trim()).toEqual('ADF_CLOUD_PROCESS_FILTERS.STATUS.RUNNING'); + expect(sortElement.innerText.trim()).toEqual('ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.ID'); + expect(orderElement.innerText.trim()).toEqual('ADF_CLOUD_PROCESS_FILTERS.DIRECTION.ASCENDING'); + }); + + it('should display state drop down', async () => { + fixture.detectChanges(); + await fixture.whenStable(); const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); @@ -331,75 +334,92 @@ describe('EditProcessFilterCloudComponent', () => { stateElement.click(); fixture.detectChanges(); - fixture.whenStable().then(() => { - const statusOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); - expect(statusOptions.length).toEqual(5); - }); - })); + await fixture.whenStable(); - it('should display sort drop down', async(() => { + const statusOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(statusOptions.length).toEqual(5); + }); + + it('should display sort drop down', async () => { fixture.detectChanges(); + await fixture.whenStable(); + const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-process-property-sort"] .mat-select-trigger'); sortElement.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); - expect(sortOptions.length).toEqual(4); - }); - })); - it('should display order drop down', async(() => { fixture.detectChanges(); + await fixture.whenStable(); + + const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(sortOptions.length).toEqual(4); + }); + + it('should display order drop down', async () => { + fixture.detectChanges(); + await fixture.whenStable(); + const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); const orderElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-process-property-order"] .mat-select-trigger'); orderElement.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const orderOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); - expect(orderOptions.length).toEqual(2); - }); - })); + await fixture.whenStable(); + + const orderOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(orderOptions.length).toEqual(2); + }); }); - it('should have floating labels when values are present', async(() => { + it('should have floating labels when values are present', async () => { fixture.detectChanges(); + await fixture.whenStable(); + const inputLabelsNodes = document.querySelectorAll('mat-form-field'); inputLabelsNodes.forEach(labelNode => { expect(labelNode.getAttribute('ng-reflect-float-label')).toBe('auto'); }); - })); + }); - it('should be able to filter filterProperties when input is defined', async(() => { + it('should be able to filter filterProperties when input is defined', async () => { fixture.detectChanges(); + await fixture.whenStable(); + component.filterProperties = ['appName', 'processName']; + fixture.detectChanges(); + await fixture.whenStable(); + const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); component.ngOnChanges({ 'id': processFilterIdChange }); + fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(component.processFilterProperties.length).toEqual(2); - expect(component.processFilterProperties[0].key).toEqual('appName'); - expect(component.processFilterProperties[1].key).toEqual('processName'); - }); - })); + await fixture.whenStable(); + + expect(component.processFilterProperties.length).toEqual(2); + expect(component.processFilterProperties[0].key).toEqual('appName'); + expect(component.processFilterProperties[1].key).toEqual('processName'); + }); it('should get form attributes', async() => { fixture.detectChanges(); + await fixture.whenStable(); + component.filterProperties = ['appName', 'completedDateRange']; fixture.detectChanges(); + await fixture.whenStable(); + const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); component.ngOnChanges({ 'id': processFilterIdChange }); + fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(component.editProcessFilterForm.get('_completedFrom')).toBeDefined(); - expect(component.editProcessFilterForm.get('_completedTo')).toBeDefined(); - expect(component.editProcessFilterForm.get('completedDateType')).toBeDefined(); - }); + await fixture.whenStable(); + + expect(component.editProcessFilterForm.get('_completedFrom')).toBeDefined(); + expect(component.editProcessFilterForm.get('_completedTo')).toBeDefined(); + expect(component.editProcessFilterForm.get('completedDateType')).toBeDefined(); }); it('should get form attributes for suspendedData', async() => { @@ -416,81 +436,98 @@ describe('EditProcessFilterCloudComponent', () => { getProcessFilterByIdSpy.and.returnValue(of(filter)); fixture.detectChanges(); + await fixture.whenStable(); + component.filterProperties = ['appName', 'suspendedDateRange']; + fixture.detectChanges(); + await fixture.whenStable(); + const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); component.ngOnChanges({ 'id': processFilterIdChange }); + fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(component.editProcessFilterForm.get('_suspendedFrom').value).toEqual(new Date(2021, 1, 1).toString()); - expect(component.editProcessFilterForm.get('_suspendedTo').value).toEqual(new Date(2021, 1, 2).toString()); - expect(component.editProcessFilterForm.get('suspendedDateType').value).toEqual(DateCloudFilterType.RANGE); - }); + await fixture.whenStable(); + + expect(component.editProcessFilterForm.get('_suspendedFrom').value).toEqual(new Date(2021, 1, 1).toString()); + expect(component.editProcessFilterForm.get('_suspendedTo').value).toEqual(new Date(2021, 1, 2).toString()); + expect(component.editProcessFilterForm.get('suspendedDateType').value).toEqual(DateCloudFilterType.RANGE); }); - it('should able to build a editProcessFilter form with default properties if input is empty', async(() => { + it('should able to build a editProcessFilter form with default properties if input is empty', async () => { fixture.detectChanges(); component.filterProperties = []; + fixture.detectChanges(); + await fixture.whenStable(); + const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); component.ngOnChanges({ 'id': processFilterIdChange }); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const stateController = component.editProcessFilterForm.get('status'); - const sortController = component.editProcessFilterForm.get('sort'); - const orderController = component.editProcessFilterForm.get('order'); - const lastModifiedFromController = component.editProcessFilterForm.get('lastModifiedFrom'); - const lastModifiedToController = component.editProcessFilterForm.get('lastModifiedTo'); - fixture.detectChanges(); - expect(component.processFilterProperties).toBeDefined(); - expect(component.processFilterProperties.length).toEqual(5); - expect(component.editProcessFilterForm).toBeDefined(); - expect(stateController).toBeDefined(); - expect(sortController).toBeDefined(); - expect(orderController).toBeDefined(); - expect(lastModifiedFromController).toBeDefined(); - expect(lastModifiedToController).toBeDefined(); - expect(stateController.value).toEqual('RUNNING'); - expect(sortController.value).toEqual('id'); - expect(orderController.value).toEqual('ASC'); - }); - })); - it('should able to fetch running applications when appName property defined in the input', async(() => { fixture.detectChanges(); + await fixture.whenStable(); + + const stateController = component.editProcessFilterForm.get('status'); + const sortController = component.editProcessFilterForm.get('sort'); + const orderController = component.editProcessFilterForm.get('order'); + const lastModifiedFromController = component.editProcessFilterForm.get('lastModifiedFrom'); + const lastModifiedToController = component.editProcessFilterForm.get('lastModifiedTo'); + + fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.processFilterProperties).toBeDefined(); + expect(component.processFilterProperties.length).toEqual(5); + expect(component.editProcessFilterForm).toBeDefined(); + expect(stateController).toBeDefined(); + expect(sortController).toBeDefined(); + expect(orderController).toBeDefined(); + expect(lastModifiedFromController).toBeDefined(); + expect(lastModifiedToController).toBeDefined(); + expect(stateController.value).toEqual('RUNNING'); + expect(sortController.value).toEqual('id'); + expect(orderController.value).toEqual('ASC'); + }); + + it('should able to fetch running applications when appName property defined in the input', async () => { component.filterProperties = ['appName', 'processName']; + fixture.detectChanges(); + await fixture.whenStable(); + const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); component.ngOnChanges({ 'id': processFilterIdChange }); - fixture.detectChanges(); - const appController = component.editProcessFilterForm.get('appName'); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(getRunningApplicationsSpy).toHaveBeenCalled(); - expect(appController).toBeDefined(); - expect(appController.value).toEqual('mock-app-name'); - }); - })); - it('should fetch applications when appName and appVersion input is set', async(() => { fixture.detectChanges(); + await fixture.whenStable(); + + const appController = component.editProcessFilterForm.get('appName'); + + expect(getRunningApplicationsSpy).toHaveBeenCalled(); + expect(appController).toBeDefined(); + expect(appController.value).toEqual('mock-app-name'); + }); + + it('should fetch applications when appName and appVersion input is set', async () => { component.filterProperties = ['appName', 'processName', 'appVersion']; fixture.detectChanges(); + await fixture.whenStable(); + const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); component.ngOnChanges({ 'id': processFilterIdChange }); + fixture.detectChanges(); + await fixture.whenStable(); + const appController = component.editProcessFilterForm.get('appName'); const appVersionController = component.editProcessFilterForm.get('appVersion'); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(getRunningApplicationsSpy).toHaveBeenCalled(); - expect(appController).toBeDefined(); - expect(appController.value).toEqual('mock-app-name'); - expect(appVersionController).toBeDefined(); - expect(appVersionController.value).toEqual(1); - }); - })); + + expect(getRunningApplicationsSpy).toHaveBeenCalled(); + expect(appController).toBeDefined(); + expect(appController.value).toEqual('mock-app-name'); + expect(appVersionController).toBeDefined(); + expect(appVersionController.value).toEqual(1); + }); it('should fetch appVersionMultiple options when appVersionMultiple filter property is set', async () => { const mockAppVersion1: ApplicationVersionModel = { @@ -535,49 +572,60 @@ describe('EditProcessFilterCloudComponent', () => { expect(appVersionOptions[1].nativeElement.innerText).toEqual('2'); }); - it('should fetch process definitions when processDefinitionName filter property is set', async(() => { + it('should fetch process definitions when processDefinitionName filter property is set', async () => { const processSpy = spyOn(processService, 'getProcessDefinitions').and.returnValue(of([new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })])); - fixture.detectChanges(); component.filterProperties = ['processDefinitionName']; + fixture.detectChanges(); + await fixture.whenStable(); + const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); component.ngOnChanges({ 'id': processFilterIdChange }); + fixture.detectChanges(); + await fixture.whenStable(); + const controller = component.editProcessFilterForm.get('processDefinitionName'); const processDefinitionNamesElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-process-property-processDefinitionName"]'); processDefinitionNamesElement.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(processSpy).toHaveBeenCalled(); - expect(controller).toBeDefined(); - const processDefinitionNamesOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); - expect(processDefinitionNamesOptions[0].nativeElement.value).toBeUndefined(); - expect(processDefinitionNamesOptions[0].nativeElement.innerText).toEqual(component.allProcessDefinitionNamesOption.label); - }); - })); - it('should display default sort properties', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(processSpy).toHaveBeenCalled(); + expect(controller).toBeDefined(); + const processDefinitionNamesOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(processDefinitionNamesOptions[0].nativeElement.value).toBeUndefined(); + expect(processDefinitionNamesOptions[0].nativeElement.innerText).toEqual(component.allProcessDefinitionNamesOption.label); + }); + + it('should display default sort properties', async () => { const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); component.ngOnChanges({ 'id': processFilterIdChange }); + fixture.detectChanges(); + await fixture.whenStable(); + const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); + fixture.detectChanges(); + await fixture.whenStable(); + const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-process-property-sort"]'); sortElement.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const sortController = component.editProcessFilterForm.get('sort'); - const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); - fixture.detectChanges(); - expect(sortController).toBeDefined(); - expect(sortController.value).toEqual('id'); - expect(sortOptions.length).toEqual(4); - }); - })); - it('should display sort properties when sort properties are specified', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const sortController = component.editProcessFilterForm.get('sort'); + const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(sortController).toBeDefined(); + expect(sortController.value).toEqual('id'); + expect(sortOptions.length).toEqual(4); + }); + + it('should display sort properties when sort properties are specified', async () => { getProcessFilterByIdSpy.and.returnValue(of({ id: 'filter-id', processName: 'process-name', @@ -586,26 +634,36 @@ describe('EditProcessFilterCloudComponent', () => { priority: '12' })); component.sortProperties = ['id', 'name', 'processDefinitionId']; + fixture.detectChanges(); + await fixture.whenStable(); + const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); component.ngOnChanges({ 'id': processFilterIdChange }); + fixture.detectChanges(); + await fixture.whenStable(); + const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); + fixture.detectChanges(); + await fixture.whenStable(); + const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-process-property-sort"]'); sortElement.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const sortController = component.editProcessFilterForm.get('sort'); - const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); - expect(sortController).toBeDefined(); - expect(component.sortProperties).toBeDefined(); - expect(component.sortProperties.length).toBe(3); - expect(sortController.value).toBe('my-custom-sort'); - expect(sortOptions.length).toEqual(3); - }); - })); + await fixture.whenStable(); + + const sortController = component.editProcessFilterForm.get('sort'); + const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(sortController).toBeDefined(); + expect(component.sortProperties).toBeDefined(); + expect(component.sortProperties.length).toBe(3); + expect(sortController.value).toBe('my-custom-sort'); + expect(sortOptions.length).toEqual(3); + }); it('should display the process name label for the name property', async () => { getProcessFilterByIdSpy.and.returnValue(of({ @@ -618,14 +676,22 @@ describe('EditProcessFilterCloudComponent', () => { component.sortProperties = ['name']; const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); component.ngOnChanges({ 'id': processFilterIdChange }); - fixture.detectChanges(); - const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); - expansionPanel.click(); - fixture.detectChanges(); - const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-process-property-sort"]'); - sortElement.click(); + fixture.detectChanges(); await fixture.whenStable(); + + const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); + expansionPanel.click(); + + fixture.detectChanges(); + await fixture.whenStable(); + + const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-process-property-sort"]'); + sortElement.click(); + + fixture.detectChanges(); + await fixture.whenStable(); + const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); expect(sortOptions[0].nativeElement.textContent).toEqual('ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.PROCESS_NAME'); }); @@ -644,28 +710,37 @@ describe('EditProcessFilterCloudComponent', () => { fixture.destroy(); }); - it('should emit save event and save the filter on click save button', async(() => { + it('should emit save event and save the filter on click save button', async () => { component.toggleFilterActions = true; const saveFilterSpy = spyOn(service, 'updateFilter').and.returnValue(of([fakeFilter])); const saveSpy: jasmine.Spy = spyOn(component.action, 'emit'); fixture.detectChanges(); + await fixture.whenStable(); + const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); + fixture.detectChanges(); + await fixture.whenStable(); + const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-process-property-status"] .mat-select-trigger'); stateElement.click(); + fixture.detectChanges(); + await fixture.whenStable(); + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); const stateOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); stateOptions[2].nativeElement.click(); saveButton.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(saveFilterSpy).toHaveBeenCalled(); - expect(saveSpy).toHaveBeenCalled(); - }); - })); + await fixture.whenStable(); + + expect(saveFilterSpy).toHaveBeenCalled(); + expect(saveSpy).toHaveBeenCalled(); + }); it('should emit delete event and delete the filter on click of delete button', async () => { component.toggleFilterActions = true; @@ -689,6 +764,7 @@ describe('EditProcessFilterCloudComponent', () => { const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); deleteButton.click(); + fixture.detectChanges(); await fixture.whenStable(); @@ -696,86 +772,97 @@ describe('EditProcessFilterCloudComponent', () => { expect(deleteSpy).toHaveBeenCalled(); }); - it('should emit saveAs event and add filter on click saveAs button', async(() => { + it('should emit saveAs event and add filter on click saveAs button', async () => { component.toggleFilterActions = true; const saveAsFilterSpy = spyOn(service, 'addFilter').and.callThrough(); - const saveAsSpy: jasmine.Spy = spyOn(component.action, 'emit'); + const saveAsSpy = spyOn(component.action, 'emit'); + fixture.detectChanges(); + await fixture.whenStable(); const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); + fixture.detectChanges(); + await fixture.whenStable(); + const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-process-property-status"] .mat-select-trigger'); stateElement.click(); + fixture.detectChanges(); + await fixture.whenStable(); + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); const stateOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); stateOptions[2].nativeElement.click(); - fixture.detectChanges(); saveButton.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(saveAsFilterSpy).toHaveBeenCalled(); - expect(saveAsSpy).toHaveBeenCalled(); - expect(dialog.open).toHaveBeenCalled(); - }); - })); - it('should display default filter actions', async(() => { fixture.detectChanges(); + await fixture.whenStable(); + + expect(saveAsFilterSpy).toHaveBeenCalled(); + expect(saveAsSpy).toHaveBeenCalled(); + expect(dialog.open).toHaveBeenCalled(); + }); + + it('should display default filter actions', async () => { component.toggleFilterActions = true; const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); - const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); - expect(component.processFilterActions).toBeDefined(); - expect(component.processFilterActions.length).toEqual(3); - expect(saveButton).toBeDefined(); - expect(saveAsButton).toBeDefined(); - expect(deleteButton).toBeDefined(); - }); - })); - it('should filter actions when input actions are specified', async(() => { fixture.detectChanges(); + await fixture.whenStable(); + + const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); + const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); + expect(component.processFilterActions).toBeDefined(); + expect(component.processFilterActions.length).toEqual(3); + expect(saveButton).toBeDefined(); + expect(saveAsButton).toBeDefined(); + expect(deleteButton).toBeDefined(); + }); + + it('should filter actions when input actions are specified', async () => { component.actions = ['save']; + fixture.detectChanges(); + await fixture.whenStable(); + const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); component.ngOnChanges({ 'id': processFilterIdChange }); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(component.processFilterActions).toBeDefined(); - expect(component.actions.length).toEqual(1); - expect(component.processFilterActions.length).toEqual(1); - }); - })); - it('should display default filter actions when input is empty', async(() => { fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.processFilterActions).toBeDefined(); + expect(component.actions.length).toEqual(1); + expect(component.processFilterActions.length).toEqual(1); + }); + + it('should display default filter actions when input is empty', async () => { component.toggleFilterActions = true; component.actions = []; component.id = 'mock-process-filter-id'; + fixture.detectChanges(); + await fixture.whenStable(); const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); fixture.detectChanges(); - fixture.whenStable().then(() => { - const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); - const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); - expect(component.processFilterActions).toBeDefined(); - expect(component.processFilterActions.length).toEqual(3); - expect(saveButton).toBeDefined(); - expect(saveAsButton).toBeDefined(); - expect(deleteButton).toBeDefined(); - }); - })); + await fixture.whenStable(); + + const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); + const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); + expect(component.processFilterActions).toBeDefined(); + expect(component.processFilterActions.length).toEqual(3); + expect(saveButton).toBeDefined(); + expect(saveAsButton).toBeDefined(); + expect(deleteButton).toBeDefined(); + }); it('should set the correct lastModifiedTo date', (done) => { component.appName = 'fake'; diff --git a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filter-dialog-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filter-dialog-cloud.component.spec.ts index edf00fe605..a961c1ed8c 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filter-dialog-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filter-dialog-cloud.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { ProcessFilterDialogCloudComponent } from './process-filter-dialog-cloud.component'; import { setupTestBed } from '@alfresco/adf-core'; @@ -70,7 +70,7 @@ describe('ProcessFilterDialogCloudComponent', () => { expect(titleElement.textContent).toEqual(' ADF_CLOUD_EDIT_PROCESS_FILTER.DIALOG.TITLE '); }); - it('should enable save button if form is valid', async(() => { + it('should enable save button if form is valid', async () => { fixture.detectChanges(); const saveButton = fixture.debugElement.nativeElement.querySelector( '#adf-save-button-id' @@ -80,48 +80,52 @@ describe('ProcessFilterDialogCloudComponent', () => { ); inputElement.value = 'My custom Name'; inputElement.dispatchEvent(new Event('input')); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(saveButton).toBeDefined(); - expect(saveButton.disabled).toBeFalsy(); - }); - })); - it('should disable save button if form is not valid', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(saveButton).toBeDefined(); + expect(saveButton.disabled).toBeFalsy(); + }); + + it('should disable save button if form is not valid', async () => { fixture.detectChanges(); const inputElement = fixture.debugElement.nativeElement.querySelector( '#adf-filter-name-id' ); inputElement.value = ''; inputElement.dispatchEvent(new Event('input')); - fixture.whenStable().then(() => { - const saveButton = fixture.debugElement.nativeElement.querySelector( - '#adf-save-button-id' - ); - fixture.detectChanges(); - expect(saveButton).toBeDefined(); - expect(saveButton.disabled).toBe(true); - }); - })); - it('should able to close dialog on click of save button if form is valid', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const saveButton = fixture.debugElement.nativeElement.querySelector( + '#adf-save-button-id' + ); + expect(saveButton).toBeDefined(); + expect(saveButton.disabled).toBe(true); + }); + + it('should able to close dialog on click of save button if form is valid', async () => { fixture.detectChanges(); const inputElement = fixture.debugElement.nativeElement.querySelector( '#adf-filter-name-id' ); inputElement.value = 'My custom Name'; inputElement.dispatchEvent(new Event('input')); - fixture.whenStable().then(() => { - const saveButton = fixture.debugElement.nativeElement.querySelector( - '#adf-save-button-id' - ); - fixture.detectChanges(); - saveButton.click(); - expect(saveButton).toBeDefined(); - expect(saveButton.disabled).toBeFalsy(); - expect(component.dialogRef.close).toHaveBeenCalled(); - }); - })); + + fixture.detectChanges(); + await fixture.whenStable(); + + const saveButton = fixture.debugElement.nativeElement.querySelector( + '#adf-save-button-id' + ); + expect(saveButton).toBeDefined(); + expect(saveButton.disabled).toBeFalsy(); + + saveButton.click(); + expect(component.dialogRef.close).toHaveBeenCalled(); + }); it('should able close dialog on click of cancel button', () => { component.data = { data: { name: '' } }; diff --git a/lib/process-services-cloud/src/lib/process/process-header/components/process-header-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/process-header/components/process-header-cloud.component.spec.ts index 5efdc98f91..e4582aba1e 100644 --- a/lib/process-services-cloud/src/lib/process/process-header/components/process-header-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-header/components/process-header-cloud.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { setupTestBed, AppConfigService } from '@alfresco/adf-core'; import { By } from '@angular/platform-browser'; import { of } from 'rxjs'; @@ -62,161 +62,160 @@ describe('ProcessHeaderCloudComponent', () => { component.processInstanceId = 'sdfsdf-323'; }); - it('should render empty component if no process instance details are provided', async(() => { + it('should render empty component if no process instance details are provided', async () => { component.appName = undefined; component.processInstanceId = undefined; component.ngOnChanges(); fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(component.properties).toBeUndefined(); - }); - })); + await fixture.whenStable(); - it('should display process instance id', async(() => { + expect(component.properties).toBeUndefined(); + }); + + it('should display process instance id', async () => { component.ngOnChanges(); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-id"]')); - expect(formNameEl.nativeElement.value).toBe('00fcc4ab-4290-11e9-b133-0a586460016a'); - }); - })); + const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-id"]')); + expect(formNameEl.nativeElement.value).toBe('00fcc4ab-4290-11e9-b133-0a586460016a'); + }); - it('should display name', async(() => { + it('should display name', async () => { component.ngOnChanges(); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-name"]')); - expect(formNameEl.nativeElement.value).toBe('new name'); - }); - })); + const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-name"]')); + expect(formNameEl.nativeElement.value).toBe('new name'); + }); - it('should display placeholder if no name is available', async(() => { + it('should display placeholder if no name is available', async () => { processInstanceDetailsCloudMock.name = null; component.ngOnChanges(); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const valueEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-name"]')); - expect(valueEl.nativeElement.value).toBe('ADF_CLOUD_PROCESS_HEADER.PROPERTIES.NAME_DEFAULT'); - }); + const valueEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-name"]')); + expect(valueEl.nativeElement.value).toBe('ADF_CLOUD_PROCESS_HEADER.PROPERTIES.NAME_DEFAULT'); + }); - })); - - it('should display status', async(() => { + it('should display status', async () => { component.ngOnChanges(); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-status"]')); - expect(formNameEl.nativeElement.value).toBe('RUNNING'); - }); - })); + const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-status"]')); + expect(formNameEl.nativeElement.value).toBe('RUNNING'); + }); - it('should display initiator', async(() => { + it('should display initiator', async () => { component.ngOnChanges(); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-initiator"]')); - expect(formNameEl.nativeElement.value).toBe('devopsuser'); - }); - })); + const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-initiator"]')); + expect(formNameEl.nativeElement.value).toBe('devopsuser'); + }); - it('should display start date', async(() => { + it('should display start date', async () => { component.ngOnChanges(); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-startDate"] .adf-property-value')); - expect(valueEl.nativeElement.innerText.trim()).toBe('Mar 9, 2019'); - }); - })); + const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-startDate"] .adf-property-value')); + expect(valueEl.nativeElement.innerText.trim()).toBe('Mar 9, 2019'); + }); - it('should display lastModified date', async(() => { + it('should display lastModified date', async () => { component.ngOnChanges(); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-lastModified"] .adf-property-value')); - expect(valueEl.nativeElement.innerText.trim()).toBe('Mar 9, 2019'); - }); - })); + const valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-lastModified"] .adf-property-value')); + expect(valueEl.nativeElement.innerText.trim()).toBe('Mar 9, 2019'); + }); - it('should display parentId', async(() => { + it('should display parentId', async () => { component.ngOnChanges(); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-parentId"]')); - expect(formNameEl.nativeElement.value).toBe('00fcc4ab-4290-11e9-b133-0a586460016b'); - }); - })); + const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-parentId"]')); + expect(formNameEl.nativeElement.value).toBe('00fcc4ab-4290-11e9-b133-0a586460016b'); + }); - it('should display default value when parentId is not available', async(() => { + it('should display default value when parentId is not available', async () => { processInstanceDetailsCloudMock.parentId = null; component.ngOnChanges(); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-parentId"]')); - expect(formNameEl.nativeElement.value).toBe('ADF_CLOUD_PROCESS_HEADER.PROPERTIES.NONE'); - }); - })); + const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-parentId"]')); + expect(formNameEl.nativeElement.value).toBe('ADF_CLOUD_PROCESS_HEADER.PROPERTIES.NONE'); + }); - it('should display businessKey', async(() => { + it('should display businessKey', async () => { component.ngOnChanges(); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-businessKey"]')); - expect(formNameEl.nativeElement.value).toBe('MyBusinessKey'); - }); - })); + const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-businessKey"]')); + expect(formNameEl.nativeElement.value).toBe('MyBusinessKey'); + }); - it('should display default value when businessKey is not available', async(() => { + it('should display default value when businessKey is not available', async () => { processInstanceDetailsCloudMock.businessKey = null; component.ngOnChanges(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-businessKey"]')); - expect(formNameEl.nativeElement.value).toBe('ADF_CLOUD_PROCESS_HEADER.PROPERTIES.NONE'); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); + + const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-businessKey"]')); + expect(formNameEl.nativeElement.value).toBe('ADF_CLOUD_PROCESS_HEADER.PROPERTIES.NONE'); + }); 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(['name', 'status']); component.ngOnChanges(); + fixture.detectChanges(); + await fixture.whenStable(); - 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(2); - expect(propertyList[0].nativeElement.textContent).toContain('ADF_CLOUD_PROCESS_HEADER.PROPERTIES.NAME'); - expect(propertyList[1].nativeElement.textContent).toContain('ADF_CLOUD_PROCESS_HEADER.PROPERTIES.STATUS'); - }); - })); + const propertyList = fixture.debugElement.queryAll(By.css('.adf-property-list .adf-property')); + expect(propertyList).toBeDefined(); + expect(propertyList).not.toBeNull(); + expect(propertyList.length).toBe(2); + expect(propertyList[0].nativeElement.textContent).toContain('ADF_CLOUD_PROCESS_HEADER.PROPERTIES.NAME'); + expect(propertyList[1].nativeElement.textContent).toContain('ADF_CLOUD_PROCESS_HEADER.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.ngOnChanges(); - 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_CLOUD_PROCESS_HEADER.PROPERTIES.ID'); - expect(propertyList[1].nativeElement.textContent).toContain('ADF_CLOUD_PROCESS_HEADER.PROPERTIES.NAME'); - }); - })); + 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_CLOUD_PROCESS_HEADER.PROPERTIES.ID'); + expect(propertyList[1].nativeElement.textContent).toContain('ADF_CLOUD_PROCESS_HEADER.PROPERTIES.NAME'); + }); }); }); diff --git a/lib/process-services-cloud/src/lib/process/process-list/components/process-list-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/process-list/components/process-list-cloud.component.spec.ts index d6f8cb121d..ce878368c7 100644 --- a/lib/process-services-cloud/src/lib/process/process-list/components/process-list-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-list/components/process-list-cloud.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ import { Component, SimpleChange, ViewChild } 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 { AppConfigService, @@ -419,7 +419,7 @@ describe('ProcessListCloudComponent', () => { fixtureEmpty.destroy(); }); - it('should render the custom template', async((done) => { + it('should render the custom template', fakeAsync((done) => { const emptyList = {list: {entries: []}}; spyOn(processListCloudService, 'getProcessByRequest').and.returnValue(of(emptyList)); component.success.subscribe(() => { diff --git a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts index 5ff234f62a..26e30442e7 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts @@ -16,7 +16,7 @@ */ import { SimpleChange, DebugElement } from '@angular/core'; -import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; +import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; import { setupTestBed } from '@alfresco/adf-core'; import { of, throwError } from 'rxjs'; import { StartProcessCloudService } from '../services/start-process-cloud.service'; @@ -141,8 +141,7 @@ describe('StartProcessCloudComponent', () => { }); })); - it('should create a process instance if the selection is valid', async(() => { - + it('should create a process instance if the selection is valid', fakeAsync(() => { getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(fakeProcessDefinitions)); component.name = 'My new process'; component.processDefinitionName = 'process'; @@ -178,29 +177,29 @@ describe('StartProcessCloudComponent', () => { }); })); - it('should have start button disabled when no process is selected', async(() => { + it('should have start button disabled when no process is selected', async () => { component.name = ''; component.processDefinitionName = ''; + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const startBtn = fixture.nativeElement.querySelector('#button-start'); - expect(startBtn.disabled).toBe(true); - expect(component.isProcessFormValid()).toBe(false); - }); - })); + const startBtn = fixture.nativeElement.querySelector('#button-start'); + expect(startBtn.disabled).toBe(true); + expect(component.isProcessFormValid()).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 () => { component.name = ''; component.processDefinitionName = 'processwithoutform2'; - fixture.detectChanges(); - fixture.whenStable().then(() => { - const startBtn = fixture.nativeElement.querySelector('#button-start'); - expect(startBtn.disabled).toBe(true); - expect(component.isProcessFormValid()).toBe(false); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); + + const startBtn = fixture.nativeElement.querySelector('#button-start'); + expect(startBtn.disabled).toBe(true); + expect(component.isProcessFormValid()).toBe(false); + }); }); describe('start a process with start form', () => { @@ -445,40 +444,41 @@ describe('StartProcessCloudComponent', () => { }); }); - it('should indicate an error to the user if process defs cannot be loaded', async(() => { + it('should indicate an error to the user if process defs cannot be loaded', async () => { getDefinitionsSpy = getDefinitionsSpy.and.returnValue(throwError({})); const change = new SimpleChange('myApp', 'myApp1', true); component.ngOnChanges({ appName: change }); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const errorEl = fixture.nativeElement.querySelector('#error-message'); - expect(errorEl.innerText.trim()).toBe('ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.LOAD_PROCESS_DEFS'); - }); - })); + const errorEl = fixture.nativeElement.querySelector('#error-message'); + expect(errorEl.innerText.trim()).toBe('ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.LOAD_PROCESS_DEFS'); + }); - 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([])); const change = new SimpleChange('myApp', 'myApp1', true); component.ngOnChanges({ appName: change }); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const noProcessElement = fixture.nativeElement.querySelector('#no-process-message'); - expect(noProcessElement).not.toBeNull('Expected no available process message to be present'); - expect(noProcessElement.innerText.trim()).toBe('ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.NO_PROCESS_DEFINITIONS'); - }); - })); + const noProcessElement = fixture.nativeElement.querySelector('#no-process-message'); + expect(noProcessElement).not.toBeNull('Expected no available process message to be present'); + expect(noProcessElement.innerText.trim()).toBe('ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.NO_PROCESS_DEFINITIONS'); + }); - it('should select automatically the processDefinition if the app contain only one', async(() => { + it('should select automatically the processDefinition if the app contain only one', async () => { getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of([fakeProcessDefinitions[0]])); const change = new SimpleChange('myApp', 'myApp1', true); component.ngOnChanges({ appName: change }); + fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(component.processForm.controls['processDefinition'].value).toBe(JSON.parse(JSON.stringify(fakeProcessDefinitions[0])).name); - }); - })); + await fixture.whenStable(); + + expect(component.processForm.controls['processDefinition'].value).toBe(JSON.parse(JSON.stringify(fakeProcessDefinitions[0])).name); + }); it('should select automatically the form when processDefinition is selected as default', fakeAsync(() => { getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of([fakeProcessDefinitions[0]])); @@ -501,17 +501,18 @@ describe('StartProcessCloudComponent', () => { }); })); - it('should not select automatically any processDefinition if the app contain multiple process and does not have any processDefinition as input', async(() => { + it('should not select automatically any processDefinition if the app contain multiple process and does not have any processDefinition as input', async () => { getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(fakeProcessDefinitions)); component.appName = 'myApp'; component.ngOnChanges({}); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(component.processPayloadCloud.name).toBeNull(); - }); - })); - it('should select the right process when the processKey begins with the name', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.processPayloadCloud.name).toBeNull(); + }); + + it('should select the right process when the processKey begins with the name', fakeAsync(() => { getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(fakeProcessDefinitions)); component.name = 'My new process'; component.processDefinitionName = 'process'; @@ -525,45 +526,48 @@ describe('StartProcessCloudComponent', () => { 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(fakeProcessDefinitions)); component.appName = 'myApp'; 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(fakeProcessDefinitions)); component.appName = 'myApp'; component.processDefinitionName = 'NewProcess 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(); getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(fakeProcessDefinitions)); component.appName = 'myApp'; component.processDefinitionName = 'NewProcess 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(); + }); }); }); @@ -571,53 +575,57 @@ describe('StartProcessCloudComponent', () => { const change = new SimpleChange('myApp', 'myApp1', false); - beforeEach(async(() => { + beforeEach(() => { component.appName = 'myApp'; fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - getDefinitionsSpy.calls.reset(); - }); - })); + }); - it('should have labels for process name and type', async(() => { + it('should have labels for process name and type', async () => { component.appName = 'myApp'; component.processDefinitionName = 'NewProcess 2'; component.ngOnChanges({ appName: firstChange }); + 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.appName = 'myApp'; component.processDefinitionName = 'NewProcess 2'; component.ngOnChanges({}); + 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 reload processes when appName input changed', async(() => { + it('should reload processes when appName input changed', async () => { component.ngOnChanges({ appName: firstChange }); component.ngOnChanges({ appName: change }); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(getDefinitionsSpy).toHaveBeenCalledWith('myApp1'); - }); - })); - it('should reload processes ONLY when appName input changed', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(getDefinitionsSpy).toHaveBeenCalledWith('myApp1'); + }); + + it('should reload processes ONLY when appName input changed', async () => { component.ngOnChanges({ appName: firstChange }); fixture.detectChanges(); + component.ngOnChanges({ maxNameLength: new SimpleChange(0, 2, false) }); fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(getDefinitionsSpy).toHaveBeenCalledTimes(1); - }); - })); + await fixture.whenStable(); + + expect(getDefinitionsSpy).toHaveBeenCalledTimes(1); + }); it('should get current processDef', () => { component.ngOnChanges({ appName: change }); @@ -643,15 +651,16 @@ describe('StartProcessCloudComponent', () => { expect(component.filteredProcesses.length).toEqual(1); })); - it('should display the process definion field as empty if are more than one process definition in the list', async(() => { + it('should display the process definion field as empty if are more than one process definition in the list', async () => { getDefinitionsSpy.and.returnValue(of(fakeProcessDefinitions)); component.ngOnChanges({ appName: change }); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const processDefinitionInput = fixture.nativeElement.querySelector('#processDefinitionName'); - expect(processDefinitionInput.textContent).toEqual(''); - }); - })); + await fixture.whenStable(); + + const processDefinitionInput = fixture.nativeElement.querySelector('#processDefinitionName'); + expect(processDefinitionInput.textContent).toEqual(''); + }); }); describe('start process', () => { @@ -663,23 +672,20 @@ describe('StartProcessCloudComponent', () => { 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', () => { component.currentCreatedProcess = fakeProcessInstance; component.startProcess(); - fixture.whenStable().then(() => { - expect(startProcessSpy).toHaveBeenCalled(); - }); - })); + expect(startProcessSpy).toHaveBeenCalled(); + }); - it('should call service to start process with the correct parameters', async(() => { + it('should call service to start process with the correct parameters', () => { component.currentCreatedProcess = fakeProcessInstance; component.startProcess(); - fixture.whenStable().then(() => { - expect(startProcessSpy).toHaveBeenCalledWith(component.appName, fakeProcessInstance.id, component.processPayloadCloud); - }); - })); - it('should call service to start process with the variables setted', async(() => { + expect(startProcessSpy).toHaveBeenCalledWith(component.appName, fakeProcessInstance.id, component.processPayloadCloud); + }); + + it('should call service to start process with the variables setted', async () => { const inputProcessVariable: Map[] = []; inputProcessVariable['name'] = { value: 'Josh' }; @@ -687,44 +693,42 @@ describe('StartProcessCloudComponent', () => { component.currentCreatedProcess = fakeProcessInstance; component.startProcess(); - fixture.whenStable().then(() => { - expect(component.processPayloadCloud.variables).toBe(inputProcessVariable); - }); - })); + await fixture.whenStable(); + expect(component.processPayloadCloud.variables).toBe(inputProcessVariable); + }); - it('should output start event when process started successfully', async(() => { + it('should output start event when process started successfully', () => { const emitSpy = spyOn(component.success, 'emit'); component.currentCreatedProcess = fakeProcessInstance; component.startProcess(); - fixture.whenStable().then(() => { - expect(emitSpy).toHaveBeenCalledWith(fakeProcessInstance); - }); - })); - it('should throw error event when process cannot be started', async(() => { + expect(emitSpy).toHaveBeenCalledWith(fakeProcessInstance); + }); + + it('should throw error event when process cannot be started', async () => { const errorSpy = spyOn(component.error, 'emit'); const error = { message: 'My error' }; startProcessSpy = startProcessSpy.and.returnValue(throwError(error)); component.currentCreatedProcess = fakeProcessInstance; component.startProcess(); - fixture.whenStable().then(() => { - expect(errorSpy).toHaveBeenCalledWith(error); - }); - })); + await fixture.whenStable(); + expect(errorSpy).toHaveBeenCalledWith(error); + }); - it('should indicate an error to the user if process cannot be started', async(() => { + it('should indicate an error to the user if process cannot be started', async () => { getDefinitionsSpy.and.returnValue(of(fakeProcessDefinitions)); const change = new SimpleChange('myApp', 'myApp1', true); component.currentCreatedProcess = fakeProcessInstance; component.ngOnChanges({ appName: change }); startProcessSpy = startProcessSpy.and.returnValue(throwError({})); component.startProcess(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const errorEl = fixture.nativeElement.querySelector('#error-message'); - expect(errorEl.innerText.trim()).toBe('ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.START'); - }); - })); + await fixture.whenStable(); + + const errorEl = fixture.nativeElement.querySelector('#error-message'); + expect(errorEl.innerText.trim()).toBe('ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.START'); + }); it('should emit start event when start select a process and add a name', (done) => { const disposableStart = component.success.subscribe(() => { @@ -761,17 +765,23 @@ describe('StartProcessCloudComponent', () => { expect(processInstanceName.valid).toBeTruthy(); }); - it('should have start button disabled process name has a space as the first or last character.', async(() => { + it('should have start button disabled process name has a space as the first or last character.', async () => { component.appName = 'myApp'; component.processDefinitionName = ' Space in the beginning'; component.ngOnChanges({ appName: firstChange }); + fixture.detectChanges(); + await fixture.whenStable(); + const startBtn = fixture.nativeElement.querySelector('#button-start'); expect(startBtn.disabled).toBe(true); component.processDefinitionName = 'Space in the end '; + fixture.detectChanges(); + await fixture.whenStable(); + expect(startBtn.disabled).toBe(true); - })); + }); it('should emit processDefinitionSelection event when a process definition is selected', (done) => { component.appName = 'myApp'; diff --git a/lib/process-services-cloud/src/lib/task/services/task-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/task/services/task-cloud.service.spec.ts index 05775882ae..c09a549087 100644 --- a/lib/process-services-cloud/src/lib/task/services/task-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/task/services/task-cloud.service.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { setupTestBed, IdentityUserService, TranslationService, AlfrescoApiService } from '@alfresco/adf-core'; import { TaskCloudService } from './task-cloud.service'; import { taskCompleteCloudMock } from '../task-header/mocks/fake-complete-task.mock'; @@ -34,6 +34,7 @@ describe('Task Cloud Service', () => { function returnFakeTaskCompleteResults(): any { return { + reply: () => {}, oauth2Auth: { callCustomApi : () => { return Promise.resolve(taskCompleteCloudMock); @@ -47,6 +48,7 @@ describe('Task Cloud Service', () => { function returnFakeTaskCompleteResultsError(): any { return { + reply: () => {}, oauth2Auth: { callCustomApi : () => { return Promise.reject(taskCompleteCloudMock); @@ -60,6 +62,7 @@ describe('Task Cloud Service', () => { function returnFakeTaskDetailsResults(): any { return { + reply: () => {}, oauth2Auth: { callCustomApi : () => { return Promise.resolve(fakeTaskDetailsCloud); @@ -73,6 +76,7 @@ describe('Task Cloud Service', () => { function returnFakeCandidateUsersResults(): any { return { + reply: () => {}, oauth2Auth: { callCustomApi : () => { return Promise.resolve(['mockuser1', 'mockuser2', 'mockuser3']); @@ -86,6 +90,7 @@ describe('Task Cloud Service', () => { function returnFakeCandidateGroupResults(): any { return { + reply: () => {}, oauth2Auth: { callCustomApi : () => { return Promise.resolve(['mockgroup1', 'mockgroup2', 'mockgroup3']); @@ -104,15 +109,14 @@ describe('Task Cloud Service', () => { ] }); - beforeEach(async(() => { + beforeEach(() => { alfrescoApiMock = TestBed.inject(AlfrescoApiService); identityUserService = TestBed.inject(IdentityUserService); translateService = TestBed.inject(TranslationService); service = TestBed.inject(TaskCloudService); spyOn(translateService, 'instant').and.callFake((key) => key ? `${key}_translated` : null); spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue(cloudMockUser); - - })); + }); it('should complete a task', (done) => { const appName = 'simple-app'; @@ -132,11 +136,13 @@ describe('Task Cloud Service', () => { const appName = 'simple-app'; const taskId = '68d54a8f'; - service.completeTask(appName, taskId).toPromise().then(() => { - }, (error) => { - expect(error).toBeDefined(); - done(); - }); + service.completeTask(appName, taskId).subscribe( + () => {}, + (err) => { + expect(err).toBeDefined(); + done(); + } + ); }); it('should canCompleteTask', () => { @@ -159,7 +165,7 @@ describe('Task Cloud Service', () => { expect(isAssigneePropertyClickable).toEqual(true); }); - it('should complete task with owner as null', async(() => { + it('should complete task with owner as null', (done) => { const appName = 'simple-app'; const taskId = '68d54a8f'; const canCompleteTaskResult = service.canCompleteTask(emptyOwnerTaskDetailsCloudMock); @@ -171,8 +177,9 @@ describe('Task Cloud Service', () => { expect(res).not.toBeNull(); expect(res.entry.appName).toBe('simple-app'); expect(res.entry.id).toBe('68d54a8f'); + done(); }); - })); + }); it('should return the task details when claiming a task', (done) => { const appName = 'taskp-app'; diff --git a/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.spec.ts index a244ba0879..ed39ca5e46 100644 --- a/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/start-task/components/start-task-cloud.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { setupTestBed, IdentityUserService, AlfrescoApiService, IdentityUserModel } from '@alfresco/adf-core'; import { StartTaskCloudComponent } from './start-task-cloud.component'; import { of, throwError } from 'rxjs'; @@ -58,7 +58,7 @@ describe('StartTaskCloudComponent', () => { schemas: [ CUSTOM_ELEMENTS_SCHEMA ] }); - beforeEach(async (() => { + beforeEach(() => { fixture = TestBed.createComponent(StartTaskCloudComponent); component = fixture.componentInstance; element = fixture.nativeElement; @@ -72,53 +72,62 @@ describe('StartTaskCloudComponent', () => { spyOn(identityService, 'getCurrentUserInfo').and.returnValue(mockUser); spyOn(formDefinitionSelectorCloudService, 'getForms').and.returnValue(of([])); fixture.detectChanges(); - })); + }); describe('create task', () => { - it('should create new task when start button is clicked', async(() => { + it('should create new task when start button is clicked', async () => { const successSpy = spyOn(component.success, 'emit'); component.taskForm.controls['name'].setValue('fakeName'); fixture.detectChanges(); - const createTaskButton = element.querySelector('#button-start'); + const createTaskButton = element.querySelector('#button-start'); createTaskButton.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(createNewTaskSpy).toHaveBeenCalled(); - expect(successSpy).toHaveBeenCalled(); - }); - })); - it('should send on success event when the task is started', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(createNewTaskSpy).toHaveBeenCalled(); + expect(successSpy).toHaveBeenCalled(); + }); + + it('should send on success event when the task is started', async () => { const successSpy = spyOn(component.success, 'emit'); component.taskForm.controls['name'].setValue('fakeName'); component.assigneeName = 'fake-assignee'; - fixture.detectChanges(); - const createTaskButton = element.querySelector('#button-start'); - createTaskButton.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(successSpy).toHaveBeenCalledWith(taskDetailsMock); - }); - })); - it('should send on success event when only name is given', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const createTaskButton = element.querySelector('#button-start'); + createTaskButton.click(); + + fixture.detectChanges(); + await fixture.whenStable(); + + expect(successSpy).toHaveBeenCalledWith(taskDetailsMock); + }); + + it('should send on success event when only name is given', async () => { const successSpy = spyOn(component.success, 'emit'); component.taskForm.controls['name'].setValue('fakeName'); + fixture.detectChanges(); - const createTaskButton = element.querySelector('#button-start'); + await fixture.whenStable(); + + const createTaskButton = element.querySelector('#button-start'); createTaskButton.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(successSpy).toHaveBeenCalled(); - }); - })); + await fixture.whenStable(); + + expect(successSpy).toHaveBeenCalled(); + }); it('should not emit success event when data not present', () => { const successSpy = spyOn(component.success, 'emit'); component.taskForm.controls['name'].setValue(''); fixture.detectChanges(); - const createTaskButton = element.querySelector('#button-start'); + const createTaskButton = element.querySelector('#button-start'); createTaskButton.click(); expect(createNewTaskSpy).not.toHaveBeenCalled(); expect(successSpy).not.toHaveBeenCalled(); @@ -128,10 +137,10 @@ describe('StartTaskCloudComponent', () => { component.taskForm.controls['name'].setValue('fakeName'); component.appName = 'fakeAppName'; fixture.detectChanges(); - const assigneeInput = element.querySelector('input.adf-cloud-input'); + const assigneeInput = element.querySelector('input.adf-cloud-input'); assigneeInput.nodeValue = 'a'; fixture.detectChanges(); - const createTaskButton = element.querySelector('#button-start'); + const createTaskButton = element.querySelector('#button-start'); createTaskButton.click(); fixture.detectChanges(); fixture.whenStable().then(() => { @@ -145,7 +154,7 @@ describe('StartTaskCloudComponent', () => { component.taskForm.controls['name'].setValue('fakeName'); component.appName = 'fakeAppName'; fixture.detectChanges(); - const createTaskButton = element.querySelector('#button-start'); + const createTaskButton = element.querySelector('#button-start'); createTaskButton.click(); fixture.detectChanges(); fixture.whenStable().then(() => { @@ -200,10 +209,10 @@ describe('StartTaskCloudComponent', () => { createNewTaskSpy.and.returnValue(throwError({})); component.appName = 'fakeAppName'; fixture.detectChanges(); - const assigneeInput = element.querySelector('input.adf-cloud-input'); + const assigneeInput = element.querySelector('input.adf-cloud-input'); assigneeInput.nodeValue = 'a'; fixture.detectChanges(); - const createTaskButton = element.querySelector('#button-start'); + const createTaskButton = element.querySelector('#button-start'); createTaskButton.click(); fixture.detectChanges(); expect(errorSpy).toHaveBeenCalled(); diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-service-task-filter-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-service-task-filter-cloud.component.spec.ts index 5c91d0d799..334eea8488 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-service-task-filter-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-service-task-filter-cloud.component.spec.ts @@ -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 { SimpleChange } from '@angular/core'; import { By } from '@angular/platform-browser'; import { setupTestBed } from '@alfresco/adf-core'; @@ -94,7 +94,7 @@ describe('EditServiceTaskFilterCloudComponent', () => { }); }); - it('should fetch process definitions when processDefinitionName filter property is set', async(() => { + it('should fetch process definitions when processDefinitionName filter property is set', async () => { const processSpy = spyOn(taskService, 'getProcessDefinitions').and.returnValue(of([ new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' }) ])); @@ -105,62 +105,66 @@ describe('EditServiceTaskFilterCloudComponent', () => { component.ngOnChanges({ 'id': taskFilterIdChange }); fixture.detectChanges(); const controller = component.editTaskFilterForm.get('processDefinitionName'); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(processSpy).toHaveBeenCalled(); - expect(controller).toBeDefined(); - }); - })); - it('should display filter name as title', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(processSpy).toHaveBeenCalled(); + expect(controller).toBeDefined(); + }); + + it('should display filter name as title', async () => { const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); + fixture.detectChanges(); + await fixture.whenStable(); + const title = fixture.debugElement.nativeElement.querySelector('#adf-edit-task-filter-title-id'); const subTitle = fixture.debugElement.nativeElement.querySelector('#adf-edit-task-filter-sub-title-id'); expect(title.innerText).toEqual('FakeInvolvedTasks'); expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_TASK_FILTER.TITLE'); - })); + }); - it('should not display filter name if showFilterName is false', async(() => { + it('should not display filter name if showFilterName is false', async () => { const taskFilterIdChange = new SimpleChange(null, 'mock-task-filter-id', true); component.showTaskFilterName = false; component.ngOnChanges({ 'id': taskFilterIdChange }); + fixture.detectChanges(); + await fixture.whenStable(); + const title = fixture.debugElement.nativeElement.querySelector('#adf-edit-task-filter-title-id'); + expect(title).toBeNull(); + }); - fixture.whenStable().then(() => { - expect(title).toBeNull(); - }); - })); - - it('should not display mat-spinner if isloading set to false', async(() => { + it('should not display mat-spinner if isloading set to false', async () => { const taskFilterIdChange = new SimpleChange(null, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); + fixture.detectChanges(); + await fixture.whenStable(); + const title = fixture.debugElement.nativeElement.querySelector('#adf-edit-task-filter-title-id'); const subTitle = fixture.debugElement.nativeElement.querySelector('#adf-edit-task-filter-sub-title-id'); const matSpinnerElement = fixture.debugElement.nativeElement.querySelector('.adf-cloud-edit-task-filter-loading-margin'); - fixture.whenStable().then(() => { - expect(matSpinnerElement).toBeNull(); - expect(title.innerText).toEqual('FakeInvolvedTasks'); - expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_TASK_FILTER.TITLE'); - }); - })); + expect(matSpinnerElement).toBeNull(); + expect(title.innerText).toEqual('FakeInvolvedTasks'); + expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_TASK_FILTER.TITLE'); + }); - it('should display mat-spinner if isloading set to true', async(() => { + it('should display mat-spinner if isloading set to true', async () => { component.isLoading = true; const taskFilterIdChange = new SimpleChange(null, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); + fixture.detectChanges(); + await fixture.whenStable(); const matSpinnerElement = fixture.debugElement.nativeElement.querySelector('.adf-cloud-edit-task-filter-loading-margin'); - - fixture.whenStable().then(() => { - expect(matSpinnerElement).toBeDefined(); - }); - })); + expect(matSpinnerElement).toBeDefined(); + }); describe('EditServiceTaskFilter form', () => { @@ -170,29 +174,25 @@ describe('EditServiceTaskFilterCloudComponent', () => { fixture.detectChanges(); }); - it('should defined editTaskFilter form ', () => { + it('should create editTaskFilter form with default user task properties', async () => { + fixture.detectChanges(); + await fixture.whenStable(); + + const appNameController = component.editTaskFilterForm.get('appName'); + const statusController = component.editTaskFilterForm.get('status'); + const sortController = component.editTaskFilterForm.get('sort'); + const orderController = component.editTaskFilterForm.get('order'); + const activityNameController = component.editTaskFilterForm.get('activityName'); expect(component.editTaskFilterForm).toBeDefined(); + expect(appNameController.value).toBe('mock-app-name'); + expect(statusController.value).toBe('COMPLETED'); + expect(sortController.value).toBe('id'); + expect(orderController.value).toBe('ASC'); + expect(activityNameController.value).toBe('fake-activity'); }); - it('should create editTaskFilter form with default user task properties', async(() => { - fixture.detectChanges(); - fixture.whenStable().then(() => { - const appNameController = component.editTaskFilterForm.get('appName'); - const statusController = component.editTaskFilterForm.get('status'); - const sortController = component.editTaskFilterForm.get('sort'); - const orderController = component.editTaskFilterForm.get('order'); - const activityNameController = component.editTaskFilterForm.get('activityName'); - expect(component.editTaskFilterForm).toBeDefined(); - expect(appNameController.value).toBe('mock-app-name'); - expect(statusController.value).toBe('COMPLETED'); - expect(sortController.value).toBe('id'); - expect(orderController.value).toBe('ASC'); - expect(activityNameController.value).toBe('fake-activity'); - }); - })); - describe('Save & Delete buttons', () => { - it('should disable save and delete button for default task filters', async(() => { + it('should disable save and delete button for default task filters', async () => { getTaskFilterSpy.and.returnValue(of({ name: 'ADF_CLOUD_SERVICE_TASK_FILTERS.ALL_SERVICE_TASKS', id: 'filter-id', @@ -210,16 +210,17 @@ describe('EditServiceTaskFilterCloudComponent', () => { component.toggleFilterActions = true; const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); - expect(saveButton.disabled).toBe(true); - const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); - expect(deleteButton.disabled).toBe(true); - }); - })); - it('should enable delete button for custom task filters', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); + expect(saveButton.disabled).toBe(true); + const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); + expect(deleteButton.disabled).toBe(true); + }); + + it('should enable delete button for custom task filters', async () => { const taskFilterIdChange = new SimpleChange(null, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); fixture.detectChanges(); @@ -227,14 +228,15 @@ describe('EditServiceTaskFilterCloudComponent', () => { component.toggleFilterActions = true; const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); - expect(saveButton.disabled).toBe(true); - const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); - expect(deleteButton.disabled).toBe(false); - }); - })); + await fixture.whenStable(); + + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); + expect(saveButton.disabled).toBe(true); + const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); + expect(deleteButton.disabled).toBe(false); + }); it('should enable save button if the filter is changed for custom task filters', (done) => { const taskFilterIdChange = new SimpleChange(null, 'mock-task-filter-id', true); @@ -263,20 +265,21 @@ describe('EditServiceTaskFilterCloudComponent', () => { fixture.detectChanges(); }); - it('should disable save button if the filter is not changed for custom filter', async(() => { + it('should disable save button if the filter is not changed for custom filter', async () => { component.toggleFilterActions = true; const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); - expect(saveButton.disabled).toBe(true); - }); - })); + await fixture.whenStable(); + + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); + expect(saveButton.disabled).toBe(true); + }); }); describe('SaveAs button', () => { - it('should disable saveAs button if the process filter is not changed for default filter', async(() => { + it('should disable saveAs button if the process filter is not changed for default filter', async () => { getTaskFilterSpy.and.returnValue(of({ name: 'ADF_CLOUD_TASK_FILTERS.MY_TASKS', id: 'filter-id', @@ -294,23 +297,25 @@ describe('EditServiceTaskFilterCloudComponent', () => { component.toggleFilterActions = true; const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); - expect(saveButton.disabled).toEqual(true); - }); - })); - it('should disable saveAs button if the process filter is not changed for custom filter', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); + expect(saveButton.disabled).toEqual(true); + }); + + it('should disable saveAs button if the process filter is not changed for custom filter', async () => { component.toggleFilterActions = true; const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); - expect(saveButton.disabled).toEqual(true); - }); - })); + await fixture.whenStable(); + + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); + expect(saveButton.disabled).toEqual(true); + }); it('should enable saveAs button if the filter values are changed for default filter', (done) => { getTaskFilterSpy.and.returnValue(of({ @@ -375,31 +380,38 @@ describe('EditServiceTaskFilterCloudComponent', () => { }); }); - it('should display current task filter details', async(() => { + it('should display current task filter details', async () => { fixture.detectChanges(); - fixture.whenStable().then(() => { - const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); - expansionPanel.click(); - fixture.detectChanges(); - const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-status"]'); - const assigneeElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-assignee"]'); - const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]'); - const orderElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-order"]'); - expect(assigneeElement).toBeDefined(); - expect(stateElement.textContent.trim()).toBe('ADF_CLOUD_SERVICE_TASK_FILTERS.STATUS.COMPLETED'); - expect(sortElement.textContent.trim()).toBe('id'); - expect(orderElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.DIRECTION.ASCENDING'); - }); - })); + await fixture.whenStable(); - it('should display all the statuses that are defined in the task filter', async(() => { const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); + fixture.detectChanges(); + await fixture.whenStable(); + + const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-status"]'); + const assigneeElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-assignee"]'); + const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]'); + const orderElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-order"]'); + expect(assigneeElement).toBeDefined(); + expect(stateElement.textContent.trim()).toBe('ADF_CLOUD_SERVICE_TASK_FILTERS.STATUS.COMPLETED'); + expect(sortElement.textContent.trim()).toBe('id'); + expect(orderElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.DIRECTION.ASCENDING'); + }); + + it('should display all the statuses that are defined in the task filter', async () => { + const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); + expansionPanel.click(); + + fixture.detectChanges(); + await fixture.whenStable(); const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-status"]'); stateElement.click(); + fixture.detectChanges(); + await fixture.whenStable(); const statusOptions = fixture.debugElement.queryAll(By.css('[data-automation-id="adf-cloud-edit-task-property-options-status"]')); @@ -408,82 +420,98 @@ describe('EditServiceTaskFilterCloudComponent', () => { expect(statusOptions[2].nativeElement.textContent.trim()).toBe('ADF_CLOUD_SERVICE_TASK_FILTERS.STATUS.COMPLETED'); expect(statusOptions[3].nativeElement.textContent.trim()).toBe('ADF_CLOUD_SERVICE_TASK_FILTERS.STATUS.CANCELLED'); expect(statusOptions[4].nativeElement.textContent.trim()).toBe('ADF_CLOUD_SERVICE_TASK_FILTERS.STATUS.ERROR'); - })); + }); - it('should display sort drop down', async(() => { + it('should display sort drop down', async () => { fixture.detectChanges(); + await fixture.whenStable(); + const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); + fixture.detectChanges(); + await fixture.whenStable(); + const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]'); sortElement.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); - expect(sortOptions.length).toEqual(4); - }); - })); - it('should display order drop down', async(() => { fixture.detectChanges(); + await fixture.whenStable(); + + const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(sortOptions.length).toEqual(4); + }); + + it('should display order drop down', async () => { + fixture.detectChanges(); + await fixture.whenStable(); + const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); + fixture.detectChanges(); + await fixture.whenStable(); + const orderElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-order"]'); orderElement.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const orderOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); - expect(orderOptions.length).toEqual(2); - }); - })); - it('should have floating labels when values are present', async(() => { fixture.detectChanges(); + await fixture.whenStable(); + + const orderOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(orderOptions.length).toEqual(2); + }); + + it('should have floating labels when values are present', async () => { + fixture.detectChanges(); + await fixture.whenStable(); + const inputLabelsNodes = document.querySelectorAll('mat-form-field'); inputLabelsNodes.forEach(labelNode => { expect(labelNode.getAttribute('ng-reflect-float-label')).toBe('auto'); }); - })); + }); - it('should able to build a editTaskFilter form with default properties if input is empty', async(() => { + it('should able to build a editTaskFilter form with default properties if input is empty', async () => { const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); component.filterProperties = []; + fixture.detectChanges(); + await fixture.whenStable(); + const stateController = component.editTaskFilterForm.get('status'); const sortController = component.editTaskFilterForm.get('sort'); const orderController = component.editTaskFilterForm.get('order'); const activityNameController = component.editTaskFilterForm.get('activityName'); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(component.taskFilterProperties.length).toBe(5); - expect(component.editTaskFilterForm).toBeDefined(); - expect(stateController.value).toBe('COMPLETED'); - expect(sortController.value).toBe('id'); - expect(orderController.value).toBe('ASC'); - expect(activityNameController.value).toBe('fake-activity'); - }); - })); - it('should able to fetch running applications when appName property defined in the input', async(() => { + expect(component.taskFilterProperties.length).toBe(5); + expect(component.editTaskFilterForm).toBeDefined(); + expect(stateController.value).toBe('COMPLETED'); + expect(sortController.value).toBe('id'); + expect(orderController.value).toBe('ASC'); + expect(activityNameController.value).toBe('fake-activity'); + }); + + it('should able to fetch running applications when appName property defined in the input', async () => { component.filterProperties = ['appName', 'processInstanceId', 'priority']; fixture.detectChanges(); const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); const appController = component.editTaskFilterForm.get('appName'); + fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(getRunningApplicationsSpy).toHaveBeenCalled(); - expect(appController).toBeDefined(); - expect(appController.value).toBe('mock-app-name'); - }); - })); + await fixture.whenStable(); + + expect(getRunningApplicationsSpy).toHaveBeenCalled(); + expect(appController).toBeDefined(); + expect(appController.value).toBe('mock-app-name'); + }); }); describe('sort properties', () => { - it('should display default sort properties', async(() => { + it('should display default sort properties', async () => { const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); fixture.detectChanges(); @@ -492,16 +520,17 @@ describe('EditServiceTaskFilterCloudComponent', () => { fixture.detectChanges(); const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]'); sortElement.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const sortController = component.editTaskFilterForm.get('sort'); - const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); - expect(sortController.value).toBe('id'); - expect(sortOptions.length).toEqual(4); - }); - })); - it('should display sort properties when sort properties are specified', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const sortController = component.editTaskFilterForm.get('sort'); + const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(sortController.value).toBe('id'); + expect(sortOptions.length).toEqual(4); + }); + + it('should display sort properties when sort properties are specified', async () => { component.sortProperties = ['id', 'name', 'processInstanceId']; getTaskFilterSpy.and.returnValue(of({ sort: 'my-custom-sort', @@ -517,17 +546,18 @@ describe('EditServiceTaskFilterCloudComponent', () => { fixture.detectChanges(); const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]'); sortElement.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const sortController = component.editTaskFilterForm.get('sort'); - const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); - expect(component.sortProperties.length).toBe(3); - expect(sortController.value).toBe('my-custom-sort'); - expect(sortOptions.length).toEqual(3); - }); - })); - it('should display default sort properties if input is empty', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const sortController = component.editTaskFilterForm.get('sort'); + const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(component.sortProperties.length).toBe(3); + expect(sortController.value).toBe('my-custom-sort'); + expect(sortOptions.length).toEqual(3); + }); + + it('should display default sort properties if input is empty', async () => { const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); fixture.detectChanges(); @@ -538,39 +568,41 @@ describe('EditServiceTaskFilterCloudComponent', () => { fixture.detectChanges(); const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]'); sortElement.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const sortController = component.editTaskFilterForm.get('sort'); - const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); - expect(sortController.value).toBe('id'); - expect(sortOptions.length).toEqual(4); - }); - })); + await fixture.whenStable(); + + const sortController = component.editTaskFilterForm.get('sort'); + const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(sortController.value).toBe('id'); + expect(sortOptions.length).toEqual(4); + }); }); describe('filter actions', () => { - it('should display default filter actions', async(() => { + it('should display default filter actions', async () => { component.toggleFilterActions = true; const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); fixture.detectChanges(); const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); - const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); - expect(component.taskFilterActions.map(action => action.actionType)).toEqual(['save', 'saveAs', 'delete']); - expect(component.taskFilterActions.length).toBe(3); - expect(saveButton.disabled).toBe(true); - expect(saveAsButton.disabled).toBe(true); - expect(deleteButton.disabled).toBe(false); - }); - })); - it('should display filter actions when input actions are specified', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); + const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); + expect(component.taskFilterActions.map(action => action.actionType)).toEqual(['save', 'saveAs', 'delete']); + expect(component.taskFilterActions.length).toBe(3); + expect(saveButton.disabled).toBe(true); + expect(saveAsButton.disabled).toBe(true); + expect(deleteButton.disabled).toBe(false); + }); + + it('should display filter actions when input actions are specified', async () => { component.actions = ['save']; fixture.detectChanges(); const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); @@ -580,18 +612,19 @@ describe('EditServiceTaskFilterCloudComponent', () => { fixture.detectChanges(); const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); - expect(component.taskFilterActions.map(action => action.actionType)).toEqual(['save']); - expect(component.taskFilterActions.length).toBe(1); - expect(saveButton.disabled).toBeTruthy(); - const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); - const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); - expect(saveAsButton).toBeFalsy(); - expect(deleteButton).toBeFalsy(); - }); - })); + await fixture.whenStable(); + + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); + expect(component.taskFilterActions.map(action => action.actionType)).toEqual(['save']); + expect(component.taskFilterActions.length).toBe(1); + expect(saveButton.disabled).toBeTruthy(); + const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); + const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); + expect(saveAsButton).toBeFalsy(); + expect(deleteButton).toBeFalsy(); + }); }); describe('edit filter actions', () => { @@ -603,7 +636,7 @@ describe('EditServiceTaskFilterCloudComponent', () => { spyOn(component.action, 'emit').and.callThrough(); }); - it('should emit save event and save the filter on click save button', async(() => { + it('should emit save event and save the filter on click save button', fakeAsync(() => { component.toggleFilterActions = true; spyOn(service, 'updateFilter').and.returnValue(of(null)); fixture.detectChanges(); @@ -626,7 +659,7 @@ describe('EditServiceTaskFilterCloudComponent', () => { }); })); - it('should emit delete event and delete the filter on click of delete button', async(() => { + it('should emit delete event and delete the filter on click of delete button', fakeAsync(() => { component.toggleFilterActions = true; spyOn(service, 'deleteFilter').and.returnValue(of(null)); fixture.detectChanges(); @@ -646,7 +679,7 @@ describe('EditServiceTaskFilterCloudComponent', () => { }); })); - it('should emit saveAs event and add filter on click saveAs button', async(() => { + it('should emit saveAs event and add filter on click saveAs button', fakeAsync(() => { component.toggleFilterActions = true; spyOn(service, 'addFilter').and.returnValue(of(null)); fixture.detectChanges(); @@ -670,7 +703,7 @@ describe('EditServiceTaskFilterCloudComponent', () => { }); })); - it('should call restore default filters service on deletion of last filter', async(() => { + it('should call restore default filters service on deletion of last filter', fakeAsync(() => { component.toggleFilterActions = true; spyOn(service, 'deleteFilter').and.returnValue(of([])); const restoreDefaultFiltersSpy = spyOn(component, 'restoreDefaultTaskFilters').and.returnValue(of([])); @@ -692,7 +725,7 @@ describe('EditServiceTaskFilterCloudComponent', () => { }); })); - it('should not call restore default filters service on deletion of first filter', async(() => { + it('should not call restore default filters service on deletion of first filter', fakeAsync(() => { component.toggleFilterActions = true; spyOn(service, 'deleteFilter').and.returnValue(of([{ name: 'mock-filter-name' }])); const restoreDefaultFiltersSpy = spyOn(component, 'restoreDefaultTaskFilters').and.returnValue(of([])); diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-task-filter-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-task-filter-cloud.component.spec.ts index a58be46701..31722198e3 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-task-filter-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-task-filter-cloud.component.spec.ts @@ -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 { SimpleChange } from '@angular/core'; import { By } from '@angular/platform-browser'; @@ -112,7 +112,7 @@ describe('EditTaskFilterCloudComponent', () => { }); }); - it('should fetch process definitions when processDefinitionName filter property is set', async(() => { + it('should fetch process definitions when processDefinitionName filter property is set', async () => { const processSpy = spyOn(taskService, 'getProcessDefinitions').and.returnValue(of([new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })])); fixture.detectChanges(); component.filterProperties = ['processDefinitionName']; @@ -121,62 +121,66 @@ describe('EditTaskFilterCloudComponent', () => { component.ngOnChanges({ 'id': taskFilterIdChange }); fixture.detectChanges(); const controller = component.editTaskFilterForm.get('processDefinitionName'); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(processSpy).toHaveBeenCalled(); - expect(controller).toBeDefined(); - }); - })); - it('should display filter name as title', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(processSpy).toHaveBeenCalled(); + expect(controller).toBeDefined(); + }); + + it('should display filter name as title', async () => { const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); + fixture.detectChanges(); + await fixture.whenStable(); + const title = fixture.debugElement.nativeElement.querySelector('#adf-edit-task-filter-title-id'); const subTitle = fixture.debugElement.nativeElement.querySelector('#adf-edit-task-filter-sub-title-id'); expect(title.innerText).toEqual('FakeInvolvedTasks'); expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_TASK_FILTER.TITLE'); - })); + }); - it('should not display filter name if showFilterName is false', async(() => { + it('should not display filter name if showFilterName is false', async () => { const taskFilterIdChange = new SimpleChange(null, 'mock-task-filter-id', true); component.showTaskFilterName = false; component.ngOnChanges({ 'id': taskFilterIdChange }); + fixture.detectChanges(); + await fixture.whenStable(); + const title = fixture.debugElement.nativeElement.querySelector('#adf-edit-task-filter-title-id'); + expect(title).toBeNull(); + }); - fixture.whenStable().then(() => { - expect(title).toBeNull(); - }); - })); - - it('should not display mat-spinner if isloading set to false', async(() => { + it('should not display mat-spinner if isloading set to false', async () => { const taskFilterIdChange = new SimpleChange(null, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); + fixture.detectChanges(); + await fixture.whenStable(); + const title = fixture.debugElement.nativeElement.querySelector('#adf-edit-task-filter-title-id'); const subTitle = fixture.debugElement.nativeElement.querySelector('#adf-edit-task-filter-sub-title-id'); const matSpinnerElement = fixture.debugElement.nativeElement.querySelector('.adf-cloud-edit-task-filter-loading-margin'); - fixture.whenStable().then(() => { - expect(matSpinnerElement).toBeNull(); - expect(title.innerText).toEqual('FakeInvolvedTasks'); - expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_TASK_FILTER.TITLE'); - }); - })); + expect(matSpinnerElement).toBeNull(); + expect(title.innerText).toEqual('FakeInvolvedTasks'); + expect(subTitle.innerText.trim()).toEqual('ADF_CLOUD_EDIT_TASK_FILTER.TITLE'); + }); - it('should display mat-spinner if isloading set to true', async(() => { + it('should display mat-spinner if isloading set to true', async () => { component.isLoading = true; const taskFilterIdChange = new SimpleChange(null, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); + fixture.detectChanges(); + await fixture.whenStable(); const matSpinnerElement = fixture.debugElement.nativeElement.querySelector('.adf-cloud-edit-task-filter-loading-margin'); - - fixture.whenStable().then(() => { - expect(matSpinnerElement).toBeDefined(); - }); - })); + expect(matSpinnerElement).toBeDefined(); + }); describe('EditTaskFilter form', () => { @@ -186,28 +190,24 @@ describe('EditTaskFilterCloudComponent', () => { fixture.detectChanges(); }); - it('should defined editTaskFilter form ', () => { + it('should create editTaskFilter form with default user task properties', async () => { + fixture.detectChanges(); + await fixture.whenStable(); + + const stateController = component.editTaskFilterForm.get('status'); + const sortController = component.editTaskFilterForm.get('sort'); + const orderController = component.editTaskFilterForm.get('order'); + const assigneeController = component.editTaskFilterForm.get('assignee'); expect(component.editTaskFilterForm).toBeDefined(); + expect(assigneeController).toBeDefined(); + expect(stateController.value).toBe('CREATED'); + expect(sortController.value).toBe('id'); + expect(orderController.value).toBe('ASC'); + expect(assigneeController.value).toBe('fake-involved'); }); - it('should create editTaskFilter form with default user task properties', async(() => { - fixture.detectChanges(); - fixture.whenStable().then(() => { - const stateController = component.editTaskFilterForm.get('status'); - const sortController = component.editTaskFilterForm.get('sort'); - const orderController = component.editTaskFilterForm.get('order'); - const assigneeController = component.editTaskFilterForm.get('assignee'); - expect(component.editTaskFilterForm).toBeDefined(); - expect(assigneeController).toBeDefined(); - expect(stateController.value).toBe('CREATED'); - expect(sortController.value).toBe('id'); - expect(orderController.value).toBe('ASC'); - expect(assigneeController.value).toBe('fake-involved'); - }); - })); - describe('Save & Delete buttons', () => { - it('should disable save and delete button for default task filters', async(() => { + it('should disable save and delete button for default task filters', async () => { getTaskFilterSpy.and.returnValue(of({ name: 'ADF_CLOUD_TASK_FILTERS.MY_TASKS', id: 'filter-id', @@ -225,16 +225,17 @@ describe('EditTaskFilterCloudComponent', () => { component.toggleFilterActions = true; const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); - expect(saveButton.disabled).toBe(true); - const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); - expect(deleteButton.disabled).toBe(true); - }); - })); - it('should enable delete button for custom task filters', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); + expect(saveButton.disabled).toBe(true); + const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); + expect(deleteButton.disabled).toBe(true); + }); + + it('should enable delete button for custom task filters', async () => { const taskFilterIdChange = new SimpleChange(null, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); fixture.detectChanges(); @@ -242,14 +243,15 @@ describe('EditTaskFilterCloudComponent', () => { component.toggleFilterActions = true; const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); - expect(saveButton.disabled).toBe(true); - const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); - expect(deleteButton.disabled).toBe(false); - }); - })); + await fixture.whenStable(); + + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); + expect(saveButton.disabled).toBe(true); + const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); + expect(deleteButton.disabled).toBe(false); + }); it('should enable save button if the filter is changed for custom task filters', (done) => { const taskFilterIdChange = new SimpleChange(null, 'mock-task-filter-id', true); @@ -278,20 +280,21 @@ describe('EditTaskFilterCloudComponent', () => { fixture.detectChanges(); }); - it('should disable save button if the filter is not changed for custom filter', async(() => { + it('should disable save button if the filter is not changed for custom filter', async () => { component.toggleFilterActions = true; const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); - expect(saveButton.disabled).toBe(true); - }); - })); + await fixture.whenStable(); + + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); + expect(saveButton.disabled).toBe(true); + }); }); describe('SaveAs button', () => { - it('should disable saveAs button if the process filter is not changed for default filter', async(() => { + it('should disable saveAs button if the process filter is not changed for default filter', async () => { getTaskFilterSpy.and.returnValue(of({ name: 'ADF_CLOUD_TASK_FILTERS.MY_TASKS', id: 'filter-id', @@ -309,23 +312,25 @@ describe('EditTaskFilterCloudComponent', () => { component.toggleFilterActions = true; const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); - expect(saveButton.disabled).toEqual(true); - }); - })); - it('should disable saveAs button if the process filter is not changed for custom filter', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); + expect(saveButton.disabled).toEqual(true); + }); + + it('should disable saveAs button if the process filter is not changed for custom filter', async () => { component.toggleFilterActions = true; const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); - expect(saveButton.disabled).toEqual(true); - }); - })); + await fixture.whenStable(); + + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); + expect(saveButton.disabled).toEqual(true); + }); it('should enable saveAs button if the filter values are changed for default filter', (done) => { getTaskFilterSpy.and.returnValue(of({ @@ -390,24 +395,27 @@ describe('EditTaskFilterCloudComponent', () => { }); }); - it('should display current task filter details', async(() => { + it('should display current task filter details', async () => { fixture.detectChanges(); - fixture.whenStable().then(() => { - const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); - expansionPanel.click(); - fixture.detectChanges(); - const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-status"]'); - const assigneeElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-assignee"]'); - const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]'); - const orderElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-order"]'); - expect(assigneeElement).toBeDefined(); - expect(stateElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.CREATED'); - expect(sortElement.textContent.trim()).toBe('id'); - expect(orderElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.DIRECTION.ASCENDING'); - }); - })); + await fixture.whenStable(); - it('should display all the statuses that are defined in the task filter', async(() => { + const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); + expansionPanel.click(); + + fixture.detectChanges(); + await fixture.whenStable(); + + const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-status"]'); + const assigneeElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-assignee"]'); + const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]'); + const orderElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-order"]'); + expect(assigneeElement).toBeDefined(); + expect(stateElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.CREATED'); + expect(sortElement.textContent.trim()).toBe('id'); + expect(orderElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.DIRECTION.ASCENDING'); + }); + + it('should display all the statuses that are defined in the task filter', () => { const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); @@ -425,37 +433,39 @@ describe('EditTaskFilterCloudComponent', () => { expect(statusOptions[3].nativeElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.SUSPENDED'); expect(statusOptions[4].nativeElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.CANCELLED'); expect(statusOptions[5].nativeElement.textContent.trim()).toBe('ADF_CLOUD_TASK_FILTERS.STATUS.COMPLETED'); - })); + }); - it('should display sort drop down', async(() => { + it('should display sort drop down', async () => { fixture.detectChanges(); const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); fixture.detectChanges(); const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]'); sortElement.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); - expect(sortOptions.length).toEqual(4); - }); - })); - it('should display order drop down', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(sortOptions.length).toEqual(4); + }); + + it('should display order drop down', async () => { fixture.detectChanges(); const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); fixture.detectChanges(); const orderElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-order"]'); orderElement.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const orderOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); - expect(orderOptions.length).toEqual(2); - }); - })); - it('should able to build a editTaskFilter form with default properties if input is empty', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const orderOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(orderOptions.length).toEqual(2); + }); + + it('should able to build a editTaskFilter form with default properties if input is empty', async () => { const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); component.filterProperties = []; @@ -463,57 +473,60 @@ describe('EditTaskFilterCloudComponent', () => { const stateController = component.editTaskFilterForm.get('status'); const sortController = component.editTaskFilterForm.get('sort'); const orderController = component.editTaskFilterForm.get('order'); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(component.taskFilterProperties.length).toBe(4); - expect(component.editTaskFilterForm).toBeDefined(); - expect(stateController.value).toBe('CREATED'); - expect(sortController.value).toBe('id'); - expect(orderController.value).toBe('ASC'); - }); - })); - it('should able to fetch running applications when appName property defined in the input', async(() => { + await fixture.whenStable(); + + expect(component.taskFilterProperties.length).toBe(4); + expect(component.editTaskFilterForm).toBeDefined(); + expect(stateController.value).toBe('CREATED'); + expect(sortController.value).toBe('id'); + expect(orderController.value).toBe('ASC'); + }); + + it('should able to fetch running applications when appName property defined in the input', async () => { component.filterProperties = ['appName', 'processInstanceId', 'priority']; fixture.detectChanges(); const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); const appController = component.editTaskFilterForm.get('appName'); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(getRunningApplicationsSpy).toHaveBeenCalled(); - expect(appController).toBeDefined(); - expect(appController.value).toBe('mock-app-name'); - }); - })); - it('should fetch data in completedBy filter', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(getRunningApplicationsSpy).toHaveBeenCalled(); + expect(appController).toBeDefined(); + expect(appController.value).toBe('mock-app-name'); + }); + + it('should fetch data in completedBy filter', async () => { component.filterProperties = ['appName', 'processInstanceId', 'priority', 'completedBy']; fixture.detectChanges(); const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); const appController = component.editTaskFilterForm.get('completedBy'); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(appController).toBeDefined(); - expect(JSON.stringify(appController.value)).toBe(JSON.stringify({ - id: 'mock-id', - username: 'testCompletedByUser' - })); - }); - })); - it('should show completedBy filter', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(appController).toBeDefined(); + expect(JSON.stringify(appController.value)).toBe(JSON.stringify({ + id: 'mock-id', + username: 'testCompletedByUser' + })); + }); + + it('should show completedBy filter', async () => { component.filterProperties = ['appName', 'processInstanceId', 'priority', 'completedBy']; fixture.detectChanges(); const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const peopleCloudComponent = fixture.debugElement.nativeElement.querySelector('adf-cloud-people'); - expect(peopleCloudComponent).toBeTruthy(); - }); - })); + await fixture.whenStable(); + + const peopleCloudComponent = fixture.debugElement.nativeElement.querySelector('adf-cloud-people'); + expect(peopleCloudComponent).toBeTruthy(); + }); it('should update form on completed by user is updated', (done) => { component.appName = 'fake'; @@ -789,7 +802,7 @@ describe('EditTaskFilterCloudComponent', () => { describe('sort properties', () => { - it('should display default sort properties', async(() => { + it('should display default sort properties', async () => { const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); fixture.detectChanges(); @@ -798,16 +811,17 @@ describe('EditTaskFilterCloudComponent', () => { fixture.detectChanges(); const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]'); sortElement.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const sortController = component.editTaskFilterForm.get('sort'); - const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); - expect(sortController.value).toBe('id'); - expect(sortOptions.length).toEqual(4); - }); - })); - it('should display sort properties when sort properties are specified', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const sortController = component.editTaskFilterForm.get('sort'); + const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(sortController.value).toBe('id'); + expect(sortOptions.length).toEqual(4); + }); + + it('should display sort properties when sort properties are specified', async () => { component.sortProperties = ['id', 'name', 'processInstanceId']; getTaskFilterSpy.and.returnValue(of({ sort: 'my-custom-sort', @@ -823,17 +837,18 @@ describe('EditTaskFilterCloudComponent', () => { fixture.detectChanges(); const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]'); sortElement.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const sortController = component.editTaskFilterForm.get('sort'); - const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); - expect(component.sortProperties.length).toBe(3); - expect(sortController.value).toBe('my-custom-sort'); - expect(sortOptions.length).toEqual(3); - }); - })); - it('should display default sort properties if input is empty', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const sortController = component.editTaskFilterForm.get('sort'); + const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(component.sortProperties.length).toBe(3); + expect(sortController.value).toBe('my-custom-sort'); + expect(sortOptions.length).toEqual(3); + }); + + it('should display default sort properties if input is empty', async () => { const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); fixture.detectChanges(); @@ -844,39 +859,41 @@ describe('EditTaskFilterCloudComponent', () => { fixture.detectChanges(); const sortElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"]'); sortElement.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const sortController = component.editTaskFilterForm.get('sort'); - const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); - expect(sortController.value).toBe('id'); - expect(sortOptions.length).toEqual(4); - }); - })); + await fixture.whenStable(); + + const sortController = component.editTaskFilterForm.get('sort'); + const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); + expect(sortController.value).toBe('id'); + expect(sortOptions.length).toEqual(4); + }); }); describe('filter actions', () => { - it('should display default filter actions', async(() => { + it('should display default filter actions', async () => { component.toggleFilterActions = true; const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); component.ngOnChanges({ 'id': taskFilterIdChange }); fixture.detectChanges(); const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); - const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); - expect(component.taskFilterActions.map(action => action.actionType)).toEqual(['save', 'saveAs', 'delete']); - expect(component.taskFilterActions.length).toBe(3); - expect(saveButton.disabled).toBe(true); - expect(saveAsButton.disabled).toBe(true); - expect(deleteButton.disabled).toBe(false); - }); - })); - it('should display filter actions when input actions are specified', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); + const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); + expect(component.taskFilterActions.map(action => action.actionType)).toEqual(['save', 'saveAs', 'delete']); + expect(component.taskFilterActions.length).toBe(3); + expect(saveButton.disabled).toBe(true); + expect(saveAsButton.disabled).toBe(true); + expect(deleteButton.disabled).toBe(false); + }); + + it('should display filter actions when input actions are specified', async () => { component.actions = ['save']; fixture.detectChanges(); const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); @@ -886,18 +903,19 @@ describe('EditTaskFilterCloudComponent', () => { fixture.detectChanges(); const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); - expect(component.taskFilterActions.map(action => action.actionType)).toEqual(['save']); - expect(component.taskFilterActions.length).toBe(1); - expect(saveButton.disabled).toBeTruthy(); - const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); - const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); - expect(saveAsButton).toBeFalsy(); - expect(deleteButton).toBeFalsy(); - }); - })); + await fixture.whenStable(); + + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); + expect(component.taskFilterActions.map(action => action.actionType)).toEqual(['save']); + expect(component.taskFilterActions.length).toBe(1); + expect(saveButton.disabled).toBeTruthy(); + const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); + const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); + expect(saveAsButton).toBeFalsy(); + expect(deleteButton).toBeFalsy(); + }); it('should set the correct lastModifiedTo date', (done) => { component.appName = 'fake'; @@ -934,7 +952,7 @@ describe('EditTaskFilterCloudComponent', () => { spyOn(component.action, 'emit').and.callThrough(); }); - it('should emit save event and save the filter on click save button', async(() => { + it('should emit save event and save the filter on click save button', fakeAsync(() => { component.toggleFilterActions = true; spyOn(service, 'updateFilter').and.returnValue(of(null)); fixture.detectChanges(); @@ -946,10 +964,10 @@ describe('EditTaskFilterCloudComponent', () => { fixture.detectChanges(); const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); sortOptions[3].nativeElement.click(); + fixture.detectChanges(); - const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); fixture.whenStable().then(() => { - fixture.detectChanges(); + const saveButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-save"]'); expect(saveButton.disabled).toBe(false); saveButton.click(); expect(service.updateFilter).toHaveBeenCalled(); @@ -957,7 +975,7 @@ describe('EditTaskFilterCloudComponent', () => { }); })); - it('should emit delete event and delete the filter on click of delete button', async(() => { + it('should emit delete event and delete the filter on click of delete button', async () => { component.toggleFilterActions = true; spyOn(service, 'deleteFilter').and.returnValue(of(null)); fixture.detectChanges(); @@ -966,18 +984,18 @@ describe('EditTaskFilterCloudComponent', () => { fixture.detectChanges(); const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger'); stateElement.click(); - fixture.detectChanges(); - const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(deleteButton.disabled).toBe(false); - deleteButton.click(); - expect(service.deleteFilter).toHaveBeenCalled(); - expect(component.action.emit).toHaveBeenCalled(); - }); - })); - it('should emit saveAs event and add filter on click saveAs button', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); + expect(deleteButton.disabled).toBe(false); + deleteButton.click(); + expect(service.deleteFilter).toHaveBeenCalled(); + expect(component.action.emit).toHaveBeenCalled(); + }); + + it('should emit saveAs event and add filter on click saveAs button', fakeAsync(() => { component.toggleFilterActions = true; spyOn(service, 'addFilter').and.returnValue(of(null)); fixture.detectChanges(); @@ -989,10 +1007,10 @@ describe('EditTaskFilterCloudComponent', () => { fixture.detectChanges(); const sortOptions = fixture.debugElement.queryAll(By.css('.mat-option-text')); sortOptions[2].nativeElement.click(); + fixture.detectChanges(); - const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); fixture.whenStable().then(() => { - fixture.detectChanges(); + const saveAsButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-saveAs"]'); expect(saveAsButton.disabled).toBe(false); saveAsButton.click(); expect(service.addFilter).toHaveBeenCalled(); @@ -1001,7 +1019,7 @@ describe('EditTaskFilterCloudComponent', () => { }); })); - it('should call restore default filters service on deletion of last filter', async(() => { + it('should call restore default filters service on deletion of last filter', async () => { component.toggleFilterActions = true; spyOn(service, 'deleteFilter').and.returnValue(of([])); const restoreDefaultFiltersSpy = spyOn(component, 'restoreDefaultTaskFilters').and.returnValue(of([])); @@ -1011,19 +1029,19 @@ describe('EditTaskFilterCloudComponent', () => { fixture.detectChanges(); const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger'); stateElement.click(); - fixture.detectChanges(); - const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(deleteButton.disabled).toBe(false); - deleteButton.click(); - expect(service.deleteFilter).toHaveBeenCalled(); - expect(component.action.emit).toHaveBeenCalled(); - expect(restoreDefaultFiltersSpy).toHaveBeenCalled(); - }); - })); - it('should not call restore default filters service on deletion of first filter', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); + expect(deleteButton.disabled).toBe(false); + deleteButton.click(); + expect(service.deleteFilter).toHaveBeenCalled(); + expect(component.action.emit).toHaveBeenCalled(); + expect(restoreDefaultFiltersSpy).toHaveBeenCalled(); + }); + + it('should not call restore default filters service on deletion of first filter', async () => { component.toggleFilterActions = true; spyOn(service, 'deleteFilter').and.returnValue(of([new TaskFilterCloudModel({ name: 'mock-filter-name' })])); const restoreDefaultFiltersSpy = spyOn(component, 'restoreDefaultTaskFilters').and.returnValue(of([])); @@ -1033,16 +1051,16 @@ describe('EditTaskFilterCloudComponent', () => { fixture.detectChanges(); const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-task-property-sort"] .mat-select-trigger'); stateElement.click(); + fixture.detectChanges(); + await fixture.whenStable(); + const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(deleteButton.disabled).toBe(false); - deleteButton.click(); - expect(service.deleteFilter).toHaveBeenCalled(); - expect(component.action.emit).toHaveBeenCalled(); - expect(restoreDefaultFiltersSpy).not.toHaveBeenCalled(); - }); - })); + expect(deleteButton.disabled).toBe(false); + deleteButton.click(); + expect(service.deleteFilter).toHaveBeenCalled(); + expect(component.action.emit).toHaveBeenCalled(); + expect(restoreDefaultFiltersSpy).not.toHaveBeenCalled(); + }); }); }); diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filter-dialog/task-filter-dialog-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filter-dialog/task-filter-dialog-cloud.component.spec.ts index 1e414b5a7e..b436367c7a 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filter-dialog/task-filter-dialog-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filter-dialog/task-filter-dialog-cloud.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { TaskFilterDialogCloudComponent } from './task-filter-dialog-cloud.component'; import { TaskFiltersCloudModule } from '../../task-filters-cloud.module'; @@ -67,46 +67,49 @@ describe('TaskFilterDialogCloudComponent', () => { expect(titleElement.textContent).toEqual(' ADF_CLOUD_EDIT_TASK_FILTER.DIALOG.TITLE '); }); - it('should enable save button if form is valid', async(() => { + it('should enable save button if form is valid', async () => { fixture.detectChanges(); const saveButton = fixture.debugElement.nativeElement.querySelector('#adf-save-button-id'); const inputElement = fixture.debugElement.nativeElement.querySelector('#adf-filter-name-id'); inputElement.value = 'My custom Name'; inputElement.dispatchEvent(new Event('input')); - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(saveButton).toBeDefined(); - expect(saveButton.disabled).toBeFalsy(); - }); - })); - it('should disable save button if form is not valid', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + expect(saveButton).toBeDefined(); + expect(saveButton.disabled).toBeFalsy(); + }); + + it('should disable save button if form is not valid', async () => { fixture.detectChanges(); const inputElement = fixture.debugElement.nativeElement.querySelector('#adf-filter-name-id'); inputElement.value = ''; inputElement.dispatchEvent(new Event('input')); - fixture.whenStable().then(() => { - const saveButton = fixture.debugElement.nativeElement.querySelector('#adf-save-button-id'); - fixture.detectChanges(); - expect(saveButton).toBeDefined(); - expect(saveButton.disabled).toBe(true); - }); - })); - it('should able to close dialog on click of save button if form is valid', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const saveButton = fixture.debugElement.nativeElement.querySelector('#adf-save-button-id'); + expect(saveButton).toBeDefined(); + expect(saveButton.disabled).toBe(true); + }); + + it('should able to close dialog on click of save button if form is valid', async () => { fixture.detectChanges(); const inputElement = fixture.debugElement.nativeElement.querySelector('#adf-filter-name-id'); inputElement.value = 'My custom Name'; inputElement.dispatchEvent(new Event('input')); - fixture.whenStable().then(() => { - const saveButton = fixture.debugElement.nativeElement.querySelector('#adf-save-button-id'); - fixture.detectChanges(); - saveButton.click(); - expect(saveButton).toBeDefined(); - expect(saveButton.disabled).toBeFalsy(); - expect(component.dialogRef.close).toHaveBeenCalled(); - }); - })); + + fixture.detectChanges(); + await fixture.whenStable(); + + const saveButton = fixture.debugElement.nativeElement.querySelector('#adf-save-button-id'); + saveButton.click(); + expect(saveButton).toBeDefined(); + expect(saveButton.disabled).toBeFalsy(); + expect(component.dialogRef.close).toHaveBeenCalled(); + }); it('should able close dialog on click of cancel button', () => { component.data = { data: { name: '' } }; diff --git a/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.spec.ts index ea27248913..56b0aadddd 100644 --- a/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.spec.ts @@ -18,7 +18,7 @@ import { DebugElement, SimpleChange } from '@angular/core'; import { By } from '@angular/platform-browser'; import { of } from 'rxjs'; -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { IdentityUserService, setupTestBed } from '@alfresco/adf-core'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { TaskFormCloudComponent } from './task-form-cloud.component'; @@ -75,183 +75,193 @@ describe('TaskFormCloudComponent', () => { describe('Complete button', () => { - it('should show complete button when status is ASSIGNED', async(() => { + it('should show complete button when status is ASSIGNED', async () => { component.appName = 'app1'; component.taskId = 'task1'; component.loadTask(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const completeBtn = debugElement.query(By.css('[adf-cloud-complete-task]')); - expect(completeBtn.nativeElement).toBeDefined(); - }); - })); - it('should not show complete button when status is ASSIGNED but assigned to a different person', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const completeBtn = debugElement.query(By.css('[adf-cloud-complete-task]')); + expect(completeBtn.nativeElement).toBeDefined(); + }); + + it('should not show complete button when status is ASSIGNED but assigned to a different person', async () => { component.appName = 'app1'; component.taskId = 'task1'; getCurrentUserSpy.and.returnValue({}); component.loadTask(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const completeBtn = debugElement.query(By.css('[adf-cloud-complete-task]')); - expect(completeBtn).toBeNull(); - }); - })); - it('should not show complete button when showCompleteButton=false', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const completeBtn = debugElement.query(By.css('[adf-cloud-complete-task]')); + expect(completeBtn).toBeNull(); + }); + + it('should not show complete button when showCompleteButton=false', async () => { component.appName = 'app1'; component.taskId = 'task1'; component.showCompleteButton = false; component.loadTask(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const completeBtn = debugElement.query(By.css('[adf-cloud-complete-task]')); - expect(completeBtn).toBeNull(); - }); - })); + await fixture.whenStable(); + + const completeBtn = debugElement.query(By.css('[adf-cloud-complete-task]')); + expect(completeBtn).toBeNull(); + }); }); describe('Claim/Unclaim buttons', () => { - it('should not show release button for standalone task', async(() => { + it('should not show release button for standalone task', async () => { component.taskId = 'task1'; component.loadTask(); - fixture.detectChanges(); getTaskSpy.and.returnValue(of(taskDetails)); - fixture.whenStable().then(() => { - const unclaimBtn = debugElement.query(By.css('[adf-cloud-unclaim-task]')); - expect(unclaimBtn).toBeNull(); - }); - })); + fixture.detectChanges(); + await fixture.whenStable(); - it('should show release button when task has candidate users and is assigned to one of these users', async(() => { + const unclaimBtn = debugElement.query(By.css('[adf-cloud-unclaim-task]')); + expect(unclaimBtn).toBeNull(); + }); + + it('should show release button when task has candidate users and is assigned to one of these users', async () => { spyOn(component, 'hasCandidateUsers').and.returnValue(true); component.appName = 'app1'; component.taskId = 'task1'; component.loadTask(); + fixture.detectChanges(); + await fixture.whenStable(); - fixture.whenStable().then(() => { - const unclaimBtn = debugElement.query(By.css('[adf-cloud-unclaim-task]')); - expect(unclaimBtn).not.toBeNull(); - }); - })); + const unclaimBtn = debugElement.query(By.css('[adf-cloud-unclaim-task]')); + expect(unclaimBtn).not.toBeNull(); + }); - it('should not show unclaim button when status is ASSIGNED but assigned to different person', async(() => { + it('should not show unclaim button when status is ASSIGNED but assigned to different person', async () => { component.appName = 'app1'; component.taskId = 'task1'; getCurrentUserSpy.and.returnValue({}); component.loadTask(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const unclaimBtn = debugElement.query(By.css('[adf-cloud-unclaim-task]')); - expect(unclaimBtn).toBeNull(); - }); - })); - it('should not show unclaim button when status is not ASSIGNED', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const unclaimBtn = debugElement.query(By.css('[adf-cloud-unclaim-task]')); + expect(unclaimBtn).toBeNull(); + }); + + it('should not show unclaim button when status is not ASSIGNED', async () => { component.appName = 'app1'; component.taskId = 'task1'; taskDetails.status = undefined; getTaskSpy.and.returnValue(of(taskDetails)); component.loadTask(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const unclaimBtn = debugElement.query(By.css('[adf-cloud-unclaim-task]')); - expect(unclaimBtn).toBeNull(); - }); - })); - it('should show claim button when status is CREATED', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const unclaimBtn = debugElement.query(By.css('[adf-cloud-unclaim-task]')); + expect(unclaimBtn).toBeNull(); + }); + + it('should show claim button when status is CREATED', async () => { component.appName = 'app1'; component.taskId = 'task1'; taskDetails.status = 'CREATED'; getTaskSpy.and.returnValue(of(taskDetails)); component.loadTask(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const claimBtn = debugElement.query(By.css('[adf-cloud-claim-task]')); - expect(claimBtn.nativeElement).toBeDefined(); - }); - })); - it('should not show claim button when status is not CREATED', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const claimBtn = debugElement.query(By.css('[adf-cloud-claim-task]')); + expect(claimBtn.nativeElement).toBeDefined(); + }); + + it('should not show claim button when status is not CREATED', async () => { component.appName = 'app1'; component.taskId = 'task1'; taskDetails.status = undefined; getTaskSpy.and.returnValue(of(taskDetails)); component.loadTask(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const claimBtn = debugElement.query(By.css('[adf-cloud-claim-task]')); - expect(claimBtn).toBeNull(); - }); - })); + await fixture.whenStable(); + + const claimBtn = debugElement.query(By.css('[adf-cloud-claim-task]')); + expect(claimBtn).toBeNull(); + }); }); describe('Cancel button', () => { - it('should show cancel button by default', async(() => { + it('should show cancel button by default', async () => { component.appName = 'app1'; component.taskId = 'task1'; component.loadTask(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const cancelBtn = debugElement.query(By.css('#adf-cloud-cancel-task')); - expect(cancelBtn.nativeElement).toBeDefined(); - }); - })); - it('should not show cancel button when showCancelButton=false', async(() => { + fixture.detectChanges(); + await fixture.whenStable(); + + const cancelBtn = debugElement.query(By.css('#adf-cloud-cancel-task')); + expect(cancelBtn.nativeElement).toBeDefined(); + }); + + it('should not show cancel button when showCancelButton=false', async () => { component.appName = 'app1'; component.taskId = 'task1'; component.showCancelButton = false; component.loadTask(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const cancelBtn = debugElement.query(By.css('#adf-cloud-cancel-task')); - expect(cancelBtn).toBeNull(); - }); - })); + await fixture.whenStable(); + + const cancelBtn = debugElement.query(By.css('#adf-cloud-cancel-task')); + expect(cancelBtn).toBeNull(); + }); }); describe('Inputs', () => { - it('should not show complete/claim/unclaim buttons when readOnly=true', async(() => { + it('should not show complete/claim/unclaim buttons when readOnly=true', async () => { component.appName = 'app1'; component.taskId = 'task1'; component.readOnly = true; component.loadTask(); + fixture.detectChanges(); - fixture.whenStable().then(() => { - const completeBtn = debugElement.query(By.css('[adf-cloud-complete-task]')); - expect(completeBtn).toBeNull(); + await fixture.whenStable(); - const claimBtn = debugElement.query(By.css('[adf-cloud-claim-task]')); - expect(claimBtn).toBeNull(); + const completeBtn = debugElement.query(By.css('[adf-cloud-complete-task]')); + expect(completeBtn).toBeNull(); - const unclaimBtn = debugElement.query(By.css('[adf-cloud-unclaim-task]')); - expect(unclaimBtn).toBeNull(); + const claimBtn = debugElement.query(By.css('[adf-cloud-claim-task]')); + expect(claimBtn).toBeNull(); - const cancelBtn = debugElement.query(By.css('#adf-cloud-cancel-task')); - expect(cancelBtn.nativeElement).toBeDefined(); - }); - })); + const unclaimBtn = debugElement.query(By.css('[adf-cloud-unclaim-task]')); + expect(unclaimBtn).toBeNull(); + + const cancelBtn = debugElement.query(By.css('#adf-cloud-cancel-task')); + expect(cancelBtn.nativeElement).toBeDefined(); + }); it('should load data when appName changes', () => { component.taskId = 'task1'; diff --git a/lib/process-services-cloud/src/lib/task/task-header/components/task-header-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-header/components/task-header-cloud.component.spec.ts index bf2eaf4c9f..120a06039f 100644 --- a/lib/process-services-cloud/src/lib/task/task-header/components/task-header-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-header/components/task-header-cloud.component.spec.ts @@ -18,7 +18,7 @@ import { TaskHeaderCloudComponent } from './task-header-cloud.component'; import { of, throwError } from 'rxjs'; import { By } from '@angular/platform-browser'; -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing'; import { setupTestBed, AppConfigService, AlfrescoApiService, CardViewArrayItem } from '@alfresco/adf-core'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { TaskCloudService } from '../../services/task-cloud.service'; @@ -186,23 +186,21 @@ describe('TaskHeaderCloudComponent', () => { done(); }); - it('should roll back task description on error', async(async () => { + it('should roll back task description on error', fakeAsync(() => { spyOn(taskCloudService, 'updateTask').and.returnValue(throwError('fake')); fixture.detectChanges(); - await fixture.whenStable(); - fixture.detectChanges(); let description = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-description"]')); expect(description.nativeElement.value.trim()).toEqual('This is the description'); const inputEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-description"]')); inputEl.nativeElement.value = 'updated description'; inputEl.nativeElement.dispatchEvent(new Event('input')); fixture.detectChanges(); - await fixture.whenStable(); - fixture.detectChanges(); - description = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-description"]')); - expect(description.nativeElement.value.trim()).toEqual('This is the description'); - expect(taskCloudService.updateTask).toHaveBeenCalled(); + fixture.whenStable().then(() => { + description = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-description"]')); + expect(description.nativeElement.value.trim()).toEqual('This is the description'); + expect(taskCloudService.updateTask).toHaveBeenCalled(); + }); })); it('should show spinner before loading task details', () => { @@ -523,22 +521,23 @@ describe('TaskHeaderCloudComponent', () => { describe('Task errors', () => { - it('should emit an error when task can not be found', async(() => { + it('should emit an error when task can not be found', (done) => { getTaskByIdSpy.and.returnValue(throwError('Task not found')); component.error.subscribe((error) => { expect(error).toEqual('Task not found'); + done(); }); component.appName = 'appName'; component.taskId = 'taskId'; component.ngOnChanges(); - })); - - it('should emit an error when app name and/or task id are not provided', async(() => { + }); + it('should emit an error when app name and/or task id are not provided', (done) => { component.error.subscribe((error) => { expect(error).toEqual('App Name and Task Id are mandatory'); + done(); }); component.appName = ''; @@ -551,7 +550,7 @@ describe('TaskHeaderCloudComponent', () => { component.appName = ''; component.taskId = 'taskId'; component.ngOnChanges(); - })); + }); it('should call the loadTaskDetailsById when both app name and task id are provided', () => { spyOn(component, 'loadTaskDetailsById'); diff --git a/lib/process-services-cloud/src/lib/task/task-list/components/service-task-list-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-list/components/service-task-list-cloud.component.spec.ts index b964f28f8d..b76e15e656 100644 --- a/lib/process-services-cloud/src/lib/task/task-list/components/service-task-list-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-list/components/service-task-list-cloud.component.spec.ts @@ -16,7 +16,7 @@ */ import { Component, SimpleChange, ViewChild } from '@angular/core'; -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { AppConfigService, setupTestBed, DataRowEvent, ObjectDataRow, EcmUserModel } from '@alfresco/adf-core'; import { ServiceTaskListCloudComponent } from './service-task-list-cloud.component'; @@ -362,7 +362,7 @@ describe('ServiceTaskListCloudComponent', () => { let fixtureCustom: ComponentFixture; let componentCustom: CustomTaskListComponent; let customCopyComponent: CustomCopyContentTaskListComponent; - let element: any; + let element: HTMLElement; let copyFixture: ComponentFixture; setupTestBed({ @@ -399,12 +399,12 @@ describe('ServiceTaskListCloudComponent', () => { expect(componentCustom.taskList.columns.length).toEqual(2); }); - it('it should show copy tooltip when key is present in data-colunn', async(() => { + it('it should show copy tooltip when key is present in data-colunn', fakeAsync(() => { copyFixture.detectChanges(); const appName = new SimpleChange(null, 'FAKE-APP-NAME', true); copyFixture.whenStable().then(() => { copyFixture.detectChanges(); - const spanHTMLElement: HTMLInputElement = element.querySelector('span[title="04fdf69f-4ddd-48ab-9563-da776c9b163c"]'); + const spanHTMLElement = element.querySelector('span[title="04fdf69f-4ddd-48ab-9563-da776c9b163c"]'); spanHTMLElement.dispatchEvent(new Event('mouseenter')); copyFixture.detectChanges(); expect(copyFixture.debugElement.nativeElement.querySelector('.adf-copy-tooltip')).not.toBeNull(); @@ -434,7 +434,7 @@ describe('ServiceTaskListCloudComponent', () => { describe('Copy cell content directive from app.config specifications', () => { - let element: any; + let element: HTMLElement; let taskSpy: jasmine.Spy; setupTestBed({ @@ -478,14 +478,14 @@ describe('ServiceTaskListCloudComponent', () => { fixture.destroy(); }); - it('shoud show tooltip if config copyContent flag is true', async(() => { + it('shoud show tooltip if config copyContent flag is true', fakeAsync(() => { taskSpy.and.returnValue(of(fakeServiceTask)); const appName = new SimpleChange(null, 'FAKE-APP-NAME', true); component.success.subscribe(() => { fixture.whenStable().then(() => { fixture.detectChanges(); - const spanHTMLElement: HTMLInputElement = element.querySelector('span[title="04fdf69f-4ddd-48ab-9563-da776c9b163c"]'); + const spanHTMLElement = element.querySelector('span[title="04fdf69f-4ddd-48ab-9563-da776c9b163c"]'); spanHTMLElement.dispatchEvent(new Event('mouseenter')); fixture.detectChanges(); expect(fixture.debugElement.nativeElement.querySelector('.adf-copy-tooltip')).not.toBeNull(); @@ -498,13 +498,13 @@ describe('ServiceTaskListCloudComponent', () => { component.ngAfterContentInit(); })); - it('shoud not show tooltip if config copyContent flag is true', async(() => { + it('shoud not show tooltip if config copyContent flag is true', fakeAsync(() => { taskSpy.and.returnValue(of(fakeServiceTask)); const appName = new SimpleChange(null, 'FAKE-APP-NAME', true); component.success.subscribe(() => { fixture.whenStable().then(() => { fixture.detectChanges(); - const spanHTMLElement: HTMLInputElement = element.querySelector('span[title="serviceTaskName"]'); + const spanHTMLElement = element.querySelector('span[title="serviceTaskName"]'); spanHTMLElement.dispatchEvent(new Event('mouseenter')); fixture.detectChanges(); expect(fixture.debugElement.nativeElement.querySelector('.adf-copy-tooltip')).toBeNull(); diff --git a/lib/process-services-cloud/src/lib/task/task-list/components/task-list-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-list/components/task-list-cloud.component.spec.ts index 8ac419faea..c181c2bc57 100644 --- a/lib/process-services-cloud/src/lib/task/task-list/components/task-list-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-list/components/task-list-cloud.component.spec.ts @@ -16,7 +16,7 @@ */ import { Component, SimpleChange, ViewChild } from '@angular/core'; -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { AppConfigService, setupTestBed, DataRowEvent, ObjectDataRow, EcmUserModel } from '@alfresco/adf-core'; import { TaskListCloudService } from '../services/task-list-cloud.service'; @@ -420,7 +420,7 @@ describe('TaskListCloudComponent', () => { expect(componentCustom.taskList.columns.length).toEqual(3); }); - it('it should show copy tooltip when key is present in data-colunn', async(() => { + it('it should show copy tooltip when key is present in data-colunn', fakeAsync(() => { copyFixture.detectChanges(); const appName = new SimpleChange(null, 'FAKE-APP-NAME', true); copyFixture.whenStable().then(() => { @@ -535,7 +535,7 @@ describe('TaskListCloudComponent', () => { // TODO: highly unstable test // tslint:disable-next-line:ban - xit('should show tooltip if config copyContent flag is true', async(() => { + xit('should show tooltip if config copyContent flag is true', fakeAsync(() => { taskSpy.and.returnValue(of(fakeGlobalTask)); const appName = new SimpleChange(null, 'FAKE-APP-NAME', true); diff --git a/lib/process-services/src/lib/app-list/apps-list.component.spec.ts b/lib/process-services/src/lib/app-list/apps-list.component.spec.ts index 1c01655393..5f74bd00af 100644 --- a/lib/process-services/src/lib/app-list/apps-list.component.spec.ts +++ b/lib/process-services/src/lib/app-list/apps-list.component.spec.ts @@ -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'); + }); }); }); diff --git a/lib/process-services/src/lib/attachment/create-process-attachment.component.spec.ts b/lib/process-services/src/lib/attachment/create-process-attachment.component.spec.ts index 910e0917a7..8f44e1cc99 100644 --- a/lib/process-services/src/lib/attachment/create-process-attachment.component.spec.ts +++ b/lib/process-services/src/lib/attachment/create-process-attachment.component.spec.ts @@ -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 = 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) }); - })); + }); }); diff --git a/lib/process-services/src/lib/attachment/process-attachment-list.component.spec.ts b/lib/process-services/src/lib/attachment/process-attachment-list.component.spec.ts index d769d36cde..75d30a3195 100644 --- a/lib/process-services/src/lib/attachment/process-attachment-list.component.spec.ts +++ b/lib/process-services/src/lib/attachment/process-attachment-list.component.spec.ts @@ -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'); + }); }); diff --git a/lib/process-services/src/lib/attachment/task-attachment-list.component.spec.ts b/lib/process-services/src/lib/attachment/task-attachment-list.component.spec.ts index 95225278cf..af22425b5e 100644 --- a/lib/process-services/src/lib/attachment/task-attachment-list.component.spec.ts +++ b/lib/process-services/src/lib/attachment/task-attachment-list.component.spec.ts @@ -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'); + }); }); diff --git a/lib/process-services/src/lib/content-widget/attach-file-widget.component.spec.ts b/lib/process-services/src/lib/content-widget/attach-file-widget.component.spec.ts index a5d3c8bae2..63938a6347 100644 --- a/lib/process-services/src/lib/content-widget/attach-file-widget.component.spec.ts +++ b/lib/process-services/src/lib/content-widget/attach-file-widget.component.spec.ts @@ -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 = 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('#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('#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('#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 = 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('#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('#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 = 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('#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 = 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 = 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 = 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 = 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('#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 = 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('#file-1155-option-menu'); expect(menuButton).not.toBeNull(); menuButton.click(); + fixture.detectChanges(); - const removeOption: HTMLButtonElement = fixture.debugElement.query(By.css('#file-1155-remove')).nativeElement; + await fixture.whenStable(); + + const removeOption = 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 = element.querySelector('#file-1155-option-menu'); + const menuButton = element.querySelector('#file-1155-option-menu'); expect(menuButton).not.toBeNull(); menuButton.click(); + fixture.detectChanges(); - const downloadOption: HTMLButtonElement = fixture.debugElement.query(By.css('#file-1155-download-file')).nativeElement; + await fixture.whenStable(); + + const downloadOption = 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 = element.querySelector('#file-1155-option-menu'); + const menuButton = element.querySelector('#file-1155-option-menu'); expect(menuButton).not.toBeNull(); menuButton.click(); fixture.detectChanges(); await fixture.whenStable(); - const showOption: HTMLButtonElement = fixture.debugElement.query(By.css('#file-1155-show-file')).nativeElement; + const showOption = 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 = element.querySelector('#file-1155-option-menu'); + const menuButton = element.querySelector('#file-1155-option-menu'); expect(menuButton).not.toBeNull(); menuButton.click(); fixture.detectChanges(); await fixture.whenStable(); - const showOption: HTMLButtonElement = fixture.debugElement.query(By.css('#file-1155-show-file')).nativeElement; + const showOption = 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 = element.querySelector('#file-1155-option-menu'); + const menuButton = element.querySelector('#file-1155-option-menu'); expect(menuButton).not.toBeNull(); menuButton.click(); fixture.detectChanges(); await fixture.whenStable(); - const downloadOption: HTMLButtonElement = fixture.debugElement.query(By.css('#file-1155-download-file')).nativeElement; + const downloadOption = 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 = element.querySelector('#file-1155-option-menu'); + const menuButton = element.querySelector('#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 = element.querySelector('#file-1155-option-menu'); + const menuButton = element.querySelector('#file-1155-option-menu'); expect(menuButton).not.toBeNull(); menuButton.click(); fixture.detectChanges(); await fixture.whenStable(); - const showOption: HTMLButtonElement = fixture.debugElement.query(By.css('#file-1155-show-file')).nativeElement; + const showOption = 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 = 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('#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(); + }); }); diff --git a/lib/process-services/src/lib/content-widget/attach-folder-widget.component.spec.ts b/lib/process-services/src/lib/content-widget/attach-folder-widget.component.spec.ts index 88a7a64eb6..2e334788ac 100644 --- a/lib/process-services/src/lib/content-widget/attach-folder-widget.component.spec.ts +++ b/lib/process-services/src/lib/content-widget/attach-folder-widget.component.spec.ts @@ -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(); + }); }); diff --git a/lib/process-services/src/lib/form/form.component.visibility.spec.ts b/lib/process-services/src/lib/form/form.component.visibility.spec.ts index 4ea47a565e..7d6ea2ab93 100644 --- a/lib/process-services/src/lib/form/form.component.visibility.spec.ts +++ b/lib/process-services/src/lib/form/form.component.visibility.spec.ts @@ -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'); + }); }); }); }); diff --git a/lib/process-services/src/lib/form/start-form.component.spec.ts b/lib/process-services/src/lib/form/start-form.component.spec.ts index 6dc19f69f1..b2b035b432 100644 --- a/lib/process-services/src/lib/form/start-form.component.spec.ts +++ b/lib/process-services/src/lib/form/start-form.component.spec.ts @@ -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; diff --git a/lib/process-services/src/lib/people/components/people/people.component.spec.ts b/lib/process-services/src/lib/people/components/people/people.component.spec.ts index 5f54719481..56918a5619 100644 --- a/lib/process-services/src/lib/people/components/people/people.component.spec.ts +++ b/lib/process-services/src/lib/people/components/people/people.component.spec.ts @@ -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 diff --git a/lib/process-services/src/lib/process-comments/process-comments.component.spec.ts b/lib/process-services/src/lib/process-comments/process-comments.component.spec.ts index ef085c1ff8..9443628c3a 100644 --- a/lib/process-services/src/lib/process-comments/process-comments.component.spec.ts +++ b/lib/process-services/src/lib/process-comments/process-comments.component.spec.ts @@ -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(); + }); }); diff --git a/lib/process-services/src/lib/process-list/components/process-instance-details.component.spec.ts b/lib/process-services/src/lib/process-list/components/process-instance-details.component.spec.ts index 8639b95733..d67f7a5623 100644 --- a/lib/process-services/src/lib/process-list/components/process-instance-details.component.spec.ts +++ b/lib/process-services/src/lib/process-list/components/process-instance-details.component.spec.ts @@ -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(); + }); }); }); diff --git a/lib/process-services/src/lib/process-list/components/process-instance-header.component.spec.ts b/lib/process-services/src/lib/process-list/components/process-instance-header.component.spec.ts index 98cfe34b8f..d530e826d2 100644 --- a/lib/process-services/src/lib/process-list/components/process-instance-header.component.spec.ts +++ b/lib/process-services/src/lib/process-list/components/process-instance-header.component.spec.ts @@ -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'); + }); }); }); diff --git a/lib/process-services/src/lib/process-list/components/process-instance-tasks.component.spec.ts b/lib/process-services/src/lib/process-list/components/process-instance-tasks.component.spec.ts index a3220adfd8..63c38fc8fe 100644 --- a/lib/process-services/src/lib/process-list/components/process-instance-tasks.component.spec.ts +++ b/lib/process-services/src/lib/process-list/components/process-instance-tasks.component.spec.ts @@ -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(); + }); }); }); diff --git a/lib/process-services/src/lib/process-list/components/process-list.component.spec.ts b/lib/process-services/src/lib/process-list/components/process-list.component.spec.ts index 09d6a54b31..25377bbe07 100644 --- a/lib/process-services/src/lib/process-list/components/process-list.component.spec.ts +++ b/lib/process-services/src/lib/process-list/components/process-list.component.spec.ts @@ -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', () => { diff --git a/lib/process-services/src/lib/process-list/components/start-process.component.spec.ts b/lib/process-services/src/lib/process-list/components/start-process.component.spec.ts index 2a83ae4202..9b279aa90f 100644 --- a/lib/process-services/src/lib/process-list/components/start-process.component.spec.ts +++ b/lib/process-services/src/lib/process-list/components/start-process.component.spec.ts @@ -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(() => { diff --git a/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts b/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts index 27d2eb281a..121d29ade4 100644 --- a/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts +++ b/lib/process-services/src/lib/process-list/services/process-filter.service.spec.ts @@ -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(); } ); - })); + }); }); }); diff --git a/lib/process-services/src/lib/process-list/services/process.service.spec.ts b/lib/process-services/src/lib/process-list/services/process.service.spec.ts index 9c691cbe2a..1365751768 100644 --- a/lib/process-services/src/lib/process-list/services/process.service.spec.ts +++ b/lib/process-services/src/lib/process-list/services/process.service.spec.ts @@ -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(); } ); - })); - + }); }); }); }); diff --git a/lib/process-services/src/lib/task-list/components/attach-form.component.spec.ts b/lib/process-services/src/lib/task-list/components/attach-form.component.spec.ts index ac5b09c98c..01320fb2a5 100644 --- a/lib/process-services/src/lib/task-list/components/attach-form.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/attach-form.component.spec.ts @@ -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(); + }); }); diff --git a/lib/process-services/src/lib/task-list/components/checklist.component.spec.ts b/lib/process-services/src/lib/task-list/components/checklist.component.spec.ts index c7af6290a4..7600a52977 100644 --- a/lib/process-services/src/lib/task-list/components/checklist.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/checklist.component.spec.ts @@ -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 = 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 = 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 = 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 = 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' }))); diff --git a/lib/process-services/src/lib/task-list/components/task-details.component.spec.ts b/lib/process-services/src/lib/task-list/components/task-details.component.spec.ts index c2265ffdc4..adb44b8f23 100644 --- a/lib/process-services/src/lib/task-list/components/task-details.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-details.component.spec.ts @@ -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 = 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(() => { diff --git a/lib/process-services/src/lib/task-list/components/task-filters.component.spec.ts b/lib/process-services/src/lib/task-list/components/task-filters.component.spec.ts index 76b6744100..f19d7b3399 100644 --- a/lib/process-services/src/lib/task-list/components/task-filters.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-filters.component.spec.ts @@ -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)); diff --git a/lib/process-services/src/lib/task-list/components/task-header.component.spec.ts b/lib/process-services/src/lib/task-list/components/task-header.component.spec.ts index 0cdb168968..3b311187ba 100644 --- a/lib/process-services/src/lib/task-list/components/task-header.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-header.component.spec.ts @@ -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'); + }); }); }); diff --git a/lib/process-services/src/lib/task-list/components/task-list.component.spec.ts b/lib/process-services/src/lib/task-list/components/task-list.component.spec.ts index 5670759040..df1e4b4b1f 100644 --- a/lib/process-services/src/lib/task-list/components/task-list.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-list.component.spec.ts @@ -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({ diff --git a/lib/process-services/src/lib/task-list/components/task-standalone.component.spec.ts b/lib/process-services/src/lib/task-list/components/task-standalone.component.spec.ts index 7f395c6908..5ef7caa0b2 100644 --- a/lib/process-services/src/lib/task-list/components/task-standalone.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-standalone.component.spec.ts @@ -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(); + }); });