Fix unit tests

This commit is contained in:
Denys Vuika
2016-09-05 10:59:26 +01:00
parent c4a593f9a2
commit f5b16468be

View File

@@ -23,10 +23,12 @@ import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiServ
import { RenderingQueueServices } from '../services/rendering-queue.services'; import { RenderingQueueServices } from '../services/rendering-queue.services';
declare let jasmine: any; declare let jasmine: any;
declare let AlfrescoApi: any;
describe('ViewerComponent', () => { describe('ViewerComponent', () => {
let viewerComponentFixture, element, component; let viewerComponentFixture, element, component;
let apiService: AlfrescoApiService;
beforeEachProviders(() => { beforeEachProviders(() => {
return [ return [
@@ -37,7 +39,10 @@ describe('ViewerComponent', () => {
]; ];
}); });
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { beforeEach(inject([TestComponentBuilder, AlfrescoApiService], (tcb: TestComponentBuilder, api: AlfrescoApiService) => {
apiService = api;
apiService.setInstance(new AlfrescoApi({}));
return tcb return tcb
.createAsync(ViewerComponent) .createAsync(ViewerComponent)
.then(fixture => { .then(fixture => {
@@ -161,27 +166,16 @@ describe('ViewerComponent', () => {
}).not.toThrow(); }).not.toThrow();
}); });
it('If FileNodeId is present the node api should be called', (done) => { it('If FileNodeId is present the node api should be called', (/*done*/) => {
component.showViewer = true; component.showViewer = true;
component.fileNodeId = 'file-node-id'; component.fileNodeId = 'file-node-id';
component.urlFile = undefined; component.urlFile = undefined;
jasmine.Ajax.stubRequest( let alfrescoApi = apiService.getInstance();
'http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/file-node-id' spyOn(alfrescoApi.nodes, 'getNodeInfo').and.stub();
).andReturn({
status: 200,
responseText: '{"entry":{"isFile":true,"createdByUser":{"id":"admin","displayName":"Administrator"},' +
'"modifiedAt":"2016-08-05T23:08:22.730+0000","nodeType":"cm:content","content":' +
'{"mimeType":"application/pdf","mimeTypeName":"Adobe PDF Document","sizeInBytes":' +
'381778,"encoding":"UTF-8"},"parentId":"8f2105b4-daaf-4874-9e8a-2152569d109b","createdAt":"2016-08-05T23:08:22.730+0000","isFolder":false,' +
'"modifiedByUser":{"id":"admin","displayName":"Administrator"},"name":"content.pdf","id":' +
'"b8bd4c81-6f2e-4ec2-9c4d-30c97cf42bc8"}}'
});
component.ngOnChanges().then(() => { component.ngOnChanges();
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('nodes/file-node-id')).toBe(true); expect(alfrescoApi.nodes.getNodeInfo).toHaveBeenCalledWith(component.fileNodeId);
done();
});
}); });
it('showViewer default value should be true', () => { it('showViewer default value should be true', () => {