[ADF-2254] always update display name for ACS nodes (#2926)

* always update display name for ACS nodes
* remove the test that tests opposite behaviour
This commit is contained in:
Denys Vuika
2018-02-09 16:48:25 +00:00
committed by Eugenio Romano
parent 3114fa4862
commit 2bfed5818f
2 changed files with 39 additions and 24 deletions

View File

@@ -18,7 +18,7 @@
import { Location } from '@angular/common'; import { Location } from '@angular/common';
import { SpyLocation } from '@angular/common/testing'; import { SpyLocation } from '@angular/common/testing';
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { AlfrescoApiService, RenditionsService } from '../../services'; import { AlfrescoApiService, RenditionsService } from '../../services';
import { MaterialModule } from './../../material.module'; import { MaterialModule } from './../../material.module';
@@ -155,6 +155,40 @@ describe('ViewerComponent', () => {
}).compileComponents(); }).compileComponents();
})); }));
beforeEach(() => {
fixture = TestBed.createComponent(ViewerComponent);
element = fixture.nativeElement;
component = fixture.componentInstance;
alfrescoApiService = TestBed.get(AlfrescoApiService);
});
it('should change display name every time node changes', fakeAsync(() => {
spyOn(alfrescoApiService.nodesApi, 'getNodeInfo').and.returnValues(
Promise.resolve({ name: 'file1', content: {} }),
Promise.resolve({ name: 'file2', content: {} })
);
component.urlFile = null;
component.displayName = null;
component.blobFile = null;
component.showViewer = true;
component.fileNodeId = 'id1';
component.ngOnChanges({});
tick();
expect(alfrescoApiService.nodesApi.getNodeInfo).toHaveBeenCalledWith('id1');
expect(component.displayName).toBe('file1');
component.fileNodeId = 'id2';
component.ngOnChanges({});
tick();
expect(alfrescoApiService.nodesApi.getNodeInfo).toHaveBeenCalledWith('id2');
expect(component.displayName).toBe('file2');
}));
describe('Viewer Example Component Rendering', () => { describe('Viewer Example Component Rendering', () => {
it('should use custom toolbar', () => { it('should use custom toolbar', () => {
@@ -193,15 +227,10 @@ describe('ViewerComponent', () => {
describe('Base component', () => { describe('Base component', () => {
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(ViewerComponent);
element = fixture.nativeElement;
component = fixture.componentInstance;
component.showToolbar = true; component.showToolbar = true;
component.urlFile = 'base/src/assets/fake-test-file.pdf'; component.urlFile = 'base/src/assets/fake-test-file.pdf';
component.mimeType = 'application/pdf'; component.mimeType = 'application/pdf';
alfrescoApiService = TestBed.get(AlfrescoApiService);
fixture.detectChanges(); fixture.detectChanges();
}); });
@@ -724,20 +753,6 @@ describe('ViewerComponent', () => {
content: { getContentUrl: () => contentUrl } content: { getContentUrl: () => contentUrl }
}; };
it('should use the displayName if displayName is set and fileNodeId is set', async(() => {
const userDefinedDisplayName = 'user defined display name';
component.fileNodeId = '12';
component.urlFile = null;
component.displayName = userDefinedDisplayName;
spyOn(alfrescoApiService, 'getInstance').and.returnValue(alfrescoApiInstanceMock);
component.ngOnChanges(null);
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#adf-viewer-display-name').textContent).toEqual(userDefinedDisplayName);
});
}));
it('should use the node name if displayName is NOT set and fileNodeId is set', async(() => { it('should use the node name if displayName is NOT set and fileNodeId is set', async(() => {
component.fileNodeId = '12'; component.fileNodeId = '12';
component.urlFile = null; component.urlFile = null;

View File

@@ -240,7 +240,7 @@ export class ViewerComponent implements OnChanges {
this.setUpUrlFile(); this.setUpUrlFile();
} else if (this.fileNodeId) { } else if (this.fileNodeId) {
this.isLoading = true; this.isLoading = true;
this.apiService.getInstance().nodes.getNodeInfo(this.fileNodeId).then( this.apiService.nodesApi.getNodeInfo(this.fileNodeId).then(
(data: MinimalNodeEntryEntity) => { (data: MinimalNodeEntryEntity) => {
this.setUpNodeFile(data); this.setUpNodeFile(data);
}, },
@@ -295,12 +295,12 @@ export class ViewerComponent implements OnChanges {
private setUpNodeFile(data: MinimalNodeEntryEntity) { private setUpNodeFile(data: MinimalNodeEntryEntity) {
this.mimeType = data.content.mimeType; this.mimeType = data.content.mimeType;
this.displayName = this.getDisplayName(data.name); this.displayName = data.name;
this.urlFileContent = this.apiService.getInstance().content.getContentUrl(data.id); this.urlFileContent = this.apiService.contentApi.getContentUrl(data.id);
this.extension = this.getFileExtension(data.name); this.extension = this.getFileExtension(data.name);
this.fileName = data.name; this.fileName = data.name;
this.downloadUrl = this.apiService.getInstance().content.getContentUrl(data.id, true); this.downloadUrl = this.apiService.contentApi.getContentUrl(data.id, true);
this.viewerType = this.getViewerTypeByExtension(this.extension); this.viewerType = this.getViewerTypeByExtension(this.extension);
if (this.viewerType === 'unknown') { if (this.viewerType === 'unknown') {