From 2651e2bde10890f0b636aea628e7dcd1d2841bd9 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Mon, 2 Oct 2023 14:33:56 +0200 Subject: [PATCH] [ACS-5601] Add missing dosc and unit tests --- extension.schema.json | 4 + .../name-column/name-column.component.spec.ts | 92 ++++++++++--------- .../src/lib/services/app.extension.service.ts | 2 - 3 files changed, 52 insertions(+), 46 deletions(-) diff --git a/extension.schema.json b/extension.schema.json index 92c6bfa420..f946bfb8fd 100644 --- a/extension.schema.json +++ b/extension.schema.json @@ -662,6 +662,10 @@ "tooltip": { "description": "Badge tooltip to display on hover.", "type": "string" + }, + "component": { + "description": "Custom component id to display", + "type": "string" } } } diff --git a/projects/aca-content/src/lib/components/dl-custom-components/name-column/name-column.component.spec.ts b/projects/aca-content/src/lib/components/dl-custom-components/name-column/name-column.component.spec.ts index dc8b997c24..e648a41523 100644 --- a/projects/aca-content/src/lib/components/dl-custom-components/name-column/name-column.component.spec.ts +++ b/projects/aca-content/src/lib/components/dl-custom-components/name-column/name-column.component.spec.ts @@ -121,50 +121,54 @@ describe('CustomNameColumnComponent', () => { expect(event.stopPropagation).toHaveBeenCalled(); }); - it('should get badges when component initializes', () => { - component.context = { - row: { - node: { - entry: { - isFile: true, - id: 'nodeId' - } - }, - getValue: (key: string) => key - } - }; - spyOn(appExtensionService, 'getBadges').and.returnValue( - of([{ id: 'test', type: ContentActionType.custom, icon: 'warning', tooltip: 'test tooltip' }]) - ); - component.ngOnInit(); - fixture.detectChanges(); - const badges = fixture.debugElement.queryAll(By.css('.adf-datatable-cell-badge')).map((badge) => badge.nativeElement); - expect(appExtensionService.getBadges).toHaveBeenCalled(); - expect(badges.length).toBe(1); - expect(badges[0].innerText).toBe('warning'); - expect(badges[0].attributes['title'].value).toBe('test tooltip'); - }); + describe('Name column badges', () => { + beforeEach(() => { + component.context = { + row: { + node: { + entry: { + isFile: true, + id: 'nodeId' + } + }, + getValue: (key: string) => key + } + }; + }); - it('should call provided handler on click', () => { - component.context = { - row: { - node: { - entry: { - isFile: true, - id: 'nodeId' - } - }, - getValue: (key: string) => key - } - }; - spyOn(appExtensionService, 'runActionById'); - spyOn(appExtensionService, 'getBadges').and.returnValue( - of([{ id: 'test', type: ContentActionType.custom, icon: 'warning', tooltip: 'test tooltip', actions: { click: 'test' } }]) - ); - component.ngOnInit(); - fixture.detectChanges(); - const badges = fixture.debugElement.queryAll(By.css('.adf-datatable-cell-badge')).map((badge) => badge.nativeElement); - badges[0].click(); - expect(appExtensionService.runActionById).toHaveBeenCalledWith('test', component.context.row.node); + it('should get badges when component initializes', () => { + spyOn(appExtensionService, 'getBadges').and.returnValue( + of([{ id: 'test', type: ContentActionType.custom, icon: 'warning', tooltip: 'test tooltip' }]) + ); + component.ngOnInit(); + fixture.detectChanges(); + const badges = fixture.debugElement.queryAll(By.css('.adf-datatable-cell-badge')).map((badge) => badge.nativeElement); + expect(appExtensionService.getBadges).toHaveBeenCalled(); + expect(badges.length).toBe(1); + expect(badges[0].innerText).toBe('warning'); + expect(badges[0].attributes['title'].value).toBe('test tooltip'); + }); + + it('should call provided handler on click', () => { + spyOn(appExtensionService, 'runActionById'); + spyOn(appExtensionService, 'getBadges').and.returnValue( + of([{ id: 'test', type: ContentActionType.custom, icon: 'warning', tooltip: 'test tooltip', actions: { click: 'test' } }]) + ); + component.ngOnInit(); + fixture.detectChanges(); + const badges = fixture.debugElement.queryAll(By.css('.adf-datatable-cell-badge')).map((badge) => badge.nativeElement); + badges[0].click(); + expect(appExtensionService.runActionById).toHaveBeenCalledWith('test', component.context.row.node); + }); + + it('should render dynamic component when badge has one provided', () => { + spyOn(appExtensionService, 'getBadges').and.returnValue( + of([{ id: 'test', type: ContentActionType.custom, icon: 'warning', tooltip: 'test tooltip', component: 'test-id' }]) + ); + component.ngOnInit(); + fixture.detectChanges(); + const dynamicComponent = fixture.debugElement.query(By.css('adf-dynamic-component')).nativeElement; + expect(dynamicComponent).toBeDefined(); + }); }); }); diff --git a/projects/aca-shared/src/lib/services/app.extension.service.ts b/projects/aca-shared/src/lib/services/app.extension.service.ts index 11e920024c..393c0339e7 100644 --- a/projects/aca-shared/src/lib/services/app.extension.service.ts +++ b/projects/aca-shared/src/lib/services/app.extension.service.ts @@ -50,7 +50,6 @@ import { mergeArrays } from '@alfresco/adf-extensions'; import { AppConfigService, AuthenticationService, LogService } from '@alfresco/adf-core'; -import { ProcessContentService } from '@alfresco/adf-process-services'; import { BehaviorSubject, Observable } from 'rxjs'; import { RepositoryInfo, NodeEntry } from '@alfresco/js-api'; import { ViewerRules } from '../models/viewer.rules'; @@ -119,7 +118,6 @@ export class AppExtensionService implements RuleContext { protected extensions: ExtensionService, public permissions: NodePermissionService, public appConfig: AppConfigService, - public processContent: ProcessContentService, protected matIconRegistry: MatIconRegistry, protected sanitizer: DomSanitizer, protected logger: LogService