mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
committed by
Eugenio Romano
parent
3114fa4862
commit
2bfed5818f
@@ -18,7 +18,7 @@
|
||||
import { Location } from '@angular/common';
|
||||
import { SpyLocation } from '@angular/common/testing';
|
||||
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 { MaterialModule } from './../../material.module';
|
||||
@@ -155,6 +155,40 @@ describe('ViewerComponent', () => {
|
||||
}).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', () => {
|
||||
|
||||
it('should use custom toolbar', () => {
|
||||
@@ -193,15 +227,10 @@ describe('ViewerComponent', () => {
|
||||
describe('Base component', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ViewerComponent);
|
||||
element = fixture.nativeElement;
|
||||
component = fixture.componentInstance;
|
||||
component.showToolbar = true;
|
||||
component.urlFile = 'base/src/assets/fake-test-file.pdf';
|
||||
component.mimeType = 'application/pdf';
|
||||
|
||||
alfrescoApiService = TestBed.get(AlfrescoApiService);
|
||||
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
@@ -724,20 +753,6 @@ describe('ViewerComponent', () => {
|
||||
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(() => {
|
||||
component.fileNodeId = '12';
|
||||
component.urlFile = null;
|
||||
|
@@ -240,7 +240,7 @@ export class ViewerComponent implements OnChanges {
|
||||
this.setUpUrlFile();
|
||||
} else if (this.fileNodeId) {
|
||||
this.isLoading = true;
|
||||
this.apiService.getInstance().nodes.getNodeInfo(this.fileNodeId).then(
|
||||
this.apiService.nodesApi.getNodeInfo(this.fileNodeId).then(
|
||||
(data: MinimalNodeEntryEntity) => {
|
||||
this.setUpNodeFile(data);
|
||||
},
|
||||
@@ -295,12 +295,12 @@ export class ViewerComponent implements OnChanges {
|
||||
|
||||
private setUpNodeFile(data: MinimalNodeEntryEntity) {
|
||||
this.mimeType = data.content.mimeType;
|
||||
this.displayName = this.getDisplayName(data.name);
|
||||
this.urlFileContent = this.apiService.getInstance().content.getContentUrl(data.id);
|
||||
this.displayName = data.name;
|
||||
this.urlFileContent = this.apiService.contentApi.getContentUrl(data.id);
|
||||
this.extension = this.getFileExtension(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);
|
||||
if (this.viewerType === 'unknown') {
|
||||
|
Reference in New Issue
Block a user