Skip to content

Commit

Permalink
[ACS-5601] Add missing dosc and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalKinas committed Oct 2, 2023
1 parent 4e35c74 commit 2651e2b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 46 deletions.
4 changes: 4 additions & 0 deletions extension.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,10 @@
"tooltip": {
"description": "Badge tooltip to display on hover.",
"type": "string"
},
"component": {
"description": "Custom component id to display",
"type": "string"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
2 changes: 0 additions & 2 deletions projects/aca-shared/src/lib/services/app.extension.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2651e2b

Please sign in to comment.