mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
Updated unit tests based on code review suggestions
This commit is contained in:
parent
3d3b156194
commit
64b8343f02
@ -21,6 +21,7 @@ import { ActivitiForm } from './activiti-form.component';
|
|||||||
import { FormModel, FormOutcomeModel, FormFieldModel, FormOutcomeEvent } from './widgets/index';
|
import { FormModel, FormOutcomeModel, FormFieldModel, FormOutcomeEvent } from './widgets/index';
|
||||||
import { FormService } from './../services/form.service';
|
import { FormService } from './../services/form.service';
|
||||||
import { WidgetVisibilityService } from './../services/widget-visibility.service';
|
import { WidgetVisibilityService } from './../services/widget-visibility.service';
|
||||||
|
import { NodeService } from './../services/node.service';
|
||||||
|
|
||||||
describe('ActivitiForm', () => {
|
describe('ActivitiForm', () => {
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ describe('ActivitiForm', () => {
|
|||||||
let formService: FormService;
|
let formService: FormService;
|
||||||
let formComponent: ActivitiForm;
|
let formComponent: ActivitiForm;
|
||||||
let visibilityService: WidgetVisibilityService;
|
let visibilityService: WidgetVisibilityService;
|
||||||
|
let nodeService: NodeService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
componentHandler = jasmine.createSpyObj('componentHandler', [
|
componentHandler = jasmine.createSpyObj('componentHandler', [
|
||||||
@ -39,7 +41,8 @@ describe('ActivitiForm', () => {
|
|||||||
window['componentHandler'] = componentHandler;
|
window['componentHandler'] = componentHandler;
|
||||||
|
|
||||||
formService = new FormService(null, null);
|
formService = new FormService(null, null);
|
||||||
formComponent = new ActivitiForm(formService, visibilityService, null, null);
|
nodeService = new NodeService(null);
|
||||||
|
formComponent = new ActivitiForm(formService, visibilityService, null, nodeService);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should upgrade MDL content on view checked', () => {
|
it('should upgrade MDL content on view checked', () => {
|
||||||
@ -635,12 +638,22 @@ describe('ActivitiForm', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should load form for ecm node', () => {
|
it('should load form for ecm node', () => {
|
||||||
spyOn(formComponent, 'loadFormForEcmNode').and.stub();
|
let metadata = {};
|
||||||
|
spyOn(nodeService, 'getNodeMetadata').and.returnValue(
|
||||||
|
Observable.create(observer => {
|
||||||
|
observer.next({ metadata: metadata });
|
||||||
|
observer.complete();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
spyOn(formComponent, 'loadFormFromActiviti').and.stub();
|
||||||
|
|
||||||
formComponent.nodeId = '<id>';
|
const nodeId = '<id>';
|
||||||
|
formComponent.nodeId = nodeId;
|
||||||
formComponent.ngOnInit();
|
formComponent.ngOnInit();
|
||||||
|
|
||||||
expect(formComponent.loadFormForEcmNode).toHaveBeenCalled();
|
expect(nodeService.getNodeMetadata).toHaveBeenCalledWith(nodeId);
|
||||||
|
expect(formComponent.loadFormFromActiviti).toHaveBeenCalled();
|
||||||
|
expect(formComponent.data).toBe(metadata);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should disable outcome buttons for readonly form', () => {
|
it('should disable outcome buttons for readonly form', () => {
|
||||||
|
@ -418,7 +418,7 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadFormForEcmNode(): void {
|
private loadFormForEcmNode(): void {
|
||||||
this.nodeService.getNodeMetadata(this.nodeId).subscribe(data => {
|
this.nodeService.getNodeMetadata(this.nodeId).subscribe(data => {
|
||||||
this.data = data.metadata;
|
this.data = data.metadata;
|
||||||
this.loadFormFromActiviti(data.nodeType);
|
this.loadFormFromActiviti(data.nodeType);
|
||||||
|
@ -64,12 +64,12 @@ describe('AttachWidget', () => {
|
|||||||
|
|
||||||
it('should setup with form field', () => {
|
it('should setup with form field', () => {
|
||||||
let nodes = [{}];
|
let nodes = [{}];
|
||||||
spyOn(contentService, 'getAlfrescoNodes').and.callFake(() => {
|
spyOn(contentService, 'getAlfrescoNodes').and.returnValue(
|
||||||
return Observable.create(observer => {
|
Observable.create(observer => {
|
||||||
observer.next(nodes);
|
observer.next(nodes);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
});
|
})
|
||||||
});
|
);
|
||||||
|
|
||||||
let config = {
|
let config = {
|
||||||
siteId: '<id>',
|
siteId: '<id>',
|
||||||
@ -97,12 +97,12 @@ describe('AttachWidget', () => {
|
|||||||
|
|
||||||
it('should link file on select', () => {
|
it('should link file on select', () => {
|
||||||
let link = <ExternalContentLink> {};
|
let link = <ExternalContentLink> {};
|
||||||
spyOn(contentService, 'linkAlfrescoNode').and.callFake(() => {
|
spyOn(contentService, 'linkAlfrescoNode').and.returnValue(
|
||||||
return Observable.create(observer => {
|
Observable.create(observer => {
|
||||||
observer.next(link);
|
observer.next(link);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
});
|
})
|
||||||
});
|
);
|
||||||
|
|
||||||
widget.field = new FormFieldModel(null, {
|
widget.field = new FormFieldModel(null, {
|
||||||
type: FormFieldTypes.UPLOAD
|
type: FormFieldTypes.UPLOAD
|
||||||
@ -145,12 +145,12 @@ describe('AttachWidget', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should show modal dialog', () => {
|
it('should show modal dialog', () => {
|
||||||
spyOn(contentService, 'getAlfrescoNodes').and.callFake(() => {
|
spyOn(contentService, 'getAlfrescoNodes').and.returnValue(
|
||||||
return Observable.create(observer => {
|
Observable.create(observer => {
|
||||||
observer.next([]);
|
observer.next([]);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
});
|
})
|
||||||
});
|
);
|
||||||
|
|
||||||
widget.field = new FormFieldModel(null, {
|
widget.field = new FormFieldModel(null, {
|
||||||
type: FormFieldTypes.UPLOAD,
|
type: FormFieldTypes.UPLOAD,
|
||||||
@ -176,12 +176,12 @@ describe('AttachWidget', () => {
|
|||||||
|
|
||||||
it('should select folder and load nodes', () => {
|
it('should select folder and load nodes', () => {
|
||||||
let nodes = [{}];
|
let nodes = [{}];
|
||||||
spyOn(contentService, 'getAlfrescoNodes').and.callFake(() => {
|
spyOn(contentService, 'getAlfrescoNodes').and.returnValue(
|
||||||
return Observable.create(observer => {
|
Observable.create(observer => {
|
||||||
observer.next(nodes);
|
observer.next(nodes);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
});
|
})
|
||||||
});
|
);
|
||||||
|
|
||||||
let node = <ExternalContent> { id: '<id>' };
|
let node = <ExternalContent> { id: '<id>' };
|
||||||
widget.selectFolder(node, null);
|
widget.selectFolder(node, null);
|
||||||
@ -245,12 +245,12 @@ describe('AttachWidget', () => {
|
|||||||
|
|
||||||
it('should get external content nodes', () => {
|
it('should get external content nodes', () => {
|
||||||
let nodes = [{}];
|
let nodes = [{}];
|
||||||
spyOn(contentService, 'getAlfrescoNodes').and.callFake(() => {
|
spyOn(contentService, 'getAlfrescoNodes').and.returnValue(
|
||||||
return Observable.create(observer => {
|
Observable.create(observer => {
|
||||||
observer.next(nodes);
|
observer.next(nodes);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
});
|
})
|
||||||
});
|
);
|
||||||
|
|
||||||
const accountId = '<accountId>';
|
const accountId = '<accountId>';
|
||||||
const pathId = '<pathId>';
|
const pathId = '<pathId>';
|
||||||
@ -264,9 +264,9 @@ describe('AttachWidget', () => {
|
|||||||
|
|
||||||
it('should handle error', () => {
|
it('should handle error', () => {
|
||||||
let error = 'error';
|
let error = 'error';
|
||||||
spyOn(contentService, 'getAlfrescoNodes').and.callFake(() => {
|
spyOn(contentService, 'getAlfrescoNodes').and.returnValue(
|
||||||
return Observable.throw(error);
|
Observable.throw(error)
|
||||||
});
|
);
|
||||||
|
|
||||||
spyOn(console, 'log').and.stub();
|
spyOn(console, 'log').and.stub();
|
||||||
widget.getExternalContentNodes();
|
widget.getExternalContentNodes();
|
||||||
|
@ -292,15 +292,15 @@ describe('DisplayValueWidget', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should setup rest field values with REST options', () => {
|
it('should setup rest field values with REST options', () => {
|
||||||
spyOn(formService, 'getRestFieldValues').and.callFake(() => {
|
spyOn(formService, 'getRestFieldValues').and.returnValue(
|
||||||
return Observable.create(observer => {
|
Observable.create(observer => {
|
||||||
observer.next([
|
observer.next([
|
||||||
{ id: '1', name: 'option 1' },
|
{ id: '1', name: 'option 1' },
|
||||||
{ id: '2', name: 'option 2' }
|
{ id: '2', name: 'option 2' }
|
||||||
]);
|
]);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
});
|
})
|
||||||
});
|
);
|
||||||
|
|
||||||
let form = new FormModel({ taskId: '<id>' });
|
let form = new FormModel({ taskId: '<id>' });
|
||||||
|
|
||||||
@ -324,15 +324,15 @@ describe('DisplayValueWidget', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not setup rest field values with missing REST option', () => {
|
it('should not setup rest field values with missing REST option', () => {
|
||||||
spyOn(formService, 'getRestFieldValues').and.callFake(() => {
|
spyOn(formService, 'getRestFieldValues').and.returnValue(
|
||||||
return Observable.create(observer => {
|
Observable.create(observer => {
|
||||||
observer.next([
|
observer.next([
|
||||||
{ id: '1', name: 'option 1' },
|
{ id: '1', name: 'option 1' },
|
||||||
{ id: '2', name: 'option 2' }
|
{ id: '2', name: 'option 2' }
|
||||||
]);
|
]);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
});
|
})
|
||||||
});
|
);
|
||||||
|
|
||||||
let form = new FormModel({ taskId: '<id>' });
|
let form = new FormModel({ taskId: '<id>' });
|
||||||
|
|
||||||
@ -352,12 +352,12 @@ describe('DisplayValueWidget', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not setup rest field values with no REST response', () => {
|
it('should not setup rest field values with no REST response', () => {
|
||||||
spyOn(formService, 'getRestFieldValues').and.callFake(() => {
|
spyOn(formService, 'getRestFieldValues').and.returnValue(
|
||||||
return Observable.create(observer => {
|
Observable.create(observer => {
|
||||||
observer.next(null);
|
observer.next(null);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
});
|
})
|
||||||
});
|
);
|
||||||
|
|
||||||
let form = new FormModel({ taskId: '<id>' });
|
let form = new FormModel({ taskId: '<id>' });
|
||||||
|
|
||||||
@ -378,9 +378,9 @@ describe('DisplayValueWidget', () => {
|
|||||||
|
|
||||||
it('should handle rest error', () => {
|
it('should handle rest error', () => {
|
||||||
const error = 'ERROR';
|
const error = 'ERROR';
|
||||||
spyOn(formService, 'getRestFieldValues').and.callFake(() => {
|
spyOn(formService, 'getRestFieldValues').and.returnValue(
|
||||||
return Observable.throw(error);
|
Observable.throw(error)
|
||||||
});
|
);
|
||||||
|
|
||||||
spyOn(console, 'log').and.stub();
|
spyOn(console, 'log').and.stub();
|
||||||
|
|
||||||
|
@ -58,10 +58,12 @@ describe('DropdownWidget', () => {
|
|||||||
restUrl: '<url>'
|
restUrl: '<url>'
|
||||||
});
|
});
|
||||||
|
|
||||||
spyOn(formService, 'getRestFieldValues').and.returnValue(Observable.create(observer => {
|
spyOn(formService, 'getRestFieldValues').and.returnValue(
|
||||||
|
Observable.create(observer => {
|
||||||
observer.next(null);
|
observer.next(null);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
widget.ngOnInit();
|
widget.ngOnInit();
|
||||||
expect(formService.getRestFieldValues).toHaveBeenCalledWith(taskId, fieldId);
|
expect(formService.getRestFieldValues).toHaveBeenCalledWith(taskId, fieldId);
|
||||||
});
|
});
|
||||||
@ -74,10 +76,12 @@ describe('DropdownWidget', () => {
|
|||||||
|
|
||||||
it('should preserve empty option when loading fields', () => {
|
it('should preserve empty option when loading fields', () => {
|
||||||
let restFieldValue: FormFieldOption = <FormFieldOption> { id: '1', name: 'Option1' };
|
let restFieldValue: FormFieldOption = <FormFieldOption> { id: '1', name: 'Option1' };
|
||||||
spyOn(formService, 'getRestFieldValues').and.returnValue(Observable.create(observer => {
|
spyOn(formService, 'getRestFieldValues').and.returnValue(
|
||||||
|
Observable.create(observer => {
|
||||||
observer.next([restFieldValue]);
|
observer.next([restFieldValue]);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
|
|
||||||
let form = new FormModel({ taskId: '<id>' });
|
let form = new FormModel({ taskId: '<id>' });
|
||||||
let emptyOption: FormFieldOption = <FormFieldOption> { id: 'empty', name: 'Empty' };
|
let emptyOption: FormFieldOption = <FormFieldOption> { id: 'empty', name: 'Empty' };
|
||||||
|
@ -80,10 +80,12 @@ describe('PeopleWidget', () => {
|
|||||||
lastName: 'Doe'
|
lastName: 'Doe'
|
||||||
});
|
});
|
||||||
|
|
||||||
spyOn(formService, 'getWorkflowUsers').and.returnValue(Observable.create(observer => {
|
spyOn(formService, 'getWorkflowUsers').and.returnValue(
|
||||||
|
Observable.create(observer => {
|
||||||
observer.next(null);
|
observer.next(null);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
|
|
||||||
widget.ngOnInit();
|
widget.ngOnInit();
|
||||||
expect(widget.value).toBe('John Doe');
|
expect(widget.value).toBe('John Doe');
|
||||||
@ -122,10 +124,12 @@ describe('PeopleWidget', () => {
|
|||||||
|
|
||||||
it('should fetch users by search term', () => {
|
it('should fetch users by search term', () => {
|
||||||
let users = [{}, {}];
|
let users = [{}, {}];
|
||||||
spyOn(formService, 'getWorkflowUsers').and.returnValue(Observable.create(observer => {
|
spyOn(formService, 'getWorkflowUsers').and.returnValue(
|
||||||
|
Observable.create(observer => {
|
||||||
observer.next(users);
|
observer.next(users);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
|
|
||||||
widget.value = 'user1';
|
widget.value = 'user1';
|
||||||
widget.onKeyUp(null);
|
widget.onKeyUp(null);
|
||||||
@ -137,10 +141,12 @@ describe('PeopleWidget', () => {
|
|||||||
|
|
||||||
it('should fetch users by search term and group id', () => {
|
it('should fetch users by search term and group id', () => {
|
||||||
let users = [{}, {}];
|
let users = [{}, {}];
|
||||||
spyOn(formService, 'getWorkflowUsers').and.returnValue(Observable.create(observer => {
|
spyOn(formService, 'getWorkflowUsers').and.returnValue(
|
||||||
|
Observable.create(observer => {
|
||||||
observer.next(users);
|
observer.next(users);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
|
|
||||||
widget.value = 'user1';
|
widget.value = 'user1';
|
||||||
widget.groupId = '1001';
|
widget.groupId = '1001';
|
||||||
@ -152,10 +158,12 @@ describe('PeopleWidget', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch users and show no popup', () => {
|
it('should fetch users and show no popup', () => {
|
||||||
spyOn(formService, 'getWorkflowUsers').and.returnValue(Observable.create(observer => {
|
spyOn(formService, 'getWorkflowUsers').and.returnValue(
|
||||||
|
Observable.create(observer => {
|
||||||
observer.next(null);
|
observer.next(null);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
|
|
||||||
widget.value = 'user1';
|
widget.value = 'user1';
|
||||||
widget.onKeyUp(null);
|
widget.onKeyUp(null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user