MockEvents.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. export function createEvent(target, position, data) {
  29. return getBpmnJS().invoke(function(eventBus) {
  30. data = assign({
  31. target: target,
  32. x: position.x,
  33. y: position.y,
  34. clientX: position.x,
  35. clientY: position.y,
  36. offsetX: position.x,
  37. offsetY: position.y
  38. }, data || {});
  39. return eventBus.createEvent(data);
  40. });
  41. }