Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Acceptance Tests #26

Open
Ericky14 opened this issue Feb 21, 2017 · 5 comments
Open

Acceptance Tests #26

Ericky14 opened this issue Feb 21, 2017 · 5 comments

Comments

@Ericky14
Copy link

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
Copy link
Owner

cbroeren commented Feb 21, 2017

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
Copy link
Author

Thank you for the help, it worked :)

@Ericky14 Ericky14 reopened this Feb 21, 2017
@Ericky14
Copy link
Author

Ericky14 commented Feb 21, 2017

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
Copy link
Owner

cbroeren commented Feb 21, 2017

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
Copy link

rayangou commented Dec 4, 2020

Any updates on how to resolve this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants