[ACA-2923] Viewer - type link node is not not displaying (#2030)

* use content node id over filelink id

* tests
This commit is contained in:
Cilibiu Bogdan
2021-03-02 12:37:36 +00:00
committed by GitHub
parent eb299dedba
commit 58cfbc075a
4 changed files with 77 additions and 3 deletions
+37 -1
View File
@@ -25,7 +25,14 @@
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { PageComponent } from './page.component';
import { ReloadDocumentListAction, SetSelectedNodesAction, SetInfoDrawerStateAction, AppState, AppStore } from '@alfresco/aca-shared/store';
import {
ReloadDocumentListAction,
SetSelectedNodesAction,
SetInfoDrawerStateAction,
AppState,
AppStore,
ViewNodeAction
} from '@alfresco/aca-shared/store';
import { AppExtensionService } from '@alfresco/aca-shared';
import { MinimalNodeEntity, NodePaging } from '@alfresco/js-api';
import { ContentManagementService } from '../services/content-management.service';
@@ -181,5 +188,34 @@ describe('PageComponent', () => {
expect(component.documentList.node).toEqual(nodePaging);
expect(store.dispatch).not.toHaveBeenCalled();
});
it('should call ViewNodeAction on showPreview for selected node', () => {
spyOn(store, 'dispatch');
const node = {
entry: {
id: 'node-id'
}
} as MinimalNodeEntity;
component.showPreview(node);
expect(store.dispatch).toHaveBeenCalledWith(new ViewNodeAction(node.entry.id));
});
it('should call ViewNodeAction on showPreview for `app:filelink` node type', () => {
spyOn(store, 'dispatch');
const linkNode = {
entry: {
id: 'node-id',
nodeType: 'app:filelink',
properties: {
'cm:destination': 'original-node-id'
}
}
} as MinimalNodeEntity;
component.showPreview(linkNode);
const id = linkNode.entry.properties['cm:destination'];
expect(store.dispatch).toHaveBeenCalledWith(new ViewNodeAction(id));
});
});
});
+7 -1
View File
@@ -116,7 +116,13 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges {
showPreview(node: MinimalNodeEntity, extras?: ViewNodeExtras) {
if (node && node.entry) {
const id = (node as any).entry.nodeId || (node as any).entry.guid || node.entry.id;
let id: string;
if (node.entry.nodeType === 'app:filelink') {
id = node.entry.properties['cm:destination'];
} else {
id = (node as any).entry.nodeId || (node as any).entry.guid || node.entry.id;
}
this.store.dispatch(new ViewNodeAction(id, extras));
}
@@ -30,6 +30,7 @@ import { CoreModule } from '@alfresco/adf-core';
import { Router } from '@angular/router';
import { of } from 'rxjs';
import { TranslateModule } from '@ngx-translate/core';
import { ViewNodeAction } from '@alfresco/aca-shared/store';
describe('ViewNodeComponent', () => {
let component: ViewNodeComponent;
@@ -99,4 +100,29 @@ describe('ViewNodeComponent', () => {
expect(mockStore.dispatch).toHaveBeenCalled();
});
it('should call ViewNodeAction for `app:filelink` node type', () => {
const linkNode = {
file: {
entry: {
id: 'nodeId',
nodeType: 'app:filelink',
properties: {
'cm:destination': 'original-node-id'
}
}
}
};
component.data = {
iconButton: true
};
mockStore.select.and.returnValue(of(linkNode));
fixture.detectChanges();
component.onClick();
const id = linkNode.file.entry.properties['cm:destination'];
expect(mockStore.dispatch).toHaveBeenCalledWith(new ViewNodeAction(id, { location: mockRouter.url }));
});
});
@@ -61,7 +61,13 @@ export class ViewNodeComponent {
.select(getAppSelection)
.pipe(take(1))
.subscribe((selection) => {
const id = (selection.file as SharedLinkEntry).entry.nodeId || (selection.file as any).entry.guid || selection.file.entry.id;
let id: string;
if (selection.file.entry.nodeType === 'app:filelink') {
id = selection.file.entry.properties['cm:destination'];
} else {
id = (selection.file as SharedLinkEntry).entry.nodeId || (selection.file as any).entry.guid || selection.file.entry.id;
}
this.store.dispatch(new ViewNodeAction(id, { location: this.router.url }));
});