MockEvents.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import {
  2. assign
  3. } from 'min-dash';
  4. import {
  5. getBpmnJS
  6. } from 'test/TestHelper';
  7. /**
  8. * Create an event with global coordinates
  9. * computed based on the loaded diagrams canvas position and the
  10. * specified canvas local coordinates.
  11. *
  12. * @param {Point} point of the event local the canvas (closure)
  13. * @param {Object} [data]
  14. *
  15. * @return {Event} event, scoped to the given canvas
  16. */
  17. export function createCanvasEvent(position, data) {
  18. return getBpmnJS().invoke(function(canvas) {
  19. var target = canvas._svg;
  20. var clientRect = canvas._container.getBoundingClientRect();
  21. var absolutePosition = {
  22. x: position.x + clientRect.left,
  23. y: position.y + clientRect.top
  24. };
  25. return createEvent(target, absolutePosition, data);
  26. });
  27. }
  28. /**
  29. * Create an Event
  30. *
  31. * @param {Element} target
  32. * @param { { x: number, y: number } } position
  33. * @param {any} [data]
  34. *
  35. * @return {Event}
  36. */
  37. export function createEvent(target, position, data) {
  38. return getBpmnJS().invoke(function(eventBus) {
  39. data = assign({
  40. target: target,
  41. x: position.x,
  42. y: position.y,
  43. clientX: position.x,
  44. clientY: position.y,
  45. offsetX: position.x,
  46. offsetY: position.y,
  47. button: 0
  48. }, data || {});
  49. return eventBus.createEvent(data);
  50. });
  51. }