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 { FormService } from './../services/form.service';
|
||||
import { WidgetVisibilityService } from './../services/widget-visibility.service';
|
||||
import { NodeService } from './../services/node.service';
|
||||
|
||||
describe('ActivitiForm', () => {
|
||||
|
||||
@ -28,6 +29,7 @@ describe('ActivitiForm', () => {
|
||||
let formService: FormService;
|
||||
let formComponent: ActivitiForm;
|
||||
let visibilityService: WidgetVisibilityService;
|
||||
let nodeService: NodeService;
|
||||
|
||||
beforeEach(() => {
|
||||
componentHandler = jasmine.createSpyObj('componentHandler', [
|
||||
@ -39,7 +41,8 @@ describe('ActivitiForm', () => {
|
||||
window['componentHandler'] = componentHandler;
|
||||
|
||||
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', () => {
|
||||
@ -635,12 +638,22 @@ describe('ActivitiForm', () => {
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
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', () => {
|
||||
|
@ -418,7 +418,7 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
||||
}
|
||||
}
|
||||
|
||||
loadFormForEcmNode(): void {
|
||||
private loadFormForEcmNode(): void {
|
||||
this.nodeService.getNodeMetadata(this.nodeId).subscribe(data => {
|
||||
this.data = data.metadata;
|
||||
this.loadFormFromActiviti(data.nodeType);
|
||||
|
@ -64,12 +64,12 @@ describe('AttachWidget', () => {
|
||||
|
||||
it('should setup with form field', () => {
|
||||
let nodes = [{}];
|
||||
spyOn(contentService, 'getAlfrescoNodes').and.callFake(() => {
|
||||
return Observable.create(observer => {
|
||||
spyOn(contentService, 'getAlfrescoNodes').and.returnValue(
|
||||
Observable.create(observer => {
|
||||
observer.next(nodes);
|
||||
observer.complete();
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
let config = {
|
||||
siteId: '<id>',
|
||||
@ -97,12 +97,12 @@ describe('AttachWidget', () => {
|
||||
|
||||
it('should link file on select', () => {
|
||||
let link = <ExternalContentLink> {};
|
||||
spyOn(contentService, 'linkAlfrescoNode').and.callFake(() => {
|
||||
return Observable.create(observer => {
|
||||
spyOn(contentService, 'linkAlfrescoNode').and.returnValue(
|
||||
Observable.create(observer => {
|
||||
observer.next(link);
|
||||
observer.complete();
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
widget.field = new FormFieldModel(null, {
|
||||
type: FormFieldTypes.UPLOAD
|
||||
@ -145,12 +145,12 @@ describe('AttachWidget', () => {
|
||||
});
|
||||
|
||||
it('should show modal dialog', () => {
|
||||
spyOn(contentService, 'getAlfrescoNodes').and.callFake(() => {
|
||||
return Observable.create(observer => {
|
||||
spyOn(contentService, 'getAlfrescoNodes').and.returnValue(
|
||||
Observable.create(observer => {
|
||||
observer.next([]);
|
||||
observer.complete();
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
widget.field = new FormFieldModel(null, {
|
||||
type: FormFieldTypes.UPLOAD,
|
||||
@ -176,12 +176,12 @@ describe('AttachWidget', () => {
|
||||
|
||||
it('should select folder and load nodes', () => {
|
||||
let nodes = [{}];
|
||||
spyOn(contentService, 'getAlfrescoNodes').and.callFake(() => {
|
||||
return Observable.create(observer => {
|
||||
spyOn(contentService, 'getAlfrescoNodes').and.returnValue(
|
||||
Observable.create(observer => {
|
||||
observer.next(nodes);
|
||||
observer.complete();
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
let node = <ExternalContent> { id: '<id>' };
|
||||
widget.selectFolder(node, null);
|
||||
@ -245,12 +245,12 @@ describe('AttachWidget', () => {
|
||||
|
||||
it('should get external content nodes', () => {
|
||||
let nodes = [{}];
|
||||
spyOn(contentService, 'getAlfrescoNodes').and.callFake(() => {
|
||||
return Observable.create(observer => {
|
||||
spyOn(contentService, 'getAlfrescoNodes').and.returnValue(
|
||||
Observable.create(observer => {
|
||||
observer.next(nodes);
|
||||
observer.complete();
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
const accountId = '<accountId>';
|
||||
const pathId = '<pathId>';
|
||||
@ -264,9 +264,9 @@ describe('AttachWidget', () => {
|
||||
|
||||
it('should handle error', () => {
|
||||
let error = 'error';
|
||||
spyOn(contentService, 'getAlfrescoNodes').and.callFake(() => {
|
||||
return Observable.throw(error);
|
||||
});
|
||||
spyOn(contentService, 'getAlfrescoNodes').and.returnValue(
|
||||
Observable.throw(error)
|
||||
);
|
||||
|
||||
spyOn(console, 'log').and.stub();
|
||||
widget.getExternalContentNodes();
|
||||
|
@ -292,15 +292,15 @@ describe('DisplayValueWidget', () => {
|
||||
});
|
||||
|
||||
it('should setup rest field values with REST options', () => {
|
||||
spyOn(formService, 'getRestFieldValues').and.callFake(() => {
|
||||
return Observable.create(observer => {
|
||||
spyOn(formService, 'getRestFieldValues').and.returnValue(
|
||||
Observable.create(observer => {
|
||||
observer.next([
|
||||
{ id: '1', name: 'option 1' },
|
||||
{ id: '2', name: 'option 2' }
|
||||
]);
|
||||
observer.complete();
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
let form = new FormModel({ taskId: '<id>' });
|
||||
|
||||
@ -324,15 +324,15 @@ describe('DisplayValueWidget', () => {
|
||||
});
|
||||
|
||||
it('should not setup rest field values with missing REST option', () => {
|
||||
spyOn(formService, 'getRestFieldValues').and.callFake(() => {
|
||||
return Observable.create(observer => {
|
||||
spyOn(formService, 'getRestFieldValues').and.returnValue(
|
||||
Observable.create(observer => {
|
||||
observer.next([
|
||||
{ id: '1', name: 'option 1' },
|
||||
{ id: '2', name: 'option 2' }
|
||||
]);
|
||||
observer.complete();
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
let form = new FormModel({ taskId: '<id>' });
|
||||
|
||||
@ -352,12 +352,12 @@ describe('DisplayValueWidget', () => {
|
||||
});
|
||||
|
||||
it('should not setup rest field values with no REST response', () => {
|
||||
spyOn(formService, 'getRestFieldValues').and.callFake(() => {
|
||||
return Observable.create(observer => {
|
||||
spyOn(formService, 'getRestFieldValues').and.returnValue(
|
||||
Observable.create(observer => {
|
||||
observer.next(null);
|
||||
observer.complete();
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
let form = new FormModel({ taskId: '<id>' });
|
||||
|
||||
@ -378,9 +378,9 @@ describe('DisplayValueWidget', () => {
|
||||
|
||||
it('should handle rest error', () => {
|
||||
const error = 'ERROR';
|
||||
spyOn(formService, 'getRestFieldValues').and.callFake(() => {
|
||||
return Observable.throw(error);
|
||||
});
|
||||
spyOn(formService, 'getRestFieldValues').and.returnValue(
|
||||
Observable.throw(error)
|
||||
);
|
||||
|
||||
spyOn(console, 'log').and.stub();
|
||||
|
||||
|
@ -58,10 +58,12 @@ describe('DropdownWidget', () => {
|
||||
restUrl: '<url>'
|
||||
});
|
||||
|
||||
spyOn(formService, 'getRestFieldValues').and.returnValue(Observable.create(observer => {
|
||||
observer.next(null);
|
||||
observer.complete();
|
||||
}));
|
||||
spyOn(formService, 'getRestFieldValues').and.returnValue(
|
||||
Observable.create(observer => {
|
||||
observer.next(null);
|
||||
observer.complete();
|
||||
})
|
||||
);
|
||||
widget.ngOnInit();
|
||||
expect(formService.getRestFieldValues).toHaveBeenCalledWith(taskId, fieldId);
|
||||
});
|
||||
@ -74,10 +76,12 @@ describe('DropdownWidget', () => {
|
||||
|
||||
it('should preserve empty option when loading fields', () => {
|
||||
let restFieldValue: FormFieldOption = <FormFieldOption> { id: '1', name: 'Option1' };
|
||||
spyOn(formService, 'getRestFieldValues').and.returnValue(Observable.create(observer => {
|
||||
observer.next([restFieldValue]);
|
||||
observer.complete();
|
||||
}));
|
||||
spyOn(formService, 'getRestFieldValues').and.returnValue(
|
||||
Observable.create(observer => {
|
||||
observer.next([restFieldValue]);
|
||||
observer.complete();
|
||||
})
|
||||
);
|
||||
|
||||
let form = new FormModel({ taskId: '<id>' });
|
||||
let emptyOption: FormFieldOption = <FormFieldOption> { id: 'empty', name: 'Empty' };
|
||||
|
@ -80,10 +80,12 @@ describe('PeopleWidget', () => {
|
||||
lastName: 'Doe'
|
||||
});
|
||||
|
||||
spyOn(formService, 'getWorkflowUsers').and.returnValue(Observable.create(observer => {
|
||||
observer.next(null);
|
||||
observer.complete();
|
||||
}));
|
||||
spyOn(formService, 'getWorkflowUsers').and.returnValue(
|
||||
Observable.create(observer => {
|
||||
observer.next(null);
|
||||
observer.complete();
|
||||
})
|
||||
);
|
||||
|
||||
widget.ngOnInit();
|
||||
expect(widget.value).toBe('John Doe');
|
||||
@ -122,10 +124,12 @@ describe('PeopleWidget', () => {
|
||||
|
||||
it('should fetch users by search term', () => {
|
||||
let users = [{}, {}];
|
||||
spyOn(formService, 'getWorkflowUsers').and.returnValue(Observable.create(observer => {
|
||||
observer.next(users);
|
||||
observer.complete();
|
||||
}));
|
||||
spyOn(formService, 'getWorkflowUsers').and.returnValue(
|
||||
Observable.create(observer => {
|
||||
observer.next(users);
|
||||
observer.complete();
|
||||
})
|
||||
);
|
||||
|
||||
widget.value = 'user1';
|
||||
widget.onKeyUp(null);
|
||||
@ -137,10 +141,12 @@ describe('PeopleWidget', () => {
|
||||
|
||||
it('should fetch users by search term and group id', () => {
|
||||
let users = [{}, {}];
|
||||
spyOn(formService, 'getWorkflowUsers').and.returnValue(Observable.create(observer => {
|
||||
observer.next(users);
|
||||
observer.complete();
|
||||
}));
|
||||
spyOn(formService, 'getWorkflowUsers').and.returnValue(
|
||||
Observable.create(observer => {
|
||||
observer.next(users);
|
||||
observer.complete();
|
||||
})
|
||||
);
|
||||
|
||||
widget.value = 'user1';
|
||||
widget.groupId = '1001';
|
||||
@ -152,10 +158,12 @@ describe('PeopleWidget', () => {
|
||||
});
|
||||
|
||||
it('should fetch users and show no popup', () => {
|
||||
spyOn(formService, 'getWorkflowUsers').and.returnValue(Observable.create(observer => {
|
||||
observer.next(null);
|
||||
observer.complete();
|
||||
}));
|
||||
spyOn(formService, 'getWorkflowUsers').and.returnValue(
|
||||
Observable.create(observer => {
|
||||
observer.next(null);
|
||||
observer.complete();
|
||||
})
|
||||
);
|
||||
|
||||
widget.value = 'user1';
|
||||
widget.onKeyUp(null);
|
||||
|
Loading…
x
Reference in New Issue
Block a user