ElementFactory.test.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import Modeler from '../../Modeler';
  2. import ElementFactory from './ElementFactory';
  3. import {
  4. Connection,
  5. Label,
  6. Root,
  7. Shape
  8. } from '../../model/Types';
  9. const modeler = new Modeler();
  10. const elementFactory = modeler.get<ElementFactory>('elementFactory');
  11. const shape1 = elementFactory.create('shape', {
  12. type: 'bpmn:Task',
  13. id: 'shape1',
  14. x: 100,
  15. y: 100,
  16. width: 100,
  17. height: 100
  18. });
  19. const shape2 = elementFactory.create('shape', {
  20. type: 'bpmn:Task',
  21. id: 'shape2',
  22. x: 100,
  23. y: 100,
  24. width: 100,
  25. height: 100
  26. });
  27. const connection = elementFactory.create('connection', {
  28. type: 'bpmn:SequenceFlow',
  29. id: 'connection',
  30. source: shape1,
  31. target: shape2,
  32. waypoints: []
  33. });
  34. elementFactory.create('root', {
  35. type: 'bpmn:Process',
  36. id: 'root'
  37. });
  38. elementFactory.create('label', {
  39. type: 'bpmn:Task',
  40. id: 'label'
  41. });
  42. elementFactory.create('shape', {
  43. type: 'bpmn:Task'
  44. });
  45. elementFactory.create('connection', {
  46. type: 'bpmn:SequenceFlow'
  47. });
  48. elementFactory.create('root', {
  49. type: 'bpmn:Process'
  50. });
  51. elementFactory.create('label', {
  52. type: 'bpmn:Task'
  53. });
  54. elementFactory.create('connection', {
  55. type: 'bpmn:Association',
  56. associationDirection: 'One'
  57. });
  58. elementFactory.create('shape', {
  59. type: 'bpmn:BoundaryEvent',
  60. cancelActivity: true,
  61. eventDefinitionType: 'bpmn:ErrorEventDefinition'
  62. });
  63. elementFactory.create('shape', {
  64. type: 'bpmn:Task',
  65. isForCompensation: false
  66. });
  67. elementFactory.create('shape', {
  68. type: 'bpmn:Participant',
  69. processRef: {}
  70. });
  71. elementFactory.create('shape', {
  72. type: 'bpmn:SubProcess',
  73. triggeredByEvent: true
  74. });
  75. elementFactory.createElement('connection', {
  76. type: 'bpmn:SequenceFlow'
  77. });
  78. elementFactory.createElement('root', {
  79. type: 'bpmn:Process'
  80. });
  81. elementFactory.createElement('shape', {
  82. type: 'bpmn:Task'
  83. });
  84. elementFactory.getDefaultSize(shape1, { type: 'bpmndi:BPMNShape' });
  85. elementFactory.getDefaultSize(connection, { type: 'bpmndi:BPMNEdge' });
  86. elementFactory.createParticipantShape();
  87. elementFactory.createParticipantShape(true);
  88. elementFactory.createParticipantShape({
  89. type: 'bpmn:Participant',
  90. isExpanded: true
  91. });
  92. /**
  93. * Customization
  94. */
  95. type CustomShape = {
  96. foo: string;
  97. } & Shape;
  98. export class CustomElementFactory extends ElementFactory<Connection, Label, Root, CustomShape> {};
  99. const customElementFactory = modeler.get<CustomElementFactory>('elementFactory');
  100. const customShape = customElementFactory.createShape({ foo: 'bar' });
  101. console.log(customShape.foo);