diff --git a/src/app/components/page.component.spec.ts b/src/app/components/page.component.spec.ts index 8057378a3..46f7723ab 100644 --- a/src/app/components/page.component.spec.ts +++ b/src/app/components/page.component.spec.ts @@ -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)); + }); }); }); diff --git a/src/app/components/page.component.ts b/src/app/components/page.component.ts index 8514a406b..8fd874422 100644 --- a/src/app/components/page.component.ts +++ b/src/app/components/page.component.ts @@ -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)); } diff --git a/src/app/components/toolbar/view-node/view-node.component.spec.ts b/src/app/components/toolbar/view-node/view-node.component.spec.ts index 61ed4cb4a..3fa37ab31 100644 --- a/src/app/components/toolbar/view-node/view-node.component.spec.ts +++ b/src/app/components/toolbar/view-node/view-node.component.spec.ts @@ -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 })); + }); }); diff --git a/src/app/components/toolbar/view-node/view-node.component.ts b/src/app/components/toolbar/view-node/view-node.component.ts index 7f8504197..c943fb0a0 100644 --- a/src/app/components/toolbar/view-node/view-node.component.ts +++ b/src/app/components/toolbar/view-node/view-node.component.ts @@ -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 })); });