[ADF-1443] Refactor Download directive (#4028)

* [ADF-1443] Refactor Download directive

* [ADF-1443] Node Download Directive now accepts single node and an array as input

* [ADF-1443] Fix Unit tests

* [ADF-1443] Fix unit test related to viewer component
This commit is contained in:
davidcanonieto
2018-12-05 16:39:21 +00:00
committed by Eugenio Romano
parent b99f6d57dc
commit 7197e1e13a
24 changed files with 386 additions and 111 deletions

View File

@@ -345,7 +345,10 @@ describe('ViewerComponent', () => {
const nodeDetails = { name: displayName, id: '12' };
const contentUrl = '/content/url/path';
const alfrescoApiInstanceMock = {
nodes: { getNodeInfo: () => Promise.resolve(nodeDetails) },
nodes: {
getNodeInfo: () => Promise.resolve(nodeDetails),
getNode: () => Promise.resolve({ id: 'fake-node' })
},
content: { getContentUrl: () => contentUrl }
};
@@ -370,6 +373,8 @@ describe('ViewerComponent', () => {
Promise.resolve({ name: 'file2', content: {} })
);
spyOn(alfrescoApiService.nodesApi, 'getNode').and.returnValue(Promise.resolve({ id: 'fake-node' }));
component.urlFile = null;
component.displayName = null;
component.blobFile = null;
@@ -549,35 +554,6 @@ describe('ViewerComponent', () => {
});
});
it('should invoke download action with the toolbar button', (done) => {
component.allowDownload = true;
spyOn(component, 'downloadContent').and.stub();
fixture.detectChanges();
const button: HTMLButtonElement = element.querySelector('[data-automation-id="adf-toolbar-download"]') as HTMLButtonElement;
button.click();
fixture.whenStable().then(() => {
expect(component.downloadContent).toHaveBeenCalled();
done();
});
});
it('should raise download event with the toolbar button', (done) => {
component.allowDownload = true;
component.downloadUrl = 'URL';
component.fileName = 'fileName';
fixture.detectChanges();
component.download.subscribe((e) => {
expect(e).not.toBeNull();
done();
});
const button: HTMLButtonElement = element.querySelector('[data-automation-id="adf-toolbar-download"]') as HTMLButtonElement;
button.click();
});
it('should render default print button', (done) => {
component.allowPrint = true;
fixture.detectChanges();
@@ -674,6 +650,30 @@ describe('ViewerComponent', () => {
button.click();
});
it('should get and assign node for download', (done) => {
const node = { id: 'fake-node' };
component.fileNodeId = '12';
component.urlFile = '';
const displayName = 'the-name';
const nodeDetails = { name: displayName, id: '12', content: { mimeType: 'txt' } };
const contentUrl = '/content/url/path';
const alfrescoApiInstanceMock = {
nodes: {
getNodeInfo: () => Promise.resolve(nodeDetails),
getNode: () => Promise.resolve(node)
},
content: { getContentUrl: () => contentUrl }
};
spyOn(alfrescoApiService, 'getInstance').and.returnValue(alfrescoApiInstanceMock);
component.ngOnChanges(null);
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(component.node).toBe(node);
done();
});
});
});
describe('View', () => {
@@ -923,7 +923,10 @@ describe('ViewerComponent', () => {
const nodeDetails = { name: displayName, id: '12', content: { mimeType: 'txt' } };
const contentUrl = '/content/url/path';
const alfrescoApiInstanceMock = {
nodes: { getNodeInfo: () => Promise.resolve(nodeDetails) },
nodes: {
getNodeInfo: () => Promise.resolve(nodeDetails),
getNode: () => Promise.resolve({ id: 'fake-node' })
},
content: { getContentUrl: () => contentUrl }
};
@@ -998,7 +1001,6 @@ describe('ViewerComponent', () => {
component.enterFullScreen();
expect(domElement.msRequestFullscreen).toHaveBeenCalled();
});
});
});