diff --git a/projects/aca-content/src/lib/components/context-menu/context-menu.component.spec.ts b/projects/aca-content/src/lib/components/context-menu/context-menu.component.spec.ts index 8c8ba2611..7dc9f99e1 100644 --- a/projects/aca-content/src/lib/components/context-menu/context-menu.component.spec.ts +++ b/projects/aca-content/src/lib/components/context-menu/context-menu.component.spec.ts @@ -70,17 +70,18 @@ describe('ContextMenuComponent', () => { component = fixture.componentInstance; extensionsService = TestBed.inject(AppExtensionService); - - spyOn(extensionsService, 'getAllowedContextMenuActions').and.returnValue(of([contextItem])); - - fixture.detectChanges(); }); it('should load context menu actions on init', () => { + spyOn(extensionsService, 'getAllowedContextMenuActions').and.returnValue(of([contextItem])); + fixture.detectChanges(); + expect(component.actions.length).toBe(1); }); it('should render defined context menu actions items', async () => { + spyOn(extensionsService, 'getAllowedContextMenuActions').and.returnValue(of([contextItem])); + fixture.detectChanges(); await fixture.whenStable(); const contextMenuElements = document.body.querySelector('.aca-context-menu')?.querySelectorAll('button'); @@ -89,4 +90,14 @@ describe('ContextMenuComponent', () => { expect(contextMenuElements?.length).toBe(1); expect(actionButtonLabel.innerText).toBe(contextItem.title); }); + + it('should not render context menu if no actions items', async () => { + spyOn(extensionsService, 'getAllowedContextMenuActions').and.returnValue(of([])); + fixture.detectChanges(); + await fixture.whenStable(); + + const contextMenuElements = document.body.querySelector('.aca-context-menu'); + + expect(contextMenuElements).toBeNull(); + }); }); diff --git a/projects/aca-content/src/lib/components/context-menu/context-menu.component.ts b/projects/aca-content/src/lib/components/context-menu/context-menu.component.ts index 13bc6ea66..76518e338 100644 --- a/projects/aca-content/src/lib/components/context-menu/context-menu.component.ts +++ b/projects/aca-content/src/lib/components/context-menu/context-menu.component.ts @@ -75,6 +75,8 @@ export class ContextMenuComponent extends BaseContextMenuDirective implements On } ngAfterViewInit() { - setTimeout(() => this.trigger.openMenu(), 0); + if (this.actions.length) { + setTimeout(() => this.trigger.openMenu(), 0); + } } }