Remove mocha and jasmine-ajax dependencies (#11813)

This commit is contained in:
Denys Vuika
2026-04-16 10:20:49 +01:00
committed by GitHub
parent b550712160
commit 6fc8dda887
31 changed files with 926 additions and 1807 deletions
@@ -19,13 +19,14 @@ import { SimpleChange } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateProcessAttachmentComponent } from './create-process-attachment.component';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
declare let jasmine: any;
import { ProcessContentService } from '../../form/services/process-content.service';
import { of } from 'rxjs';
describe('CreateProcessAttachmentComponent', () => {
let component: CreateProcessAttachmentComponent;
let fixture: ComponentFixture<CreateProcessAttachmentComponent>;
let element: HTMLElement;
let processContentService: ProcessContentService;
const file = new File([new Blob()], 'Test');
const fileObj = { entry: null, file, relativeFolder: '/' };
@@ -53,19 +54,12 @@ describe('CreateProcessAttachmentComponent', () => {
fixture = TestBed.createComponent(CreateProcessAttachmentComponent);
component = fixture.componentInstance;
element = fixture.nativeElement;
processContentService = TestBed.inject(ProcessContentService);
component.processInstanceId = '9999';
fixture.detectChanges();
});
beforeEach(() => {
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('should update the processInstanceId when it is changed', () => {
component.processInstanceId = null;
@@ -76,20 +70,17 @@ describe('CreateProcessAttachmentComponent', () => {
});
it('should emit content created event when the file is uploaded', (done) => {
spyOn(processContentService, 'createProcessRelatedContent').and.returnValue(of(fakeUploadResponse) as any);
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(res).not.toBeNull();
expect(res.id).toBe(9999);
expect(processContentService.createProcessRelatedContent).toHaveBeenCalledWith('9999', file, { isRelatedContent: true });
done();
});
component.onFileUpload(customEvent);
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeUploadResponse)
});
});
it('should allow user to upload files via button', (done) => {
@@ -97,6 +88,8 @@ describe('CreateProcessAttachmentComponent', () => {
expect(buttonUpload).toBeDefined();
expect(buttonUpload).not.toBeNull();
spyOn(processContentService, 'createProcessRelatedContent').and.returnValue(of(fakeUploadResponse) as any);
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(res).not.toBeNull();
@@ -107,11 +100,5 @@ describe('CreateProcessAttachmentComponent', () => {
const dropEvent = new CustomEvent('upload-files', customEvent);
buttonUpload.dispatchEvent(dropEvent);
fixture.detectChanges();
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeUploadResponse)
});
});
});
@@ -21,8 +21,6 @@ import { EcmModelService } from './ecm-model.service';
import { TestBed } from '@angular/core/testing';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
declare let jasmine: any;
describe('EcmModelService', () => {
let service: EcmModelService;
@@ -32,76 +30,48 @@ describe('EcmModelService', () => {
providers: [{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }]
});
service = TestBed.inject(EcmModelService);
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('Should fetch ECM models', (done) => {
service.getEcmModels().subscribe(() => {
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('alfresco/versions/1/cmm')).toBeTruthy();
done();
});
spyOn(service.customModelApi, 'getAllCustomModel').and.returnValue(Promise.resolve({} as any));
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify({})
service.getEcmModels().subscribe(() => {
expect(service.customModelApi.getAllCustomModel).toHaveBeenCalled();
done();
});
});
it('Should fetch ECM types', (done) => {
const modelName = 'modelTest';
spyOn(service.customModelApi, 'getAllCustomType').and.returnValue(Promise.resolve({} as any));
service.getEcmType(modelName).subscribe(() => {
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('versions/1/cmm/' + modelName + '/types')).toBeTruthy();
expect(service.customModelApi.getAllCustomType).toHaveBeenCalledWith(modelName);
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify({})
});
});
it('Should create ECM types', (done) => {
const typeName = 'typeTest';
const mockResponse = { entry: { name: typeName } };
const createTypeSpy = spyOn(service.customModelApi, 'createCustomType').and.returnValue(Promise.resolve(mockResponse as any));
service.createEcmType(typeName, EcmModelService.MODEL_NAME, EcmModelService.TYPE_MODEL).subscribe(() => {
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('versions/1/cmm/' + EcmModelService.MODEL_NAME + '/types')).toBeTruthy();
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).name).toEqual(typeName);
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).title).toEqual(typeName);
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).parentName).toEqual(EcmModelService.TYPE_MODEL);
expect(createTypeSpy).toHaveBeenCalledWith(EcmModelService.MODEL_NAME, typeName, EcmModelService.TYPE_MODEL, typeName, '');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify({})
});
});
it('Should create ECM types with a clean and preserve real name in the title', (done) => {
const typeName = 'typeTest:testName@#$*!';
const cleanName = 'testName';
const mockResponse = { entry: { name: cleanName } };
const createTypeSpy = spyOn(service.customModelApi, 'createCustomType').and.returnValue(Promise.resolve(mockResponse as any));
service.createEcmType(typeName, EcmModelService.MODEL_NAME, EcmModelService.TYPE_MODEL).subscribe(() => {
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('versions/1/cmm/' + EcmModelService.MODEL_NAME + '/types')).toBeTruthy();
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).name).toEqual(cleanName);
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).title).toEqual(typeName);
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).parentName).toEqual(EcmModelService.TYPE_MODEL);
expect(createTypeSpy).toHaveBeenCalledWith(EcmModelService.MODEL_NAME, cleanName, EcmModelService.TYPE_MODEL, typeName, '');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify({})
});
});
it('Should add property to a type', (done) => {
@@ -113,37 +83,26 @@ describe('EcmModelService', () => {
}
};
service.addPropertyToAType(EcmModelService.MODEL_NAME, typeName, formFields).subscribe(() => {
expect(
jasmine.Ajax.requests.mostRecent().url.endsWith('1/cmm/' + EcmModelService.MODEL_NAME + '/types/' + typeName + '?select=props')
).toBeTruthy();
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).properties).toEqual([
{
name: 'test',
title: 'test',
description: 'test',
dataType: 'd:text',
multiValued: false,
mandatory: false,
mandatoryEnforced: false
},
{
name: 'test2',
title: 'test2',
description: 'test2',
dataType: 'd:text',
multiValued: false,
mandatory: false,
mandatoryEnforced: false
}
]);
done();
});
const mockResponse = { entry: { properties: [] } };
const addPropertySpy = spyOn(service.customModelApi, 'addPropertyToType').and.returnValue(Promise.resolve(mockResponse as any));
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify({})
service.addPropertyToAType(EcmModelService.MODEL_NAME, typeName, formFields).subscribe(() => {
const callArgs = addPropertySpy.calls.mostRecent().args;
expect(callArgs[0]).toEqual(EcmModelService.MODEL_NAME);
expect(callArgs[1]).toEqual(typeName);
expect(callArgs[2]).toEqual(
jasmine.arrayContaining([
jasmine.objectContaining({
name: 'test',
title: 'test'
}),
jasmine.objectContaining({
name: 'test2',
title: 'test2'
})
])
);
done();
});
});
@@ -157,67 +116,52 @@ describe('EcmModelService', () => {
}
};
service.addPropertyToAType(EcmModelService.MODEL_NAME, typeName, formFields).subscribe(() => {
expect(
jasmine.Ajax.requests.mostRecent().url.endsWith('1/cmm/' + EcmModelService.MODEL_NAME + '/types/' + cleanName + '?select=props')
).toBeTruthy();
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).properties).toEqual([
{
name: 'test',
title: 'test',
description: 'test',
dataType: 'd:text',
multiValued: false,
mandatory: false,
mandatoryEnforced: false
},
{
name: 'test2',
title: 'test2',
description: 'test2',
dataType: 'd:text',
multiValued: false,
mandatory: false,
mandatoryEnforced: false
}
]);
done();
});
const mockResponse = { entry: { properties: [] } };
const addPropertySpy = spyOn(service.customModelApi, 'addPropertyToType').and.returnValue(Promise.resolve(mockResponse as any));
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify({})
service.addPropertyToAType(EcmModelService.MODEL_NAME, typeName, formFields).subscribe(() => {
const callArgs = addPropertySpy.calls.mostRecent().args;
expect(callArgs[0]).toEqual(EcmModelService.MODEL_NAME);
expect(callArgs[1]).toEqual(cleanName);
expect(callArgs[2]).toEqual(
jasmine.arrayContaining([
jasmine.objectContaining({
name: 'test',
title: 'test'
}),
jasmine.objectContaining({
name: 'test2',
title: 'test2'
})
])
);
done();
});
});
it('Should create ECM model', (done) => {
service.createEcmModel(EcmModelService.MODEL_NAME, EcmModelService.MODEL_NAMESPACE).subscribe(() => {
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('alfresco/versions/1/cmm')).toBeTruthy();
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).status).toEqual('DRAFT');
done();
});
const mockResponse = { entry: { name: EcmModelService.MODEL_NAME } };
const createModelSpy = spyOn(service.customModelApi, 'createCustomModel').and.returnValue(Promise.resolve(mockResponse as any));
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify({})
service.createEcmModel(EcmModelService.MODEL_NAME, EcmModelService.MODEL_NAMESPACE).subscribe(() => {
expect(createModelSpy).toHaveBeenCalledWith(
'DRAFT',
'',
EcmModelService.MODEL_NAME,
EcmModelService.MODEL_NAME,
EcmModelService.MODEL_NAMESPACE
);
done();
});
});
it('Should activate ECM model', (done) => {
service.activeEcmModel(EcmModelService.MODEL_NAME).subscribe(() => {
expect(
jasmine.Ajax.requests.mostRecent().url.endsWith('alfresco/versions/1/cmm/' + EcmModelService.MODEL_NAME + '?select=status')
).toBeTruthy();
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).status).toEqual('ACTIVE');
done();
});
const mockResponse = { entry: { status: 'ACTIVE' } };
const activateModelSpy = spyOn(service.customModelApi, 'activateCustomModel').and.returnValue(Promise.resolve(mockResponse as any));
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify({})
service.activeEcmModel(EcmModelService.MODEL_NAME).subscribe(() => {
expect(activateModelSpy).toHaveBeenCalledWith(EcmModelService.MODEL_NAME);
done();
});
});
@@ -19,8 +19,6 @@ import { TestBed } from '@angular/core/testing';
import { ProcessContentService } from './process-content.service';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
declare let jasmine: any;
const fileContentPdfResponseBody = {
id: 999,
name: 'fake-name.pdf',
@@ -71,15 +69,43 @@ describe('ProcessContentService', () => {
service = TestBed.inject(ProcessContentService);
});
beforeEach(() => {
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('Should fetch the attachments', (done) => {
const mockResponse = {
size: 2,
total: 2,
start: 0,
data: [
{
id: 8,
name: 'fake.zip',
created: 1494595697381,
createdBy: { id: 2, firstName: 'user', lastName: 'user', email: 'user@user.com' },
relatedContent: true,
contentAvailable: true,
link: false,
mimeType: 'application/zip',
simpleType: 'content',
previewStatus: 'unsupported',
thumbnailStatus: 'unsupported'
},
{
id: 9,
name: 'fake.jpg',
created: 1494595655381,
createdBy: { id: 2, firstName: 'user', lastName: 'user', email: 'user@user.com' },
relatedContent: true,
contentAvailable: true,
link: false,
mimeType: 'image/jpeg',
simpleType: 'image',
previewStatus: 'unsupported',
thumbnailStatus: 'unsupported'
}
]
};
spyOn(service.contentApi, 'getRelatedContentForTask').and.returnValue(Promise.resolve(mockResponse as any));
service.getTaskRelatedContent('1234').subscribe((res) => {
expect(res.data).toBeDefined();
expect(res.data.length).toBe(2);
@@ -91,49 +117,13 @@ describe('ProcessContentService', () => {
expect(res.data[1].relatedContent).toBeTruthy();
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify({
size: 2,
total: 2,
start: 0,
data: [
{
id: 8,
name: 'fake.zip',
created: 1494595697381,
createdBy: { id: 2, firstName: 'user', lastName: 'user', email: 'user@user.com' },
relatedContent: true,
contentAvailable: true,
link: false,
mimeType: 'application/zip',
simpleType: 'content',
previewStatus: 'unsupported',
thumbnailStatus: 'unsupported'
},
{
id: 9,
name: 'fake.jpg',
created: 1494595655381,
createdBy: { id: 2, firstName: 'user', lastName: 'user', email: 'user@user.com' },
relatedContent: true,
contentAvailable: true,
link: false,
mimeType: 'image/jpeg',
simpleType: 'image',
previewStatus: 'unsupported',
thumbnailStatus: 'unsupported'
}
]
})
});
});
it('should return the unsupported content when the file is an image', (done) => {
const contentId: number = 888;
spyOn(service.contentApi, 'getContent').and.returnValue(Promise.resolve(fileContentJpgResponseBody as any));
service.getFileContent(contentId).subscribe((result) => {
expect(result.id).toEqual(contentId);
expect(result.name).toEqual('fake-name.jpg');
@@ -141,17 +131,13 @@ describe('ProcessContentService', () => {
expect(result.thumbnailStatus).toEqual('unsupported');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify(fileContentJpgResponseBody)
});
});
it('should return the supported content when the file is a pdf', (done) => {
const contentId: number = 999;
spyOn(service.contentApi, 'getContent').and.returnValue(Promise.resolve(fileContentPdfResponseBody as any));
service.getFileContent(contentId).subscribe((result) => {
expect(result.id).toEqual(contentId);
expect(result.name).toEqual('fake-name.pdf');
@@ -159,12 +145,6 @@ describe('ProcessContentService', () => {
expect(result.thumbnailStatus).toEqual('created');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify(fileContentPdfResponseBody)
});
});
it('should return the raw content URL', () => {
@@ -24,8 +24,6 @@ import { ContentWidgetComponent } from './content.widget';
import { ProcessContentService } from '../../services/process-content.service';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
declare let jasmine: any;
describe('ContentWidgetComponent', () => {
let component: ContentWidgetComponent;
let fixture: ComponentFixture<ContentWidgetComponent>;
@@ -75,14 +73,6 @@ describe('ContentWidgetComponent', () => {
});
describe('Rendering tests', () => {
beforeEach(() => {
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('should display content thumbnail', () => {
component.showDocumentContent = true;
component.content = new ContentLinkModel();
@@ -94,6 +84,26 @@ describe('ContentWidgetComponent', () => {
it('should load the thumbnail preview of the png image', fakeAsync(() => {
const blob = createFakeImageBlob();
const mockResponse = {
id: 4004,
name: 'Useful expressions - Email_English.png',
created: 1490354907883,
createdBy: {
id: 2,
firstName: 'admin',
lastName: 'admin',
email: 'administrator@admin.com'
},
relatedContent: false,
contentAvailable: true,
link: false,
mimeType: 'image/png',
simpleType: 'image',
previewStatus: 'unsupported',
thumbnailStatus: 'unsupported'
};
spyOn(processContentService, 'getFileContent').and.returnValue(of(mockResponse as any));
spyOn(processContentService, 'getFileRawContent').and.returnValue(of(blob));
component.thumbnailLoaded.subscribe((res) => {
@@ -109,33 +119,30 @@ describe('ContentWidgetComponent', () => {
const contentId = 1;
const change = new SimpleChange(null, contentId, true);
component.ngOnChanges({ id: change });
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: {
id: 4004,
name: 'Useful expressions - Email_English.png',
created: 1490354907883,
createdBy: {
id: 2,
firstName: 'admin',
lastName: 'admin',
email: 'administrator@admin.com'
},
relatedContent: false,
contentAvailable: true,
link: false,
mimeType: 'image/png',
simpleType: 'image',
previewStatus: 'unsupported',
thumbnailStatus: 'unsupported'
}
});
}));
it('should load the thumbnail preview of a pdf', fakeAsync(() => {
const blob = createFakePdfBlob();
const mockResponse = {
id: 4004,
name: 'FakeBlob.pdf',
created: 1490354907883,
createdBy: {
id: 2,
firstName: 'admin',
lastName: 'admin',
email: 'administrator@admin.com'
},
relatedContent: false,
contentAvailable: true,
link: false,
mimeType: 'application/pdf',
simpleType: 'pdf',
previewStatus: 'created',
thumbnailStatus: 'created'
};
spyOn(processContentService, 'getFileContent').and.returnValue(of(mockResponse as any));
spyOn(processContentService, 'getContentThumbnail').and.returnValue(of(blob));
component.thumbnailLoaded.subscribe((res) => {
@@ -151,32 +158,30 @@ describe('ContentWidgetComponent', () => {
const contentId = 1;
const change = new SimpleChange(null, contentId, true);
component.ngOnChanges({ id: change });
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: {
id: 4004,
name: 'FakeBlob.pdf',
created: 1490354907883,
createdBy: {
id: 2,
firstName: 'admin',
lastName: 'admin',
email: 'administrator@admin.com'
},
relatedContent: false,
contentAvailable: true,
link: false,
mimeType: 'application/pdf',
simpleType: 'pdf',
previewStatus: 'created',
thumbnailStatus: 'created'
}
});
}));
it('should show unsupported preview with unsupported file', fakeAsync(() => {
const mockResponse = {
id: 4004,
name: 'FakeBlob.zip',
created: 1490354907883,
createdBy: {
id: 2,
firstName: 'admin',
lastName: 'admin',
email: 'administrator@admin.com'
},
relatedContent: false,
contentAvailable: false,
link: false,
mimeType: 'application/zip',
simpleType: 'zip',
previewStatus: 'unsupported',
thumbnailStatus: 'unsupported'
};
spyOn(processContentService, 'getFileContent').and.returnValue(of(mockResponse as any));
const contentId = 1;
const change = new SimpleChange(null, contentId, true);
component.ngOnChanges({ id: change });
@@ -187,29 +192,6 @@ describe('ContentWidgetComponent', () => {
expect(thumbnailPreview).toBeDefined();
expect(element.querySelector('div.upload-widget__content-text').innerHTML).toEqual('FakeBlob.zip');
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: {
id: 4004,
name: 'FakeBlob.zip',
created: 1490354907883,
createdBy: {
id: 2,
firstName: 'admin',
lastName: 'admin',
email: 'administrator@admin.com'
},
relatedContent: false,
contentAvailable: false,
link: false,
mimeType: 'application/zip',
simpleType: 'zip',
previewStatus: 'unsupported',
thumbnailStatus: 'unsupported'
}
});
}));
it('should open the viewer when the view button is clicked', () => {
@@ -21,8 +21,6 @@ import { ProcessInstanceFilterRepresentation, UserProcessInstanceFilterRepresent
import { of } from 'rxjs';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
declare let jasmine: any;
const fakeProcessFiltersResponse: any = {
size: 1,
total: 1,
@@ -60,12 +58,6 @@ describe('Process filter', () => {
beforeEach(() => {
getFilters = spyOn(service.userFiltersApi, 'getUserProcessInstanceFilters').and.returnValue(Promise.resolve(fakeProcessFiltersResponse));
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
describe('get filters', () => {
@@ -102,6 +94,30 @@ describe('Process filter', () => {
});
it('should return the default filters', (done) => {
const runningFilterResponse = {
appId: 1001,
id: 111,
name: 'Running',
icon: 'fake-icon',
recent: false
};
const completedFilterResponse = {
appId: 1001,
id: 222,
name: 'Completed',
icon: 'fake-icon',
recent: false
};
const allFilterResponse = {
appId: 1001,
id: 333,
name: 'All',
icon: 'fake-icon',
recent: false
};
spyOn(service, 'addProcessFilter').and.returnValues(of(runningFilterResponse), of(completedFilterResponse), of(allFilterResponse));
service.createDefaultFilters(1234).subscribe((res) => {
expect(res).toBeDefined();
expect(res.length).toEqual(3);
@@ -113,45 +129,33 @@ describe('Process filter', () => {
expect(res[2].id).toEqual(333);
done();
});
jasmine.Ajax.requests.at(0).respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify({
appId: 1001,
id: 111,
name: 'Running',
icon: 'fake-icon',
recent: false
})
});
jasmine.Ajax.requests.at(1).respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify({
appId: 1001,
id: 222,
name: 'Completed',
icon: 'fake-icon',
recent: false
})
});
jasmine.Ajax.requests.at(2).respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify({
appId: 1001,
id: 333,
name: 'All',
icon: 'fake-icon',
recent: false
})
});
});
it('should be able create filters and add sorting information to the response', (done) => {
const runningFilterResponse = {
appId: 1001,
id: 111,
name: 'Running',
icon: 'fake-icon',
recent: false
};
const completedFilterResponse = {
appId: 1001,
id: 222,
name: 'Completed',
icon: 'fake-icon',
recent: false
};
const allFilterResponse = {
appId: 1001,
id: 333,
name: 'All',
icon: 'fake-icon',
recent: false
};
spyOn(service, 'addProcessFilter').and.returnValues(of(runningFilterResponse), of(completedFilterResponse), of(allFilterResponse));
service.createDefaultFilters(1234).subscribe((res) => {
expect(res).toBeDefined();
expect(res.length).toEqual(3);
@@ -168,42 +172,6 @@ describe('Process filter', () => {
expect(res[2].filter.state).toEqual('all');
done();
});
jasmine.Ajax.requests.at(0).respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify({
appId: 1001,
id: 111,
name: 'Running',
icon: 'fake-icon',
recent: false
})
});
jasmine.Ajax.requests.at(1).respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify({
appId: 1001,
id: 222,
name: 'Completed',
icon: 'fake-icon',
recent: false
})
});
jasmine.Ajax.requests.at(2).respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify({
appId: 1001,
id: 333,
name: 'All',
icon: 'fake-icon',
recent: false
})
});
});
it('should pass on any error that is returned by the API', (done) => {
@@ -20,8 +20,6 @@ import { PeopleProcessService } from './people-process.service';
import { LightUserRepresentation } from '@alfresco/js-api';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
declare let jasmine: any;
const firstInvolvedUser: LightUserRepresentation = {
id: 1,
email: 'fake-user1@fake.com',
@@ -51,15 +49,9 @@ describe('PeopleProcessService', () => {
});
describe('when user is logged in', () => {
beforeEach(() => {
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('should be able to retrieve people to involve in the task', fakeAsync(() => {
spyOn(service.userApi, 'getUsers').and.returnValue(Promise.resolve({ data: fakeInvolveUserList } as any));
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe((users) => {
expect(users).toBeDefined();
expect(users.length).toBe(2);
@@ -68,27 +60,17 @@ describe('PeopleProcessService', () => {
expect(users[0].firstName).toEqual('fakeName1');
expect(users[0].lastName).toEqual('fakeLast1');
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: { data: fakeInvolveUserList }
});
}));
it('should be able to get people images for people retrieved', fakeAsync(() => {
spyOn(service.userApi, 'getUsers').and.returnValue(Promise.resolve({ data: fakeInvolveUserList } as any));
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe((users) => {
expect(users).toBeDefined();
expect(users.length).toBe(2);
expect(service.getUserImage(users[0].id.toString())).toContain('/users/' + users[0].id + '/picture');
expect(service.getUserImage(users[1].id.toString())).toContain('/users/' + users[1].id + '/picture');
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: { data: fakeInvolveUserList }
});
}));
it('should return user image url', () => {
@@ -98,77 +80,61 @@ describe('PeopleProcessService', () => {
});
it('should return empty list when there are no users to involve', fakeAsync(() => {
spyOn(service.userApi, 'getUsers').and.returnValue(Promise.resolve({} as any));
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe((users) => {
expect(users).toBeDefined();
expect(users.length).toBe(0);
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: {}
});
}));
it('getWorkflowUsers catch errors call', fakeAsync(() => {
spyOn(service.userApi, 'getUsers').and.returnValue(Promise.reject(errorResponse));
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe(
() => {},
(error) => {
expect(error).toEqual(errorResponse);
}
);
jasmine.Ajax.requests.mostRecent().respondWith({
status: 403
});
}));
it('should be able to involve people in the task', fakeAsync(() => {
service.involveUserWithTask('fake-task-id', 'fake-user-id').subscribe(() => {
expect(jasmine.Ajax.requests.mostRecent().method).toBe('PUT');
expect(jasmine.Ajax.requests.mostRecent().url).toContain('tasks/fake-task-id/action/involve');
});
const involveSpy = spyOn(service.taskActionsApi, 'involveUser').and.returnValue(Promise.resolve([] as any));
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200
service.involveUserWithTask('fake-task-id', 'fake-user-id').subscribe(() => {
expect(involveSpy).toHaveBeenCalledWith('fake-task-id', { userId: 'fake-user-id' });
});
}));
it('involveUserWithTask catch errors call', fakeAsync(() => {
spyOn(service.taskActionsApi, 'involveUser').and.returnValue(Promise.reject(errorResponse));
service.involveUserWithTask('fake-task-id', 'fake-user-id').subscribe(
() => {},
(error) => {
expect(error).toEqual(errorResponse);
}
);
jasmine.Ajax.requests.mostRecent().respondWith({
status: 403
});
}));
it('should be able to remove involved people from task', fakeAsync(() => {
service.removeInvolvedUser('fake-task-id', 'fake-user-id').subscribe(() => {
expect(jasmine.Ajax.requests.mostRecent().method).toBe('PUT');
expect(jasmine.Ajax.requests.mostRecent().url).toContain('tasks/fake-task-id/action/remove-involved');
});
const removeSpy = spyOn(service.taskActionsApi, 'removeInvolvedUser').and.returnValue(Promise.resolve([] as any));
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200
service.removeInvolvedUser('fake-task-id', 'fake-user-id').subscribe(() => {
expect(removeSpy).toHaveBeenCalledWith('fake-task-id', { userId: 'fake-user-id' });
});
}));
it('removeInvolvedUser catch errors call', fakeAsync(() => {
spyOn(service.taskActionsApi, 'removeInvolvedUser').and.returnValue(Promise.reject(errorResponse));
service.removeInvolvedUser('fake-task-id', 'fake-user-id').subscribe(
() => {},
(error) => {
expect(error).toEqual(errorResponse);
}
);
jasmine.Ajax.requests.mostRecent().respondWith({
status: 403
});
}));
});
});
@@ -42,8 +42,6 @@ import { MatMenuItemHarness } from '@angular/material/menu/testing';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
import { CommonModule } from '@angular/common';
declare let jasmine: any;
describe('TaskListComponent', () => {
let component: TaskListComponent;
let fixture: ComponentFixture<TaskListComponent>;
@@ -51,16 +49,22 @@ describe('TaskListComponent', () => {
let appConfig: AppConfigService;
let taskListService: TaskListService;
const transformDates = (taskData: any) => ({
...taskData,
data: taskData.data.map((task: any) => ({
...task,
created: task.created ? new Date(task.created) : undefined,
dueDate: task.dueDate ? new Date(task.dueDate) : undefined,
endDate: task.endDate ? new Date(task.endDate) : undefined
}))
});
const testMostRecentCall = (changes: SimpleChanges) => {
spyOn(taskListService, 'findTasksByState').and.returnValue(of(transformDates(fakeGlobalTask)));
component.ngAfterContentInit();
component.ngOnChanges(changes);
fixture.detectChanges();
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeGlobalTask)
});
};
const testSubscribeForFilteredTaskList = (done: DoneFn) => {
@@ -76,7 +80,7 @@ describe('TaskListComponent', () => {
};
const testRowSelection = async (selectionMode?: string) => {
spyOn(taskListService, 'findTasksByState').and.returnValues(of(fakeGlobalTask));
spyOn(taskListService, 'findTasksByState').and.returnValues(of(transformDates(fakeGlobalTask)));
const state = new SimpleChange(null, 'open', true);
component.multiselect = true;
if (selectionMode) {
@@ -129,12 +133,7 @@ describe('TaskListComponent', () => {
});
});
beforeEach(() => {
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
fixture.destroy();
});
@@ -314,14 +313,11 @@ describe('TaskListComponent', () => {
expect(component.rows[0]['name']).toEqual('nameFake1');
done();
});
spyOn(taskListService, 'findTasksByState').and.returnValue(of(transformDates(fakeGlobalTask)));
fixture.detectChanges();
component.reload();
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeGlobalTask)
});
});
it('should emit row click event', (done) => {
@@ -363,6 +359,8 @@ describe('TaskListComponent', () => {
const landingTaskId = '888';
const change = new SimpleChange(null, landingTaskId, true);
spyOn(taskListService, 'findTasksByState').and.returnValue(of(transformDates(fakeGlobalTask)));
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.rows).toBeDefined();
@@ -371,12 +369,6 @@ describe('TaskListComponent', () => {
});
component.ngOnChanges({ landingTaskId: change });
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeGlobalTask)
});
});
it('should NOT reload the task list when no parameters changed', () => {
@@ -390,6 +382,8 @@ describe('TaskListComponent', () => {
const appId = '1';
const change = new SimpleChange(null, appId, true);
spyOn(taskListService, 'findTasksByState').and.returnValue(of(transformDates(fakeGlobalTask)));
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.rows).toBeDefined();
@@ -399,18 +393,14 @@ describe('TaskListComponent', () => {
done();
});
component.ngOnChanges({ appId: change });
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeGlobalTask)
});
});
it('should reload the list when the processDefinitionKey parameter changes', (done) => {
const processDefinitionKey = 'fakeprocess';
const change = new SimpleChange(null, processDefinitionKey, true);
spyOn(taskListService, 'findTasksByState').and.returnValue(of(transformDates(fakeGlobalTask)));
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.rows).toBeDefined();
@@ -421,18 +411,14 @@ describe('TaskListComponent', () => {
});
component.ngOnChanges({ processDefinitionKey: change });
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeGlobalTask)
});
});
it('should reload the list when the state parameter changes', (done) => {
const state = 'open';
const change = new SimpleChange(null, state, true);
spyOn(taskListService, 'findTasksByState').and.returnValue(of(transformDates(fakeGlobalTask)));
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.rows).toBeDefined();
@@ -443,18 +429,14 @@ describe('TaskListComponent', () => {
});
component.ngOnChanges({ state: change });
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeGlobalTask)
});
});
it('should reload the list when the sort parameter changes', (done) => {
const sort = 'desc';
const change = new SimpleChange(null, sort, true);
spyOn(taskListService, 'findTasksByState').and.returnValue(of(transformDates(fakeGlobalTask)));
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.rows).toBeDefined();
@@ -465,18 +447,14 @@ describe('TaskListComponent', () => {
});
component.ngOnChanges({ sort: change });
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeGlobalTask)
});
});
it('should reload the process list when the name parameter changes', (done) => {
const name = 'FakeTaskName';
const change = new SimpleChange(null, name, true);
spyOn(taskListService, 'findTasksByState').and.returnValue(of(transformDates(fakeGlobalTask)));
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.rows).toBeDefined();
@@ -487,18 +465,14 @@ describe('TaskListComponent', () => {
});
component.ngOnChanges({ name: change });
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeGlobalTask)
});
});
it('should reload the list when the assignment parameter changes', (done) => {
const assignment = 'assignee';
const change = new SimpleChange(null, assignment, true);
spyOn(taskListService, 'findTasksByState').and.returnValue(of(transformDates(fakeGlobalTask)));
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.rows).toBeDefined();
@@ -509,12 +483,6 @@ describe('TaskListComponent', () => {
});
component.ngOnChanges({ assignment: change });
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: JSON.stringify(fakeGlobalTask)
});
});
});