Skip to content

Commit

Permalink
[ACS-5551]added null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
AnukritiGL committed Sep 13, 2023
1 parent 512437e commit 201e207
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 20 deletions.
1 change: 1 addition & 0 deletions projects/aca-content/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@
"TITLE": "Details",
"CLOSE": "Close",
"DATA_LOADING": "Data is loading",
"ICON": "Node Icon",
"TABS": {
"PROPERTIES": "Properties",
"LIBRARY_PROPERTIES": "About",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="acs-details-title">
<div class="acs-details-breadcrumb" role="heading" aria-level="2" *ngIf="node">
<span class="acs-details-breadcrumb-library">
<img class="acs-details-breadcrumb-icon" alt="Info Drawer icon" src="{{ getInfoDrawerIcon(node) }}">
<img class="acs-details-breadcrumb-icon" alt="{{ 'APP.INFO_DRAWER.ICON' | translate }}" src="{{ getNodeIcon(node) }}">
{{ node.name }} </span>
</div>
<button class="aca-close-details-button" mat-icon-button data-automation-id="close-library" title="{{ 'APP.INFO_DRAWER.CLOSE' | translate }}" (click)="goBack()">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ describe('DetailsComponent', () => {
expect(store.dispatch).toHaveBeenCalledWith(new SetSelectedNodesAction([node]));
});

it('should return the icon when getInfoDrawerIcon is called', () => {
it('should return the icon when getNodeIcon is called', () => {
const expectedIcon = 'assets/images/ft_ic_folder';
spyOn(component['nodeActionsService'], 'getInfoDrawerIcon').and.returnValue(expectedIcon);
spyOn(component['nodeActionsService'], 'getNodeIcon').and.returnValue(expectedIcon);
fixture.detectChanges();
const result = component.getInfoDrawerIcon(mockNode);
const result = component.getNodeIcon(mockNode);
expect(result).toContain(expectedIcon);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export class DetailsComponent extends PageComponent implements OnInit, OnDestroy
});
}

getInfoDrawerIcon(node: Node): string {
return this.nodeActionsService.getInfoDrawerIcon(node);
getNodeIcon(node: Node): string {
return this.nodeActionsService.getNodeIcon(node);
}

setActiveTab(tabName: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ describe('NodeActionsService', () => {
thumbnailService = TestBed.inject(ThumbnailService);
});

function testInfoDrawerIcon(iconPath: string, isFoldeType: boolean, isFileType: boolean) {
function testNodeIcon(iconPath: string, isFoldeType: boolean, isFileType: boolean) {
spyOn(thumbnailService, 'getMimeTypeIcon').and.returnValue(iconPath);
mockNode.isFolder = isFoldeType;
mockNode.isFile = isFileType;
Expand All @@ -1255,23 +1255,23 @@ describe('NodeActionsService', () => {
}

it('should resolve folder icon', () => {
testInfoDrawerIcon('assets/images/ft_ic_folder.svg', true, false);
testNodeIcon('assets/images/ft_ic_folder.svg', true, false);
});

it('should resolve smart folder icon', () => {
testInfoDrawerIcon('assets/images/ft_ic_smart_folder.svg', true, false);
testNodeIcon('assets/images/ft_ic_smart_folder.svg', true, false);
});

it('should resolve link folder icon', () => {
testInfoDrawerIcon('assets/images/ft_ic_folder_shortcut_link.svg', true, false);
testNodeIcon('assets/images/ft_ic_folder_shortcut_link.svg', true, false);
});

it('should resolve rule folder icon', () => {
testInfoDrawerIcon('assets/images/ft_ic_folder_rule.svg', true, false);
testNodeIcon('assets/images/ft_ic_folder_rule.svg', true, false);
});

it('should resolve file icon for content type', () => {
testInfoDrawerIcon('assets/images/ft_ic_raster_image.svg', false, true);
testNodeIcon('assets/images/ft_ic_raster_image.svg', false, true);
});

it('should resolve fallback file icon for unknown node', () => {
Expand Down
16 changes: 10 additions & 6 deletions projects/aca-content/src/lib/services/node-actions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,12 @@ export class NodeActionsService {
return null;
}

getInfoDrawerIcon(node: Node): string {
if (node.isFolder) {
getNodeIcon(node: Node): string {
if (node?.isFolder) {
return this.getFolderIcon(node);
}
if (node.isFile) {
return this.thumbnailService.getMimeTypeIcon(node.content.mimeType);
if (node?.isFile) {
return this.thumbnailService.getMimeTypeIcon(node?.content?.mimeType);
}
return this.thumbnailService.getDefaultMimeTypeIcon();
}
Expand All @@ -586,15 +586,19 @@ export class NodeActionsService {
}

isSmartFolder(node: Node): boolean {
const nodeAspects = this.getNodeAspectNames(node);
return nodeAspects.includes('smf:customConfigSmartFolder') || nodeAspects.includes('smf:systemConfigSmartFolder');
if (node) {
const nodeAspects = this.getNodeAspectNames(node);
return nodeAspects?.includes('smf:customConfigSmartFolder') || nodeAspects?.includes('smf:systemConfigSmartFolder');
}
return false;
}

isRuleFolder(node: Node): boolean {
if (node) {
const nodeAspects = this.getNodeAspectNames(node);
return nodeAspects?.includes('rule:rules');
}
return false;
}

isLinkFolder(node: Node): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<mat-progress-bar mode="indeterminate" [attr.aria-label]="'APP.INFO_DRAWER.DATA_LOADING' | translate"></mat-progress-bar>
</div>
<ng-container *ngIf="!isLoading && !!displayNode">
<adf-info-drawer [drawerIcon]="node.entry" [title]="node?.entry ? node.entry.name : 'APP.INFO_DRAWER.TITLE'" cdkTrapFocus cdkTrapFocusAutoCapture>
<adf-info-drawer [nodeIcon]="getNodeIcon(node?.entry)" [title]="node?.entry?.name || 'APP.INFO_DRAWER.TITLE'" cdkTrapFocus cdkTrapFocusAutoCapture>
<aca-toolbar [items]="actions" info-drawer-buttons></aca-toolbar>

<adf-info-drawer-tab *ngFor="let tab of tabs" [icon]="tab.icon" [label]="tab.title">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,38 @@ describe('InfoDrawerComponent', () => {
])
};

const mockNode = {
isFile: false,
createdByUser: { id: 'admin', displayName: 'Administrator' },
modifiedAt: new Date('2017-05-24T15:08:55.640Z'),
nodeType: 'cm:content',
content: {
mimeType: 'application/rtf',
mimeTypeName: 'Rich Text Format',
sizeInBytes: 14530,
encoding: 'UTF-8'
},
parentId: 'd124de26-6ba0-4f40-8d98-4907da2d337a',
createdAt: new Date('2017-05-24T15:08:55.640Z'),
path: {
name: '/Company Home/Guest Home',
isComplete: true,
elements: [
{
id: '94acfc73-7014-4475-9bd9-93a2162f0f8c',
name: 'Company Home'
},
{ id: 'd124de26-6ba0-4f40-8d98-4907da2d337a', name: 'Guest Home' }
]
},
isFolder: true,
modifiedByUser: { id: 'admin', displayName: 'Administrator' },
name: 'b_txt_file.rtf',
id: '70e1cc6a-6918-468a-b84a-1048093b06fd',
properties: { 'cm:versionLabel': '1.0', 'cm:versionType': 'MAJOR' },
allowableOperations: ['delete', 'update']
};

beforeEach(() => {
TestBed.configureTestingModule({
imports: [LibTestingModule, InfoDrawerComponent],
Expand Down Expand Up @@ -182,4 +214,12 @@ describe('InfoDrawerComponent', () => {
} as ContentActionRef
]);
});

it('should return the icon when getNodeIcon is called', () => {
const expectedIcon = 'assets/images/ft_ic_folder';
spyOn(component['nodeActionsService'], 'getNodeIcon').and.returnValue(expectedIcon);
fixture.detectChanges();
const result = component.getNodeIcon(mockNode);
expect(result).toContain(expectedIcon);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { InfoDrawerModule } from '@alfresco/adf-core';
import { TranslateModule } from '@ngx-translate/core';
import { A11yModule } from '@angular/cdk/a11y';
import { ToolbarComponent } from '../toolbar/toolbar.component';
import { NodeActionsService } from '../../../../../aca-content/src/lib/services/node-actions.service';

@Component({
standalone: true,
Expand Down Expand Up @@ -64,7 +65,12 @@ export class InfoDrawerComponent implements OnChanges, OnInit, OnDestroy {
this.close();
}

constructor(private store: Store<any>, private contentApi: ContentApiService, private extensions: AppExtensionService) {}
constructor(
private store: Store<any>,
private contentApi: ContentApiService,
private extensions: AppExtensionService,
private nodeActionsService: NodeActionsService
) {}

ngOnInit() {
this.tabs = this.extensions.getSidebarTabs();
Expand Down Expand Up @@ -125,4 +131,8 @@ export class InfoDrawerComponent implements OnChanges, OnInit, OnDestroy {
private setDisplayNode(node: any) {
this.displayNode = node;
}

getNodeIcon(node: Node): string {
return this.nodeActionsService.getNodeIcon(node);
}
}

0 comments on commit 201e207

Please sign in to comment.