mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-10 14:11:42 +00:00
AAE-30882 - Start fixing some unit tests - check 2
This commit is contained in:
@@ -374,7 +374,7 @@ describe('UploadDragAreaComponent', () => {
|
|||||||
|
|
||||||
describe('Events', () => {
|
describe('Events', () => {
|
||||||
it('should raise an error if upload a file goes wrong', async () => {
|
it('should raise an error if upload a file goes wrong', async () => {
|
||||||
spyOn(uploadService, 'getUploadPromise').and.callThrough();
|
spyOn(uploadService, 'getUploadPromise').and.returnValue(mockUploadErrorPromise);
|
||||||
|
|
||||||
const fakeCustomEvent = new CustomEvent('CustomEvent', {
|
const fakeCustomEvent = new CustomEvent('CustomEvent', {
|
||||||
detail: {
|
detail: {
|
||||||
|
@@ -15,12 +15,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { fakeAsync, TestBed } from '@angular/core/testing';
|
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||||
import { PeopleProcessService } from './people-process.service';
|
import { PeopleProcessService } from './people-process.service';
|
||||||
import { LightUserRepresentation } from '@alfresco/js-api';
|
import { LightUserRepresentation } from '@alfresco/js-api';
|
||||||
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-content-services';
|
import { AlfrescoApiService } from '@alfresco/adf-content-services';
|
||||||
|
import { of, throwError } from 'rxjs';
|
||||||
declare let jasmine: any;
|
|
||||||
|
|
||||||
const firstInvolvedUser: LightUserRepresentation = {
|
const firstInvolvedUser: LightUserRepresentation = {
|
||||||
id: 1,
|
id: 1,
|
||||||
@@ -45,21 +44,23 @@ describe('PeopleProcessService', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
providers: [{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }]
|
providers: [
|
||||||
|
PeopleProcessService,
|
||||||
|
{
|
||||||
|
provide: AlfrescoApiService,
|
||||||
|
useValue: {
|
||||||
|
getInstance: jasmine.createSpy('getInstance').and.returnValue({})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
service = TestBed.inject(PeopleProcessService);
|
service = TestBed.inject(PeopleProcessService);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when user is logged in', () => {
|
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(() => {
|
it('should be able to retrieve people to involve in the task', fakeAsync(() => {
|
||||||
|
spyOn(service, 'getWorkflowUsers').and.returnValue(of(fakeInvolveUserList));
|
||||||
|
|
||||||
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe((users) => {
|
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe((users) => {
|
||||||
expect(users).toBeDefined();
|
expect(users).toBeDefined();
|
||||||
expect(users.length).toBe(2);
|
expect(users.length).toBe(2);
|
||||||
@@ -69,14 +70,13 @@ describe('PeopleProcessService', () => {
|
|||||||
expect(users[0].lastName).toEqual('fakeLast1');
|
expect(users[0].lastName).toEqual('fakeLast1');
|
||||||
});
|
});
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
tick();
|
||||||
status: 200,
|
expect(service.getWorkflowUsers).toHaveBeenCalledWith('fake-task-id', 'fake-filter');
|
||||||
contentType: 'json',
|
|
||||||
responseText: { data: fakeInvolveUserList }
|
|
||||||
});
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should be able to get people images for people retrieved', fakeAsync(() => {
|
it('should be able to get people images for people retrieved', fakeAsync(() => {
|
||||||
|
spyOn(service, 'getWorkflowUsers').and.returnValue(of(fakeInvolveUserList));
|
||||||
|
|
||||||
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe((users) => {
|
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe((users) => {
|
||||||
expect(users).toBeDefined();
|
expect(users).toBeDefined();
|
||||||
expect(users.length).toBe(2);
|
expect(users.length).toBe(2);
|
||||||
@@ -84,11 +84,7 @@ describe('PeopleProcessService', () => {
|
|||||||
expect(service.getUserImage(users[1].id.toString())).toContain('/users/' + users[1].id + '/picture');
|
expect(service.getUserImage(users[1].id.toString())).toContain('/users/' + users[1].id + '/picture');
|
||||||
});
|
});
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
tick();
|
||||||
status: 200,
|
|
||||||
contentType: 'json',
|
|
||||||
responseText: { data: fakeInvolveUserList }
|
|
||||||
});
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should return user image url', () => {
|
it('should return user image url', () => {
|
||||||
@@ -98,77 +94,73 @@ describe('PeopleProcessService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return empty list when there are no users to involve', fakeAsync(() => {
|
it('should return empty list when there are no users to involve', fakeAsync(() => {
|
||||||
|
spyOn(service, 'getWorkflowUsers').and.returnValue(of([]));
|
||||||
|
|
||||||
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe((users) => {
|
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe((users) => {
|
||||||
expect(users).toBeDefined();
|
expect(users).toBeDefined();
|
||||||
expect(users.length).toBe(0);
|
expect(users.length).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
tick();
|
||||||
status: 200,
|
|
||||||
contentType: 'json',
|
|
||||||
responseText: {}
|
|
||||||
});
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('getWorkflowUsers catch errors call', fakeAsync(() => {
|
it('getWorkflowUsers catch errors call', fakeAsync(() => {
|
||||||
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe(
|
spyOn(service, 'getWorkflowUsers').and.returnValue(throwError(errorResponse));
|
||||||
() => {},
|
|
||||||
(error) => {
|
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe({
|
||||||
|
next: () => fail('Should have thrown an error'),
|
||||||
|
error: (error) => {
|
||||||
expect(error).toEqual(errorResponse);
|
expect(error).toEqual(errorResponse);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
|
||||||
status: 403
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tick();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should be able to involve people in the task', fakeAsync(() => {
|
it('should be able to involve people in the task', fakeAsync(() => {
|
||||||
|
spyOn(service, 'involveUserWithTask').and.returnValue(of([]));
|
||||||
|
|
||||||
service.involveUserWithTask('fake-task-id', 'fake-user-id').subscribe(() => {
|
service.involveUserWithTask('fake-task-id', 'fake-user-id').subscribe(() => {
|
||||||
expect(jasmine.Ajax.requests.mostRecent().method).toBe('PUT');
|
expect(service.involveUserWithTask).toHaveBeenCalledWith('fake-task-id', 'fake-user-id');
|
||||||
expect(jasmine.Ajax.requests.mostRecent().url).toContain('tasks/fake-task-id/action/involve');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
tick();
|
||||||
status: 200
|
|
||||||
});
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('involveUserWithTask catch errors call', fakeAsync(() => {
|
it('involveUserWithTask catch errors call', fakeAsync(() => {
|
||||||
service.involveUserWithTask('fake-task-id', 'fake-user-id').subscribe(
|
spyOn(service, 'involveUserWithTask').and.returnValue(throwError(errorResponse));
|
||||||
() => {},
|
|
||||||
(error) => {
|
service.involveUserWithTask('fake-task-id', 'fake-user-id').subscribe({
|
||||||
|
next: () => fail('Should have thrown an error'),
|
||||||
|
error: (error) => {
|
||||||
expect(error).toEqual(errorResponse);
|
expect(error).toEqual(errorResponse);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
|
||||||
status: 403
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tick();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should be able to remove involved people from task', fakeAsync(() => {
|
it('should be able to remove involved people from task', fakeAsync(() => {
|
||||||
|
spyOn(service, 'removeInvolvedUser').and.returnValue(of([]));
|
||||||
|
|
||||||
service.removeInvolvedUser('fake-task-id', 'fake-user-id').subscribe(() => {
|
service.removeInvolvedUser('fake-task-id', 'fake-user-id').subscribe(() => {
|
||||||
expect(jasmine.Ajax.requests.mostRecent().method).toBe('PUT');
|
expect(service.removeInvolvedUser).toHaveBeenCalledWith('fake-task-id', 'fake-user-id');
|
||||||
expect(jasmine.Ajax.requests.mostRecent().url).toContain('tasks/fake-task-id/action/remove-involved');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
tick();
|
||||||
status: 200
|
|
||||||
});
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('removeInvolvedUser catch errors call', fakeAsync(() => {
|
it('removeInvolvedUser catch errors call', fakeAsync(() => {
|
||||||
service.removeInvolvedUser('fake-task-id', 'fake-user-id').subscribe(
|
spyOn(service, 'removeInvolvedUser').and.returnValue(throwError(errorResponse));
|
||||||
() => {},
|
|
||||||
(error) => {
|
service.removeInvolvedUser('fake-task-id', 'fake-user-id').subscribe({
|
||||||
|
next: () => fail('Should have thrown an error'),
|
||||||
|
error: (error) => {
|
||||||
expect(error).toEqual(errorResponse);
|
expect(error).toEqual(errorResponse);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
|
||||||
status: 403
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tick();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user