Modeling.test.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { expectType } from 'ts-expect';
  2. import Modeler from '../../Modeler';
  3. import {
  4. Connection,
  5. Element,
  6. Label,
  7. Parent,
  8. Shape
  9. } from '../../model/Types';
  10. import ElementFactory from './ElementFactory';
  11. import Modeling from './Modeling';
  12. import { getBusinessObject } from '../../util/ModelUtil';
  13. import { CustomElementFactory } from './ElementFactory.test';
  14. const modeler = new Modeler();
  15. const elementFactory = modeler.get<ElementFactory>('elementFactory');
  16. const sequenceFlow = elementFactory.create('connection', { type: 'bpmn:SequenceFlow' }),
  17. process = elementFactory.create('root', { type: 'bpmn:Process' }),
  18. subProcess = elementFactory.create('shape', { type: 'bpmn:SubProcess' }),
  19. task = elementFactory.create('shape', { type: 'bpmn:Task' });
  20. const modeling = modeler.get<Modeling>('modeling');
  21. modeling.updateLabel(task, 'foo');
  22. modeling.updateLabel(task, 'foo', {
  23. x: 100,
  24. y: 100,
  25. width: 100,
  26. height: 100
  27. });
  28. modeling.updateLabel(task, 'foo', {
  29. x: 100,
  30. y: 100,
  31. width: 100,
  32. height: 100
  33. }, { removeShape: true });
  34. modeling.connect(subProcess, task, sequenceFlow);
  35. modeling.connect(subProcess, task, sequenceFlow, { foo: 'bar' });
  36. modeling.updateModdleProperties(task, { type: 'bpmn:ExtensionElements' }, {
  37. values: []
  38. });
  39. modeling.updateProperties(task, {
  40. name: 'foo'
  41. });
  42. const participant = elementFactory.create('shape', { type: 'bpmn:Participant'}),
  43. lane = elementFactory.create('shape', { type: 'bpmn:Lane'});
  44. modeling.resizeLane(lane, {
  45. x: 100,
  46. y: 100,
  47. width: 100,
  48. height: 100
  49. });
  50. modeling.resizeLane(lane, {
  51. x: 100,
  52. y: 100,
  53. width: 100,
  54. height: 100
  55. }, true);
  56. modeling.addLane(participant, 'top');
  57. modeling.addLane(participant, 'bottom');
  58. modeling.splitLane(lane, 3);
  59. modeling.makeCollaboration();
  60. modeling.makeProcess();
  61. modeling.updateLaneRefs([ task ], [ lane ]);
  62. modeling.claimId('foo', task.businessObject);
  63. modeling.unclaimId('foo', task.businessObject);
  64. modeling.setColor([ task ], { fill: 'red', stroke: 'green' });
  65. modeling.setColor([ task ], { fill: 'red' });
  66. modeling.setColor([ task ], { stroke: 'green' });
  67. /**
  68. * Integration
  69. */
  70. expectType<Connection>(modeling.createConnection(subProcess, task, sequenceFlow, process));
  71. expectType<Label>(modeling.createLabel(task, { x: 100, y: 100 }, {
  72. businessObject: getBusinessObject(task)
  73. }));
  74. expectType<Shape>(modeling.createShape(task, { x: 100, y: 100 }, process));
  75. expectType<Element[]>(modeling.createElements([
  76. subProcess,
  77. task,
  78. sequenceFlow
  79. ], { x: 100, y: 100 }, process));
  80. modeling.moveShape(task, { x: 100, y: 100 });
  81. modeling.moveConnection(sequenceFlow, { x: 100, y: 100 });
  82. modeling.moveElements([ subProcess, task ], { x: 100, y: 100 });
  83. /**
  84. * Customization
  85. */
  86. type CustomElement = {
  87. foo: string;
  88. } & Element;
  89. type CustomShape = {
  90. bar: string;
  91. } & Shape & CustomElement;
  92. class CustomModeling extends Modeling<Connection, CustomElement, Label, Parent, CustomShape> {};
  93. const customModeling = modeler.get<CustomModeling>('modeling');
  94. const customShape = customModeling.createShape({ bar: 'bar' }, { x: 100, y: 100 }, modeler.get<CustomElementFactory>('elementFactory').create('root'));
  95. customModeling.distributeElements([
  96. {
  97. elements: [ customShape ],
  98. range: {
  99. min: 100,
  100. max: 200
  101. }
  102. }
  103. ], 'x', 'width');