prepare tests for ng-12 upgrade (#7099)

* prepare tests for ng12 upgrade

* fix lint

* fix tests

* test fixes

* fix code and tests

* fix code and tests

* test fixes

* test fixes
This commit is contained in:
Denys Vuika
2021-06-11 07:36:32 +01:00
committed by GitHub
parent 558056b05c
commit eb71a79d1e
112 changed files with 982 additions and 1057 deletions

View File

@@ -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<string[]>();
fixture.detectChanges();

View File

@@ -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();
});

View File

@@ -124,7 +124,7 @@ describe('AspectListService', () => {
componentInstance: {
error: new Subject<any>()
}
});
} as any);
spyOnDialogClose = spyOn(materialDialog, 'closeAll');
});

View File

@@ -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');

View File

@@ -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) });

View File

@@ -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 = <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 = <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) => {

View File

@@ -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: [

View File

@@ -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'])

View File

@@ -90,7 +90,7 @@ describe('ContentNodeDialogService', () => {
componentInstance: {
error: new Subject<any>()
}
});
} as any);
});
it('should not open the lock node dialog if have no permission', () => {

View File

@@ -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(<NodeEntry> { 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: [<SiteEntry> { entry: { guid: 'namek', id: 'namek' } },
<SiteEntry> { 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(<NodeEntry> { 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 = [<DataRow> {}, <DataRow> {}];
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)', () => {

View File

@@ -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;

View File

@@ -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')

View File

@@ -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'
};

View File

@@ -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<LibraryDialogComponent>;
@@ -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();

View File

@@ -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();

View File

@@ -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('<display name>');
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-'];

View File

@@ -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

View File

@@ -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<NodeEntry> {
return from(this.apiService.getInstance().nodes.moveNode(nodeId, { targetParentId })).pipe(
catchError((err) => this.handleError(err))
);

View File

@@ -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) => {

View File

@@ -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: {

View File

@@ -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() {
}
]
}
};
});
}

View File

@@ -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();

View File

@@ -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();

View File

@@ -53,7 +53,7 @@ describe('NodePermissionDialogService', () => {
componentInstance: {
error: new Subject<any>()
}
});
} 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');

View File

@@ -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();
});

View File

@@ -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();
});

View File

@@ -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: [

View File

@@ -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();

View File

@@ -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', () => {