cbroeren / ember-context-menu

An ember addon for custom context-menu
https://cbroeren.github.com/ember-context-menu
MIT License
23 stars 15 forks source link

Acceptance Tests #26

Open Ericky14 opened 7 years ago

Ericky14 commented 7 years ago

Does anyone know how to test this add-on with an acceptance test?

I tried like this triggerEvent('.file-item:first', 'contextmenu'); and got this error Uncaught Error: Assertion Failed: You need to pass event to the context-menu activate()

I would appreciate very much if anyone could help me.

cbroeren commented 7 years ago

Hi @Ericky14,

Like the error said, you need to pass the JavaScript event to the context-menu. Normally this will be send automatically when you trigger the context-menu on right-clicking, but in acceptance tests you have to pass it yourself.

The event is used to know the cursor position, so it needs a clientX and clientY.

By using jQuery, you can do something like:

this.$('.file-item:first').trigger($.Event('contextmenu', { clientX: 0, clientY: 0 }));

In my own acceptance tests, I create an event variable, which I can use in all my tests:

let contextMenuEvent = $.Event('contextMenu', { clientX: 0, clientY: 0 });

this.$('.my-element').trigger(contextMenuEvent);
Ericky14 commented 7 years ago

Thank you for the help, it worked :)

Ericky14 commented 7 years ago

Sorry for re-opening it after so closing it so soon, but I want to discuss something else with you if possible.

After opening the context-menu with trigger, any button that I click on makes the menu close, but does not fire the click() action of context-menu__item.

I am using a page object and clicking the button like this, firstAction: clickable('ul li:first', { testContainer: '#wormhole-context-menu' }),

  let contextMenuEvent = $.Event('contextmenu', { clientX: 0, clientY: 0 });
  $('.file-item:first').trigger(contextMenuEvent);

  andThen(() => {
    page.firstAction();
  });

Does it not work because I need to pass a certain type of event instead of a normal click?

I also tried doing $('.context-menu__item:first').click(), $('.context-menu__item:first').trigger($.Event('click')) and some other variations, but they all have the same result.

cbroeren commented 7 years ago

No problem you re-opened it. It didn't come in mind earlier today, but you're right about this. I remember a time I tried to trigger the action in my integration test, but I didn't get it to work. I guess it's working on the integration test for the context-menu-item itself, but not on rendering the whole context-menu. Have tried debugging this for days, and finally just decided to remove the test. On debugging everything looked fine, every action was there and it came everywhere is should come, except for the action itself.

So basically, I didn't find a solution for this, or even the reason why it would not trigger the action in tests where it does work in the real application.

I'm really busy for now and probably the next 6 or 7 weeks, so can't promise I can take a look at it again before the end of April. I suggest we keep this issue open until someone has find a solution for it

rayangou commented 3 years ago

Any updates on how to resolve this issue?