Jump to content

Dispatch Events


Siddi
 Share

Recommended Posts

Hi,

I'd like to develop some automated UI tests for my PixiJS application (PixiJS 4.8.1). My test procedure should look something like this later:

const test = new UITest()
test.click({x: 100, y: 80})
test.drag({x: 100, y: 80}, {x: 120, y: 40})
test.dblClick({x: 200, y: 120})

etc.

For this I have to trigger events. I know that the InteractionManager and DisplayObject inherit from EventEmitter. Which option is the best way to trigger events?

1. directly on the canvas element?

const originalEvent = new MouseEvent('click', {
    bubbles: true,
    cancelable: true,
    ...
})

app.view.dispatchEvent(originalEvent)


2. or via app.renderer.plugins.interaction.onPointerUp (originalEvent) for example?

3. or via app.renderer.plugins.interaction.emit(originalEvent)

 

Unfortunately, I have not yet managed to trigger an event with these three ways ?

 

What already worked was to call the emit method directly on a PIXI.DisplayObject, but I needed to create a PIXI.InteractionEvent object myself, which was quite expensive ...

 

Thanks in advance!

Siddi

 

Link to comment
Share on other sites

I've looked into the sources, but still don't know if it's best to use 

app.renderer.plugins.interaction.emit('pointerup', originalEvent)

or

app.renderer.plugins.interaction.onPointerUp(originalEvent)

 

But I think both should work, or not?

 

Edited by Siddi
Link to comment
Share on other sites

Depends on what you want to test. If you want to test your code and assume the interaction manager works, then dispatch events from the interaction manager. If you want to test that the interaction manager works, and that your code works using it, then dispatch mouse events onto the canvas. The second is also more similar to what "a user would do".

Link to comment
Share on other sites

I assume that the interaction manager works, and want to test my own code. 

I found a solution for me. I fire standard JavaScript events (MouseEvent and PointerEvent) directly on the canvas element. The rest (triggering the events on a certain DisplayObject) then takes over pixi for me. It is easier than expected ?, thank you!

Link to comment
Share on other sites

  • 2 years later...

How did you achieve that @Siddi ? 
i have tried 
 

function pressMe() {
  console.log('INCEARCA SA DEA CLICK');

  const eventObject = document.createEvent('MouseEvents');

  console.log(app.view);

  eventObject.initMouseEvent(
    'click',
    true,
    true,
    window,
    1,
    100,
    100,
    100,
    100,
    false,
    false,
    false,
    false,
    0,
    null
  );
  const element = document.getElementsByTagName('canvas')[0];
  console.log("my canvas is", element);
  element.dispatchEvent(eventObject);
}

and it doesn't work 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...