ngx-contextmenu icon indicating copy to clipboard operation
ngx-contextmenu copied to clipboard

How should i unit-test the context menu

Open saulide opened this issue 8 years ago • 2 comments

Currenlty for sake of simplicity, i packed the context-menu with its templates in one component

Since its a button area for context menu, i get this with treeItemButton = fixture.debugElement.query(By.css('button'));

Then i trigger left click

treeItemButton.triggerEventHandler('click', {button: 0}); // make left click

Finally i want to trigger click event on the context menu

fixture.debugElement.query(By.css('.context-menu-delete'));

which should find this ng-template inside context-menu:

<ng-template contextMenuItem (execute)="delete({object_id: item?.sequence_element})"> <div class="context-menu-delete">Delete</div> </ng-template>

The problem is, that the div could not be found... Any hints, ideas?

saulide avatar Feb 27 '18 13:02 saulide

The context menu is attached in a .cdk-overlay-pane just above the </body> tag, so it may not be inside the debugElement. Let me do a little research on how to get a reference to that element.

isaacplmann avatar Feb 27 '18 13:02 isaacplmann

The material team gets a reference to the .cdk-overlay-container (which contains all the .cdk-overlay-panes) like this:

expect(document.querySelector('.cdk-overlay-container'))

Reference

That should get you what you need.

isaacplmann avatar Feb 27 '18 13:02 isaacplmann