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 74bf145607..53e58195e4 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 @@ -25,7 +25,7 @@ import { AspectListDialogComponentData } from './aspect-list-dialog-data.interfa import { NodesApiService } from 'core'; import { AspectListService } from './aspect-list.service'; import { delay } from 'rxjs/operators'; -import { AspectEntry } from '@alfresco/js-api'; +import { AspectEntry, MinimalNode } from '@alfresco/js-api'; const aspectListMock: AspectEntry[] = [{ entry: { @@ -274,7 +274,7 @@ describe('AspectListDialogComponent', () => { spyOn(aspectListService, 'getAspects').and.returnValue(of([...aspectListMock, ...customAspectListMock])); spyOn(aspectListService, 'getVisibleAspects').and.returnValue(['frs:AspectOne']); spyOn(aspectListService, 'getCustomAspects').and.returnValue(of(customAspectListMock)); - spyOn(nodeService, 'getNode').and.returnValue(of({ id: 'fake-node-id', aspectNames: ['frs:AspectOne', 'cst:customAspect'] }).pipe(delay(0))); + spyOn(nodeService, 'getNode').and.returnValue(of(new MinimalNode({ id: 'fake-node-id', aspectNames: ['frs:AspectOne', 'cst:customAspect'] })).pipe(delay(0))); fixture = TestBed.createComponent(AspectListDialogComponent); fixture.componentInstance.data.select = new Subject(); fixture.detectChanges(); diff --git a/lib/content-services/src/lib/aspect-list/aspect-list.component.spec.ts b/lib/content-services/src/lib/aspect-list/aspect-list.component.spec.ts index 255650a036..6a42554b7b 100644 --- a/lib/content-services/src/lib/aspect-list/aspect-list.component.spec.ts +++ b/lib/content-services/src/lib/aspect-list/aspect-list.component.spec.ts @@ -127,7 +127,7 @@ describe('AspectListComponent', () => { }); it('should show the loading spinner when result is loading', () => { - const delayReusult = of([]).pipe(delay(0)); + const delayReusult = of(null).pipe(delay(0)); spyOn(nodeService, 'getNode').and.returnValue(delayReusult); spyOn(aspectListService, 'getAspects').and.returnValue(delayReusult); fixture.detectChanges(); @@ -147,7 +147,7 @@ describe('AspectListComponent', () => { spyOn(aspectListService, 'getCustomAspects').and.returnValue(of(customAspectListMock)); spyOn(aspectListService, 'getVisibleAspects').and.returnValue(['frs:AspectOne']); nodeService = TestBed.inject(NodesApiService); - spyOn(nodeService, 'getNode').and.returnValue(of({ id: 'fake-node-id', aspectNames: ['frs:AspectOne'] })); + spyOn(nodeService, 'getNode').and.returnValue(of({ id: 'fake-node-id', aspectNames: ['frs:AspectOne'] } as any)); component.nodeId = 'fake-node-id'; fixture.detectChanges(); }); 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 6236a542cb..051f115233 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 @@ -124,7 +124,7 @@ describe('AspectListService', () => { componentInstance: { error: new Subject() } - }); + } as any); spyOnDialogClose = spyOn(materialDialog, 'closeAll'); }); diff --git a/lib/content-services/src/lib/aspect-list/node-aspect.service.spec.ts b/lib/content-services/src/lib/aspect-list/node-aspect.service.spec.ts index 31acf9561e..e950ab4fc0 100644 --- a/lib/content-services/src/lib/aspect-list/node-aspect.service.spec.ts +++ b/lib/content-services/src/lib/aspect-list/node-aspect.service.spec.ts @@ -15,6 +15,7 @@ * limitations under the License. */ +import { MinimalNode } from '@alfresco/js-api'; import { TestBed } from '@angular/core/testing'; import { TranslateModule } from '@ngx-translate/core'; import { AlfrescoApiService, CardViewUpdateService, NodesApiService, setupTestBed } from 'core'; @@ -48,7 +49,7 @@ describe('NodeAspectService', () => { it('should open the aspect list dialog', () => { spyOn(aspectListService, 'openAspectListDialog').and.returnValue(of([])); - spyOn(nodeApiService, 'updateNode').and.returnValue(of({})); + spyOn(nodeApiService, 'updateNode').and.returnValue(of(null)); nodeAspectService.updateNodeAspects('fake-node-id'); expect(aspectListService.openAspectListDialog).toHaveBeenCalledWith('fake-node-id'); }); @@ -56,7 +57,7 @@ describe('NodeAspectService', () => { it('should update the node when the aspect dialog apply the changes', () => { const expectedParameters = { aspectNames: ['a', 'b', 'c'] }; spyOn(aspectListService, 'openAspectListDialog').and.returnValue(of(['a', 'b', 'c'])); - spyOn(nodeApiService, 'updateNode').and.returnValue(of({})); + spyOn(nodeApiService, 'updateNode').and.returnValue(of(null)); nodeAspectService.updateNodeAspects('fake-node-id'); expect(nodeApiService.updateNode).toHaveBeenCalledWith('fake-node-id', expectedParameters); }); @@ -67,7 +68,7 @@ describe('NodeAspectService', () => { expect(nodeUpdated.aspectNames).toEqual(['a', 'b', 'c']); done(); }); - const fakeNode = { id: 'fake-node-id', aspectNames: ['a', 'b', 'c'] }; + const fakeNode = new MinimalNode({ id: 'fake-node-id', aspectNames: ['a', 'b', 'c'] }); spyOn(aspectListService, 'openAspectListDialog').and.returnValue(of(['a', 'b', 'c'])); spyOn(nodeApiService, 'updateNode').and.returnValue(of(fakeNode)); nodeAspectService.updateNodeAspects('fake-node-id'); @@ -79,7 +80,7 @@ describe('NodeAspectService', () => { expect(nodeUpdated.aspectNames).toEqual(['a', 'b', 'c']); done(); }); - const fakeNode = { id: 'fake-node-id', aspectNames: ['a', 'b', 'c'] }; + const fakeNode = new MinimalNode({ id: 'fake-node-id', aspectNames: ['a', 'b', 'c'] }); spyOn(aspectListService, 'openAspectListDialog').and.returnValue(of(['a', 'b', 'c'])); spyOn(nodeApiService, 'updateNode').and.returnValue(of(fakeNode)); nodeAspectService.updateNodeAspects('fake-node-id'); 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 3475af62c5..0c4da5162c 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 @@ -310,9 +310,7 @@ describe('ContentMetadataComponent', () => { const expectedProperties = []; component.expanded = true; fixture.detectChanges(); - spyOn(contentMetadataService, 'getGroupedProperties').and.callFake(() => { - return of([{ properties: expectedProperties }]); - }); + spyOn(contentMetadataService, 'getGroupedProperties').and.returnValue(of([{ properties: expectedProperties } as any])); spyOn(component, 'showGroup').and.returnValue(true); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); @@ -328,7 +326,7 @@ describe('ContentMetadataComponent', () => { component.expanded = true; component.displayEmpty = false; fixture.detectChanges(); - spyOn(contentMetadataService, 'getGroupedProperties').and.returnValue(of([{ properties: [] }])); + spyOn(contentMetadataService, 'getGroupedProperties').and.returnValue(of([{ properties: [] } as any])); spyOn(component, 'showGroup').and.returnValue(true); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); @@ -343,7 +341,7 @@ describe('ContentMetadataComponent', () => { it('should hide card views group when the grouped properties are empty', async(() => { component.expanded = true; fixture.detectChanges(); - spyOn(contentMetadataService, 'getGroupedProperties').and.returnValue(of([{ properties: [] }])); + spyOn(contentMetadataService, 'getGroupedProperties').and.returnValue(of([{ properties: [] } as any])); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); @@ -367,7 +365,7 @@ describe('ContentMetadataComponent', () => { label: 'To' }] }; - spyOn(contentMetadataService, 'getGroupedProperties').and.returnValue(of([{ properties: [cardViewGroup] }])); + spyOn(contentMetadataService, 'getGroupedProperties').and.returnValue(of([{ properties: [cardViewGroup] } as any])); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); diff --git a/lib/content-services/src/lib/content-metadata/services/content-metadata.service.spec.ts b/lib/content-services/src/lib/content-metadata/services/content-metadata.service.spec.ts index 2d958f2346..8abb5c0f8f 100644 --- a/lib/content-services/src/lib/content-metadata/services/content-metadata.service.spec.ts +++ b/lib/content-services/src/lib/content-metadata/services/content-metadata.service.spec.ts @@ -103,7 +103,7 @@ describe('ContentMetaDataService', () => { modifiedByUser: {displayName: 'test-user-modified'}, properties: [] }; - spyOn(contentPropertyService, 'getContentTypeCardItem').and.returnValue(of({ label: 'hello i am a weird content type'})); + spyOn(contentPropertyService, 'getContentTypeCardItem').and.returnValue(of({ label: 'hello i am a weird content type'} as any)); service.getContentTypeProperty(fakeNode).subscribe( (res: any) => { @@ -130,9 +130,7 @@ describe('ContentMetaDataService', () => { const fakeNode: Node = { name: 'Node', id: 'fake-id', isFile: true, aspectNames: ['exif:exif'] } ; setConfig('default', { 'exif:exif': '*' }); - spyOn(classesApi, 'getClass').and.callFake(() => { - return of(exifResponse); - }); + spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(exifResponse)); service.getGroupedProperties(fakeNode).subscribe( (res) => { @@ -150,9 +148,7 @@ describe('ContentMetaDataService', () => { const fakeNode: Node = { name: 'Node', id: 'fake-id', isFile: true, aspectNames: ['exif:exif'] } ; setConfig('default', { 'exif:exif': '*', 'rma:record': '*' }); - spyOn(classesApi, 'getClass').and.callFake(() => { - return of(exifResponse); - }); + spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(exifResponse)); service.getGroupedProperties(fakeNode).subscribe( (res) => { @@ -187,9 +183,7 @@ describe('ContentMetaDataService', () => { ]; setConfig('custom', customLayoutOrientedScheme); - spyOn(classesApi, 'getClass').and.callFake(() => { - return of(contentResponse); - }); + spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(contentResponse)); service.getGroupedProperties(fakeNode, 'custom').subscribe( (res) => { @@ -232,9 +226,7 @@ describe('ContentMetaDataService', () => { ]; setConfig('custom', customLayoutOrientedScheme); - spyOn(classesApi, 'getClass').and.callFake(() => { - return of(contentResponse); - }); + spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(contentResponse)); service.getGroupedProperties(fakeNode, 'custom').subscribe( (res) => { @@ -268,9 +260,7 @@ describe('ContentMetaDataService', () => { ]; setConfig('custom', customLayoutOrientedScheme); - spyOn(classesApi, 'getClass').and.callFake(() => { - return of(contentResponse); - }); + spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(contentResponse)); service.getGroupedProperties(fakeNode, 'custom').subscribe( (res) => { diff --git a/lib/content-services/src/lib/content-metadata/services/content-type-property.service.spec.ts b/lib/content-services/src/lib/content-metadata/services/content-type-property.service.spec.ts index f94b67cb95..39d036bf6b 100644 --- a/lib/content-services/src/lib/content-metadata/services/content-type-property.service.spec.ts +++ b/lib/content-services/src/lib/content-metadata/services/content-type-property.service.spec.ts @@ -22,7 +22,7 @@ import { ContentTestingModule } from '../../testing/content.testing.module'; import { TranslateModule } from '@ngx-translate/core'; import { ContentTypeService } from '../../content-type'; import { of } from 'rxjs'; -import { Node } from '@alfresco/js-api'; +import { Node, TypeEntry } from '@alfresco/js-api'; describe('ContentTypePropertyService', () => { @@ -83,40 +83,35 @@ describe('ContentTypePropertyService', () => { } }; - const mockSelectOptions = { - 'list': + const mockSelectOptions: TypeEntry[] = [ { - 'pagination': { 'count': 1, 'hasMoreItems': false, 'totalItems': 1, 'skipCount': 0, 'maxItems': 100 }, - 'entries': [ - { - 'entry': { - 'isArchive': true, - 'includedInSupertypeQuery': true, - 'isContainer': false, - 'model': { - 'id': 'e2e:test', - 'author': 'E2e Automation User', - 'description': 'Custom type e2e model', - 'namespaceUri': 'http://www.customModel.com/whatever', - 'namespacePrefix': 'e2e' - }, - 'id': 'e2e:test', - 'title': 'Test type', - 'properties': [{ - 'id': 'cm:name', - 'title': 'Name', - 'description': 'Name', - 'dataType': 'd:text', - 'isMultiValued': false, - 'isMandatory': true, - 'isMandatoryEnforced': true, - 'isProtected': false - }], - 'parentId': 'cm:content' - } - }] + 'entry': { + 'isArchive': true, + 'includedInSupertypeQuery': true, + 'isContainer': false, + 'model': { + 'id': 'e2e:test', + 'author': 'E2e Automation User', + 'description': 'Custom type e2e model', + 'namespaceUri': 'http://www.customModel.com/whatever', + 'namespacePrefix': 'e2e' + }, + 'id': 'e2e:test', + 'title': 'Test type', + 'properties': [{ + 'id': 'cm:name', + 'title': 'Name', + 'description': 'Name', + 'dataType': 'd:text', + 'isMultiValued': false, + 'isMandatory': true, + 'isMandatoryEnforced': true, + 'isProtected': false + }], + 'parentId': 'cm:content' + } } - }; + ]; setupTestBed({ imports: [ diff --git a/lib/content-services/src/lib/content-metadata/services/property-descriptors.service.spec.ts b/lib/content-services/src/lib/content-metadata/services/property-descriptors.service.spec.ts index 63ffdf7f47..2223440df3 100644 --- a/lib/content-services/src/lib/content-metadata/services/property-descriptors.service.spec.ts +++ b/lib/content-services/src/lib/content-metadata/services/property-descriptors.service.spec.ts @@ -18,7 +18,6 @@ import { TestBed } from '@angular/core/testing'; import { PropertyDescriptorsService } from './property-descriptors.service'; import { AlfrescoApiService, setupTestBed } from '@alfresco/adf-core'; -import { of } from 'rxjs'; import { ClassesApi } from '@alfresco/js-api'; import { PropertyGroup } from '../interfaces/content-metadata.interfaces'; import { ContentTestingModule } from '../../testing/content.testing.module'; @@ -77,7 +76,7 @@ describe('PropertyDescriptorLoaderService', () => { let counter = 0; spyOn(classesApi, 'getClass').and.callFake(() => { - return of(apiResponses[counter++]); + return Promise.resolve(apiResponses[counter++]); }); service.load(['exif:exif', 'cm:content']) diff --git a/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.spec.ts index ef3b156d07..2c50237ad2 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.spec.ts @@ -90,7 +90,7 @@ describe('ContentNodeDialogService', () => { componentInstance: { error: new Subject() } - }); + } as any); }); it('should not open the lock node dialog if have no permission', () => { diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts index 032fc91d2e..a192879c0d 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts @@ -18,7 +18,7 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { Node, NodeEntry, NodePaging, RequestScope, ResultSetPaging, SiteEntry, SitePaging, UserInfo } from '@alfresco/js-api'; +import { MinimalNode, Node, NodeEntry, NodePaging, RequestScope, ResultSetPaging, SiteEntry, SitePaging, UserInfo } from '@alfresco/js-api'; import { AppConfigService, FileModel, FileUploadStatus, NodesApiService, setupTestBed, SitesService, UploadService, FileUploadCompleteEvent, DataRow, ThumbnailService, ContentService, DataColumn } from '@alfresco/adf-core'; import { of, throwError } from 'rxjs'; import { DropdownBreadcrumbComponent } from '../breadcrumb'; @@ -105,7 +105,7 @@ describe('ContentNodeSelectorPanelComponent', () => { searchQueryBuilderService = component.queryBuilderService; component.queryBuilderService.resetToDefaults(); - spyOn(nodeService, 'getNode').and.returnValue(of({ id: 'fake-node', path: { elements: [{ nodeType: 'st:site', name: 'fake-site'}] } })); + spyOn(nodeService, 'getNode').and.returnValue(of(new MinimalNode({ id: 'fake-node', path: { elements: [{ nodeType: 'st:site', name: 'fake-site'}] } }))); searchSpy = spyOn(searchQueryBuilderService, 'execute'); const fakeSite = new SiteEntry({ entry: { id: 'fake-site', guid: 'fake-site', title: 'fake-site', visibility: 'visible' } }); spyOn(sitesService, 'getSite').and.returnValue(of(fakeSite)); @@ -124,12 +124,12 @@ describe('ContentNodeSelectorPanelComponent', () => { spyOn(documentListService, 'getFolderNode').and.returnValue(of( { entry: { path: { elements: [] } } })); spyOn(documentListService, 'getFolder').and.returnValue(throwError('No results for test')); - spyOn(sitesService, 'getSites').and.returnValue(of({ + spyOn(sitesService, 'getSites').and.returnValue(of(new SitePaging({ list: { entries: [ { entry: { guid: 'namek', id: 'namek' } }, { entry: { guid: 'blog', id: 'blog' } }] } - })); + }))); component.currentFolderId = 'cat-girl-nuku-nuku'; fixture.detectChanges(); @@ -229,7 +229,7 @@ describe('ContentNodeSelectorPanelComponent', () => { spyOn(documentListService, 'getFolderNode').and.returnValue(of( { entry: { path: { elements: [] } } })); spyOn(documentListService, 'getFolder').and.returnValue(throwError('No results for test')); - spyOn(sitesService, 'getSites').and.returnValue(of({ list: { entries: [] } })); + spyOn(sitesService, 'getSites').and.returnValue(of(new SitePaging({ list: { entries: [] } }))); component.currentFolderId = 'cat-girl-nuku-nuku'; fixture.detectChanges(); @@ -338,7 +338,7 @@ describe('ContentNodeSelectorPanelComponent', () => { describe('Site selection', () => { beforeEach(() => { - spyOn(sitesService, 'getSites').and.returnValue(of({ list: { entries: [] } })); + spyOn(sitesService, 'getSites').and.returnValue(of(new SitePaging({ list: { entries: [] } }))); component.currentFolderId = 'fake-starting-folder'; }); @@ -380,15 +380,15 @@ describe('ContentNodeSelectorPanelComponent', () => { component.isSelectionValid = (node: Node) => node.isFile; spyOn(documentListService, 'getFolderNode').and.returnValue(of(expectedDefaultFolderNode)); - spyOn(documentListService, 'getFolder').and.returnValue(of({ + spyOn(documentListService, 'getFolder').and.returnValue(of(new NodePaging({ list: { pagination: {}, entries: [], source: {} } - })); + }))); - spyOn(sitesService, 'getSites').and.returnValue(of({ list: { entries: [] } })); + spyOn(sitesService, 'getSites').and.returnValue(of(new SitePaging({ list: { entries: [] } }))); customResourcesService = TestBed.inject(CustomResourcesService); getCorrespondingNodeIdsSpy = spyOn(customResourcesService, 'getCorrespondingNodeIds').and @@ -1034,7 +1034,7 @@ describe('ContentNodeSelectorPanelComponent', () => { const rows = [ {}, {}]; component.documentList.data = new ShareDataTableAdapter(thumbnailService, contentService, schema); spyOn(component.documentList.data, 'getRows').and.returnValue(rows); - spyOn(sitesService, 'getSites').and.returnValue(of({ list: { entries: [] } })); + spyOn(sitesService, 'getSites').and.returnValue(of(new SitePaging({ list: { entries: [] } }))); }); it('should the selection become the currently navigated folder when the folder loads (Acts as destination for cases like copy action)', () => { diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts index cf5909187d..cd06e99455 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts @@ -19,7 +19,7 @@ import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/materia import { CUSTOM_ELEMENTS_SCHEMA, EventEmitter } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ContentNodeSelectorComponent } from './content-node-selector.component'; -import { Node, NodeEntry } from '@alfresco/js-api'; +import { Node, NodeEntry, SitePaging } from '@alfresco/js-api'; import { By } from '@angular/platform-browser'; import { SitesService, ContentService, UploadService, FileModel, FileUploadEvent } from '@alfresco/adf-core'; import { of } from 'rxjs'; @@ -77,7 +77,7 @@ describe('ContentNodeSelectorComponent', () => { spyOn(documentListService, 'getFolder').and.callThrough(); spyOn(documentListService, 'getFolderNode').and.callThrough(); - spyOn(sitesService, 'getSites').and.returnValue(of({ list: { entries: [] } })); + spyOn(sitesService, 'getSites').and.returnValue(of(new SitePaging({ list: { entries: [] } }))); fixture = TestBed.createComponent(ContentNodeSelectorComponent); component = fixture.componentInstance; diff --git a/lib/content-services/src/lib/content-node-share/content-node-share.dialog.spec.ts b/lib/content-services/src/lib/content-node-share/content-node-share.dialog.spec.ts index 1d6481c937..b9f6a731c2 100644 --- a/lib/content-services/src/lib/content-node-share/content-node-share.dialog.spec.ts +++ b/lib/content-services/src/lib/content-node-share/content-node-share.dialog.spec.ts @@ -76,7 +76,7 @@ describe('ShareDialogComponent', () => { } }; - spyOn(nodesApiService, 'updateNode').and.returnValue(of({})); + spyOn(nodesApiService, 'updateNode').and.returnValue(of(null)); }); afterEach(() => { @@ -158,7 +158,7 @@ describe('ShareDialogComponent', () => { }); it('should open a confirmation dialog when unshare button is triggered', () => { - spyOn(matDialog, 'open').and.returnValue({ beforeClosed: () => of(false) }); + spyOn(matDialog, 'open').and.returnValue({ beforeClosed: () => of(false) } as any); spyOn(sharedLinksApiService, 'deleteSharedLink').and.callThrough(); node.entry.properties['qshare:sharedId'] = 'sharedId'; @@ -179,7 +179,7 @@ describe('ShareDialogComponent', () => { }); it('should unshare file when confirmation dialog returns true', fakeAsync(() => { - spyOn(matDialog, 'open').and.returnValue({ beforeClosed: () => of(true) }); + spyOn(matDialog, 'open').and.returnValue({ beforeClosed: () => of(true) } as any); spyOn(sharedLinksApiService, 'deleteSharedLink').and.returnValue(of({})); node.entry.properties['qshare:sharedId'] = 'sharedId'; @@ -199,7 +199,7 @@ describe('ShareDialogComponent', () => { })); it('should not unshare file when confirmation dialog returns false', fakeAsync(() => { - spyOn(matDialog, 'open').and.returnValue({ beforeClosed: () => of(false) }); + spyOn(matDialog, 'open').and.returnValue({ beforeClosed: () => of(false) } as any); spyOn(sharedLinksApiService, 'deleteSharedLink').and.callThrough(); node.entry.properties['qshare:sharedId'] = 'sharedId'; @@ -313,7 +313,7 @@ describe('ShareDialogComponent', () => { describe('datetimepicker type', () => { beforeEach(() => { - spyOn(sharedLinksApiService, 'createSharedLinks').and.returnValue(of({})); + spyOn(sharedLinksApiService, 'createSharedLinks').and.returnValue(of(null)); node.entry.allowableOperations = ['update']; component.data = { node, @@ -324,7 +324,7 @@ describe('ShareDialogComponent', () => { it('it should update node with input date and end of day time when type is `date`', fakeAsync(() => { const dateTimePickerType = 'date'; const date = moment('2525-01-01 13:00:00'); - spyOn(appConfigService, 'get').and.callFake(() => dateTimePickerType); + spyOn(appConfigService, 'get').and.callFake(() => dateTimePickerType as any); fixture.detectChanges(); fixture.nativeElement.querySelector('mat-slide-toggle[data-automation-id="adf-expire-toggle"] label') 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 5ae1c263fb..b1b278169a 100644 --- a/lib/content-services/src/lib/dialogs/folder.dialog.spec.ts +++ b/lib/content-services/src/lib/dialogs/folder.dialog.spec.ts @@ -93,7 +93,7 @@ describe('FolderDialogComponent', () => { }); it('should submit updated values if form is valid', () => { - spyOn(nodesApi, 'updateNode').and.returnValue(of({})); + spyOn(nodesApi, 'updateNode').and.returnValue(of(null)); component.form.controls['name'].setValue('folder-name-update'); component.form.controls['title'].setValue('folder-title-update'); @@ -114,7 +114,7 @@ describe('FolderDialogComponent', () => { }); it('should call dialog to close with form data when submit is successfully', () => { - const folder = { + const folder: any = { data: 'folder-data' }; @@ -126,7 +126,7 @@ describe('FolderDialogComponent', () => { }); it('should emit success output event with folder when submit is successful', async(() => { - const folder = { data: 'folder-data' }; + const folder: any = { data: 'folder-data' }; let expectedNode = null; spyOn(nodesApi, 'updateNode').and.returnValue(of(folder)); @@ -191,7 +191,7 @@ describe('FolderDialogComponent', () => { }); it('should submit updated values if form is valid', () => { - spyOn(nodesApi, 'createFolder').and.returnValue(of({})); + spyOn(nodesApi, 'createFolder').and.returnValue(of(null)); component.form.controls['name'].setValue('folder-name-update'); component.form.controls['title'].setValue('folder-title-update'); @@ -213,7 +213,7 @@ describe('FolderDialogComponent', () => { }); it('should submit updated values if form is valid (with custom nodeType)', () => { - spyOn(nodesApi, 'createFolder').and.returnValue(of({})); + spyOn(nodesApi, 'createFolder').and.returnValue(of(null)); component.form.controls['name'].setValue('folder-name-update'); component.form.controls['title'].setValue('folder-title-update'); @@ -236,7 +236,7 @@ describe('FolderDialogComponent', () => { }); it('should call dialog to close with form data when submit is successfully', () => { - const folder = { + const folder: any = { data: 'folder-data' }; diff --git a/lib/content-services/src/lib/dialogs/library/library.dialog.spec.ts b/lib/content-services/src/lib/dialogs/library/library.dialog.spec.ts index fd7982d441..f1faae21bd 100644 --- a/lib/content-services/src/lib/dialogs/library/library.dialog.spec.ts +++ b/lib/content-services/src/lib/dialogs/library/library.dialog.spec.ts @@ -24,6 +24,7 @@ import { ContentTestingModule } from '../../testing/content.testing.module'; import { TranslateModule } from '@ngx-translate/core'; import { of, throwError } from 'rxjs'; import { delay } from 'rxjs/operators'; +import { SiteEntry } from '@alfresco/js-api'; describe('LibraryDialogComponent', () => { let fixture: ComponentFixture; @@ -128,7 +129,7 @@ describe('LibraryDialogComponent', () => { it('should create site when form is valid', fakeAsync(() => { findSitesSpy.and.returnValue(Promise.resolve(findSitesResponse)); spyOn(sitesService, 'createSite').and.returnValue( - of({entry: {id: 'fake-id'}}).pipe(delay(100)) + of({entry: {id: 'fake-id'}} as SiteEntry).pipe(delay(100)) ); spyOn(sitesService, 'getSite').and.callFake(() => { return throwError('error'); @@ -163,9 +164,7 @@ describe('LibraryDialogComponent', () => { it('should not create site when form is invalid', fakeAsync(() => { findSitesSpy.and.returnValue(Promise.resolve(findSitesResponse)); - spyOn(sitesService, 'createSite').and.returnValue( - Promise.resolve({}) - ); + spyOn(sitesService, 'createSite').and.returnValue(of(null)); spyOn(sitesService, 'getSite').and.returnValue(of(null)); fixture.detectChanges(); diff --git a/lib/content-services/src/lib/dialogs/node-lock.dialog.spec.ts b/lib/content-services/src/lib/dialogs/node-lock.dialog.spec.ts index 375dcdb17d..d579df4e72 100644 --- a/lib/content-services/src/lib/dialogs/node-lock.dialog.spec.ts +++ b/lib/content-services/src/lib/dialogs/node-lock.dialog.spec.ts @@ -99,7 +99,7 @@ describe('NodeLockDialogComponent', () => { }); it('should submit the form and lock the node', () => { - spyOn(alfrescoApi.nodesApi, 'lockNode').and.returnValue(Promise.resolve({})); + spyOn(alfrescoApi.nodesApi, 'lockNode').and.returnValue(Promise.resolve(null)); component.submit(); @@ -114,7 +114,7 @@ describe('NodeLockDialogComponent', () => { }); it('should submit the form and unlock the node', () => { - spyOn(alfrescoApi.nodesApi, 'unlockNode').and.returnValue(Promise.resolve({})); + spyOn(alfrescoApi.nodesApi, 'unlockNode').and.returnValue(Promise.resolve(null)); component.form.controls['isLocked'].setValue(false); component.submit(); @@ -123,7 +123,7 @@ describe('NodeLockDialogComponent', () => { }); it('should call dialog to close with form data when submit is successfully', fakeAsync(() => { - const node = { entry: {} }; + const node: any = { entry: {} }; spyOn(alfrescoApi.nodesApi, 'lockNode').and.returnValue(Promise.resolve(node)); component.submit(); diff --git a/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts b/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts index 6f30a98bad..506c05e8f7 100644 --- a/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts +++ b/lib/content-services/src/lib/document-list/components/document-list.component.spec.ts @@ -53,11 +53,12 @@ import { DocumentListService } from './../services/document-list.service'; import { CustomResourcesService } from './../services/custom-resources.service'; import { DocumentListComponent } from './document-list.component'; import { ContentTestingModule } from '../../testing/content.testing.module'; -import { NodeEntry } from '@alfresco/js-api'; +import { FavoritePaging, NodeEntry } from '@alfresco/js-api'; import { By } from '@angular/platform-browser'; import { DocumentListModule } from '../document-list.module'; import { TranslateModule } from '@ngx-translate/core'; import { ShareDataRow } from '../data/share-data-row.model'; +import { DocumentLoaderNode } from '../models/document-folder.model'; describe('DocumentList', () => { @@ -100,23 +101,15 @@ describe('DocumentList', () => { thumbnailService = TestBed.inject(ThumbnailService); contentService = TestBed.inject(ContentService); - spyFolder = spyOn(documentListService, 'getFolder').and.callFake(() => { - return Promise.resolve({ list: {} }); - }); - - spyFolderNode = spyOn(documentListService, 'getFolderNode').and.callFake(() => { - return Promise.resolve({ entry: {} }); - }); - - spyOn(apiService.nodesApi, 'getNode').and.callFake(() => { - return Promise.resolve({ entry: {} }); - }); + spyFolder = spyOn(documentListService, 'getFolder').and.returnValue(of({ list: {} })); + spyFolderNode = spyOn(documentListService, 'getFolderNode').and.returnValue(of(new NodeEntry({ entry: {} }))); + spyOn(apiService.nodesApi, 'getNode').and.returnValue(Promise.resolve(new NodeEntry({ entry: {} }))); documentList.ngOnInit(); documentList.currentFolderId = 'no-node'; spyGetSites = spyOn(customResourcesService.sitesApi, 'listSites').and.returnValue(Promise.resolve(fakeGetSitesAnswer)); - spyFavorite = spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue(Promise.resolve({ list: { entries: [] } })); + spyFavorite = spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue(Promise.resolve(new FavoritePaging({ list: { entries: [] } }))); }); afterEach(() => { @@ -871,7 +864,7 @@ describe('DocumentList', () => { it('should display folder content on click', () => { const node = new FolderNode(''); - spyOn(documentList, 'loadFolder').and.returnValue(Promise.resolve(true)); + spyOn(documentList, 'loadFolder').and.stub(); documentList.navigationMode = DocumentListComponent.SINGLE_CLICK_NAVIGATION; documentList.onNodeClick(node); @@ -1236,7 +1229,7 @@ describe('DocumentList', () => { }); it('should load folder by ID on init', async () => { - spyOn(documentList, 'loadFolder').and.returnValue(Promise.resolve()); + spyOn(documentList, 'loadFolder').and.stub(); fixture.detectChanges(); @@ -1328,7 +1321,7 @@ describe('DocumentList', () => { it('should allow to perform navigation for virtual sources', () => { spyFolderNode = spyOn(documentListService, 'loadFolderByNodeId').and.callFake(() => { - return of({ currentNode: {}, children: { list: { pagination: {} } } }); + return of(new DocumentLoaderNode(null, { list: { pagination: {} } })); }); const sources = ['-trashcan-', '-sharedlinks-', '-sites-', '-mysites-', '-favorites-', '-recent-']; diff --git a/lib/content-services/src/lib/document-list/services/custom-resources.service.spec.ts b/lib/content-services/src/lib/document-list/services/custom-resources.service.spec.ts index 4d7a114b67..de44b15bed 100644 --- a/lib/content-services/src/lib/document-list/services/custom-resources.service.spec.ts +++ b/lib/content-services/src/lib/document-list/services/custom-resources.service.spec.ts @@ -19,6 +19,7 @@ import { CustomResourcesService } from './custom-resources.service'; import { PaginationModel } from '@alfresco/adf-core'; import { TestBed } from '@angular/core/testing'; import { ContentTestingModule } from '../../testing/content.testing.module'; +import { FavoritePaging } from '@alfresco/js-api'; describe('CustomResourcesService', () => { let customResourcesService: CustomResourcesService; @@ -33,7 +34,7 @@ describe('CustomResourcesService', () => { describe('loadFavorites', () => { it('should return a list of items with default properties when target properties does not exist', (done) => { - spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue(Promise.resolve({ + spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue(Promise.resolve(new FavoritePaging({ list: { entries: [ { @@ -48,7 +49,7 @@ describe('CustomResourcesService', () => { } ] } - })); + }))); const pagination: PaginationModel = { maxItems: 100, skipCount: 0 @@ -72,7 +73,7 @@ describe('CustomResourcesService', () => { }); it('should return a list of items with merged properties when target properties exist', (done) => { - spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue(Promise.resolve({ + spyOn(customResourcesService.favoritesApi, 'listFavorites').and.returnValue(Promise.resolve(new FavoritePaging({ list: { entries: [ { @@ -90,7 +91,7 @@ describe('CustomResourcesService', () => { } ] } - })); + }))); const pagination: PaginationModel = { maxItems: 100, skipCount: 0 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 b960c80adb..dd1193d14e 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 @@ -69,7 +69,7 @@ export class DocumentListService implements DocumentListLoader { * @param targetParentId The id of the folder where the node will be moved * @returns NodeEntry for the moved node */ - moveNode(nodeId: string, targetParentId: string) { + moveNode(nodeId: string, targetParentId: string): Observable { return from(this.apiService.getInstance().nodes.moveNode(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 e02f305f94..f34e62f1ea 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 @@ -16,7 +16,7 @@ */ import { async, TestBed } from '@angular/core/testing'; -import { Node } from '@alfresco/js-api'; +import { Node, NodeEntry } from '@alfresco/js-api'; import { AppConfigService, setupTestBed } from '@alfresco/adf-core'; import { DocumentListService } from './document-list.service'; import { NodeActionsService } from './node-actions.service'; @@ -59,7 +59,7 @@ describe('NodeActionsService', () => { }); it('should be able to copy content', async(() => { - spyOn(documentListService, 'copyNode').and.returnValue(of('FAKE-OK')); + spyOn(documentListService, 'copyNode').and.returnValue(of(new NodeEntry())); spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode])); service.copyContent(fakeNode, 'allowed').subscribe((value) => { @@ -68,7 +68,7 @@ describe('NodeActionsService', () => { })); it('should be able to move content', async(() => { - spyOn(documentListService, 'moveNode').and.returnValue(of('FAKE-OK')); + spyOn(documentListService, 'moveNode').and.returnValue(of(new NodeEntry())); spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode])); service.moveContent(fakeNode, 'allowed').subscribe((value) => { @@ -77,7 +77,7 @@ describe('NodeActionsService', () => { })); it('should be able to move folder', async(() => { - spyOn(documentListService, 'moveNode').and.returnValue(of('FAKE-OK')); + spyOn(documentListService, 'moveNode').and.returnValue(of(new NodeEntry())); spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode])); service.moveFolder(fakeNode, 'allowed').subscribe((value) => { @@ -86,7 +86,7 @@ describe('NodeActionsService', () => { })); it('should be able to copy folder', async(() => { - spyOn(documentListService, 'copyNode').and.returnValue(of('FAKE-OK')); + spyOn(documentListService, 'copyNode').and.returnValue(of(new NodeEntry())); spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode])); service.copyFolder(fakeNode, 'allowed').subscribe((value) => { diff --git a/lib/content-services/src/lib/mock/search.component.mock.ts b/lib/content-services/src/lib/mock/search.component.mock.ts index a0d89a1e1d..385e4bffc6 100644 --- a/lib/content-services/src/lib/mock/search.component.mock.ts +++ b/lib/content-services/src/lib/mock/search.component.mock.ts @@ -17,7 +17,7 @@ import { Component, ViewChild } from '@angular/core'; import { SearchComponent } from '../search/components/search.component'; -import { QueryBody } from '@alfresco/js-api'; +import { QueryBody, ResultSetPaging } from '@alfresco/js-api'; const entryItem = { entry: { @@ -53,21 +53,21 @@ const entryDifferentItem = { } }; -export let result = { +export let result = new ResultSetPaging({ list: { entries: [ entryItem ] } -}; +}); -export let differentResult = { +export let differentResult = new ResultSetPaging({ list: { entries: [ entryDifferentItem ] } -}; +}); export let results = { list: { diff --git a/lib/content-services/src/lib/mock/sites-dropdown.component.mock.ts b/lib/content-services/src/lib/mock/sites-dropdown.component.mock.ts index e1a40657ae..ebd1165a2f 100644 --- a/lib/content-services/src/lib/mock/sites-dropdown.component.mock.ts +++ b/lib/content-services/src/lib/mock/sites-dropdown.component.mock.ts @@ -171,7 +171,7 @@ export function getFakeSitePagingLastPage(): SitePaging { } export function getFakeSitePagingWithMembers() { - return { + return new SitePaging({ 'list': { 'entries': [{ 'entry': { @@ -289,5 +289,5 @@ export function getFakeSitePagingWithMembers() { } ] } - }; + }); } 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 4e3897c21c..3474ec0735 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 @@ -42,9 +42,8 @@ describe('AddPermissionComponent', () => { beforeEach(() => { nodePermissionService = TestBed.inject(NodePermissionService); - spyOn(nodePermissionService, 'getNodeWithRoles').and.returnValue( - of({ node: { id: 'fake-node', allowableOperations: ['updatePermissions']}, roles: [{ label: 'Test' , role: 'test'}] }) - ); + const response: any = { node: { id: 'fake-node', allowableOperations: ['updatePermissions']}, roles: [{ label: 'Test' , role: 'test'}] }; + spyOn(nodePermissionService, 'getNodeWithRoles').and.returnValue(of(response)); fixture = TestBed.createComponent(AddPermissionComponent); element = fixture.nativeElement; fixture.detectChanges(); @@ -86,7 +85,7 @@ describe('AddPermissionComponent', () => { it('should emit a success event when the node is updated', async (done) => { fixture.componentInstance.selectedItems = fakeAuthorityResults; - spyOn(nodePermissionService, 'updateNodePermissions').and.returnValue(of({ id: 'fake-node-id'})); + spyOn(nodePermissionService, 'updateNodePermissions').and.returnValue(of(new Node({ id: 'fake-node-id'}))); fixture.componentInstance.success.subscribe((node) => { expect(node.id).toBe('fake-node-id'); @@ -101,7 +100,7 @@ describe('AddPermissionComponent', () => { it('should NOT emit a success event when the user does not have permission to update the node', () => { fixture.componentInstance.selectedItems = fakeAuthorityResults; fixture.componentInstance.currentNode = new Node({ id: 'fake-node-id' }); - spyOn(nodePermissionService, 'updateNodePermissions').and.returnValue(of({ id: 'fake-node-id' })); + spyOn(nodePermissionService, 'updateNodePermissions').and.returnValue(of(new Node({ id: 'fake-node-id' }))); const spySuccess = spyOn(fixture.componentInstance, 'success'); fixture.componentInstance.applySelection(); 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 bb4ddae164..52cd89d617 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 @@ -34,6 +34,7 @@ import { fakeSiteRoles } from '../../../mock/permission-list.component.mock'; import { ContentTestingModule } from '../../../testing/content.testing.module'; +import { MinimalNode } from '@alfresco/js-api'; describe('PermissionListComponent', () => { @@ -221,7 +222,7 @@ describe('PermissionListComponent', () => { }); it('should update the role when another value is chosen', async () => { - spyOn(nodeService, 'updateNode').and.returnValue(of({id: 'fake-uwpdated-node'})); + spyOn(nodeService, 'updateNode').and.returnValue(of(new MinimalNode({id: 'fake-uwpdated-node'}))); searchQuerySpy.and.returnValue(of(fakeEmptyResponse)); component.ngOnInit(); @@ -242,7 +243,7 @@ describe('PermissionListComponent', () => { }); it('should delete the person', async () => { - spyOn(nodeService, 'updateNode').and.returnValue(of({id: 'fake-uwpdated-node'})); + spyOn(nodeService, 'updateNode').and.returnValue(of(new MinimalNode({id: 'fake-uwpdated-node'}))); searchQuerySpy.and.returnValue(of(fakeEmptyResponse)); component.ngOnInit(); await fixture.detectChanges(); diff --git a/lib/content-services/src/lib/permission-manager/services/node-permission-dialog.service.spec.ts b/lib/content-services/src/lib/permission-manager/services/node-permission-dialog.service.spec.ts index b1c4cea9fe..665a47d7de 100644 --- a/lib/content-services/src/lib/permission-manager/services/node-permission-dialog.service.spec.ts +++ b/lib/content-services/src/lib/permission-manager/services/node-permission-dialog.service.spec.ts @@ -53,7 +53,7 @@ describe('NodePermissionDialogService', () => { componentInstance: { error: new Subject() } - }); + } as any); }); describe('when node has permission to update permissions', () => { @@ -70,8 +70,8 @@ describe('NodePermissionDialogService', () => { }); it('should return the updated node', (done) => { - spyOn(nodePermissionService, 'updateNodePermissions').and.returnValue(of({id : 'fake-node-updated'})); - spyOn(service, 'openAddPermissionDialog').and.returnValue(of({})); + spyOn(nodePermissionService, 'updateNodePermissions').and.returnValue(of(new Node({id : 'fake-node-updated'}))); + spyOn(service, 'openAddPermissionDialog').and.returnValue(of(null)); spyOn(nodePermissionService, 'getNodeWithRoles').and.returnValue(of({ node: fakePermissionNode, roles: [] })); service.updateNodePermissionByDialog('fake-node-id', 'fake-title').subscribe((node) => { expect(node.id).toBe('fake-node-updated'); @@ -81,7 +81,7 @@ describe('NodePermissionDialogService', () => { it('should throw an error if the update of the node fails', (done) => { spyOn(nodePermissionService, 'updateNodePermissions').and.returnValue(throwError({error : 'error'})); - spyOn(service, 'openAddPermissionDialog').and.returnValue(of({})); + spyOn(service, 'openAddPermissionDialog').and.returnValue(of(null)); spyOn(nodePermissionService, 'getNodeWithRoles').and.returnValue(of({ node: fakePermissionNode, roles: [] })); service.updateNodePermissionByDialog('fake-node-id', 'fake-title').subscribe(() => { throwError('This call should fail'); 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 3b83c43de8..d1c6ad6edf 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 @@ -84,7 +84,7 @@ describe('SearchControlComponent', () => { component = fixture.componentInstance; element = fixture.nativeElement; - searchServiceSpy = spyOn(searchService, 'search').and.returnValue(of('')); + searchServiceSpy = spyOn(searchService, 'search').and.returnValue(of(null)); fixture.detectChanges(); }); diff --git a/lib/content-services/src/lib/search/components/search-filter-container/search-filter-container.component.spec.ts b/lib/content-services/src/lib/search/components/search-filter-container/search-filter-container.component.spec.ts index 64223becfe..de259e60f3 100644 --- a/lib/content-services/src/lib/search/components/search-filter-container/search-filter-container.component.spec.ts +++ b/lib/content-services/src/lib/search/components/search-filter-container/search-filter-container.component.spec.ts @@ -115,7 +115,7 @@ describe('SearchFilterContainerComponent', () => { it('should emit filterChange after the Apply button is clicked', async (done) => { spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(Promise.resolve(fakeNodePaging)); - spyOn(queryBuilder, 'buildQuery').and.returnValue({}); + spyOn(queryBuilder, 'buildQuery').and.returnValue(null); component.filterChange.subscribe(() => { done(); }); @@ -147,7 +147,7 @@ describe('SearchFilterContainerComponent', () => { it('should emit filterChange after the Clear button is clicked', async (done) => { spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(Promise.resolve(fakeNodePaging)); - spyOn(queryBuilder, 'buildQuery').and.returnValue({}); + spyOn(queryBuilder, 'buildQuery').and.returnValue(null); component.filterChange.subscribe(() => { done(); }); @@ -164,7 +164,7 @@ describe('SearchFilterContainerComponent', () => { }); it('should emit filterChange after the Enter key is pressed', async (done) => { - spyOn(queryBuilder, 'buildQuery').and.returnValue({}); + spyOn(queryBuilder, 'buildQuery').and.returnValue(null); component.filterChange.subscribe(() => { done(); }); diff --git a/lib/content-services/src/lib/tree-view/services/tree-view.service.spec.ts b/lib/content-services/src/lib/tree-view/services/tree-view.service.spec.ts index 2b3b13e21a..bba011375d 100644 --- a/lib/content-services/src/lib/tree-view/services/tree-view.service.spec.ts +++ b/lib/content-services/src/lib/tree-view/services/tree-view.service.spec.ts @@ -22,20 +22,21 @@ import { ContentTestingModule } from '../../testing/content.testing.module'; import { of } from 'rxjs'; import { TreeBaseNode } from '../models/tree-view.model'; import { TranslateModule } from '@ngx-translate/core'; +import { NodePaging } from '@alfresco/js-api'; describe('TreeViewService', () => { let service: TreeViewService; let nodeService: NodesApiService; - const fakeNodeList = { list: { entries: [ + const fakeNodeList = new NodePaging({ list: { entries: [ { entry: { id: 'fake-node-id', name: 'fake-node-name', isFolder: true } } - ] } }; + ] } }); - const fakeMixedNodeList = { list: { entries: [ + const fakeMixedNodeList = new NodePaging({ list: { entries: [ { entry: { id: 'fake-node-id', name: 'fake-node-name', isFolder: true } }, { entry: { id: 'fake-file-id', name: 'fake-file-name', isFolder: false } } - ] } }; + ] } }); setupTestBed({ imports: [ diff --git a/lib/content-services/src/lib/version-manager/version-list.component.spec.ts b/lib/content-services/src/lib/version-manager/version-list.component.spec.ts index d012c026f4..db7181b274 100644 --- a/lib/content-services/src/lib/version-manager/version-list.component.spec.ts +++ b/lib/content-services/src/lib/version-manager/version-list.component.spec.ts @@ -77,7 +77,7 @@ describe('VersionListComponent', () => { afterClosed() { return of(false); } - }); + } as any); component.deleteVersion('1'); @@ -91,7 +91,7 @@ describe('VersionListComponent', () => { afterClosed() { return of(true); } - }); + } as any); spyOn(alfrescoApiService.versionsApi, 'deleteVersion').and.returnValue(Promise.resolve(true)); @@ -108,7 +108,7 @@ describe('VersionListComponent', () => { afterClosed() { return of(false); } - }); + } as any); spyOn(alfrescoApiService.versionsApi, 'deleteVersion').and.returnValue(Promise.resolve(true)); @@ -157,7 +157,7 @@ describe('VersionListComponent', () => { it('should show the versions after loading', (done) => { fixture.detectChanges(); spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.callFake(() => { - return Promise.resolve({ + return Promise.resolve(new VersionPaging({ list: { entries: [ { @@ -165,7 +165,7 @@ describe('VersionListComponent', () => { } ] } - }); + })); }); component.ngOnChanges(); @@ -186,7 +186,7 @@ describe('VersionListComponent', () => { it('should NOT show the versions comments if input property is set not to show them', (done) => { spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and .callFake(() => Promise.resolve( - { + new VersionPaging({ list: { entries: [ { @@ -194,7 +194,7 @@ describe('VersionListComponent', () => { } ] } - } + }) )); component.showComments = false; @@ -219,7 +219,7 @@ describe('VersionListComponent', () => { versionComment: 'test-version-comment' } }; - spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.returnValue(Promise.resolve({ list: { entries: [versionEntry] } })); + spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and.returnValue(Promise.resolve(new VersionPaging({ list: { entries: [versionEntry] } }))); spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.returnValue('the/download/url'); fixture.detectChanges(); @@ -329,7 +329,7 @@ describe('VersionListComponent', () => { const spyOnListVersionHistory = spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and .callFake(() => Promise.resolve({ list: { entries: versionTest } })); - spyOn(alfrescoApiService.versionsApi, 'revertVersion').and.callFake(() => Promise.resolve()); + spyOn(alfrescoApiService.versionsApi, 'revertVersion').and.callFake(() => Promise.resolve(null)); component.restore(versionId); fixture.detectChanges(); 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 3423413842..a7820a6520 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 @@ -19,7 +19,7 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { AlfrescoApiService, setupTestBed } from '@alfresco/adf-core'; -import { Node } from '@alfresco/js-api'; +import { Node, VersionPaging } from '@alfresco/js-api'; import { VersionManagerComponent } from './version-manager.component'; import { ContentTestingModule } from '../testing/content.testing.module'; import { TranslateModule } from '@ngx-translate/core'; @@ -59,7 +59,7 @@ describe('VersionManagerComponent', () => { alfrescoApiService = TestBed.inject(AlfrescoApiService); spyOnListVersionHistory = spyOn(alfrescoApiService.versionsApi, 'listVersionHistory').and - .callFake(() => Promise.resolve({ list: { entries: [ versionEntry ] }})); + .callFake(() => Promise.resolve(new VersionPaging({ list: { entries: [ versionEntry ] }}))); }); it('should load the versions for a given node', () => { diff --git a/lib/core/about/about.mock.ts b/lib/core/about/about.mock.ts index 949f6fa1c8..913b56273f 100644 --- a/lib/core/about/about.mock.ts +++ b/lib/core/about/about.mock.ts @@ -58,7 +58,7 @@ export const aboutAPSMockDetails = { minorVersion: '10' }; -export const mockModules = { +export const mockModules: any = { edition: 'Enterprise', version: { major: '6', diff --git a/lib/core/card-view/components/card-view-textitem/card-view-textitem.component.spec.ts b/lib/core/card-view/components/card-view-textitem/card-view-textitem.component.spec.ts index 6e6145ed30..0e401ab20d 100644 --- a/lib/core/card-view/components/card-view-textitem/card-view-textitem.component.spec.ts +++ b/lib/core/card-view/components/card-view-textitem/card-view-textitem.component.spec.ts @@ -62,6 +62,7 @@ describe('CardViewTextItemComponent', () => { editable: false }); component.ngOnChanges({ property: new SimpleChange(null, null, true) }); + fixture.detectChanges(); }); it('should render the label and value', async () => { @@ -256,6 +257,7 @@ describe('CardViewTextItemComponent', () => { editable: false }); component.ngOnChanges({ property: new SimpleChange(null, null, true) }); + fixture.detectChanges(); }); it('should render the default as value if the value is empty, clickable is false and displayEmpty is true', (done) => { @@ -468,6 +470,7 @@ describe('CardViewTextItemComponent', () => { editable: true }); component.ngOnChanges({ property: new SimpleChange(null, null, true) }); + fixture.detectChanges(); }); it('should call the isValid method with the edited value', fakeAsync((done) => { @@ -563,7 +566,7 @@ describe('CardViewTextItemComponent', () => { }); })); - it('should reset erros when exiting editable mode', fakeAsync((done) => { + it('should reset erros when exiting editable mode', fakeAsync(() => { let errorMessage: string; const expectedErrorMessages = [{ message: 'Something went wrong' } as CardViewItemValidator]; component.property.isValid = () => false; @@ -584,7 +587,6 @@ describe('CardViewTextItemComponent', () => { errorMessage = fixture.debugElement.nativeElement.querySelector('.adf-textitem-editable-error'); expect(errorMessage).toBe(null); expect(component.errors).toEqual([]); - done(); }); }); })); @@ -620,7 +622,7 @@ describe('CardViewTextItemComponent', () => { inputField.nativeElement.click(); })); - it('should trigger an update event on the CardViewUpdateService [integration]', fakeAsync((done) => { + it('should trigger an update event on the CardViewUpdateService [integration]', (done) => { component.property.isValid = () => true; const cardViewUpdateService = TestBed.inject(CardViewUpdateService); const expectedText = 'changed text'; @@ -639,7 +641,7 @@ describe('CardViewTextItemComponent', () => { updateTextField(component.property.key, expectedText); }); - })); + }); it('should update the value using the updateItem$ subject', (async () => { component.property.isValid = () => true; @@ -664,7 +666,7 @@ describe('CardViewTextItemComponent', () => { })); - it('should update multiline input the value on input updated', fakeAsync((done) => { + it('should update multiline input the value on input updated', (done) => { component.property.isValid = () => true; component.property.multiline = true; const expectedText = 'changed text'; @@ -693,7 +695,7 @@ describe('CardViewTextItemComponent', () => { expect(component.property.value).toBe(expectedText); }); }); - })); + }); }); describe('number', () => { @@ -711,6 +713,7 @@ describe('CardViewTextItemComponent', () => { component.editable = true; component.property.validators.push(new CardViewItemIntValidator()); component.ngOnChanges({ property: new SimpleChange(null, null, true) }); + fixture.detectChanges(); }); it('should show validation error when string passed', fakeAsync((done) => { @@ -793,7 +796,7 @@ describe('CardViewTextItemComponent', () => { }); })); - it('should update input the value on input updated', fakeAsync((done) => { + it('should update input the value on input updated', (done) => { const expectedNumber = 2020; spyOn(component, 'update').and.callThrough(); fixture.detectChanges(); @@ -817,7 +820,7 @@ describe('CardViewTextItemComponent', () => { expect(component.property.value).toBe(expectedNumber.toString()); }); }); - })); + }); }); describe('float', () => { @@ -830,12 +833,13 @@ describe('CardViewTextItemComponent', () => { label: 'Text label', value: floatValue, key: 'textkey', - default: 'FAKE-DEFAULT-KEY', + default: 1, editable: true }); component.editable = true; component.property.validators.push(new CardViewItemFloatValidator()); component.ngOnChanges({ property: new SimpleChange(null, null, true) }); + fixture.detectChanges(); }); it('should show validation error when string passed', fakeAsync((done) => { @@ -854,7 +858,7 @@ describe('CardViewTextItemComponent', () => { }); })); - it('should show validation error for empty string', fakeAsync((done) => { + it('should show validation error for empty string (float)', fakeAsync((done) => { fixture.detectChanges(); fixture.whenStable().then(() => { @@ -870,7 +874,7 @@ describe('CardViewTextItemComponent', () => { }); })); - it('should update input the value on input updated', fakeAsync((done) => { + it('should update input the value on input updated', (done) => { const expectedNumber = 88.44; spyOn(component, 'update').and.callThrough(); fixture.detectChanges(); @@ -894,7 +898,7 @@ describe('CardViewTextItemComponent', () => { expect(component.property.value).toBe(expectedNumber.toString()); }); }); - })); + }); }); function updateTextField(key, value) { diff --git a/lib/core/comments/comments.component.spec.ts b/lib/core/comments/comments.component.spec.ts index 555259ad9d..1bcca94002 100644 --- a/lib/core/comments/comments.component.spec.ts +++ b/lib/core/comments/comments.component.spec.ts @@ -24,6 +24,7 @@ import { CommentContentService } from '../services/comment-content.service'; import { setupTestBed } from '../testing/setup-test-bed'; import { CoreTestingModule } from '../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; +import { CommentModel } from '../models/comment.model'; describe('CommentsComponent', () => { @@ -51,28 +52,28 @@ describe('CommentsComponent', () => { commentProcessService = fixture.debugElement.injector.get(CommentProcessService); commentContentService = fixture.debugElement.injector.get(CommentContentService); - addContentCommentSpy = spyOn(commentContentService, 'addNodeComment').and.returnValue(of({ + addContentCommentSpy = spyOn(commentContentService, 'addNodeComment').and.returnValue(of(new CommentModel({ id: 123, message: 'Test Comment', createdBy: {id: '999'} - })); + }))); getContentCommentsSpy = spyOn(commentContentService, 'getNodeComments').and.returnValue(of([ - {message: 'Test1', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}, - {message: 'Test2', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}, - {message: 'Test3', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}} + new CommentModel({message: 'Test1', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}), + new CommentModel({message: 'Test2', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}), + new CommentModel({message: 'Test3', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}) ])); getProcessCommentsSpy = spyOn(commentProcessService, 'getTaskComments').and.returnValue(of([ - {message: 'Test1', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}, - {message: 'Test2', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}, - {message: 'Test3', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}} + new CommentModel({message: 'Test1', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}), + new CommentModel({message: 'Test2', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}), + new CommentModel({message: 'Test3', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}) ])); - addProcessCommentSpy = spyOn(commentProcessService, 'addTaskComment').and.returnValue(of({ + addProcessCommentSpy = spyOn(commentProcessService, 'addTaskComment').and.returnValue(of(new CommentModel({ id: 123, message: 'Test Comment', createdBy: {id: '999'} - })); + }))); }); afterEach(() => { diff --git a/lib/core/directives/node-download.directive.spec.ts b/lib/core/directives/node-download.directive.spec.ts index f1575ff875..a01d1c62dc 100755 --- a/lib/core/directives/node-download.directive.spec.ts +++ b/lib/core/directives/node-download.directive.spec.ts @@ -41,7 +41,7 @@ describe('NodeDownloadDirective', () => { let apiService: AlfrescoApiService; let contentService; let dialogSpy; - const mockOauth2Auth = { + const mockOauth2Auth: any = { oauth2Auth: { callCustomApi: () => Promise.resolve() }, @@ -159,7 +159,7 @@ describe('NodeDownloadDirective', () => { }); it('should create link element to download file node', () => { - const dummyLinkElement = { + const dummyLinkElement: any = { download: null, href: null, click: () => null, diff --git a/lib/core/directives/node-favorite.directive.spec.ts b/lib/core/directives/node-favorite.directive.spec.ts index 109db075e8..dbef29872e 100644 --- a/lib/core/directives/node-favorite.directive.spec.ts +++ b/lib/core/directives/node-favorite.directive.spec.ts @@ -72,7 +72,7 @@ describe('NodeFavoriteDirective', () => { }); it('should reset favorites if selection is empty', fakeAsync(() => { - spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve()); + spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve(null)); const selection = [ { entry: { id: '1', name: 'name1' } } @@ -97,7 +97,7 @@ describe('NodeFavoriteDirective', () => { beforeEach(() => { favoritesApiSpy = spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite') - .and.returnValue(Promise.resolve()); + .and.returnValue(Promise.resolve(null)); }); it('should check each selected node if it is a favorite', fakeAsync(() => { @@ -341,7 +341,7 @@ describe('NodeFavoriteDirective', () => { })); it('should process node as favorite', fakeAsync(() => { - spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve()); + spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve(null)); const selection = [ { entry: { id: '1', name: 'name1' } } diff --git a/lib/core/directives/upload.directive.spec.ts b/lib/core/directives/upload.directive.spec.ts index 4937774135..4d7743dbe2 100644 --- a/lib/core/directives/upload.directive.spec.ts +++ b/lib/core/directives/upload.directive.spec.ts @@ -110,7 +110,7 @@ describe('UploadDirective', () => { it('should raise upload-files event on files drop', (done) => { directive.enabled = true; const event = jasmine.createSpyObj('event', ['preventDefault', 'stopPropagation']); - spyOn(directive, 'getDataTransfer').and.returnValue({}); + spyOn(directive, 'getDataTransfer').and.returnValue({} as any); spyOn(directive, 'getFilesDropped').and.returnValue(Promise.resolve([ {}, {} @@ -127,7 +127,7 @@ describe('UploadDirective', () => { {} ]; const event = jasmine.createSpyObj('event', ['preventDefault', 'stopPropagation']); - spyOn(directive, 'getDataTransfer').and.returnValue({}); + spyOn(directive, 'getDataTransfer').and.returnValue({} as any); spyOn(directive, 'getFilesDropped').and.returnValue(Promise.resolve(files)); spyOn(nativeElement, 'dispatchEvent').and.callFake((e) => { diff --git a/lib/core/directives/version-compatibility.directive.spec.ts b/lib/core/directives/version-compatibility.directive.spec.ts index 120c973a1d..7cd3c7dc55 100644 --- a/lib/core/directives/version-compatibility.directive.spec.ts +++ b/lib/core/directives/version-compatibility.directive.spec.ts @@ -22,6 +22,7 @@ import { TestBed, ComponentFixture } from '@angular/core/testing'; import { setupTestBed } from '../testing/setup-test-bed'; import { CoreTestingModule } from '../testing/core.testing.module'; import { VersionCompatibilityService } from '../services/version-compatibility.service'; +import { VersionModel } from '../models/product-version.model'; @Component({ template: ` @@ -51,12 +52,12 @@ describe('VersionCompatibilityDirective', () => { let fixture: ComponentFixture; let versionCompatibilityService: VersionCompatibilityService; - const acsResponceMock = { + const acsResponceMock = new VersionModel({ display: '7.0.1', major: '7', minor: '0', patch: '1' - }; + }); setupTestBed({ imports: [ 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 58ab09ac65..b7410ef678 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 @@ -129,7 +129,7 @@ describe('RadioButtonsWidgetComponent', () => { }); it('should update the field value when an option is selected', () => { - spyOn(widget, 'onFieldChanged').and.returnValue(of({})); + spyOn(widget, 'onFieldChanged').and.stub(); widget.onOptionClick('fake-opt'); expect(widget.field.value).toEqual('fake-opt'); 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 ea53721a8c..623b0b2974 100644 --- a/lib/core/form/components/widgets/upload/upload.widget.spec.ts +++ b/lib/core/form/components/widgets/upload/upload.widget.spec.ts @@ -28,8 +28,9 @@ import { UploadWidgetComponent } from './upload.widget'; import { setupTestBed } from '../../../../testing/setup-test-bed'; import { CoreTestingModule } from '../../../../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; +import { RelatedContentRepresentation } from '@alfresco/js-api'; -const fakePngAnswer = { +const fakePngAnswer = new RelatedContentRepresentation({ 'id': 1155, 'name': 'a_png_file.png', 'created': '2017-07-25T17:17:37.099Z', @@ -41,7 +42,7 @@ const fakePngAnswer = { 'simpleType': 'image', 'previewStatus': 'queued', 'thumbnailStatus': 'queued' -}; +}); const fakeJpgAnswer = { 'id': 1156, @@ -211,7 +212,7 @@ describe('UploadWidgetComponent', () => { return of(fakeJpgAnswer); } - return of(); + return of(null); }); uploadWidgetComponent.field.params.multiple = true; @@ -241,7 +242,7 @@ describe('UploadWidgetComponent', () => { return of(fakeJpgAnswer); } - return of(); + return of(null); }); uploadWidgetComponent.field.params.multiple = true; diff --git a/lib/core/form/services/form.service.spec.ts b/lib/core/form/services/form.service.spec.ts index 1c08c96d7b..886bb79211 100644 --- a/lib/core/form/services/form.service.spec.ts +++ b/lib/core/form/services/form.service.spec.ts @@ -233,7 +233,7 @@ describe('Form service', () => { activiti: { processApi: processApiSpy } - }); + } as any); processApiSpy.getProcessDefinitionStartForm.and.returnValue(Promise.resolve({ id: '1' })); service.getStartFormDefinition('myprocess:1').subscribe(() => { diff --git a/lib/core/layout/components/sidenav-layout/sidenav-layout.component.spec.ts b/lib/core/layout/components/sidenav-layout/sidenav-layout.component.spec.ts index 95d94a92f2..7f77e0a40e 100644 --- a/lib/core/layout/components/sidenav-layout/sidenav-layout.component.spec.ts +++ b/lib/core/layout/components/sidenav-layout/sidenav-layout.component.spec.ts @@ -228,13 +228,13 @@ describe('SidenavLayoutComponent', () => { describe('Template transclusion', () => { - let fixture: ComponentFixture, - mediaMatcher: MediaMatcher; - const mediaQueryList = { + let fixture: ComponentFixture; + let mediaMatcher: MediaMatcher; + const mediaQueryList: any = { matches: false, addListener: () => {}, removeListener: () => {} - }; + }; setupTestBed({ imports: [ diff --git a/lib/core/login/components/login.component.spec.ts b/lib/core/login/components/login.component.spec.ts index e7bd3ef934..e530666868 100644 --- a/lib/core/login/components/login.component.spec.ts +++ b/lib/core/login/components/login.component.spec.ts @@ -25,7 +25,7 @@ import { AuthenticationService } from '../../services/authentication.service'; import { LoginErrorEvent } from '../models/login-error.event'; import { LoginSuccessEvent } from '../models/login-success.event'; import { LoginComponent } from './login.component'; -import { of, throwError, Observable } from 'rxjs'; +import { of, throwError } from 'rxjs'; import { OauthConfigModel } from '../../models/oauth-config.model'; import { AlfrescoApiService } from '../../services/alfresco-api.service'; @@ -177,12 +177,7 @@ describe('LoginComponent', () => { it('should update user preferences upon login', async(() => { spyOn(userPreferences, 'setStoragePrefix').and.callThrough(); - spyOn(alfrescoApiService.getInstance(), 'login').and.callFake(() => { - return new Observable((observer) => { - observer.next(); - observer.complete(); - }); - }); + spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.resolve()); component.success.subscribe(() => { expect(userPreferences.setStoragePrefix).toHaveBeenCalledWith('fake-username'); @@ -202,10 +197,7 @@ describe('LoginComponent', () => { }); it('should be changed to the "checking key" after a login attempt', () => { - spyOn(authService, 'login').and.returnValue({ - subscribe: () => { - } - }); + spyOn(authService, 'login').and.stub(); loginWithCredentials('fake-username', 'fake-password'); @@ -247,10 +239,7 @@ describe('LoginComponent', () => { }); it('should be taken into consideration during login attempt', () => { - spyOn(authService, 'login').and.returnValue({ - subscribe: () => { - } - }); + spyOn(authService, 'login').and.stub(); component.rememberMe = false; loginWithCredentials('fake-username', 'fake-password'); @@ -409,12 +398,7 @@ describe('LoginComponent', () => { }); it('should return error with a wrong username', (done) => { - spyOn(alfrescoApiService.getInstance(), 'login').and.callFake(() => { - return new Observable((observer) => { - observer.next(); - observer.error(); - }); - }); + spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject()); component.error.subscribe(() => { fixture.detectChanges(); @@ -429,12 +413,7 @@ describe('LoginComponent', () => { }); it('should return error with a wrong password', (done) => { - spyOn(alfrescoApiService.getInstance(), 'login').and.callFake(() => { - return new Observable((observer) => { - observer.next(); - observer.error(); - }); - }); + spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject()); component.error.subscribe(() => { fixture.detectChanges(); @@ -450,12 +429,7 @@ describe('LoginComponent', () => { }); it('should return error with a wrong username and password', (done) => { - spyOn(alfrescoApiService.getInstance(), 'login').and.callFake(() => { - return new Observable((observer) => { - observer.next(); - observer.error(); - }); - }); + spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject()); component.error.subscribe(() => { fixture.detectChanges(); @@ -623,12 +597,7 @@ describe('LoginComponent', () => { }); it('should emit only the username and not the password as part of the executeSubmit', async(() => { - spyOn(alfrescoApiService.getInstance(), 'login').and.callFake(() => { - return new Observable((observer) => { - observer.next(); - observer.complete(); - }); - }); + spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.resolve()); component.executeSubmit.subscribe((res) => { fixture.detectChanges(); @@ -668,7 +637,7 @@ describe('LoginComponent', () => { spyOn(authService, 'isOauth').and.returnValue(true); appConfigService.config.oauth2 = { implicitFlow: true, silentLogin: true }; - spyOn(component, 'redirectToImplicitLogin').and.returnValue(Promise.resolve({})); + spyOn(component, 'redirectToImplicitLogin').and.stub(); component.ngOnInit(); fixture.detectChanges(); diff --git a/lib/core/mock/bpm-user.service.mock.ts b/lib/core/mock/bpm-user.service.mock.ts index ad58bfaad4..52c8236a7f 100644 --- a/lib/core/mock/bpm-user.service.mock.ts +++ b/lib/core/mock/bpm-user.service.mock.ts @@ -15,6 +15,8 @@ * limitations under the License. */ +import { BpmUserModel } from '../models'; + export let fakeBpmUserNoImage = { apps: [], capabilities: 'fake-capability', @@ -37,7 +39,7 @@ export let fakeBpmUserNoImage = { type: 'fake-type' }; -export let fakeBpmUser = { +export let fakeBpmUser = new BpmUserModel({ apps: [], capabilities: null, company: 'fake-company', @@ -57,7 +59,7 @@ export let fakeBpmUser = { tenantName: 'fake-tenant-name', tenantPictureId: 'fake-tenant-picture-id', type: 'fake-type' -}; +}); export let fakeBpmEditedUser = { apps: [], diff --git a/lib/core/mock/ecm-user.service.mock.ts b/lib/core/mock/ecm-user.service.mock.ts index f87f649086..deccb1ceee 100644 --- a/lib/core/mock/ecm-user.service.mock.ts +++ b/lib/core/mock/ecm-user.service.mock.ts @@ -16,7 +16,8 @@ */ import { EcmCompanyModel } from '../models/ecm-company.model'; -import { PersonEntry, Person } from '@alfresco/js-api'; +import { PersonEntry, Person, PersonPaging } from '@alfresco/js-api'; +import { EcmUserModel } from '../models'; export const fakeEcmCompany: EcmCompanyModel = { organization: 'company-fake-name', @@ -29,7 +30,7 @@ export const fakeEcmCompany: EcmCompanyModel = { email: 'fakeCompany@fake.com' }; -export const fakeEcmUser = { +export const fakeEcmUser = new EcmUserModel({ id: 'fake-id', firstName: 'fake-ecm-first-name', lastName: 'fake-ecm-last-name', @@ -48,7 +49,7 @@ export const fakeEcmUser = { userStatus: 'active', enabled: true, emailNotificationsEnabled: true -}; +}); export const fakeEcmUser2 = { id: 'another-fake-id', @@ -103,7 +104,7 @@ export const fakeEcmEditedUser = { emailNotificationsEnabled: true }; -export const fakeEcmUserList = { +export const fakeEcmUserList = new PersonPaging({ list: { pagination: { count: 2, @@ -121,7 +122,7 @@ export const fakeEcmUserList = { } ] } -}; +}); export const createNewPersonMock = { id: 'fake-id', diff --git a/lib/core/mock/identity-group.service.mock.ts b/lib/core/mock/identity-group.service.mock.ts index 20ffb684b2..139a075498 100644 --- a/lib/core/mock/identity-group.service.mock.ts +++ b/lib/core/mock/identity-group.service.mock.ts @@ -50,7 +50,7 @@ export const roleMappingMock = [ { id: 'role-id-1', name: 'role-name-1' }, { id: 'role-id-2', name: 'role-name-2' } ]; -export const roleMappingApi = { +export const roleMappingApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(roleMappingMock); @@ -58,7 +58,7 @@ export const roleMappingApi = { } }; -export const noRoleMappingApi = { +export const noRoleMappingApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve([]); @@ -66,7 +66,7 @@ export const noRoleMappingApi = { } }; -export const groupsMockApi = { +export const groupsMockApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(mockIdentityGroups); @@ -74,7 +74,7 @@ export const groupsMockApi = { } }; -export const createGroupMappingApi = { +export const createGroupMappingApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(); @@ -82,7 +82,7 @@ export const createGroupMappingApi = { } }; -export const updateGroupMappingApi = { +export const updateGroupMappingApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(); @@ -90,7 +90,7 @@ export const updateGroupMappingApi = { } }; -export const deleteGroupMappingApi = { +export const deleteGroupMappingApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(); @@ -98,7 +98,7 @@ export const deleteGroupMappingApi = { } }; -export const applicationDetailsMockApi = { +export const applicationDetailsMockApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve([mockApplicationDetails]); @@ -112,4 +112,7 @@ export const mockIdentityRoles = [ new IdentityRoleModel({id: 'mock-role-id', name: 'MOCK-ROLE-1'}) ]; -export const clientRoles = [ 'MOCK-ADMIN-ROLE', 'MOCK-USER-ROLE']; +export const clientRoles: IdentityRoleModel[] = [ + new IdentityRoleModel({ name: 'MOCK-ADMIN-ROLE' }), + new IdentityRoleModel({ name: 'MOCK-USER-ROLE' }) +]; diff --git a/lib/core/mock/identity-user.service.mock.ts b/lib/core/mock/identity-user.service.mock.ts index 495d43f58c..b6203df2e2 100644 --- a/lib/core/mock/identity-user.service.mock.ts +++ b/lib/core/mock/identity-user.service.mock.ts @@ -70,7 +70,7 @@ export const mockGroups = [ { id: 'mock-group-id-2', name: 'Mock Group 2', path: '', subGroups: [] } ]; -export const queryUsersMockApi = { +export const queryUsersMockApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(mockIdentityUsers); @@ -78,7 +78,7 @@ export const queryUsersMockApi = { } }; -export const createUserMockApi = { +export const createUserMockApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(); @@ -86,7 +86,7 @@ export const createUserMockApi = { } }; -export const updateUserMockApi = { +export const updateUserMockApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(); @@ -94,7 +94,7 @@ export const updateUserMockApi = { } }; -export const deleteUserMockApi = { +export const deleteUserMockApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(); @@ -102,7 +102,7 @@ export const deleteUserMockApi = { } }; -export const getInvolvedGroupsMockApi = { +export const getInvolvedGroupsMockApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(mockGroups); @@ -110,7 +110,7 @@ export const getInvolvedGroupsMockApi = { } }; -export const joinGroupMockApi = { +export const joinGroupMockApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(); @@ -118,7 +118,7 @@ export const joinGroupMockApi = { } }; -export const leaveGroupMockApi = { +export const leaveGroupMockApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(); @@ -126,7 +126,7 @@ export const leaveGroupMockApi = { } }; -export const getAvailableRolesMockApi = { +export const getAvailableRolesMockApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(mockAvailableRoles); @@ -134,7 +134,7 @@ export const getAvailableRolesMockApi = { } }; -export const getAssignedRolesMockApi = { +export const getAssignedRolesMockApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(mockAssignedRoles); @@ -142,7 +142,7 @@ export const getAssignedRolesMockApi = { } }; -export const getEffectiveRolesMockApi = { +export const getEffectiveRolesMockApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(mockEffectiveRoles); @@ -150,7 +150,7 @@ export const getEffectiveRolesMockApi = { } }; -export const assignRolesMockApi = { +export const assignRolesMockApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(); @@ -158,7 +158,7 @@ export const assignRolesMockApi = { } }; -export const removeRolesMockApi = { +export const removeRolesMockApi: any = { oauth2Auth: { callCustomApi: () => { return Promise.resolve(); diff --git a/lib/core/mock/search.service.mock.ts b/lib/core/mock/search.service.mock.ts index e3fbcc494c..3c6adebd14 100644 --- a/lib/core/mock/search.service.mock.ts +++ b/lib/core/mock/search.service.mock.ts @@ -54,7 +54,7 @@ export let mockError = { } }; -export let searchMockApi = { +export let searchMockApi: any = { core: { queriesApi: { findNodes: () => Promise.resolve(fakeSearch) diff --git a/lib/core/services/discovery-api.service.spec.ts b/lib/core/services/discovery-api.service.spec.ts index e91e029d95..6d9e0c1421 100644 --- a/lib/core/services/discovery-api.service.spec.ts +++ b/lib/core/services/discovery-api.service.spec.ts @@ -22,11 +22,11 @@ import { AlfrescoApiService } from './alfresco-api.service'; import { AuthenticationService } from './authentication.service'; import { setupTestBed } from '../testing/setup-test-bed'; import { CoreTestingModule } from '../testing/core.testing.module'; -import { SystemPropertiesRepresentation } from '@alfresco/js-api'; +import { DiscoveryEntry, SystemPropertiesRepresentation } from '@alfresco/js-api'; import { TranslateModule } from '@ngx-translate/core'; -import { of, throwError } from 'rxjs'; +import { of } from 'rxjs'; -const fakeEcmDiscoveryResponse: any = { +const fakeEcmDiscoveryResponse = new DiscoveryEntry({ entry: { repository: { edition: 'FAKE', @@ -79,7 +79,7 @@ const fakeEcmDiscoveryResponse: any = { ] } } -}; +}); const fakeBPMDiscoveryResponse: any = { revisionVersion: '2', @@ -89,7 +89,7 @@ const fakeBPMDiscoveryResponse: any = { minorVersion: '6' }; -const fakeBPMDiscoverySystemPropertyResponse: any = { +const fakeBPMDiscoverySystemPropertyResponse = new SystemPropertiesRepresentation({ allowInvolveByEmail: true, disableJavaScriptEventsInFormEditor: false, logoutDisabled: false, @@ -99,7 +99,7 @@ const fakeBPMDiscoverySystemPropertyResponse: any = { clientId: 'fakeClient', useBrowserLogout: true } -}; +}); describe('Discovery Api Service', () => { let service: DiscoveryApiService; @@ -119,7 +119,7 @@ describe('Discovery Api Service', () => { describe('For ECM', () => { it('Should retrieve the info about the product for ECM', done => { spyOn(apiService.getInstance().discovery.discoveryApi, 'getRepositoryInformation') - .and.returnValue(of(fakeEcmDiscoveryResponse)); + .and.returnValue(Promise.resolve(fakeEcmDiscoveryResponse)); service.getEcmProductInfo() .subscribe((data: EcmProductVersionModel) => { @@ -137,7 +137,7 @@ describe('Discovery Api Service', () => { it('getEcmProductInfo catch errors call', done => { spyOn(apiService.getInstance().discovery.discoveryApi, 'getRepositoryInformation') - .and.returnValue(throwError({ status: 403 })); + .and.returnValue(Promise.reject({ status: 403 })); service.getEcmProductInfo().subscribe( () => {}, @@ -151,7 +151,7 @@ describe('Discovery Api Service', () => { describe('For BPM', () => { it('Should retrieve the info about the product for BPM', done => { spyOn(apiService.getInstance().activiti.aboutApi, 'getAppVersion') - .and.returnValue(of(fakeBPMDiscoveryResponse)); + .and.returnValue(Promise.resolve(fakeBPMDiscoveryResponse)); service.getBpmProductInfo().subscribe((data: BpmProductVersionModel) => { expect(data).not.toBeNull(); @@ -164,7 +164,7 @@ describe('Discovery Api Service', () => { it('getBpmProductInfo catch errors call', done => { spyOn(apiService.getInstance().activiti.aboutApi, 'getAppVersion') - .and.returnValue(throwError({ status: 403 })); + .and.returnValue(Promise.reject({ status: 403 })); service.getBpmProductInfo().subscribe( () => {}, @@ -176,7 +176,7 @@ describe('Discovery Api Service', () => { it('Should retrieve the system properties for BPM', done => { spyOn(apiService.getInstance().activiti.systemPropertiesApi, 'getProperties') - .and.returnValue(of(fakeBPMDiscoverySystemPropertyResponse)); + .and.returnValue(Promise.resolve(fakeBPMDiscoverySystemPropertyResponse)); service.getBPMSystemProperties().subscribe((data: SystemPropertiesRepresentation) => { expect(data).not.toBeNull(); @@ -196,7 +196,7 @@ describe('Discovery Api Service', () => { apiService.getInstance().activiti.systemPropertiesApi, 'getProperties' ).and.returnValue( - throwError({ + Promise.reject({ error: { response: { statusCode: 404, diff --git a/lib/core/services/login-dialog.service.spec.ts b/lib/core/services/login-dialog.service.spec.ts index f85fc837ab..0e460eb4fd 100644 --- a/lib/core/services/login-dialog.service.spec.ts +++ b/lib/core/services/login-dialog.service.spec.ts @@ -45,7 +45,7 @@ describe('LoginDialogService', () => { componentInstance: { error: new Subject() } - }); + } as any); }); it('should be able to open the dialog when node has permission', () => { diff --git a/lib/core/services/nodes-api.service.spec.ts b/lib/core/services/nodes-api.service.spec.ts index b9bed530e7..743eb284ad 100644 --- a/lib/core/services/nodes-api.service.spec.ts +++ b/lib/core/services/nodes-api.service.spec.ts @@ -38,7 +38,7 @@ describe('NodesApiService', () => { } } }; - const mockSpy = { + const mockSpy: any = { core: { nodesApi: { getNode: jasmine.createSpy('getNode'), diff --git a/lib/core/services/people-content.service.spec.ts b/lib/core/services/people-content.service.spec.ts index e24edb095a..9c2498087b 100644 --- a/lib/core/services/people-content.service.spec.ts +++ b/lib/core/services/people-content.service.spec.ts @@ -24,7 +24,7 @@ import { setupTestBed } from '../testing/setup-test-bed'; import { TranslateModule } from '@ngx-translate/core'; import { TestBed } from '@angular/core/testing'; import { LogService } from './log.service'; -import { of } from 'rxjs'; +import { PersonEntry } from '@alfresco/js-api'; describe('PeopleContentService', () => { @@ -47,7 +47,7 @@ describe('PeopleContentService', () => { }); it('should be able to fetch person details based on id', (done) => { - spyOn(service.peopleApi, 'getPerson').and.returnValue(Promise.resolve({ entry: fakeEcmUser })); + spyOn(service.peopleApi, 'getPerson').and.returnValue(Promise.resolve(new PersonEntry({ entry: fakeEcmUser }))); service.getPerson('fake-id').subscribe((person) => { expect(person.entry.id).toEqual('fake-id'); expect(person.entry.email).toEqual('fakeEcm@ecmUser.com'); @@ -56,7 +56,7 @@ describe('PeopleContentService', () => { }); it('calls getPerson api method by an id', (done) => { - const getPersonSpy = spyOn(service.peopleApi, 'getPerson').and.returnValue(Promise.resolve({})); + const getPersonSpy = spyOn(service.peopleApi, 'getPerson').and.returnValue(Promise.resolve(null)); service.getPerson('fake-id').subscribe(() => { expect(getPersonSpy).toHaveBeenCalledWith('fake-id'); done(); @@ -64,7 +64,7 @@ describe('PeopleContentService', () => { }); it('calls getPerson api method with "-me-"', (done) => { - const getPersonSpy = spyOn(service.peopleApi, 'getPerson').and.returnValue(Promise.resolve({})); + const getPersonSpy = spyOn(service.peopleApi, 'getPerson').and.returnValue(Promise.resolve(null)); service.getPerson('-me-').subscribe(() => { expect(getPersonSpy).toHaveBeenCalledWith('-me-'); done(); @@ -95,7 +95,7 @@ describe('PeopleContentService', () => { }); it('should be able to create new person', (done) => { - spyOn(service.peopleApi, 'createPerson').and.returnValue(Promise.resolve({ entry: fakeEcmUser })); + spyOn(service.peopleApi, 'createPerson').and.returnValue(Promise.resolve(new PersonEntry({ entry: fakeEcmUser }))); service.createPerson(createNewPersonMock).subscribe((person) => { expect(person.id).toEqual('fake-id'); expect(person.email).toEqual('fakeEcm@ecmUser.com'); @@ -104,7 +104,7 @@ describe('PeopleContentService', () => { }); it('should be able to call createPerson api with new person details', (done) => { - const createPersonSpy = spyOn(service.peopleApi, 'createPerson').and.returnValue(Promise.resolve({ entry: fakeEcmUser })); + const createPersonSpy = spyOn(service.peopleApi, 'createPerson').and.returnValue(Promise.resolve(new PersonEntry({ entry: fakeEcmUser }))); service.createPerson(createNewPersonMock).subscribe((person) => { expect(person.id).toEqual('fake-id'); expect(person.email).toEqual('fakeEcm@ecmUser.com'); @@ -127,7 +127,7 @@ describe('PeopleContentService', () => { }); it('Should make the api call to check if the user is a content admin only once', async () => { - const getCurrentPersonSpy = spyOn(service.peopleApi, 'getPerson').and.returnValue(of(getFakeUserWithContentAdminCapability())); + const getCurrentPersonSpy = spyOn(service.peopleApi, 'getPerson').and.returnValue(Promise.resolve(getFakeUserWithContentAdminCapability())); expect(await service.isContentAdmin()).toBe(true); expect(getCurrentPersonSpy.calls.count()).toEqual(1); diff --git a/lib/core/userinfo/components/user-info.component.spec.ts b/lib/core/userinfo/components/user-info.component.spec.ts index 32b3abb27f..f59676631c 100644 --- a/lib/core/userinfo/components/user-info.component.spec.ts +++ b/lib/core/userinfo/components/user-info.component.spec.ts @@ -105,7 +105,7 @@ describe('User info component', () => { contentService = TestBed.inject(ContentService); identityUserService = TestBed.inject(IdentityUserService); - spyOn(window, 'requestAnimationFrame').and.returnValue(true); + spyOn(window, 'requestAnimationFrame').and.returnValue(1); spyOn(bpmUserService, 'getCurrentUserProfileImage').and.returnValue('app/rest/admin/profile-picture'); spyOn(contentService, 'getContentUrl').and.returnValue('alfresco-logo.svg'); })); @@ -175,37 +175,36 @@ describe('User info component', () => { }); it('should show the username when showName attribute is true', async () => { - await fixture.whenStable().then(() => { fixture.detectChanges(); expect(component.showName).toBeTruthy(); expect(element.querySelector('#adf-userinfo-ecm-name-display')).not.toBeNull(); }); + }); - it('should hide the username when showName attribute is false', async () => { - component.showName = false; + it('should hide the username when showName attribute is false', async () => { + component.showName = false; - await fixture.whenStable(); - fixture.detectChanges(); - expect(element.querySelector('#adf-userinfo-ecm-name-display')).toBeNull(); - }); + await fixture.whenStable(); + fixture.detectChanges(); + expect(element.querySelector('#adf-userinfo-ecm-name-display')).toBeNull(); + }); - it('should have the defined class to show the name on the right side', async () => { - fixture.detectChanges(); + it('should have the defined class to show the name on the right side', async () => { + fixture.detectChanges(); - await fixture.whenStable(); - fixture.detectChanges(); - expect(element.querySelector('#userinfo_container').classList).toContain('adf-userinfo-name-right'); - }); + await fixture.whenStable(); + fixture.detectChanges(); + expect(element.querySelector('#userinfo_container').classList).toContain('adf-userinfo-name-right'); + }); - it('should not have the defined class to show the name on the left side', async () => { - component.namePosition = 'left'; - fixture.detectChanges(); + it('should not have the defined class to show the name on the left side', async () => { + component.namePosition = 'left'; + fixture.detectChanges(); - await fixture.whenStable(); - fixture.detectChanges(); - expect(element.querySelector('#userinfo_container').classList).not.toContain('adf-userinfo-name-right'); - }); + await fixture.whenStable(); + fixture.detectChanges(); + expect(element.querySelector('#userinfo_container').classList).not.toContain('adf-userinfo-name-right'); }); describe('and has image', () => { diff --git a/lib/core/viewer/components/media-player.component.spec.ts b/lib/core/viewer/components/media-player.component.spec.ts index ccec1e8cd7..6a8010590d 100644 --- a/lib/core/viewer/components/media-player.component.spec.ts +++ b/lib/core/viewer/components/media-player.component.spec.ts @@ -22,7 +22,7 @@ import { setupTestBed } from '../../testing/setup-test-bed'; import { CoreTestingModule } from '../../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; import { AlfrescoApiService } from '../../services'; -import { NodeEntry } from '@alfresco/js-api'; +import { NodeEntry, RenditionPaging } from '@alfresco/js-api'; describe('Test Media player component ', () => { @@ -52,13 +52,13 @@ describe('Test Media player component ', () => { it('should generate tracks for media file when webvtt rendition exists', fakeAsync(() => { const fakeRenditionUrl = 'http://fake.rendition.url'; - spyOn(alfrescoApiService.nodesApi, 'getNode').and.returnValues( + spyOn(alfrescoApiService.nodesApi, 'getNode').and.returnValue( Promise.resolve(new NodeEntry({ entry: { name: 'file1', content: {} } })) ); - spyOn(alfrescoApiService.renditionsApi, 'getRenditions').and.returnValues( - { list: { entries: [{ entry: { id: 'webvtt', status: 'CREATED' } }] } } + spyOn(alfrescoApiService.renditionsApi, 'getRenditions').and.returnValue( + Promise.resolve(new RenditionPaging({ list: { entries: [{ entry: { id: 'webvtt', status: 'CREATED' } }] } })) ); - spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.returnValues('http://iam-fake.url'); + spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.returnValue('http://iam-fake.url'); spyOn(alfrescoApiService.contentApi, 'getRenditionUrl').and.returnValue(fakeRenditionUrl); component.ngOnChanges(change); @@ -68,15 +68,15 @@ describe('Test Media player component ', () => { })); it('should not generate tracks for media file when webvtt rendition is not created', fakeAsync(() => { - spyOn(alfrescoApiService.nodesApi, 'getNode').and.returnValues( + spyOn(alfrescoApiService.nodesApi, 'getNode').and.returnValue( Promise.resolve(new NodeEntry({ entry: { name: 'file1', content: {} } })) ); - spyOn(alfrescoApiService.renditionsApi, 'getRenditions').and.returnValues( - { list: { entries: [{ entry: { id: 'webvtt', status: 'NOT_CREATED' } }] } } + spyOn(alfrescoApiService.renditionsApi, 'getRenditions').and.returnValue( + Promise.resolve(new RenditionPaging({ list: { entries: [{ entry: { id: 'webvtt', status: 'NOT_CREATED' } }] } })) ); - spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.returnValues('http://iam-fake.url'); + spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.returnValue('http://iam-fake.url'); component.ngOnChanges(change); tick(); @@ -85,15 +85,15 @@ describe('Test Media player component ', () => { })); it('should not generate tracks for media file when webvtt rendition does not exist', fakeAsync(() => { - spyOn(alfrescoApiService.nodesApi, 'getNode').and.returnValues( + spyOn(alfrescoApiService.nodesApi, 'getNode').and.returnValue( Promise.resolve(new NodeEntry({ entry: { name: 'file1', content: {} } })) ); - spyOn(alfrescoApiService.renditionsApi, 'getRenditions').and.returnValues( - { list: { entries: [] } } + spyOn(alfrescoApiService.renditionsApi, 'getRenditions').and.returnValue( + Promise.resolve(new RenditionPaging({ list: { entries: [] } })) ); - spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.returnValues('http://iam-fake.url'); + spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.returnValue('http://iam-fake.url'); component.ngOnChanges(change); tick(); diff --git a/lib/core/viewer/components/pdf-viewer.component.spec.ts b/lib/core/viewer/components/pdf-viewer.component.spec.ts index 9a547a2d4f..ed0e8de860 100644 --- a/lib/core/viewer/components/pdf-viewer.component.spec.ts +++ b/lib/core/viewer/components/pdf-viewer.component.spec.ts @@ -337,13 +337,13 @@ describe('Test PdfViewer component', () => { if (context.data.reason === pdfjsLib.PasswordResponses.NEED_PASSWORD) { return { afterClosed: () => of('wrong_password') - }; + } as any; } if (context.data.reason === pdfjsLib.PasswordResponses.INCORRECT_PASSWORD) { return { afterClosed: () => of('password') - }; + } as any; } return undefined; @@ -404,7 +404,7 @@ describe('Test PdfViewer component', () => { done(); return of(''); } - }; + } as any; }); spyOn(componentUrlTestPasswordComponent.pdfViewerComponent.close, 'emit'); diff --git a/lib/core/viewer/components/viewer.component.spec.ts b/lib/core/viewer/components/viewer.component.spec.ts index 0a212337ab..dc9e65f063 100644 --- a/lib/core/viewer/components/viewer.component.spec.ts +++ b/lib/core/viewer/components/viewer.component.spec.ts @@ -293,7 +293,7 @@ describe('ViewerComponent', () => { const displayName = 'the-name'; const nodeDetails = { name: displayName, id: '12' }; const contentUrl = '/content/url/path'; - const alfrescoApiInstanceMock = { + const alfrescoApiInstanceMock: any = { nodes: { getNodeInfo: () => Promise.resolve(nodeDetails), getNode: () => Promise.resolve({ id: 'fake-node', entry: { content: {} } }) @@ -687,7 +687,7 @@ describe('ViewerComponent', () => { const node = new NodeEntry({ entry: { name: displayName, id: '12', content: { mimeType: 'txt' } } }); const nodeDetails = { name: displayName, id: '12', content: { mimeType: 'txt' } }; const contentUrl = '/content/url/path'; - const alfrescoApiInstanceMock = { + const alfrescoApiInstanceMock: any = { nodes: { getNodeInfo: () => Promise.resolve(nodeDetails), getNode: () => Promise.resolve(node) @@ -1066,7 +1066,7 @@ describe('ViewerComponent', () => { const displayName = 'the-name'; const nodeDetails = new NodeEntry({ entry: { name: displayName, id: '12', content: { mimeType: 'txt' } } }); const contentUrl = '/content/url/path'; - const alfrescoApiInstanceMock = { + const alfrescoApiInstanceMock: any = { nodes: { getNode: () => Promise.resolve(nodeDetails) }, 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 8b9f13dc6a..37f3e3a76a 100644 --- a/lib/extensions/src/lib/services/extension-loader.service.spec.ts +++ b/lib/extensions/src/lib/services/extension-loader.service.spec.ts @@ -90,7 +90,7 @@ describe('ExtensionLoaderService', () => { return of(pluginConfig3); } - return of({}); + return of(null); }); }); 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 ce1726d762..9859c69333 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 @@ -342,7 +342,7 @@ describe('AnalyticsReportParametersComponent', () => { it('Should load the task list when a process definition is selected', () => { component.successReportParams.subscribe((res) => { expect(res).toBeDefined(); - expect(res.length).toEqual(2); + expect(res['length']).toEqual(2); expect(res[0].id).toEqual('Fake task name 1'); expect(res[0].name).toEqual('Fake task name 1'); expect(res[1].id).toEqual('Fake task name 2'); 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 1ed6200206..6e403d0dbc 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 @@ -34,7 +34,7 @@ describe('AppListCloudComponent', () => { let getAppsSpy: jasmine.Spy; let alfrescoApiService: AlfrescoApiService; - const mock = { + const mock: any = { oauth2Auth: { callCustomApi: () => Promise.resolve(fakeApplicationInstance) }, diff --git a/lib/process-services-cloud/src/lib/app/services/apps-process-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/app/services/apps-process-cloud.service.spec.ts index 65e1b8f3e7..5c630fbbaa 100644 --- a/lib/process-services-cloud/src/lib/app/services/apps-process-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/app/services/apps-process-cloud.service.spec.ts @@ -30,7 +30,7 @@ describe('AppsProcessCloudService', () => { let appConfigService: AppConfigService; let apiService: AlfrescoApiService; - const apiMock = { + const apiMock: any = { oauth2Auth: { callCustomApi: () => Promise.resolve({list : { entries: [ {entry: fakeApplicationInstance[0]}, {entry: fakeApplicationInstance[1]}] }}) }, 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 1b0686c813..3eed28edfb 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 @@ -53,7 +53,7 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { CloudFormRenderingService } from './cloud-form-rendering.service'; import { Node } from '@alfresco/js-api'; -const mockOauth2Auth = { +const mockOauth2Auth: any = { oauth2Auth: { callCustomApi: () => Promise.resolve() }, @@ -310,7 +310,7 @@ describe('FormCloudComponent', () => { spyOn(formCloudService, 'getTaskVariables').and.returnValue(of([])); spyOn(formCloudService, 'getTask').and.callFake((currentTaskId) => { return new Observable((observer) => { - observer.next({ formRepresentation: { taskId: currentTaskId } }); + observer.next({ formRepresentation: { taskId: currentTaskId } } as any); observer.complete(); }); }); @@ -357,7 +357,7 @@ describe('FormCloudComponent', () => { }); it('should refresh visibility when the form is loaded', () => { - spyOn(formCloudService, 'getForm').and.returnValue(of({ formRepresentation: {} })); + spyOn(formCloudService, 'getForm').and.returnValue(of({ formRepresentation: {} } as any)); const formId = '123'; const appName = 'test-app'; diff --git a/lib/process-services-cloud/src/lib/form/components/form-definition-selector-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/form/components/form-definition-selector-cloud.component.spec.ts index 9c285c84f9..a06fc1f5d6 100644 --- a/lib/process-services-cloud/src/lib/form/components/form-definition-selector-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/form-definition-selector-cloud.component.spec.ts @@ -44,7 +44,7 @@ describe('FormDefinitionCloudComponent', () => { fixture = TestBed.createComponent(FormDefinitionSelectorCloudComponent); element = fixture.nativeElement; service = TestBed.inject(FormDefinitionSelectorCloudService); - getFormsSpy = spyOn(service, 'getStandAloneTaskForms').and.returnValue(of([{ id: 'fake-form', name: 'fakeForm' }])); + getFormsSpy = spyOn(service, 'getStandAloneTaskForms').and.returnValue(of([{ id: 'fake-form', name: 'fakeForm' } as any])); }); it('should load the forms by default', () => { diff --git a/lib/process-services-cloud/src/lib/form/mocks/attach-file-cloud-widget.mock.ts b/lib/process-services-cloud/src/lib/form/mocks/attach-file-cloud-widget.mock.ts index e6c21a3447..142a1c61e7 100644 --- a/lib/process-services-cloud/src/lib/form/mocks/attach-file-cloud-widget.mock.ts +++ b/lib/process-services-cloud/src/lib/form/mocks/attach-file-cloud-widget.mock.ts @@ -227,11 +227,11 @@ export const expectedValues = { pfx_property_two: true }; -export const mockNodeId = new Promise(function(resolve) { +export const mockNodeId = new Promise(function(resolve) { resolve('mock-node-id'); }); -export const mockNodeIdBasedOnStringVariableValue = new Promise(function(resolve) { +export const mockNodeIdBasedOnStringVariableValue = new Promise(function(resolve) { resolve('mock-string-value-node-id'); }); diff --git a/lib/process-services-cloud/src/lib/form/mocks/cloud-form.mock.ts b/lib/process-services-cloud/src/lib/form/mocks/cloud-form.mock.ts index 68451ef5d8..2394924369 100644 --- a/lib/process-services-cloud/src/lib/form/mocks/cloud-form.mock.ts +++ b/lib/process-services-cloud/src/lib/form/mocks/cloud-form.mock.ts @@ -759,7 +759,7 @@ export const emptyFormRepresentationJSON = { 'version': 0 }; -export const conditionalUploadWidgetsMock = { +export const conditionalUploadWidgetsMock: any = { 'formRepresentation': { 'id': 'form-fb7858f7-5cf6-4afe-b462-c15a5dc0c34c', 'name': 'AttachVisibility', @@ -847,7 +847,7 @@ export const conditionalUploadWidgetsMock = { } }; -export const multilingualForm = { +export const multilingualForm: any = { 'formRepresentation': { 'id': 'form-2aaaf20e-43d3-46bf-89be-859d5f512dd2', 'name': 'multilingualform', diff --git a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts index 4d9bc79107..0273609da0 100644 --- a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts @@ -56,7 +56,7 @@ describe('Form Cloud service', () => { return false; }, reply: jasmine.createSpy('reply') - }); + } as any); }); describe('Form tests', () => { @@ -195,8 +195,11 @@ describe('Form Cloud service', () => { it('should fetch task form flattened', (done) => { spyOn(service, 'getTask').and.returnValue(of(responseBody.entry)); spyOn(service, 'getForm').and.returnValue(of({ - formRepresentation: {name: 'task-form', formDefinition: {} } - })); + formRepresentation: { + name: 'task-form', + formDefinition: {} + } + } as any)); service.getTaskForm(appName, taskId).subscribe((result) => { expect(result).toBeDefined(); diff --git a/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.spec.ts index a59f55eef0..365ee9905e 100644 --- a/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.spec.ts @@ -76,7 +76,7 @@ describe('Form Definition Selector Cloud Service', () => { return false; }, reply: jasmine.createSpy('reply') - }); + } as any); }); it('should fetch all the forms when getForms is called', (done) => { 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 d8f11ca41e..77a6366d78 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 @@ -40,7 +40,7 @@ describe('GroupCloudComponent', () => { let alfrescoApiService: AlfrescoApiService; let findGroupsByNameSpy: jasmine.Spy; - const mock = { + const mock: any = { oauth2Auth: { callCustomApi: () => Promise.resolve(mockIdentityGroups) }, @@ -648,7 +648,7 @@ describe('GroupCloudComponent', () => { describe('Preselected groups and validation enabled', () => { it('should check validation only for the first group and emit warning when group is invalid - single mode', (done) => { - spyOn(identityGroupService, 'findGroupsByName').and.returnValue(Promise.resolve([])); + spyOn(identityGroupService, 'findGroupsByName').and.returnValue(of([])); const expectedWarning = { message: 'INVALID_PRESELECTED_GROUPS', @@ -671,7 +671,7 @@ describe('GroupCloudComponent', () => { }); it('should check validation for all the groups and emit warning - multiple mode', (done) => { - spyOn(identityGroupService, 'findGroupsByName').and.returnValue(Promise.resolve(undefined)); + spyOn(identityGroupService, 'findGroupsByName').and.returnValue(of(undefined)); const expectedWarning = { message: 'INVALID_PRESELECTED_GROUPS', 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 f51f936a65..009cd90c68 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 @@ -40,7 +40,7 @@ describe('PeopleCloudComponent', () => { let alfrescoApiService: AlfrescoApiService; let findUsersByNameSpy: jasmine.Spy; - const mock = { + const mock: any = { oauth2Auth: { callCustomApi: () => Promise.resolve(mockUsers) }, @@ -740,7 +740,7 @@ describe('PeopleCloudComponent', () => { describe('Preselected users and validation enabled', () => { it('should check validation only for the first user and emit warning when user is invalid - single mode', (done) => { - spyOn(identityService, 'findUserById').and.returnValue(Promise.resolve([])); + spyOn(identityService, 'findUserById').and.returnValue(of([])); const expectedWarning = { message: 'INVALID_PRESELECTED_USERS', users: [{ @@ -762,7 +762,7 @@ describe('PeopleCloudComponent', () => { }); it('should skip warnings if validation disabled', () => { - spyOn(identityService, 'findUserById').and.returnValue(Promise.resolve([])); + spyOn(identityService, 'findUserById').and.returnValue(of([])); spyOn(component, 'compare').and.returnValue(false); let warnings = 0; @@ -779,7 +779,7 @@ describe('PeopleCloudComponent', () => { }); it('should check validation for all the users and emit warning - multiple mode', (done) => { - spyOn(identityService, 'findUserById').and.returnValue(Promise.resolve(undefined)); + spyOn(identityService, 'findUserById').and.returnValue(of(undefined)); const expectedWarning = { message: 'INVALID_PRESELECTED_USERS', diff --git a/lib/process-services-cloud/src/lib/pipes/process-name-cloud.pipe.spec.ts b/lib/process-services-cloud/src/lib/pipes/process-name-cloud.pipe.spec.ts index 4bc804a038..10c32fe081 100644 --- a/lib/process-services-cloud/src/lib/pipes/process-name-cloud.pipe.spec.ts +++ b/lib/process-services-cloud/src/lib/pipes/process-name-cloud.pipe.spec.ts @@ -30,7 +30,7 @@ describe('ProcessNameCloudPipe', () => { const defaultName = 'default-name'; const datetimeIdentifier = '%{datetime}'; const processDefinitionIdentifier = '%{processDefinition}'; - const mockCurrentDate = 'Wed Oct 23 2019'; + const mockCurrentDate = new Date('Wed Oct 23 2019'); const mockLocalizedCurrentDate = 'Oct 23, 2019, 12:00:00 AM'; const nameWithProcessDefinitionIdentifier = `${defaultName} - ${processDefinitionIdentifier}`; const nameWithDatetimeIdentifier = `${defaultName} - ${datetimeIdentifier}`; 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 c2ec42250b..4fdd8b2f70 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 @@ -39,6 +39,7 @@ import { ProcessCloudService } from '../../services/process-cloud.service'; import { DateCloudFilterType } from '../../../models/date-cloud-filter.model'; import { ApplicationVersionModel } from '../../../models/application-version.model'; import { MatIconTestingModule } from '@angular/material/icon/testing'; +import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model'; describe('EditProcessFilterCloudComponent', () => { let component: EditProcessFilterCloudComponent; @@ -64,7 +65,7 @@ describe('EditProcessFilterCloudComponent', () => { sort: 'id' }); - const mock = { + const mock: any = { oauth2Auth: { callCustomApi: () => Promise.resolve(fakeApplicationInstance) }, @@ -103,7 +104,7 @@ describe('EditProcessFilterCloudComponent', () => { name: 'fake-name' }); } - }); + } as any); getProcessFilterByIdSpy = spyOn(service, 'getFilterById').and.returnValue(of(fakeFilter)); getRunningApplicationsSpy = spyOn(appsService, 'getDeployedApplicationsByStatus').and.returnValue(of(fakeApplicationInstance)); spyOn(alfrescoApiService, 'getInstance').and.returnValue(mock); @@ -535,7 +536,7 @@ describe('EditProcessFilterCloudComponent', () => { }); it('should fetch process definitions when processDefinitionName filter property is set', async(() => { - const processSpy = spyOn(processService, 'getProcessDefinitions').and.returnValue(of([{ id: 'fake-id', name: 'fake-name' }])); + const processSpy = spyOn(processService, 'getProcessDefinitions').and.returnValue(of([new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })])); fixture.detectChanges(); component.filterProperties = ['processDefinitionName']; fixture.detectChanges(); @@ -633,14 +634,19 @@ describe('EditProcessFilterCloudComponent', () => { beforeEach(() => { const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true); - component.ngOnChanges({ 'id': processFilterIdChange }); getProcessFilterByIdSpy.and.returnValue(of(fakeFilter)); + + component.ngOnChanges({ 'id': processFilterIdChange }); fixture.detectChanges(); }); + afterEach(() => { + fixture.destroy(); + }); + 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 saveFilterSpy = spyOn(service, 'updateFilter').and.returnValue(of([fakeFilter])); const saveSpy: jasmine.Spy = spyOn(component.action, 'emit'); fixture.detectChanges(); @@ -661,30 +667,33 @@ describe('EditProcessFilterCloudComponent', () => { }); })); - it('should emit delete event and delete the filter on click of delete button', (done) => { + it('should emit delete event and delete the filter on click of delete button', async () => { component.toggleFilterActions = true; - const deleteFilterSpy = spyOn(service, 'deleteFilter').and.returnValue(of({})); + const deleteFilterSpy = spyOn(service, 'deleteFilter').and.returnValue(of({} as any)); const deleteSpy = 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 deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]'); deleteButton.click(); fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(deleteFilterSpy).toHaveBeenCalled(); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(deleteSpy).toHaveBeenCalled(); - done(); - }); + await fixture.whenStable(); - }); + expect(deleteFilterSpy).toHaveBeenCalled(); + expect(deleteSpy).toHaveBeenCalled(); }); it('should emit saveAs event and add filter on click saveAs button', async(() => { @@ -910,7 +919,7 @@ describe('EditProcessFilterCloudComponent', () => { it('should not call restore default filters service on deletion first filter', (done) => { component.toggleFilterActions = true; - const deleteFilterSpy = spyOn(service, 'deleteFilter').and.returnValue(of([{ name: 'mock-filter-name'}])); + const deleteFilterSpy = spyOn(service, 'deleteFilter').and.returnValue(of([new ProcessFilterCloudModel({ name: 'mock-filter-name'})])); const restoreFiltersSpy = spyOn(component, 'restoreDefaultProcessFilters').and.returnValue(of([])); const deleteSpy: jasmine.Spy = spyOn(component.action, 'emit'); fixture.detectChanges(); diff --git a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.spec.ts index 3ba0c4b05f..26de9a8a69 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.spec.ts @@ -16,9 +16,9 @@ */ import { SimpleChange } from '@angular/core'; -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { setupTestBed } from '@alfresco/adf-core'; -import { from, Observable } from 'rxjs'; +import { of, throwError } from 'rxjs'; import { ProcessFilterCloudService } from '../services/process-filter-cloud.service'; import { ProcessFiltersCloudComponent } from './process-filters-cloud.component'; import { By } from '@angular/platform-browser'; @@ -30,27 +30,10 @@ import { TranslateModule } from '@ngx-translate/core'; import { mockProcessFilters } from '../mock/process-filters-cloud.mock'; describe('ProcessFiltersCloudComponent', () => { - let processFilterService: ProcessFilterCloudService; - - const fakeGlobalFilterObservable = - new Observable(function(observer) { - observer.next(mockProcessFilters); - observer.complete(); - }); - - const fakeGlobalFilterPromise = new Promise(function (resolve) { - resolve(mockProcessFilters); - }); - - const mockErrorFilterList = { - error: 'wrong request' - }; - - const mockErrorFilterPromise = Promise.reject(mockErrorFilterList); - let component: ProcessFiltersCloudComponent; let fixture: ComponentFixture; + let getProcessFiltersSpy: jasmine.Spy; setupTestBed({ imports: [ @@ -68,198 +51,183 @@ describe('ProcessFiltersCloudComponent', () => { component = fixture.componentInstance; processFilterService = TestBed.inject(ProcessFilterCloudService); + getProcessFiltersSpy = spyOn(processFilterService, 'getProcessFilters').and.returnValue(of(mockProcessFilters)); }); - it('should attach specific icon for each filter if hasIcon is true', async(() => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable); + afterEach(() => { + fixture.destroy(); + }); + + it('should attach specific icon for each filter if hasIcon is true', async () => { const change = new SimpleChange(undefined, 'my-app-1', true); component.ngOnChanges({'appName': change}); + fixture.detectChanges(); + await fixture.whenStable(); + component.showIcons = true; - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(component.filters.length).toBe(3); - const filters = fixture.nativeElement.querySelectorAll('.adf-icon'); - expect(filters.length).toBe(3); - expect(filters[0].innerText).toContain('adjust'); - expect(filters[1].innerText).toContain('inbox'); - expect(filters[2].innerText).toContain('done'); - }); - })); - it('should not attach icons for each filter if hasIcon is false', (done) => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise)); + fixture.detectChanges(); + await fixture.whenStable(); + expect(component.filters.length).toBe(3); + const filters = fixture.nativeElement.querySelectorAll('.adf-icon'); + expect(filters.length).toBe(3); + expect(filters[0].innerText).toContain('adjust'); + expect(filters[1].innerText).toContain('inbox'); + expect(filters[2].innerText).toContain('done'); + }); + + it('should not attach icons for each filter if hasIcon is false', async () => { component.showIcons = false; const change = new SimpleChange(undefined, 'my-app-1', true); component.ngOnChanges({'appName': change}); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const filters: any = fixture.debugElement.queryAll(By.css('.adf-icon')); - expect(filters.length).toBe(0); - done(); - }); + fixture.detectChanges(); + await fixture.whenStable(); + + const filters: any = fixture.debugElement.queryAll(By.css('.adf-icon')); + expect(filters.length).toBe(0); }); - it('should display the filters', async(() => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable); + it('should display the filters', async () => { const change = new SimpleChange(undefined, 'my-app-1', true); component.ngOnChanges({'appName': change}); + fixture.detectChanges(); + await fixture.whenStable(); + component.showIcons = true; - fixture.whenStable().then(() => { - fixture.detectChanges(); - const filters = fixture.debugElement.queryAll(By.css('.adf-filters__entry')); - expect(component.filters.length).toBe(3); - expect(filters.length).toBe(3); - expect(filters[0].nativeElement.innerText).toContain('FakeAllProcesses'); - expect(filters[1].nativeElement.innerText).toContain('FakeRunningProcesses'); - expect(filters[2].nativeElement.innerText).toContain('FakeCompletedProcesses'); - }); - })); + + fixture.detectChanges(); + await fixture.whenStable(); + + const filters = fixture.debugElement.queryAll(By.css('.adf-filters__entry')); + expect(component.filters.length).toBe(3); + expect(filters.length).toBe(3); + expect(filters[0].nativeElement.innerText).toContain('FakeAllProcesses'); + expect(filters[1].nativeElement.innerText).toContain('FakeRunningProcesses'); + expect(filters[2].nativeElement.innerText).toContain('FakeCompletedProcesses'); + }); it('should emit an error with a bad response', (done) => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(mockErrorFilterPromise)); + const mockErrorFilterList = { + error: 'wrong request' + }; + getProcessFiltersSpy.and.returnValue(throwError(mockErrorFilterList)); const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); - component.ngOnChanges({'appName': change}); component.error.subscribe((err) => { expect(err).toBeDefined(); done(); }); - }); - - it('should emit success with the filters when filters are loaded', (done) => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise)); - const appName = 'my-app-1'; - const change = new SimpleChange(null, appName, true); - component.ngOnChanges({ 'appName': change }); - - component.success.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.filters).toBeDefined(); - expect(component.filters[0].name).toEqual('FakeAllProcesses'); - expect(component.filters[1].name).toEqual('FakeRunningProcesses'); - expect(component.filters[2].name).toEqual('FakeCompletedProcesses'); - done(); - }); - }); - - it('should select the first filter as default', async(() => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable); - - const appName = 'my-app-1'; - const change = new SimpleChange(null, appName, true); + component.ngOnChanges({'appName': change}); fixture.detectChanges(); + }); + + it('should emit success with the filters when filters are loaded', async () => { + const appName = 'my-app-1'; + const change = new SimpleChange(null, appName, true); + component.ngOnChanges({ 'appName': change }); + fixture.detectChanges(); + await fixture.whenStable(); - component.success.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.currentFilter).toBeDefined(); - expect(component.currentFilter.name).toEqual('FakeAllProcesses'); - }); + expect(component.filters).toBeDefined(); + expect(component.filters[0].name).toEqual('FakeAllProcesses'); + expect(component.filters[1].name).toEqual('FakeRunningProcesses'); + expect(component.filters[2].name).toEqual('FakeCompletedProcesses'); + }); - })); + it('should select the first process cloud filter as default', async () => { + const appName = 'my-app-1'; + const change = new SimpleChange(null, appName, true); - it('should select the filter based on the input by name param', (done) => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable); + component.ngOnChanges({ 'appName': change }); + fixture.detectChanges(); + await fixture.whenStable(); + expect(component.currentFilter).toBeDefined(); + expect(component.currentFilter.name).toEqual('FakeAllProcesses'); + }); + + it('should select the filter based on the input by name param', async () => { component.filterParam = { name: 'FakeRunningProcesses' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); - component.filterSelected.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.currentFilter).toBeDefined(); - expect(component.currentFilter.name).toEqual('FakeRunningProcesses'); - done(); - }); + component.ngOnChanges({ 'appName': change }); fixture.detectChanges(); - component.ngOnChanges({ 'appName': change }); + await fixture.whenStable(); + + expect(component.currentFilter).toBeDefined(); + expect(component.currentFilter.name).toEqual('FakeRunningProcesses'); }); - it('should select the filter based on the input by key param', (done) => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable); - + it('should select the filter based on the input by key param', async () => { component.filterParam = { key: 'completed-processes' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); - fixture.detectChanges(); - - component.filterSelected.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.currentFilter).toBeDefined(); - expect(component.currentFilter.name).toEqual('FakeCompletedProcesses'); - done(); - }); - component.ngOnChanges({ 'appName': change }); + + fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.currentFilter).toBeDefined(); + expect(component.currentFilter.name).toEqual('FakeCompletedProcesses'); }); - it('should select the filter based on the input by index param', (done) => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable); - + it('should select the filter based on the input by index param', async () => { component.filterParam = { index: 2 }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); - fixture.detectChanges(); - - component.filterSelected.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.currentFilter).toBeDefined(); - expect(component.currentFilter.name).toEqual('FakeCompletedProcesses'); - done(); - }); component.ngOnChanges({ 'appName': change }); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.currentFilter).toBeDefined(); + expect(component.currentFilter.name).toEqual('FakeCompletedProcesses'); }); - it('should select the filter based on the input by id param', (done) => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable); - + it('should select the filter based on the input by id param', async () => { component.filterParam = { id: '12' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); - fixture.detectChanges(); - - component.filterSelected.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.currentFilter).toBeDefined(); - expect(component.currentFilter.name).toEqual('FakeCompletedProcesses'); - done(); - }); component.ngOnChanges({ 'appName': change }); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.currentFilter).toBeDefined(); + expect(component.currentFilter.name).toEqual('FakeCompletedProcesses'); }); - it('should filterClicked emit when a filter is clicked from the UI', (done) => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable); - + it('should filterClicked emit when a filter is clicked from the UI', async () => { component.filterParam = { id: '10' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); component.ngOnChanges({ 'appName': change }); - fixture.detectChanges(); - component.filterClicked.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.currentFilter).toBeDefined(); - expect(component.currentFilter.name).toEqual('FakeAllProcesses'); - done(); - }); + fixture.detectChanges(); + await fixture.whenStable(); const filterButton = fixture.debugElement.nativeElement.querySelector(`[data-automation-id="${mockProcessFilters[0].key}_filter"]`); filterButton.click(); + + fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.currentFilter).toBeDefined(); + expect(component.currentFilter.name).toEqual('FakeAllProcesses'); }); it('should not emit a filter click event on binding changes', () => { @@ -270,7 +238,7 @@ describe('ProcessFiltersCloudComponent', () => { fixture.detectChanges(); expect(component.selectFilterAndEmit).toHaveBeenCalled(); - expect(component.currentFilter).not.toBeDefined(); + expect(component.currentFilter).toBe(mockProcessFilters[0]); }); it('should reload filters by appName on binding changes', () => { diff --git a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.ts b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.ts index a805ef75f1..4afbc28cf0 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.ts @@ -94,8 +94,16 @@ export class ProcessFiltersCloudComponent implements OnInit, OnChanges, OnDestro this.filters$.pipe(takeUntil(this.onDestroy$)).subscribe( (res: ProcessFilterCloudModel[]) => { this.resetFilter(); - this.filters = Object.assign([], res); - this.selectFilterAndEmit(this.filterParam); + this.filters = res || []; + + if (this.filterParam) { + this.selectFilterAndEmit(this.filterParam); + } + + if (!this.currentFilter && this.filters.length > 0) { + this.currentFilter = this.filters[0]; + } + this.success.emit(res); }, (err: any) => { diff --git a/lib/process-services-cloud/src/lib/process/process-filters/mock/process-filters-cloud.mock.ts b/lib/process-services-cloud/src/lib/process/process-filters/mock/process-filters-cloud.mock.ts index 7ace303ffb..7511ad518f 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/mock/process-filters-cloud.mock.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/mock/process-filters-cloud.mock.ts @@ -51,28 +51,28 @@ export const fakeProcessCloudFilters = [ } ]; -export const mockProcessFilters = [ - new ProcessFilterCloudModel({ +export const mockProcessFilters: any[] = [ + { name: 'FakeAllProcesses', key: 'FakeAllProcesses', icon: 'adjust', id: '10', status: '' - }), - new ProcessFilterCloudModel({ + }, + { name: 'FakeRunningProcesses', key: 'FakeRunningProcesses', icon: 'inbox', id: '11', status: 'RUNNING' - }), - new ProcessFilterCloudModel({ + }, + { name: 'FakeCompletedProcesses', key: 'completed-processes', icon: 'done', id: '12', status: 'COMPLETED' - }) + } ]; export const fakeProcessFilter: ProcessFilterCloudModel = new ProcessFilterCloudModel({ 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 8db723f831..5efdc98f91 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 @@ -24,16 +24,17 @@ import { ProcessHeaderCloudComponent } from './process-header-cloud.component'; import { ProcessHeaderCloudModule } from '../process-header-cloud.module'; import { ProcessCloudService } from '../../services/process-cloud.service'; import { TranslateModule } from '@ngx-translate/core'; +import { ProcessInstanceCloud } from '../../start-process/models/process-instance-cloud.model'; -const processInstanceDetailsCloudMock = { +const processInstanceDetailsCloudMock: ProcessInstanceCloud = { appName: 'app-form-mau', businessKey: 'MyBusinessKey', id: '00fcc4ab-4290-11e9-b133-0a586460016a', initiator: 'devopsuser', - lastModified: 1552152187081, + lastModified: new Date(1552152187081), name: 'new name', parentId: '00fcc4ab-4290-11e9-b133-0a586460016b', - startDate: 1552152187080, + startDate: new Date(1552152187080), status: 'RUNNING' }; diff --git a/lib/process-services-cloud/src/lib/process/process-list/services/process-list-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/process/process-list/services/process-list-cloud.service.spec.ts index bd5d19189c..dc1135d174 100644 --- a/lib/process-services-cloud/src/lib/process/process-list/services/process-list-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-list/services/process-list-cloud.service.spec.ts @@ -24,7 +24,7 @@ describe('ProcessListCloudService', () => { let service: ProcessListCloudService; let alfrescoApiService: AlfrescoApiService; - function returnCallQueryParameters() { + function returnCallQueryParameters(): any { return { oauth2Auth: { callCustomApi: (_queryUrl, _operation, _context, queryParams) => { @@ -37,7 +37,7 @@ describe('ProcessListCloudService', () => { }; } - function returnCallUrl() { + function returnCallUrl(): any { return { oauth2Auth: { callCustomApi: (queryUrl) => { diff --git a/lib/process-services-cloud/src/lib/process/start-process/services/start-process-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/process/start-process/services/start-process-cloud.service.spec.ts index bbb94b5ce6..482f38e0a9 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/services/start-process-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/services/start-process-cloud.service.spec.ts @@ -28,7 +28,7 @@ describe('StartProcessCloudService', () => { let service: StartProcessCloudService; let alfrescoApiService: AlfrescoApiService; - const mock = { + const mock: any = { oauth2Auth: { callCustomApi: () => Promise.resolve({ entry: { @@ -86,7 +86,7 @@ describe('StartProcessCloudService', () => { }); it('should be able to get all the process definitions', (done) => { - spyOn(service, 'getProcessDefinitions').and.returnValue(of([{ id: 'fake-id', name: 'fake-name' }])); + spyOn(service, 'getProcessDefinitions').and.returnValue(of([new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })])); service.getProcessDefinitions('appName1') .subscribe( (res: ProcessDefinitionCloud[]) => { diff --git a/lib/process-services-cloud/src/lib/services/notification-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/services/notification-cloud.service.spec.ts index e88e1fee12..cd3d3fe4af 100644 --- a/lib/process-services-cloud/src/lib/services/notification-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/services/notification-cloud.service.spec.ts @@ -25,10 +25,10 @@ import { Apollo } from 'apollo-angular'; describe('NotificationCloudService', () => { let service: NotificationCloudService; let apollo: Apollo; - let apolloCreateSpy; - let apolloSubscribeSpy; + let apolloCreateSpy: jasmine.Spy; + let apolloSubscribeSpy: jasmine.Spy; let apiService: AlfrescoApiService; - const useMock = { + const useMock: any = { subscribe() {} }; @@ -43,7 +43,7 @@ describe('NotificationCloudService', () => { } `; - const apiServiceMock = { + const apiServiceMock: any = { oauth2Auth: { token: '1234567' }, diff --git a/lib/process-services-cloud/src/lib/services/user-preference-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/services/user-preference-cloud.service.spec.ts index 32f6e1933d..fd4a295ccd 100644 --- a/lib/process-services-cloud/src/lib/services/user-preference-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/services/user-preference-cloud.service.spec.ts @@ -33,7 +33,7 @@ describe('PreferenceService', () => { state: 404, stateText: 'Not Found' }; - function apiMock(mockResponse) { + function apiMock(mockResponse): any { return { oauth2Auth: { callCustomApi: () => { @@ -47,7 +47,7 @@ describe('PreferenceService', () => { }; } - const apiErrorMock = { + const apiErrorMock: any = { oauth2Auth: { callCustomApi: () => Promise.reject(errorResponse) }, 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 0756f4af65..05775882ae 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 @@ -32,7 +32,7 @@ describe('Task Cloud Service', () => { let identityUserService: IdentityUserService; let translateService: TranslationService; - function returnFakeTaskCompleteResults() { + function returnFakeTaskCompleteResults(): any { return { oauth2Auth: { callCustomApi : () => { @@ -45,7 +45,7 @@ describe('Task Cloud Service', () => { }; } - function returnFakeTaskCompleteResultsError() { + function returnFakeTaskCompleteResultsError(): any { return { oauth2Auth: { callCustomApi : () => { @@ -58,7 +58,7 @@ describe('Task Cloud Service', () => { }; } - function returnFakeTaskDetailsResults() { + function returnFakeTaskDetailsResults(): any { return { oauth2Auth: { callCustomApi : () => { @@ -71,7 +71,7 @@ describe('Task Cloud Service', () => { }; } - function returnFakeCandidateUsersResults() { + function returnFakeCandidateUsersResults(): any { return { oauth2Auth: { callCustomApi : () => { @@ -84,7 +84,7 @@ describe('Task Cloud Service', () => { }; } - function returnFakeCandidateGroupResults() { + function returnFakeCandidateGroupResults(): any { return { oauth2Auth: { callCustomApi : () => { 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 914b0dbc82..a244ba0879 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 @@ -38,7 +38,7 @@ describe('StartTaskCloudComponent', () => { let createNewTaskSpy: jasmine.Spy; let alfrescoApiService: AlfrescoApiService; - const mock = { + const mock: any = { oauth2Auth: { callCustomApi: () => Promise.resolve(taskDetailsMock) }, @@ -68,7 +68,7 @@ describe('StartTaskCloudComponent', () => { alfrescoApiService = TestBed.inject(AlfrescoApiService); formDefinitionSelectorCloudService = TestBed.inject(FormDefinitionSelectorCloudService); spyOn(alfrescoApiService, 'getInstance').and.returnValue(mock); - createNewTaskSpy = spyOn(service, 'createNewTask').and.returnValue(of(taskDetailsMock)); + createNewTaskSpy = spyOn(service, 'createNewTask').and.returnValue(of(taskDetailsMock as any)); spyOn(identityService, 'getCurrentUserInfo').and.returnValue(mockUser); spyOn(formDefinitionSelectorCloudService, 'getForms').and.returnValue(of([])); fixture.detectChanges(); 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 51af624530..5c91d0d799 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 @@ -34,6 +34,7 @@ import { fakeServiceFilter } from '../../mock/task-filters-cloud.mock'; import { TranslateModule } from '@ngx-translate/core'; import { EditServiceTaskFilterCloudComponent } from './edit-service-task-filter-cloud.component'; import { MatIconTestingModule } from '@angular/material/icon/testing'; +import { ProcessDefinitionCloud } from '../../../../models/process-definition-cloud.model'; describe('EditServiceTaskFilterCloudComponent', () => { let component: EditServiceTaskFilterCloudComponent; @@ -71,7 +72,7 @@ describe('EditServiceTaskFilterCloudComponent', () => { icon: 'icon', name: 'fake-name' }) - }); + } as any); getTaskFilterSpy = spyOn(service, 'getTaskFilterById').and.returnValue(of(fakeServiceFilter)); getRunningApplicationsSpy = spyOn(appsService, 'getDeployedApplicationsByStatus').and.returnValue(of(fakeApplicationInstance)); fixture.detectChanges(); @@ -94,7 +95,9 @@ describe('EditServiceTaskFilterCloudComponent', () => { }); it('should fetch process definitions when processDefinitionName filter property is set', async(() => { - const processSpy = spyOn(taskService, 'getProcessDefinitions').and.returnValue(of([{ id: 'fake-id', name: 'fake-name' }])); + const processSpy = spyOn(taskService, 'getProcessDefinitions').and.returnValue(of([ + new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' }) + ])); fixture.detectChanges(); component.filterProperties = ['processDefinitionName']; fixture.detectChanges(); @@ -602,7 +605,7 @@ describe('EditServiceTaskFilterCloudComponent', () => { it('should emit save event and save the filter on click save button', async(() => { component.toggleFilterActions = true; - spyOn(service, 'updateFilter').and.returnValue(of({})); + spyOn(service, 'updateFilter').and.returnValue(of(null)); fixture.detectChanges(); const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); @@ -625,7 +628,7 @@ describe('EditServiceTaskFilterCloudComponent', () => { it('should emit delete event and delete the filter on click of delete button', async(() => { component.toggleFilterActions = true; - spyOn(service, 'deleteFilter').and.returnValue(of({})); + spyOn(service, 'deleteFilter').and.returnValue(of(null)); fixture.detectChanges(); const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); @@ -645,7 +648,7 @@ describe('EditServiceTaskFilterCloudComponent', () => { it('should emit saveAs event and add filter on click saveAs button', async(() => { component.toggleFilterActions = true; - spyOn(service, 'addFilter').and.returnValue(of({})); + spyOn(service, 'addFilter').and.returnValue(of(null)); fixture.detectChanges(); const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); 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 9df80ab117..a58be46701 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 @@ -39,6 +39,7 @@ import { TranslateModule } from '@ngx-translate/core'; import { DateCloudFilterType } from '../../../../models/date-cloud-filter.model'; import { TaskFilterCloudModel } from '../../models/filter-cloud.model'; import { PeopleCloudModule } from '../../../../people/people-cloud.module'; +import { ProcessDefinitionCloud } from '../../../../models/process-definition-cloud.model'; describe('EditTaskFilterCloudComponent', () => { let component: EditTaskFilterCloudComponent; @@ -51,7 +52,7 @@ describe('EditTaskFilterCloudComponent', () => { let getRunningApplicationsSpy: jasmine.Spy; let taskService: TaskCloudService; - const mock = { + const mock: any = { oauth2Auth: { callCustomApi: () => Promise.resolve(fakeApplicationInstance) }, @@ -88,7 +89,7 @@ describe('EditTaskFilterCloudComponent', () => { icon: 'icon', name: 'fake-name' }) - }); + } as any); spyOn(alfrescoApiService, 'getInstance').and.returnValue(mock); getTaskFilterSpy = spyOn(service, 'getTaskFilterById').and.returnValue(of(fakeFilter)); getRunningApplicationsSpy = spyOn(appsService, 'getDeployedApplicationsByStatus').and.returnValue(of(fakeApplicationInstance)); @@ -112,7 +113,7 @@ describe('EditTaskFilterCloudComponent', () => { }); it('should fetch process definitions when processDefinitionName filter property is set', async(() => { - const processSpy = spyOn(taskService, 'getProcessDefinitions').and.returnValue(of([{ id: 'fake-id', name: 'fake-name' }])); + const processSpy = spyOn(taskService, 'getProcessDefinitions').and.returnValue(of([new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })])); fixture.detectChanges(); component.filterProperties = ['processDefinitionName']; fixture.detectChanges(); @@ -935,7 +936,7 @@ describe('EditTaskFilterCloudComponent', () => { it('should emit save event and save the filter on click save button', async(() => { component.toggleFilterActions = true; - spyOn(service, 'updateFilter').and.returnValue(of({})); + spyOn(service, 'updateFilter').and.returnValue(of(null)); fixture.detectChanges(); const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); @@ -958,7 +959,7 @@ describe('EditTaskFilterCloudComponent', () => { it('should emit delete event and delete the filter on click of delete button', async(() => { component.toggleFilterActions = true; - spyOn(service, 'deleteFilter').and.returnValue(of({})); + spyOn(service, 'deleteFilter').and.returnValue(of(null)); fixture.detectChanges(); const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); @@ -978,7 +979,7 @@ describe('EditTaskFilterCloudComponent', () => { it('should emit saveAs event and add filter on click saveAs button', async(() => { component.toggleFilterActions = true; - spyOn(service, 'addFilter').and.returnValue(of({})); + spyOn(service, 'addFilter').and.returnValue(of(null)); fixture.detectChanges(); const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); expansionPanel.click(); @@ -1024,7 +1025,7 @@ describe('EditTaskFilterCloudComponent', () => { it('should not call restore default filters service on deletion of first filter', async(() => { component.toggleFilterActions = true; - spyOn(service, 'deleteFilter').and.returnValue(of([{ name: 'mock-filter-name' }])); + spyOn(service, 'deleteFilter').and.returnValue(of([new TaskFilterCloudModel({ name: 'mock-filter-name' })])); const restoreDefaultFiltersSpy = spyOn(component, 'restoreDefaultTaskFilters').and.returnValue(of([])); fixture.detectChanges(); const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header'); diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.spec.ts index 39152e72c0..755ad5cb90 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.spec.ts @@ -16,9 +16,9 @@ */ import { SimpleChange } from '@angular/core'; -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { setupTestBed } from '@alfresco/adf-core'; -import { from, Observable } from 'rxjs'; +import { of, throwError } from 'rxjs'; import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service'; import { LocalPreferenceCloudService } from '../../../services/local-preference-cloud.service'; import { By } from '@angular/platform-browser'; @@ -30,24 +30,8 @@ import { ServiceTaskFilterCloudService } from '../services/service-task-filter-c import { ServiceTaskFiltersCloudComponent } from './service-task-filters-cloud.component'; describe('ServiceTaskFiltersCloudComponent', () => { - let serviceTaskFilterCloudService: ServiceTaskFilterCloudService; - - const fakeGlobalFilterObservable = - new Observable(function(observer) { - observer.next(fakeGlobalServiceFilters); - observer.complete(); - }); - - const fakeGlobalFilterPromise = new Promise(function (resolve) { - resolve(fakeGlobalServiceFilters); - }); - - const mockErrorFilterList = { - error: 'wrong request' - }; - - const mockErrorFilterPromise = Promise.reject(mockErrorFilterList); + let getTaskListFiltersSpy: jasmine.Spy; let component: ServiceTaskFiltersCloudComponent; let fixture: ComponentFixture; @@ -68,194 +52,186 @@ describe('ServiceTaskFiltersCloudComponent', () => { component = fixture.componentInstance; serviceTaskFilterCloudService = TestBed.inject(ServiceTaskFilterCloudService); + getTaskListFiltersSpy = spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(of(fakeGlobalServiceFilters)); }); - it('should attach specific icon for each filter if hasIcon is true', async(() => { - spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); + afterEach(() => { + fixture.destroy(); + }); + + it('should attach specific icon for each filter if hasIcon is true', async () => { const change = new SimpleChange(undefined, 'my-app-1', true); + component.ngOnChanges({'appName': change}); + fixture.detectChanges(); + await fixture.whenStable(); + component.showIcons = true; - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(component.filters.length).toBe(3); - const filters = fixture.nativeElement.querySelectorAll('.adf-icon'); - expect(filters.length).toBe(3); - expect(filters[0].innerText).toContain('adjust'); - expect(filters[1].innerText).toContain('done'); - expect(filters[2].innerText).toContain('inbox'); - }); - })); - it('should not attach icons for each filter if hasIcon is false', (done) => { - spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise)); + fixture.detectChanges(); + await fixture.whenStable(); + expect(component.filters.length).toBe(3); + + const filters = fixture.nativeElement.querySelectorAll('.adf-icon'); + expect(filters.length).toBe(3); + expect(filters[0].innerText).toContain('adjust'); + expect(filters[1].innerText).toContain('done'); + expect(filters[2].innerText).toContain('inbox'); + }); + + it('should not attach icons for each filter if hasIcon is false', async () => { component.showIcons = false; const change = new SimpleChange(undefined, 'my-app-1', true); component.ngOnChanges({'appName': change}); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const filters: any = fixture.debugElement.queryAll(By.css('.adf-icon')); - expect(filters.length).toBe(0); - done(); - }); + fixture.detectChanges(); + await fixture.whenStable(); + + const filters: any = fixture.debugElement.queryAll(By.css('.adf-icon')); + expect(filters.length).toBe(0); }); - it('should display the filters', async(() => { - spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); + it('should display the filters', async () => { const change = new SimpleChange(undefined, 'my-app-1', true); + component.ngOnChanges({'appName': change}); + fixture.detectChanges(); + await fixture.whenStable(); + component.showIcons = true; - fixture.whenStable().then(() => { - fixture.detectChanges(); - const filters = fixture.debugElement.queryAll(By.css('.adf-task-filters__entry')); - expect(component.filters.length).toBe(3); - expect(filters.length).toBe(3); - expect(filters[0].nativeElement.innerText).toContain('FakeServiceTasks'); - expect(filters[1].nativeElement.innerText).toContain('FakeMyServiceTasks1'); - expect(filters[2].nativeElement.innerText).toContain('FakeMyServiceTasks2'); - }); - })); + + fixture.detectChanges(); + await fixture.whenStable(); + + const filters = fixture.debugElement.queryAll(By.css('.adf-task-filters__entry')); + expect(component.filters.length).toBe(3); + expect(filters.length).toBe(3); + expect(filters[0].nativeElement.innerText).toContain('FakeServiceTasks'); + expect(filters[1].nativeElement.innerText).toContain('FakeMyServiceTasks1'); + expect(filters[2].nativeElement.innerText).toContain('FakeMyServiceTasks2'); + }); it('should emit an error with a bad response', (done) => { - spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(from(mockErrorFilterPromise)); + const mockErrorFilterList = { + error: 'wrong request' + }; + getTaskListFiltersSpy.and.returnValue(throwError(mockErrorFilterList)); const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); - component.ngOnChanges({'appName': change}); component.error.subscribe((err) => { expect(err).toBeDefined(); done(); }); + + component.ngOnChanges({'appName': change}); + fixture.detectChanges(); }); - it('should return the filter task list', (done) => { - spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise)); + it('should return the filter task list', async () => { const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); + component.ngOnChanges({ 'appName': change }); - component.success.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.filters).toBeDefined(); - expect(component.filters.length).toEqual(3); - done(); - }); - }); - - it('should return the filter task list, filtered By Name', (done) => { - spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise)); - const appName = 'my-app-1'; - const change = new SimpleChange(null, appName, true); - component.ngOnChanges({ 'appName': change }); - - component.success.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.filters).toBeDefined(); - expect(component.filters[0].name).toEqual('FakeServiceTasks'); - expect(component.filters[1].name).toEqual('FakeMyServiceTasks1'); - expect(component.filters[2].name).toEqual('FakeMyServiceTasks2'); - done(); - }); - }); - - it('should select the first filter as default', async(() => { - spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); - - const appName = 'my-app-1'; - const change = new SimpleChange(null, appName, true); - fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.filters).toBeDefined(); + expect(component.filters.length).toEqual(3); + }); + + it('should return the filter task list, filtered By Name', async () => { + const appName = 'my-app-1'; + const change = new SimpleChange(null, appName, true); + component.ngOnChanges({ 'appName': change }); - component.success.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.currentFilter).toBeDefined(); - expect(component.currentFilter.name).toEqual('FakeServiceTasks'); - }); + fixture.detectChanges(); + await fixture.whenStable(); - })); + expect(component.filters).toBeDefined(); + expect(component.filters[0].name).toEqual('FakeServiceTasks'); + expect(component.filters[1].name).toEqual('FakeMyServiceTasks1'); + expect(component.filters[2].name).toEqual('FakeMyServiceTasks2'); + }); - it('should select the task filter based on the input by name param', async(() => { - spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); + it('should select the first service task filter as default', async () => { + const appName = 'my-app-1'; + const change = new SimpleChange(null, appName, true); + component.ngOnChanges({ 'appName': change }); + + fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.currentFilter).toBeDefined(); + expect(component.currentFilter.name).toEqual('FakeServiceTasks'); + }); + + it('should select the task filter based on the input by name param', async () => { component.filterParam = { name: 'FakeMyServiceTasks1' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); - fixture.detectChanges(); component.ngOnChanges({ 'appName': change }); - component.success.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.currentFilter).toBeDefined(); - expect(component.currentFilter.name).toEqual('FakeMyServiceTasks1'); - }); + fixture.detectChanges(); + await fixture.whenStable(); - })); - - it('should select the default task filter if filter input does not exist', async(() => { - spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); + expect(component.currentFilter).toBeDefined(); + expect(component.currentFilter.name).toEqual('FakeMyServiceTasks1'); + }); + it('should select the default task filter if filter input does not exist', async () => { component.filterParam = { name: 'UnexistableFilter' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); - fixture.detectChanges(); component.ngOnChanges({ 'appName': change }); - component.success.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.currentFilter).toBeDefined(); - expect(component.currentFilter.name).toEqual('FakeServiceTasks'); - }); + fixture.detectChanges(); + await fixture.whenStable(); - })); - - it('should select the task filter based on the input by index param', async(() => { - spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); + expect(component.currentFilter).toBeDefined('current filter not found'); + expect(component.currentFilter.name).toEqual('FakeServiceTasks'); + }); + it('should select the task filter based on the input by index param', async () => { component.filterParam = { index: 2 }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); - fixture.detectChanges(); component.ngOnChanges({ 'appName': change }); - component.success.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.currentFilter).toBeDefined(); - expect(component.currentFilter.name).toEqual('FakeMyServiceTasks2'); - }); + fixture.detectChanges(); + await fixture.whenStable(); - })); - - it('should select the task filter based on the input by id param', async(() => { - spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); + expect(component.currentFilter).toBeDefined(); + expect(component.currentFilter.name).toEqual('FakeMyServiceTasks2'); + }); + it('should select the task filter based on the input by id param', async () => { component.filterParam = { id: '12' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); - fixture.detectChanges(); component.ngOnChanges({ 'appName': change }); - component.success.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.currentFilter).toBeDefined(); - expect(component.currentFilter.name).toEqual('FakeMyServiceTasks2'); - }); + fixture.detectChanges(); + await fixture.whenStable(); - })); + expect(component.currentFilter).toBeDefined(); + expect(component.currentFilter.name).toEqual('FakeMyServiceTasks2'); + }); it('should emit the selected filter based on the filterParam input', async () => { - spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); spyOn(component.filterSelected, 'emit'); const filterParam = { id: '10' }; @@ -264,12 +240,12 @@ describe('ServiceTaskFiltersCloudComponent', () => { component.ngOnChanges({ 'filterParam': change }); fixture.detectChanges(); + await fixture.whenStable(); expect(component.filterSelected.emit).toHaveBeenCalledWith(fakeGlobalServiceFilters[0]); }); it('should filterClicked emit when a filter is clicked from the UI', async () => { - spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); spyOn(component.filterClicked, 'emit'); fixture.detectChanges(); @@ -284,9 +260,7 @@ describe('ServiceTaskFiltersCloudComponent', () => { expect(component.filterClicked.emit).toHaveBeenCalledWith(fakeGlobalServiceFilters[0]); }); - it('should reset the filter when the param is undefined', async(() => { - spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); - spyOn(component, 'selectFilterAndEmit'); + it('should reset the filter when the param is undefined', async () => { component.currentFilter = null; const filterName = undefined; @@ -294,9 +268,10 @@ describe('ServiceTaskFiltersCloudComponent', () => { component.ngOnChanges({ 'filterParam': change }); fixture.detectChanges(); - expect(component.selectFilterAndEmit).toHaveBeenCalledWith(undefined); - expect(component.currentFilter).toEqual(undefined); - })); + await fixture.whenStable(); + + expect(component.currentFilter).toBe(fakeGlobalServiceFilters[0]); + }); it('should reload filters by appName on binding changes', () => { spyOn(component, 'getFilters').and.stub(); @@ -312,37 +287,35 @@ describe('ServiceTaskFiltersCloudComponent', () => { component.filters = fakeGlobalServiceFilters; component.currentFilter = null; - const change = new SimpleChange(null, { name: fakeGlobalServiceFilters[1].name }, true); + const name = fakeGlobalServiceFilters[1].name; + const change = new SimpleChange(null, { name }, true); + component.ngOnChanges({ 'filterParam': change }); - fixture.whenStable().then(() => { - expect(component.currentFilter.name).toEqual(fakeGlobalServiceFilters[1].name); - }); + expect(component.currentFilter).toBeDefined('current filter not found'); + expect(component.currentFilter.name).toEqual(name); }); it('should change current filter when filterParam (key) changes', () => { component.filters = fakeGlobalServiceFilters; component.currentFilter = null; - const change = new SimpleChange(null, { key: fakeGlobalServiceFilters[2].key }, true); + const key = fakeGlobalServiceFilters[2].key; + const change = new SimpleChange(null, { key }, true); + component.ngOnChanges({ 'filterParam': change }); - fixture.whenStable().then(() => { - expect(component.currentFilter.key).toEqual(fakeGlobalServiceFilters[2].key); - }); + expect(component.currentFilter.key).toEqual(key); }); it('should change current filter when filterParam (index) changes', () => { component.filters = fakeGlobalServiceFilters; component.currentFilter = null; - const position = 1; - const change = new SimpleChange(null, { index: position }, true); + const change = new SimpleChange(null, { index: 1 }, true); component.ngOnChanges({ 'filterParam': change }); - fixture.whenStable().then(() => { - expect(component.currentFilter.name).toEqual(fakeGlobalServiceFilters[position].name); - }); + expect(component.currentFilter.name).toEqual(fakeGlobalServiceFilters[1].name); }); it('should reload filters by app name on binding changes', () => { diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.ts index 0417445b26..17d99991b7 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.ts @@ -69,8 +69,13 @@ export class ServiceTaskFiltersCloudComponent extends BaseTaskFiltersCloudCompon this.filters$.pipe(takeUntil(this.onDestroy$)).subscribe( (res: ServiceTaskFilterCloudModel[]) => { this.resetFilter(); - this.filters = Object.assign([], res); - this.selectFilterAndEmit(this.filterParam); + this.filters = res || []; + + if (this.filterParam) { + this.selectFilterAndEmit(this.filterParam); + } + + this.ensureFilterSelected(); this.success.emit(res); }, (err: any) => { @@ -88,15 +93,24 @@ export class ServiceTaskFiltersCloudComponent extends BaseTaskFiltersCloudCompon (paramFilter.name && (paramFilter.name.toLocaleLowerCase() === this.translationService.instant(filter.name).toLocaleLowerCase()) )); + + if (this.currentFilter) { + this.filterSelected.emit(this.currentFilter); + } } } public selectFilterAndEmit(newParamFilter: FilterParamsModel) { if (newParamFilter) { this.selectFilter(newParamFilter); - this.filterSelected.emit(this.currentFilter); - } else { - this.currentFilter = undefined; + } + + this.ensureFilterSelected(); + } + + private ensureFilterSelected() { + if (!this.currentFilter && this.filters.length > 0) { + this.currentFilter = this.filters[0]; } } diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.spec.ts index 51f98357a2..c2e82c7f9e 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.spec.ts @@ -16,9 +16,9 @@ */ import { SimpleChange } from '@angular/core'; -import { ComponentFixture, TestBed, async, fakeAsync, tick } from '@angular/core/testing'; +import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; import { AppConfigService, setupTestBed } from '@alfresco/adf-core'; -import { from, Observable, of } from 'rxjs'; +import { of, throwError } from 'rxjs'; import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service'; import { LocalPreferenceCloudService } from '../../../services/local-preference-cloud.service'; import { TaskFilterCloudService } from '../services/task-filter-cloud.service'; @@ -30,29 +30,13 @@ import { fakeGlobalFilter, taskNotifications } from '../mock/task-filters-cloud. import { TranslateModule } from '@ngx-translate/core'; describe('TaskFiltersCloudComponent', () => { - let taskFilterService: TaskFilterCloudService; let appConfigService: AppConfigService; - const fakeGlobalFilterObservable = - new Observable(function (observer) { - observer.next(fakeGlobalFilter); - observer.complete(); - }); - - const fakeGlobalFilterPromise = new Promise(function (resolve) { - resolve(fakeGlobalFilter); - }); - - const mockErrorFilterList = { - error: 'wrong request' - }; - - const mockErrorFilterPromise = Promise.reject(mockErrorFilterList); - let component: TaskFiltersCloudComponent; let fixture: ComponentFixture; - let getTaskFilterCounterSpy; + let getTaskFilterCounterSpy: jasmine.Spy; + let getTaskListFiltersSpy: jasmine.Spy; setupTestBed({ imports: [ @@ -66,202 +50,190 @@ describe('TaskFiltersCloudComponent', () => { }); beforeEach(() => { - fixture = TestBed.createComponent(TaskFiltersCloudComponent); - component = fixture.componentInstance; - taskFilterService = TestBed.inject(TaskFilterCloudService); getTaskFilterCounterSpy = spyOn(taskFilterService, 'getTaskFilterCounter').and.returnValue(of(11)); spyOn(taskFilterService, 'getTaskNotificationSubscription').and.returnValue(of(taskNotifications)); + getTaskListFiltersSpy = spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeGlobalFilter)); appConfigService = TestBed.inject(AppConfigService); + + fixture = TestBed.createComponent(TaskFiltersCloudComponent); + component = fixture.componentInstance; }); - it('should attach specific icon for each filter if hasIcon is true', async(() => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); + afterEach(() => { + fixture.destroy(); + }); + + it('should attach specific icon for each filter if hasIcon is true', async () => { const change = new SimpleChange(undefined, 'my-app-1', true); component.ngOnChanges({ 'appName': change }); + fixture.detectChanges(); + await fixture.whenStable(); + component.showIcons = true; - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(component.filters.length).toBe(3); - const filters = fixture.nativeElement.querySelectorAll('.adf-icon'); - expect(filters.length).toBe(3); - expect(filters[0].innerText).toContain('adjust'); - expect(filters[1].innerText).toContain('done'); - expect(filters[2].innerText).toContain('inbox'); - }); - })); - it('should not attach icons for each filter if hasIcon is false', (done) => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise)); + fixture.detectChanges(); + await fixture.whenStable(); + expect(component.filters.length).toBe(3); + + const filters = fixture.nativeElement.querySelectorAll('.adf-icon'); + expect(filters.length).toBe(3); + expect(filters[0].innerText).toContain('adjust'); + expect(filters[1].innerText).toContain('done'); + expect(filters[2].innerText).toContain('inbox'); + }); + + it('should not attach icons for each filter if hasIcon is false', async () => { component.showIcons = false; const change = new SimpleChange(undefined, 'my-app-1', true); component.ngOnChanges({ 'appName': change }); - fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const filters: any = fixture.debugElement.queryAll(By.css('.adf-icon')); - expect(filters.length).toBe(0); - done(); - }); + fixture.detectChanges(); + await fixture.whenStable(); + + const filters: any = fixture.debugElement.queryAll(By.css('.adf-icon')); + expect(filters.length).toBe(0); }); - it('should display the filters', async(() => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); + it('should display the filters', async () => { const change = new SimpleChange(undefined, 'my-app-1', true); component.ngOnChanges({ 'appName': change }); + fixture.detectChanges(); + await fixture.whenStable(); + component.showIcons = true; - fixture.whenStable().then(() => { - fixture.detectChanges(); - const filters = fixture.debugElement.queryAll(By.css('.adf-task-filters__entry')); - expect(component.filters.length).toBe(3); - expect(filters.length).toBe(3); - expect(filters[0].nativeElement.innerText).toContain('FakeInvolvedTasks'); - expect(filters[1].nativeElement.innerText).toContain('FakeMyTasks1'); - expect(filters[2].nativeElement.innerText).toContain('FakeMyTasks2'); - }); - })); + + fixture.detectChanges(); + await fixture.whenStable(); + + const filters = fixture.debugElement.queryAll(By.css('.adf-task-filters__entry')); + expect(component.filters.length).toBe(3); + expect(filters.length).toBe(3); + expect(filters[0].nativeElement.innerText).toContain('FakeInvolvedTasks'); + expect(filters[1].nativeElement.innerText).toContain('FakeMyTasks1'); + expect(filters[2].nativeElement.innerText).toContain('FakeMyTasks2'); + }); it('should emit an error with a bad response', (done) => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(mockErrorFilterPromise)); + const mockErrorFilterList = { + error: 'wrong request' + }; + getTaskListFiltersSpy.and.returnValue(throwError(mockErrorFilterList)); const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); - component.ngOnChanges({ 'appName': change }); component.error.subscribe((err) => { expect(err).toBeDefined(); done(); }); - }); - it('should return the filter task list', (done) => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise)); - const appName = 'my-app-1'; - const change = new SimpleChange(null, appName, true); component.ngOnChanges({ 'appName': change }); - - component.success.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.filters).toBeDefined(); - expect(component.filters.length).toEqual(3); - done(); - }); }); - it('should return the filter task list, filtered By Name', (done) => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise)); + it('should return the filter task list', async () => { const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); + component.ngOnChanges({ 'appName': change }); - component.success.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.filters).toBeDefined(); - expect(component.filters[0].name).toEqual('FakeInvolvedTasks'); - expect(component.filters[1].name).toEqual('FakeMyTasks1'); - expect(component.filters[2].name).toEqual('FakeMyTasks2'); - done(); - }); - }); - - it('should select the first filter as default', async(() => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); - - const appName = 'my-app-1'; - const change = new SimpleChange(null, appName, true); - fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.filters).toBeDefined(); + expect(component.filters.length).toEqual(3); + }); + + it('should return the filter task list, filtered By Name', async () => { + const appName = 'my-app-1'; + const change = new SimpleChange(null, appName, true); + component.ngOnChanges({ 'appName': change }); - component.success.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.currentFilter).toBeDefined(); - expect(component.currentFilter.name).toEqual('FakeInvolvedTasks'); - }); + fixture.detectChanges(); + await fixture.whenStable(); - })); + expect(component.filters).toBeDefined(); + expect(component.filters[0].name).toEqual('FakeInvolvedTasks'); + expect(component.filters[1].name).toEqual('FakeMyTasks1'); + expect(component.filters[2].name).toEqual('FakeMyTasks2'); + }); - it('should select the task filter based on the input by name param', async(() => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); + it('should select the first cloud task filter as default', async () => { + const appName = 'my-app-1'; + const change = new SimpleChange(null, appName, true); + component.ngOnChanges({ 'appName': change }); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(component.filters.length).toBe(fakeGlobalFilter.length); + expect(component.currentFilter).toBeDefined('current filter not found'); + expect(component.currentFilter.name).toEqual('FakeInvolvedTasks'); + }); + + it('should select the task filter based on the input by name param', async () => { component.filterParam = { name: 'FakeMyTasks1' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); - fixture.detectChanges(); component.ngOnChanges({ 'appName': change }); + fixture.detectChanges(); + await fixture.whenStable(); - component.success.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.currentFilter).toBeDefined(); - expect(component.currentFilter.name).toEqual('FakeMyTasks1'); - }); - - })); - - it('should select the default task filter if filter input does not exist', async(() => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); + expect(component.currentFilter).toBeDefined(); + expect(component.currentFilter.name).toEqual('FakeMyTasks1'); + }); + it('should select the default task filter if filter input does not exist', async () => { component.filterParam = { name: 'UnexistableFilter' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); - fixture.detectChanges(); component.ngOnChanges({ 'appName': change }); - component.success.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.currentFilter).toBeDefined(); - expect(component.currentFilter.name).toEqual('FakeInvolvedTasks'); - }); + fixture.detectChanges(); + await fixture.whenStable(); - })); - - it('should select the task filter based on the input by index param', async(() => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); + expect(component.currentFilter).toBeDefined('current filter not found'); + expect(component.currentFilter.name).toEqual('FakeInvolvedTasks'); + }); + it('should select the task filter based on the input by index param', async () => { component.filterParam = { index: 2 }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); - fixture.detectChanges(); component.ngOnChanges({ 'appName': change }); - component.success.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.currentFilter).toBeDefined(); - expect(component.currentFilter.name).toEqual('FakeMyTasks2'); - }); + fixture.detectChanges(); + await fixture.whenStable(); - })); - - it('should select the task filter based on the input by id param', async(() => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); + expect(component.currentFilter).toBeDefined(); + expect(component.currentFilter.name).toEqual('FakeMyTasks2'); + }); + it('should select the task filter based on the input by id param', async () => { component.filterParam = { id: '12' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); - fixture.detectChanges(); component.ngOnChanges({ 'appName': change }); - component.success.subscribe((res) => { - expect(res).toBeDefined(); - expect(component.currentFilter).toBeDefined(); - expect(component.currentFilter.name).toEqual('FakeMyTasks2'); - }); + fixture.detectChanges(); + await fixture.whenStable(); - })); + expect(component.currentFilter).toBeDefined(); + expect(component.currentFilter.name).toEqual('FakeMyTasks2'); + }); - it('should emit the selected filter based on the filterParam input', async(() => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); + it('should emit the selected filter based on the filterParam input', async () => { spyOn(component.filterSelected, 'emit'); const filterParam = { id: '10' }; @@ -269,13 +241,14 @@ describe('TaskFiltersCloudComponent', () => { component.filterParam = filterParam; component.ngOnChanges({ 'filterParam': change }); + fixture.detectChanges(); + await fixture.whenStable(); expect(component.filterSelected.emit).toHaveBeenCalledWith(fakeGlobalFilter[0]); - })); + }); it('should filterClicked emit when a filter is clicked from the UI', async () => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); spyOn(component.filterClicked, 'emit'); fixture.detectChanges(); @@ -290,9 +263,7 @@ describe('TaskFiltersCloudComponent', () => { expect(component.filterClicked.emit).toHaveBeenCalledWith(fakeGlobalFilter[0]); }); - it('should reset the filter when the param is undefined', async(() => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); - spyOn(component, 'selectFilterAndEmit'); + it('should reset the filter when the param is undefined', async () => { component.currentFilter = null; const filterName = undefined; @@ -300,9 +271,10 @@ describe('TaskFiltersCloudComponent', () => { component.ngOnChanges({ 'filterParam': change }); fixture.detectChanges(); - expect(component.selectFilterAndEmit).toHaveBeenCalledWith(undefined); - expect(component.currentFilter).toEqual(undefined); - })); + await fixture.whenStable(); + + expect(component.currentFilter).toEqual(fakeGlobalFilter[0]); + }); it('should reload filters by appName on binding changes', () => { spyOn(component, 'getFilters').and.stub(); @@ -333,9 +305,7 @@ describe('TaskFiltersCloudComponent', () => { const change = new SimpleChange(null, { key: fakeGlobalFilter[2].key }, true); component.ngOnChanges({ 'filterParam': change }); - fixture.whenStable().then(() => { - expect(component.currentFilter.key).toEqual(fakeGlobalFilter[2].key); - }); + expect(component.currentFilter.key).toEqual(fakeGlobalFilter[2].key); }); it('should change current filter when filterParam (index) changes', () => { @@ -346,9 +316,7 @@ describe('TaskFiltersCloudComponent', () => { const change = new SimpleChange(null, { index: position }, true); component.ngOnChanges({ 'filterParam': change }); - fixture.whenStable().then(() => { - expect(component.currentFilter.name).toEqual(fakeGlobalFilter[position].name); - }); + expect(component.currentFilter.name).toEqual(fakeGlobalFilter[position].name); }); it('should reload filters by app name on binding changes', () => { @@ -370,23 +338,25 @@ describe('TaskFiltersCloudComponent', () => { expect(component.currentFilter).toBe(fakeGlobalFilter[0]); }); - it('should display filter counter if property set to true', async(() => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); + it('should display filter counter if property set to true', async () => { const change = new SimpleChange(undefined, 'my-app-1', true); component.ngOnChanges({ 'appName': change }); + fixture.detectChanges(); + await fixture.whenStable(); + component.showIcons = true; - fixture.whenStable().then(() => { - fixture.detectChanges(); - const filterCounters = fixture.debugElement.queryAll(By.css('.adf-filter-action-button__counter')); - expect(component.filters.length).toBe(3); - expect(filterCounters.length).toBe(1); - expect(filterCounters[0].nativeElement.innerText).toContain('11'); - }); - })); + + fixture.detectChanges(); + await fixture.whenStable(); + + const filterCounters = fixture.debugElement.queryAll(By.css('.adf-filter-action-button__counter')); + expect(component.filters.length).toBe(3); + expect(filterCounters.length).toBe(1); + expect(filterCounters[0].nativeElement.innerText).toContain('11'); + }); it('should update filter counter when notification received', fakeAsync(() => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); spyOn(appConfigService, 'get').and.returnValue(true); component.appName = 'my-app-1'; component.ngOnInit(); @@ -403,7 +373,6 @@ describe('TaskFiltersCloudComponent', () => { })); it('should not update filter counter when notifications are disabled from app.config.json', fakeAsync(() => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); spyOn(appConfigService, 'get').and.returnValue(false); component.appName = 'my-app-1'; component.ngOnInit(); @@ -418,7 +387,6 @@ describe('TaskFiltersCloudComponent', () => { })); it('should reset filter counter notification when filter is selected', fakeAsync(() => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); spyOn(appConfigService, 'get').and.returnValue(true); let change = new SimpleChange(undefined, 'my-app-1', true); component.appName = 'my-app-1'; @@ -446,7 +414,6 @@ describe('TaskFiltersCloudComponent', () => { })); it('should update filter counter when filter is selected', fakeAsync(() => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); component.appName = 'my-app-1'; component.ngOnInit(); tick(5000); diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.ts index c7dc5c584d..cccad6ff4f 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.ts @@ -79,8 +79,16 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp this.filters$.pipe(takeUntil(this.onDestroy$)).subscribe( (res: TaskFilterCloudModel[]) => { this.resetFilter(); - this.filters = Object.assign([], res); - this.selectFilterAndEmit(this.filterParam); + this.filters = res || []; + + if (this.filterParam) { + this.selectFilterAndEmit(this.filterParam); + } + + if (!this.currentFilter && this.filters.length > 0) { + this.currentFilter = this.filters[0]; + } + this.updateFilterCounters(); this.success.emit(res); }, @@ -145,12 +153,19 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp public selectFilterAndEmit(newParamFilter: FilterParamsModel) { if (newParamFilter) { this.selectFilter(newParamFilter); + if (this.currentFilter) { this.resetFilterCounter(this.currentFilter.key); this.filterSelected.emit(this.currentFilter); } - } else { - this.currentFilter = undefined; + } + + this.ensureFilterSelected(); + } + + private ensureFilterSelected() { + if (!this.currentFilter && this.filters.length > 0) { + this.currentFilter = this.filters[0]; } } diff --git a/lib/process-services-cloud/src/lib/task/task-filters/mock/task-filters-cloud.mock.ts b/lib/process-services-cloud/src/lib/task/task-filters/mock/task-filters-cloud.mock.ts index c20ccdda76..45788643e7 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/mock/task-filters-cloud.mock.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/mock/task-filters-cloud.mock.ts @@ -18,8 +18,8 @@ import { assignedTaskDetailsCloudMock } from '../../task-header/mocks/task-details-cloud.mock'; import { TaskFilterCloudModel, ServiceTaskFilterCloudModel } from '../models/filter-cloud.model'; -export const fakeGlobalFilter = [ - new TaskFilterCloudModel({ +export const fakeGlobalFilter: any[] = [ + { name: 'FakeInvolvedTasks', key: 'fake-involved-tasks', icon: 'adjust', @@ -27,8 +27,8 @@ export const fakeGlobalFilter = [ status: 'ASSIGNED', assignee: 'AssignedTaskUser', showCounter: true - }), - new TaskFilterCloudModel({ + }, + { name: 'FakeMyTasks1', key: 'fake-my-tast1', icon: 'done', @@ -36,18 +36,18 @@ export const fakeGlobalFilter = [ status: 'open', assignee: 'fake-assignee', showCounter: false - }), - new TaskFilterCloudModel({ + }, + { name: 'FakeMyTasks2', key: 'fake-my-tast2', icon: 'inbox', id: '12', status: 'open', assignee: 'fake-assignee' - }) + } ]; -export const fakeGlobalServiceFilters = [ +export const fakeGlobalServiceFilters: ServiceTaskFilterCloudModel[] = [ { name: 'FakeServiceTasks', key: 'fake-involved-tasks', 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 2b0ab252ae..bf2eaf4c9f 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 @@ -49,7 +49,7 @@ describe('TaskHeaderCloudComponent', () => { const mockCandidateUsers = ['mockuser1', 'mockuser2', 'mockuser3']; const mockCandidateGroups = ['mockgroup1', 'mockgroup2', 'mockgroup3']; - const mock = { + const mock: any = { oauth2Auth: { callCustomApi: () => Promise.resolve({}) }, diff --git a/lib/process-services-cloud/src/lib/task/task-header/mocks/fake-claim-task.mock.ts b/lib/process-services-cloud/src/lib/task/task-header/mocks/fake-claim-task.mock.ts index 9e94d83ea6..955cb0402f 100644 --- a/lib/process-services-cloud/src/lib/task/task-header/mocks/fake-claim-task.mock.ts +++ b/lib/process-services-cloud/src/lib/task/task-header/mocks/fake-claim-task.mock.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -export const taskClaimCloudMock = { +export const taskClaimCloudMock: any = { 'entry': { 'appName': 'simple-app', 'appVersion': '', diff --git a/lib/process-services-cloud/src/lib/task/task-header/mocks/fake-complete-task.mock.ts b/lib/process-services-cloud/src/lib/task/task-header/mocks/fake-complete-task.mock.ts index 9e1b4b5c97..7b75749659 100644 --- a/lib/process-services-cloud/src/lib/task/task-header/mocks/fake-complete-task.mock.ts +++ b/lib/process-services-cloud/src/lib/task/task-header/mocks/fake-complete-task.mock.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -export const taskCompleteCloudMock = { +export const taskCompleteCloudMock: any = { 'entry': { 'appName': 'simple-app', 'appVersion': '', diff --git a/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.spec.ts index 5d2ab18d01..2c5934213f 100644 --- a/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-list/services/service-task-list-cloud.service.spec.ts @@ -26,7 +26,7 @@ describe('Activiti ServiceTaskList Cloud Service', () => { let service: ServiceTaskListCloudService; let alfrescoApiService: AlfrescoApiService; - function returnCallQueryParameters() { + function returnCallQueryParameters(): any { return { oauth2Auth: { callCustomApi: (_queryUrl, _operation, _context, queryParams) => { @@ -40,7 +40,7 @@ describe('Activiti ServiceTaskList Cloud Service', () => { }; } - function returnCallUrl() { + function returnCallUrl(): any { return { oauth2Auth: { callCustomApi: (queryUrl) => { diff --git a/lib/process-services-cloud/src/lib/task/task-list/services/task-list-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/task/task-list/services/task-list-cloud.service.spec.ts index 0cd9c61af8..fa4120a1d4 100644 --- a/lib/process-services-cloud/src/lib/task/task-list/services/task-list-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-list/services/task-list-cloud.service.spec.ts @@ -27,7 +27,7 @@ describe('TaskListCloudService', () => { let service: TaskListCloudService; let alfrescoApiService: AlfrescoApiService; - function returnCallQueryParameters() { + function returnCallQueryParameters(): any { return { oauth2Auth: { callCustomApi : (_queryUrl, _operation, _context, queryParams) => { @@ -41,7 +41,7 @@ describe('TaskListCloudService', () => { }; } - function returnCallUrl() { + function returnCallUrl(): any { return { oauth2Auth: { callCustomApi : (queryUrl) => { diff --git a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.spec.ts b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.spec.ts index 78e7a5759c..ee18e86ddb 100644 --- a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.spec.ts +++ b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.spec.ts @@ -25,7 +25,7 @@ import { setupTestBed, AuthenticationService, SitesService, AlfrescoApiService, import { AttachFileWidgetDialogComponentData } from './attach-file-widget-dialog-component.interface'; import { of, throwError } from 'rxjs'; import { By } from '@angular/platform-browser'; -import { Node, SiteEntry, NodeEntry } from '@alfresco/js-api'; +import { Node, SiteEntry, NodeEntry, SitePaging } from '@alfresco/js-api'; import { TranslateModule } from '@ngx-translate/core'; describe('AttachFileWidgetDialogComponent', () => { @@ -76,10 +76,10 @@ describe('AttachFileWidgetDialogComponent', () => { spyOn(documentListService, 'getFolderNode').and.returnValue(of( { entry: { path: { elements: [] } } })); spyOn(documentListService, 'getFolder').and.returnValue(throwError('No results for test')); - spyOn(nodeService, 'getNode').and.returnValue(of({ id: 'fake-node', path: { elements: [{ nodeType: 'st:site', name: 'fake-site'}] } })); + spyOn(nodeService, 'getNode').and.returnValue(of(new Node({ id: 'fake-node', path: { elements: [{ nodeType: 'st:site', name: 'fake-site'}] } }))); spyOn(siteService, 'getSite').and.returnValue(of(fakeSite)); - spyOn(siteService, 'getSites').and.returnValue(of({ list: { entries: [] } })); + spyOn(siteService, 'getSites').and.returnValue(of(new SitePaging({ list: { entries: [] } }))); spyOn(widget, 'isLoggedIn').and.callFake(() => { return isLogged; }); @@ -203,7 +203,7 @@ describe('AttachFileWidgetDialogComponent', () => { it('should close the dialog immediately if user already loggedIn', () => { isLogged = true; fixture.detectChanges(); - spyOn(apiService, 'getInstance').and.returnValue({ isLoggedIn: () => true }); + spyOn(apiService, 'getInstance').and.returnValue({ isLoggedIn: () => true } as any); widget.updateExternalHost(); expect(matDialogRef.close).toHaveBeenCalled(); }); diff --git a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.spec.ts b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.spec.ts index 9fdeaac2d1..eef600fa0b 100644 --- a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.spec.ts +++ b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.spec.ts @@ -45,7 +45,7 @@ describe('AttachFileWidgetDialogService', () => { componentInstance: { error: new Subject() } - }); + } as any); }); it('should be able to open the dialog when node has permission', () => { 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 1c8864f1ac..a5d3c8bae2 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 @@ -110,7 +110,7 @@ const fakeMinimalNode: Node = { } }; -const fakePngUpload = { +const fakePngUpload: any = { 'id': 1166, 'name': 'fake-png.png', 'created': '2017-07-25T17:17:37.099Z', @@ -125,7 +125,7 @@ const fakePngUpload = { 'thumbnailStatus': 'queued' }; -const fakePngAnswer = { +const fakePngAnswer: any = { 'id': 1155, 'name': 'a_png_file.png', 'created': '2017-07-25T17:17:37.099Z', diff --git a/lib/process-services/src/lib/form/form.component.spec.ts b/lib/process-services/src/lib/form/form.component.spec.ts index f117cee2db..a1ca65eefb 100644 --- a/lib/process-services/src/lib/form/form.component.spec.ts +++ b/lib/process-services/src/lib/form/form.component.spec.ts @@ -21,7 +21,8 @@ import { TestBed, ComponentFixture } from '@angular/core/testing'; import { Observable, of, throwError } from 'rxjs'; import { FormFieldModel, FormFieldTypes, FormModel, FormOutcomeEvent, FormOutcomeModel, FormService, WidgetVisibilityService, NodeService, ContainerModel, fakeForm, - setupTestBed } from '@alfresco/adf-core'; + setupTestBed, + NodeMetadata } from '@alfresco/adf-core'; import { FormComponent } from './form.component'; import { ProcessFormRenderingService } from './process-form-rendering.service'; import { ProcessTestingModule } from '../testing/process.testing.module'; @@ -235,7 +236,7 @@ describe('FormComponent', () => { }); }); - spyOn(visibilityService, 'getTaskProcessVariable').and.returnValue(of({})); + spyOn(visibilityService, 'getTaskProcessVariable').and.returnValue(of(null)); spyOn(formService, 'getTask').and.callFake((currentTaskId) => { return new Observable((observer) => { observer.next({ taskId: currentTaskId, processDefinitionId: '10201' }); @@ -258,7 +259,7 @@ describe('FormComponent', () => { }); }); - spyOn(visibilityService, 'getTaskProcessVariable').and.returnValue(of({})); + spyOn(visibilityService, 'getTaskProcessVariable').and.returnValue(of(null)); spyOn(formService, 'getTask').and.callFake((currentTaskId) => { return new Observable((observer) => { observer.next({ taskId: currentTaskId, processDefinitionId: 'null' }); @@ -758,10 +759,7 @@ describe('FormComponent', () => { it('should load form for ecm node', () => { const metadata = {}; spyOn(nodeService, 'getNodeMetadata').and.returnValue( - new Observable((observer) => { - observer.next({ metadata: metadata }); - observer.complete(); - }) + of(new NodeMetadata(metadata, null)) ); spyOn(formComponent, 'loadFormFromActiviti').and.stub(); diff --git a/lib/process-services/src/lib/mock/process/process-comments.mock.ts b/lib/process-services/src/lib/mock/process/process-comments.mock.ts index aaa4c00279..6e226e4244 100644 --- a/lib/process-services/src/lib/mock/process/process-comments.mock.ts +++ b/lib/process-services/src/lib/mock/process/process-comments.mock.ts @@ -15,8 +15,10 @@ * limitations under the License. */ +import { CommentModel } from '@alfresco/adf-core'; + export let mockProcessInstanceComments = [ - { message: 'Test1', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'} }, - { message: 'Test2', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'} }, - { message: 'Test3', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'} } + new CommentModel({ message: 'Test1', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'} }), + new CommentModel({ message: 'Test2', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'} }), + new CommentModel({ message: 'Test3', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'} }) ]; diff --git a/lib/process-services/src/lib/mock/process/process-instances-list.mock.ts b/lib/process-services/src/lib/mock/process/process-instances-list.mock.ts index d3840171ee..d9f75eec4a 100644 --- a/lib/process-services/src/lib/mock/process/process-instances-list.mock.ts +++ b/lib/process-services/src/lib/mock/process/process-instances-list.mock.ts @@ -15,7 +15,9 @@ * limitations under the License. */ -export let fakeProcessInstance = { +import { ProcessListModel } from '../../process-list/models/process-list.model'; + +export let fakeProcessInstance = new ProcessListModel({ size: 2, total: 2, start: 0, @@ -81,7 +83,7 @@ export let fakeProcessInstance = { ] } ] -}; +}); export let fakeProcessInstancesWithNoName = { size: 2, @@ -123,12 +125,12 @@ export let fakeProcessInstancesWithNoName = { ] }; -export let fakeProcessInstancesEmpty = { +export let fakeProcessInstancesEmpty = new ProcessListModel({ size: 0, total: 0, start: 0, data: [] -}; +}); export let fakeProcessCustomSchema = [ { diff --git a/lib/process-services/src/lib/mock/task/task-details.mock.ts b/lib/process-services/src/lib/mock/task/task-details.mock.ts index c126fc95e9..57557ee11b 100644 --- a/lib/process-services/src/lib/mock/task/task-details.mock.ts +++ b/lib/process-services/src/lib/mock/task/task-details.mock.ts @@ -15,6 +15,7 @@ * limitations under the License. */ +import { UserRepresentation } from '@alfresco/js-api'; import { TaskDetailsModel } from '../../task-list/models/task-details.model'; export let standaloneTaskWithForm = new TaskDetailsModel({ @@ -938,7 +939,7 @@ export const involvedGroupTaskForm = { managerOfCandidateGroup: false }; -export const fakeUser = { +export const fakeUser = new UserRepresentation({ id: 1001, email: 'fake-email@gmail.com', firstName: 'fake', @@ -972,4 +973,4 @@ export const fakeUser = { apps: [], tenantPictureId: null, tenantName: 'abc' -}; +}); diff --git a/lib/process-services/src/lib/mock/task/task-filters.mock.ts b/lib/process-services/src/lib/mock/task/task-filters.mock.ts index 9834836ece..a571ab141b 100644 --- a/lib/process-services/src/lib/mock/task/task-filters.mock.ts +++ b/lib/process-services/src/lib/mock/task/task-filters.mock.ts @@ -15,17 +15,15 @@ * limitations under the License. */ -import { AppDefinitionRepresentationModel, FilterRepresentationModel } from '../../task-list/models/filter.model'; +import { FilterRepresentationModel } from '../../task-list/models/filter.model'; -export let fakeFiltersResponse = { +export let fakeFiltersResponse: any = { size: 2, total: 2, start: 0, data: [ - new AppDefinitionRepresentationModel( - { - id: 1, name: 'FakeInvolvedTasks', recent: false, icon: 'glyphicon-align-left', - filter: { sort: 'created-desc', name: '', state: 'open', assignment: 'fake-involved' } - } - ), + { + id: 1, name: 'FakeInvolvedTasks', recent: false, icon: 'glyphicon-align-left', + filter: { sort: 'created-desc', name: '', state: 'open', assignment: 'fake-involved' } + }, { id: 2, name: 'FakeMyTasks', recent: false, icon: 'glyphicon-align-left', filter: { sort: 'created-desc', name: '', state: 'open', assignment: 'fake-assignee' } diff --git a/lib/process-services/src/lib/mock/task/task-list.mock.ts b/lib/process-services/src/lib/mock/task/task-list.mock.ts index ab87b4ede1..8a525e01be 100644 --- a/lib/process-services/src/lib/mock/task/task-list.mock.ts +++ b/lib/process-services/src/lib/mock/task/task-list.mock.ts @@ -15,7 +15,9 @@ * limitations under the License. */ -export const fakeGlobalTask = { +import { TaskListModel } from '../../task-list/models/task-list.model'; + +export const fakeGlobalTask = new TaskListModel({ size: 2, start: 0, total: 2, @@ -74,7 +76,7 @@ export const fakeGlobalTask = { endDate: null } ] -}; +}); export let fakeCustomSchema = [ { @@ -124,7 +126,7 @@ export let fakeEmptyTask = { data: [] }; -export const paginatedTask = { +export const paginatedTask = new TaskListModel({ 'size': 5, 'total': 9, 'start': 0, @@ -284,4 +286,4 @@ export const paginatedTask = { 'memberOfCandidateUsers': false, 'managerOfCandidateGroup': false }] -}; +}); diff --git a/lib/process-services/src/lib/mock/task/tasklist-service.mock.ts b/lib/process-services/src/lib/mock/task/tasklist-service.mock.ts index 5dc13dc37d..cbd3c1837d 100644 --- a/lib/process-services/src/lib/mock/task/tasklist-service.mock.ts +++ b/lib/process-services/src/lib/mock/task/tasklist-service.mock.ts @@ -15,6 +15,7 @@ * limitations under the License. */ +import { TaskListModel } from '../../task-list/models/task-list.model'; import { fakeAppFilter } from './task-filters.mock'; export let fakeApps = { @@ -35,7 +36,7 @@ export let fakeUser1 = { id: 1, email: 'fake-email@dom.com', firstName: 'firstNa export let fakeUser2 = { id: 1001, email: 'some-one@somegroup.com', firstName: 'some', lastName: 'one' }; -export let fakeTaskList = { +export let fakeTaskList = new TaskListModel({ size: 1, total: 1, start: 0, data: [ { @@ -44,7 +45,7 @@ export let fakeTaskList = { created: '2016-07-15T11:19:17.440+0000' } ] -}; +}); export let fakeTaskListDifferentProcessDefinitionKey = { size: 2, total: 1, start: 0, @@ -188,16 +189,16 @@ export let fakeTaskCompleted2 = { endDate: '2016-11-03T15:25:42.749+0000' }; -export let fakeOpenTaskList = { +export let fakeOpenTaskList = new TaskListModel({ size: 2, total: 2, start: 0, data: [fakeTaskOpen1, fakeTaskOpen2] -}; +}); -export let fakeCompletedTaskList = { +export let fakeCompletedTaskList = new TaskListModel({ size: 2, total: 2, start: 0, data: [fakeTaskCompleted1, fakeTaskCompleted2] -}; +}); diff --git a/lib/process-services/src/lib/pipes/process-name.pipe.spec.ts b/lib/process-services/src/lib/pipes/process-name.pipe.spec.ts index 18a8d0a40c..433e57633d 100644 --- a/lib/process-services/src/lib/pipes/process-name.pipe.spec.ts +++ b/lib/process-services/src/lib/pipes/process-name.pipe.spec.ts @@ -30,7 +30,7 @@ describe('ProcessNamePipe', () => { const defaultName = 'default-name'; const datetimeIdentifier = '%{datetime}'; const processDefinitionIdentifier = '%{processDefinition}'; - const mockCurrentDate = 'Wed Oct 23 2019'; + const mockCurrentDate = new Date('Wed Oct 23 2019'); const mockLocalizedCurrentDate = 'Oct 23, 2019, 12:00:00 AM'; const nameWithProcessDefinitionIdentifier = `${defaultName} - ${processDefinitionIdentifier}`; const nameWithDatetimeIdentifier = `${defaultName} - ${datetimeIdentifier}`; diff --git a/lib/process-services/src/lib/process-list/components/process-filters.component.spec.ts b/lib/process-services/src/lib/process-list/components/process-filters.component.spec.ts index 4fec2a0f54..74f4ef4632 100644 --- a/lib/process-services/src/lib/process-list/components/process-filters.component.spec.ts +++ b/lib/process-services/src/lib/process-list/components/process-filters.component.spec.ts @@ -17,7 +17,7 @@ import { CUSTOM_ELEMENTS_SCHEMA, SimpleChange } from '@angular/core'; import { AppsProcessService, setupTestBed } from '@alfresco/adf-core'; -import { from } from 'rxjs'; +import { from, of } from 'rxjs'; import { FilterProcessRepresentationModel } from '../models/filter-process.model'; import { ProcessFilterService } from '../services/process-filter.service'; import { ProcessFiltersComponent } from './process-filters.component'; @@ -33,8 +33,6 @@ describe('ProcessFiltersComponent', () => { let fixture: ComponentFixture; let processFilterService: ProcessFilterService; let appsProcessService: AppsProcessService; - let fakeGlobalFilterPromise; - let mockErrorFilterPromise; setupTestBed({ imports: [ @@ -47,7 +45,6 @@ describe('ProcessFiltersComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(ProcessFiltersComponent); filterList = fixture.componentInstance; - fakeGlobalFilterPromise = Promise.resolve(fakeProcessFilters); processFilterService = TestBed.inject(ProcessFilterService); appsProcessService = TestBed.inject(AppsProcessService); }); @@ -56,11 +53,10 @@ describe('ProcessFiltersComponent', () => { fixture.destroy(); }); - it('should return the filter task list', (done) => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise)); + it('should return the filter task list', async (done) => { + spyOn(processFilterService, 'getProcessFilters').and.returnValue(of(fakeProcessFilters)); const appId = '1'; const change = new SimpleChange(null, appId, true); - filterList.ngOnChanges({ 'appId': change }); filterList.success.subscribe((res) => { expect(res).toBeDefined(); @@ -72,16 +68,21 @@ describe('ProcessFiltersComponent', () => { done(); }); - fixture.detectChanges(); - }); + spyOn(filterList, 'getFiltersByAppId').and.callThrough(); - it('should select the Running process filter', (done) => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise)); - const appId = '1'; - const change = new SimpleChange(null, appId, true); filterList.ngOnChanges({ 'appId': change }); - expect(filterList.currentFilter).toBeUndefined(); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(filterList.getFiltersByAppId).toHaveBeenCalled(); + }); + + it('should select the Running process filter', async (done) => { + spyOn(processFilterService, 'getProcessFilters').and.returnValue(of(fakeProcessFilters)); + + const appId = '1'; + const change = new SimpleChange(null, appId, true); filterList.success.subscribe(() => { filterList.selectRunningFilter(); @@ -89,24 +90,26 @@ describe('ProcessFiltersComponent', () => { done(); }); + filterList.ngOnChanges({ 'appId': change }); + fixture.detectChanges(); + await fixture.whenStable(); }); - it('should emit the selected filter based on the filterParam input', (done) => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise)); + it('should emit the selected filter based on the filterParam input', async (done) => { + spyOn(processFilterService, 'getProcessFilters').and.returnValue(of(fakeProcessFilters)); filterList.filterParam = new FilterProcessRepresentationModel({ id: 10 }); const appId = '1'; const change = new SimpleChange(null, appId, true); - filterList.ngOnChanges({ 'appId': change }); - - expect(filterList.currentFilter).toBeUndefined(); filterList.filterSelected.subscribe((filter) => { expect(filter.name).toEqual('FakeCompleted'); done(); }); + filterList.ngOnChanges({ 'appId': change }); fixture.detectChanges(); + await fixture.whenStable(); }); it('should filterClicked emit when a filter is clicked from the UI', async () => { @@ -123,7 +126,7 @@ describe('ProcessFiltersComponent', () => { }); it('should reset selection when filterParam is a filter that does not exist', async () => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise)); + spyOn(processFilterService, 'getProcessFilters').and.returnValue(of(fakeProcessFilters)); const nonExistingFilterParam = { name: 'non-existing-filter' }; const appId = '1'; @@ -141,7 +144,7 @@ describe('ProcessFiltersComponent', () => { it('should return the filter task list, filtered By Name', (done) => { spyOn(appsProcessService, 'getDeployedApplicationsByName').and.returnValue(from(Promise.resolve({ id: 1 }))); - spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise)); + spyOn(processFilterService, 'getProcessFilters').and.returnValue(of(fakeProcessFilters)); const change = new SimpleChange(null, 'test', true); filterList.ngOnChanges({ 'appName': change }); @@ -157,7 +160,7 @@ describe('ProcessFiltersComponent', () => { }); it('should emit an error with a bad response', (done) => { - mockErrorFilterPromise = Promise.reject({ + const mockErrorFilterPromise = Promise.reject({ error: 'wrong request' }); spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(mockErrorFilterPromise)); @@ -175,6 +178,9 @@ describe('ProcessFiltersComponent', () => { }); it('should emit an error with a bad response', (done) => { + const mockErrorFilterPromise = Promise.reject({ + error: 'wrong request' + }); spyOn(appsProcessService, 'getDeployedApplicationsByName').and.returnValue(from(mockErrorFilterPromise)); const appId = 'fake-app'; @@ -196,7 +202,7 @@ describe('ProcessFiltersComponent', () => { filter: { state: 'open', assignment: 'fake-involved' } }); - filterList.filterClicked.subscribe((filter: FilterProcessRepresentationModel) => { + filterList.filterClicked.subscribe((filter) => { expect(filter).toBeDefined(); expect(filter).toEqual(currentFilter); expect(filterList.currentFilter).toEqual(currentFilter); @@ -247,7 +253,7 @@ describe('ProcessFiltersComponent', () => { }); it('should select the filter passed as input by id', (done) => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise)); + spyOn(processFilterService, 'getProcessFilters').and.returnValue(of(fakeProcessFilters)); filterList.filterParam = new FilterProcessRepresentationModel({ id: 20 }); @@ -267,7 +273,7 @@ describe('ProcessFiltersComponent', () => { }); it('should select the filter passed as input by name', (done) => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise)); + spyOn(processFilterService, 'getProcessFilters').and.returnValue(of(fakeProcessFilters)); filterList.filterParam = new FilterProcessRepresentationModel({ name: 'FakeAll' }); @@ -287,7 +293,7 @@ describe('ProcessFiltersComponent', () => { }); it('should attach specific icon for each filter if hasIcon is true', (done) => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise)); + spyOn(processFilterService, 'getProcessFilters').and.returnValue(of(fakeProcessFilters)); filterList.showIcon = true; const change = new SimpleChange(undefined, 1, true); filterList.ngOnChanges({ 'appId': change }); @@ -305,7 +311,7 @@ describe('ProcessFiltersComponent', () => { }); it('should not attach icons for each filter if hasIcon is false', (done) => { - spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise)); + spyOn(processFilterService, 'getProcessFilters').and.returnValue(of(fakeProcessFilters)); filterList.showIcon = false; const change = new SimpleChange(undefined, 1, true); filterList.ngOnChanges({ 'appId': change }); 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 f3b56f3263..09d6a54b31 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 @@ -125,7 +125,7 @@ describe('ProcessInstanceListComponent', () => { component.state = 'open'; fixture.detectChanges(); tick(); - expect(emitSpy).toHaveBeenCalledWith(fakeProcessInstance); + expect(emitSpy).toHaveBeenCalledWith(jasmine.objectContaining(fakeProcessInstance)); })); it('should return the process instances list in original order when datalist passed non-existent columns', async(() => { @@ -207,7 +207,7 @@ describe('ProcessInstanceListComponent', () => { const emitSpy = spyOn(component.success, 'emit'); component.reload(); tick(); - expect(emitSpy).toHaveBeenCalledWith(fakeProcessInstance); + expect(emitSpy).toHaveBeenCalledWith(jasmine.objectContaining(fakeProcessInstance)); })); it('should reload processes when reload() is called', (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 07fa816a5b..ac5b09c98c 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 @@ -137,7 +137,7 @@ describe('AttachFormComponent', () => { component.taskId = 1; component.attachFormControl.setValue(10); component.formKey = 12; - spyOn(taskService, 'deleteForm').and.returnValue(of({})); + spyOn(taskService, 'deleteForm').and.returnValue(of(null)); fixture.detectChanges(); fixture.whenStable().then(() => { 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 35a7043a04..c7af6290a4 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 @@ -42,10 +42,10 @@ describe('ChecklistComponent', () => { beforeEach(async(() => { service = TestBed.inject(TaskListService); - spyOn(service, 'getTaskChecklist').and.returnValue(of([{ + spyOn(service, 'getTaskChecklist').and.returnValue(of([new TaskDetailsModel({ id: 'fake-check-changed-id', name: 'fake-check-changed-name' - }])); + })])); fixture = TestBed.createComponent(ChecklistComponent); checklistComponent = fixture.componentInstance; @@ -177,9 +177,9 @@ describe('ChecklistComponent', () => { }); it('should add checklist', async(() => { - spyOn(service, 'addTask').and.returnValue(of({ + spyOn(service, 'addTask').and.returnValue(of(new TaskDetailsModel({ id: 'fake-check-added-id', name: 'fake-check-added-name' - })); + }))); showChecklistDialog.click(); const addButtonDialog = window.document.querySelector('#add-check'); @@ -193,7 +193,7 @@ describe('ChecklistComponent', () => { })); it('should remove a checklist element', async(() => { - spyOn(service, 'deleteTask').and.returnValue(of('')); + spyOn(service, 'deleteTask').and.returnValue(of(null)); checklistComponent.taskId = 'new-fake-task-id'; checklistComponent.checklist.push(new TaskDetailsModel({ @@ -213,7 +213,7 @@ describe('ChecklistComponent', () => { })); it('should send an event when the checklist is deleted', async(() => { - spyOn(service, 'deleteTask').and.returnValue(of('')); + spyOn(service, 'deleteTask').and.returnValue(of(null)); checklistComponent.taskId = 'new-fake-task-id'; checklistComponent.checklist.push(new TaskDetailsModel({ id: 'fake-check-id', @@ -273,7 +273,7 @@ describe('ChecklistComponent', () => { })); it('should emit checklist task created event when the checklist is successfully added', (done) => { - spyOn(service, 'addTask').and.returnValue(of({ id: 'fake-check-added-id', name: 'fake-check-added-name' })); + spyOn(service, 'addTask').and.returnValue(of(new TaskDetailsModel({ id: 'fake-check-added-id', name: 'fake-check-added-name' }))); const disposableCreated = checklistComponent.checklistTaskCreated.subscribe((taskAdded: TaskDetailsModel) => { fixture.detectChanges(); diff --git a/lib/process-services/src/lib/task-list/components/start-task.component.spec.ts b/lib/process-services/src/lib/task-list/components/start-task.component.spec.ts index 56ef00410a..215fd0fcb3 100644 --- a/lib/process-services/src/lib/task-list/components/start-task.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/start-task.component.spec.ts @@ -17,7 +17,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { setupTestBed, LogService } from '@alfresco/adf-core'; -import { of, throwError, Observable } from 'rxjs'; +import { of, throwError } from 'rxjs'; import { TaskListService } from '../services/tasklist.service'; import { StartTaskComponent } from './start-task.component'; import { ProcessTestingModule } from '../../testing/process.testing.module'; @@ -64,10 +64,7 @@ describe('StartTaskComponent', () => { service = TestBed.inject(TaskListService); logService = TestBed.inject(LogService); - getFormListSpy = spyOn(service, 'getFormList').and.returnValue(new Observable((observer) => { - observer.next(fakeForms$); - observer.complete(); - })); + getFormListSpy = spyOn(service, 'getFormList').and.returnValue(of(fakeForms$)); fixture.detectChanges(); })); @@ -93,7 +90,7 @@ describe('StartTaskComponent', () => { name: 'fakeName', formKey: null, assignee: null - } + } as any )); }); @@ -150,7 +147,7 @@ describe('StartTaskComponent', () => { name: 'fakeName', formKey: null, assignee: null - } + } as any )); }); @@ -213,7 +210,7 @@ describe('StartTaskComponent', () => { name: 'fakeName', formKey: null, assignee: null - } + } as any )); spyOn(service, 'attachFormToATask').and.returnValue(of( { @@ -229,7 +226,7 @@ describe('StartTaskComponent', () => { name: 'fakeName', formKey: 1204, assignee: testUser - } + } as any )); }); @@ -288,14 +285,8 @@ describe('StartTaskComponent', () => { }); it('should not attach a form when a form id is not selected', () => { - const attachFormToATask = spyOn(service, 'attachFormToATask').and.returnValue([]); - spyOn(service, 'createNewTask').and.callFake( - function() { - return new Observable((observer) => { - observer.next({ id: 'task-id'}); - observer.complete(); - }); - }); + const attachFormToATask = spyOn(service, 'attachFormToATask').and.returnValue(of([])); + spyOn(service, 'createNewTask').and.returnValue(of(new TaskDetailsModel({ id: 'task-id'}))); component.taskForm.controls['name'].setValue('fakeName'); fixture.detectChanges(); const createTaskButton = element.querySelector('#button-start'); 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 b097eefb7c..c2265ffdc4 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 @@ -28,7 +28,8 @@ import { BpmUserService, CommentProcessService, LogService, AuthenticationService, UserProcessModel, - PeopleProcessService + PeopleProcessService, + CommentModel } from '@alfresco/adf-core'; import { TaskDetailsModel } from '../models/task-details.model'; import { @@ -43,7 +44,14 @@ import { TaskDetailsComponent } from './task-details.component'; import { ProcessTestingModule } from '../../testing/process.testing.module'; import { TranslateModule } from '@ngx-translate/core'; -const fakeUser: UserProcessModel = new UserProcessModel({ +const fakeUser = new UserProcessModel({ + id: 'fake-id', + firstName: 'fake-name', + lastName: 'fake-last', + email: 'fake@mail.com' +}); + +const fakeTaskAssignResponse = new TaskDetailsModel({ id: 'fake-id', firstName: 'fake-name', lastName: 'fake-last', @@ -76,7 +84,7 @@ describe('TaskDetailsComponent', () => { logService = TestBed.inject(LogService); const userService: BpmUserService = TestBed.inject(BpmUserService); - spyOn(userService, 'getCurrentUserInfo').and.returnValue(of({})); + spyOn(userService, 'getCurrentUserInfo').and.returnValue(of(null)); service = TestBed.inject(TaskListService); spyOn(service, 'getTaskChecklist').and.returnValue(of(noDataMock)); @@ -89,16 +97,16 @@ describe('TaskDetailsComponent', () => { spyOn(formService, 'getTask').and.returnValue(of(taskDetailsMock)); getTasksSpy = spyOn(service, 'getTasks').and.returnValue(of(tasksMock)); - assignTaskSpy = spyOn(service, 'assignTask').and.returnValue(of(fakeUser)); + assignTaskSpy = spyOn(service, 'assignTask').and.returnValue(of(fakeTaskAssignResponse)); commentProcessService = TestBed.inject(CommentProcessService); authService = TestBed.inject(AuthenticationService); spyOn(authService, 'getBpmLoggedUser').and.returnValue(of({ email: 'fake-email' })); spyOn(commentProcessService, 'getTaskComments').and.returnValue(of([ - { message: 'Test1', created: Date.now(), createdBy: { firstName: 'Admin', lastName: 'User' } }, - { message: 'Test2', created: Date.now(), createdBy: { firstName: 'Admin', lastName: 'User' } }, - { message: 'Test3', created: Date.now(), createdBy: { firstName: 'Admin', lastName: 'User' } } + new CommentModel({ message: 'Test1', created: Date.now(), createdBy: { firstName: 'Admin', lastName: 'User' } }), + new CommentModel({ message: 'Test2', created: Date.now(), createdBy: { firstName: 'Admin', lastName: 'User' } }), + new CommentModel({ message: 'Test3', created: Date.now(), createdBy: { firstName: 'Admin', lastName: 'User' } }) ])); fixture = TestBed.createComponent(TaskDetailsComponent); 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 b804e740f6..76b6744100 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 @@ -33,23 +33,6 @@ describe('TaskFiltersComponent', () => { let taskListService: TaskListService; let taskFilterService: TaskFilterService; let appsProcessService: AppsProcessService; - - const fakeGlobalFilterPromise = new Promise(function (resolve) { - resolve(fakeTaskFilters); - }); - - const fakeGlobalEmptyFilter = { - message: 'invalid data' - }; - - const fakeGlobalEmptyFilterPromise = new Promise(function (resolve) { - resolve(fakeGlobalEmptyFilter); - }); - - const mockErrorFilterList = { - error: 'wrong request' - }; - let component: TaskFiltersComponent; let fixture: ComponentFixture; @@ -73,6 +56,9 @@ describe('TaskFiltersComponent', () => { }); it('should emit an error with a bad response', (done) => { + const mockErrorFilterList = { + error: 'wrong request' + }; const mockErrorFilterPromise = Promise.reject(mockErrorFilterList); spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(mockErrorFilterPromise)); @@ -86,11 +72,10 @@ describe('TaskFiltersComponent', () => { }); }); - it('should return the filter task list', (done) => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise)); + it('should return the filter task list', async (done) => { + spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters)); const appId = '1'; const change = new SimpleChange(null, appId, true); - component.ngOnChanges({ 'appId': change }); component.success.subscribe((res) => { expect(res).toBeDefined(); @@ -103,11 +88,15 @@ describe('TaskFiltersComponent', () => { }); component.ngOnInit(); + component.ngOnChanges({ 'appId': change }); + + fixture.detectChanges(); + await fixture.whenStable(); }); it('Should call the API to create the default task filters when no task filters exist', async () => { spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of([])); - const filtersMock = [{ name: 'default-task-filter-1'}, { name: 'default-task-filter-2'}]; + const filtersMock: any[] = [{ name: 'default-task-filter-1'}, { name: 'default-task-filter-2'}]; const createDefaultFiltersSpy = spyOn(taskFilterService, 'createDefaultFilters').and.returnValue(of(filtersMock)); const appId = '2'; const change = new SimpleChange(null, appId, true); @@ -117,17 +106,11 @@ describe('TaskFiltersComponent', () => { expect(createDefaultFiltersSpy).toHaveBeenCalledWith(appId); }); - it('should return the filter task list, filtered By Name', (done) => { - - const fakeDeployedApplicationsPromise = new Promise(function (resolve) { - resolve({}); - }); - - spyOn(appsProcessService, 'getDeployedApplicationsByName').and.returnValue(from(fakeDeployedApplicationsPromise)); - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise)); + it('should return the filter task list, filtered By Name', async (done) => { + spyOn(appsProcessService, 'getDeployedApplicationsByName').and.returnValue(of({} as any)); + spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters)); const change = new SimpleChange(null, 'test', true); - component.ngOnChanges({ 'appName': change }); component.success.subscribe((res) => { const deployApp: any = appsProcessService.getDeployedApplicationsByName; @@ -137,77 +120,90 @@ describe('TaskFiltersComponent', () => { }); component.ngOnInit(); + component.ngOnChanges({ 'appName': change }); + + fixture.detectChanges(); + await fixture.whenStable(); }); - it('should be able to fetch and select the default if the input filter is not valid', (done) => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(fakeGlobalEmptyFilterPromise)); + it('should be able to fetch and select the default if the input filter is not valid', async (done) => { + const fakeGlobalEmptyFilter: any = { + message: 'invalid data' + }; + spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeGlobalEmptyFilter)); spyOn(component, 'createFiltersByAppId').and.stub(); const appId = '1'; const change = new SimpleChange(null, appId, true); - component.ngOnChanges({ 'appId': change }); component.success.subscribe((res) => { expect(res).toBeDefined(); expect(component.createFiltersByAppId).not.toHaveBeenCalled(); done(); }); + + component.ngOnChanges({ 'appId': change }); + fixture.detectChanges(); + await fixture.whenStable(); }); - it('should select the task filter based on the input by name param', (done) => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise)); + it('should select the task filter based on the input by name param', async (done) => { + spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters)); component.filterParam = new FilterParamsModel({ name: 'FakeMyTasks1' }); const appId = '1'; const change = new SimpleChange(null, appId, true); - fixture.detectChanges(); - component.ngOnChanges({ 'appId': change }); - component.success.subscribe((res) => { expect(res).toBeDefined(); expect(component.currentFilter).toBeDefined(); expect(component.currentFilter.name).toEqual('FakeMyTasks1'); done(); }); + + component.ngOnChanges({ 'appId': change }); + fixture.detectChanges(); + await fixture.whenStable(); }); - it('should select the task filter based on the input by index param', (done) => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise)); + it('should select the task filter based on the input by index param', async (done) => { + spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters)); component.filterParam = new FilterParamsModel({ index: 2 }); const appId = '1'; const change = new SimpleChange(null, appId, true); - fixture.detectChanges(); - component.ngOnChanges({ 'appId': change }); - component.success.subscribe((res) => { expect(res).toBeDefined(); expect(component.currentFilter).toBeDefined(); expect(component.currentFilter.name).toEqual('FakeMyTasks2'); done(); }); + + component.ngOnChanges({ 'appId': change }); + fixture.detectChanges(); + await fixture.whenStable(); }); - it('should select the task filter based on the input by id param', (done) => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise)); + it('should select the task filter based on the input by id param', async (done) => { + spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters)); component.filterParam = new FilterParamsModel({ id: 10 }); const appId = '1'; const change = new SimpleChange(null, appId, true); - fixture.detectChanges(); - component.ngOnChanges({ 'appId': change }); - component.success.subscribe((res) => { expect(res).toBeDefined(); expect(component.currentFilter).toBeDefined(); expect(component.currentFilter.name).toEqual('FakeInvolvedTasks'); done(); }); + + component.ngOnChanges({ 'appId': change }); + fixture.detectChanges(); + await fixture.whenStable(); }); it('should emit the selected filter based on the filterParam input', () => { @@ -321,7 +317,7 @@ describe('TaskFiltersComponent', () => { })); it('should attach specific icon for each filter if showIcon is true', (done) => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise)); + spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters)); component.showIcon = true; const change = new SimpleChange(undefined, 1, true); component.ngOnChanges({ 'appId': change }); @@ -339,7 +335,7 @@ describe('TaskFiltersComponent', () => { }); it('should not attach icons for each filter if showIcon is false', (done) => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise)); + spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters)); component.showIcon = false; const change = new SimpleChange(undefined, 1, true); component.ngOnChanges({ 'appId': change }); @@ -353,7 +349,7 @@ describe('TaskFiltersComponent', () => { }); it('should reset selection when filterParam is a filter that does not exist', async () => { - spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise)); + spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters)); component.currentFilter = fakeTaskFilters[0]; component.filterParam = new FilterRepresentationModel( {name: 'non-existing-filter'}); const appId = '1'; @@ -368,7 +364,7 @@ describe('TaskFiltersComponent', () => { it('Should be able to display default task filters', async () => { spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of([])); - const defaultTaskFiltersMock = [ + const defaultTaskFiltersMock: any = [ { name: 'default-my-filter' }, { name: 'default-involved-filter' }, { name: 'default-completed-filter' } diff --git a/lib/process-services/src/lib/task-list/components/task-form/claim-task.directive.spec.ts b/lib/process-services/src/lib/task-list/components/task-form/claim-task.directive.spec.ts index 86f4fcacb4..3affc16365 100644 --- a/lib/process-services/src/lib/task-list/components/task-form/claim-task.directive.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-form/claim-task.directive.spec.ts @@ -57,7 +57,7 @@ describe('ClaimTaskDirective', () => { }); it('Should be able to call claim task service', () => { - const claimTaskSpy = spyOn(taskListService, 'claimTask').and.returnValue(of({})); + const claimTaskSpy = spyOn(taskListService, 'claimTask').and.returnValue(of(null)); const button = fixture.nativeElement.querySelector('button'); button.click(); @@ -66,7 +66,7 @@ describe('ClaimTaskDirective', () => { }); it('Should be able to catch success event on click of claim button', async() => { - spyOn(taskListService, 'claimTask').and.returnValue(of({})); + spyOn(taskListService, 'claimTask').and.returnValue(of(null)); const unclaimSpy = spyOn(fixture.componentInstance.claim, 'emit'); const button = fixture.nativeElement.querySelector('button'); diff --git a/lib/process-services/src/lib/task-list/components/task-form/task-form.component.spec.ts b/lib/process-services/src/lib/task-list/components/task-form/task-form.component.spec.ts index 5000760d1a..61667e3fa8 100644 --- a/lib/process-services/src/lib/task-list/components/task-form/task-form.component.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-form/task-form.component.spec.ts @@ -663,7 +663,7 @@ describe('TaskFormComponent', () => { }); it('should emit taskClaimed when task is claimed', (done) => { - spyOn(taskListService, 'claimTask').and.returnValue(of({})); + spyOn(taskListService, 'claimTask').and.returnValue(of(null)); getTaskDetailsSpy.and.returnValue(of(claimableTaskDetailsMock)); component.taskId = 'mock-task-id'; @@ -700,7 +700,7 @@ describe('TaskFormComponent', () => { }); it('should emit taskUnClaimed when task is unclaimed', (done) => { - spyOn(taskListService, 'unclaimTask').and.returnValue(of({})); + spyOn(taskListService, 'unclaimTask').and.returnValue(of(null)); getBpmLoggedUserSpy.and.returnValue(of(claimedTaskDetailsMock.assignee)); getTaskDetailsSpy.and.returnValue(of(claimedTaskDetailsMock)); diff --git a/lib/process-services/src/lib/task-list/components/task-form/unclaim-task.directive.spec.ts b/lib/process-services/src/lib/task-list/components/task-form/unclaim-task.directive.spec.ts index 24b094d55d..7f317239fa 100644 --- a/lib/process-services/src/lib/task-list/components/task-form/unclaim-task.directive.spec.ts +++ b/lib/process-services/src/lib/task-list/components/task-form/unclaim-task.directive.spec.ts @@ -57,7 +57,7 @@ describe('UnclaimTaskDirective', () => { }); it('Should be able to call unclaim task service', () => { - const claimTaskSpy = spyOn(taskListService, 'unclaimTask').and.returnValue(of({})); + const claimTaskSpy = spyOn(taskListService, 'unclaimTask').and.returnValue(of(null)); const button = fixture.nativeElement.querySelector('button'); button.click(); @@ -66,7 +66,7 @@ describe('UnclaimTaskDirective', () => { }); it('Should be able to catch success event on click of unclaim button', async() => { - spyOn(taskListService, 'unclaimTask').and.returnValue(of({})); + spyOn(taskListService, 'unclaimTask').and.returnValue(of(null)); const unclaimSpy = spyOn(fixture.componentInstance.unclaim, 'emit'); const button = fixture.nativeElement.querySelector('button'); 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 0e27c54cb7..0cdb168968 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 @@ -17,7 +17,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { AppConfigService, setupTestBed, BpmUserService } from '@alfresco/adf-core'; +import { AppConfigService, setupTestBed, BpmUserService, BpmUserModel } from '@alfresco/adf-core'; import { of } from 'rxjs'; import { completedTaskDetailsMock, @@ -42,7 +42,7 @@ describe('TaskHeaderComponent', () => { let userBpmService: BpmUserService; let appConfigService: AppConfigService; - const fakeBpmAssignedUser = { + const fakeBpmAssignedUser = new BpmUserModel({ id: 1001, apps: [], capabilities: 'fake-capability', @@ -54,7 +54,7 @@ describe('TaskHeaderComponent', () => { lastName: 'Adams', fullname: 'Wilbur Adams', groups: [] - }; + }); setupTestBed({ imports: [ @@ -252,7 +252,7 @@ describe('TaskHeaderComponent', () => { })); it('should emit claim event when task is claimed', (done) => { - spyOn(service, 'claimTask').and.returnValue(of({})); + spyOn(service, 'claimTask').and.returnValue(of(null)); component.taskDetails = claimableTaskDetailsMock; component.claim.subscribe((taskId) => { @@ -268,7 +268,7 @@ describe('TaskHeaderComponent', () => { }); it('should emit unclaim event when task is unclaimed', (done) => { - spyOn(service, 'unclaimTask').and.returnValue(of({})); + spyOn(service, 'unclaimTask').and.returnValue(of(null)); component.taskDetails = claimedTaskDetailsMock; component.unclaim.subscribe((taskId: string) => {