LassoToolSpec.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import {
  2. bootstrapDiagram,
  3. inject
  4. } from 'test/TestHelper';
  5. import {
  6. createCanvasEvent as canvasEvent
  7. } from '../../../util/MockEvents';
  8. import modelingModule from 'lib/features/modeling';
  9. import lassoToolModule from 'lib/features/lasso-tool';
  10. import draggingModule from 'lib/features/dragging';
  11. describe('features/lasso-tool', function() {
  12. beforeEach(bootstrapDiagram({ modules: [ modelingModule, lassoToolModule, draggingModule ] }));
  13. var rootShape, childShape, childShape2, childShape3, childShape4;
  14. beforeEach(inject(function(elementFactory, canvas) {
  15. rootShape = elementFactory.createRoot({
  16. id: 'root'
  17. });
  18. canvas.setRootElement(rootShape);
  19. childShape = elementFactory.createShape({
  20. id: 'child',
  21. x: 110, y: 110, width: 50, height: 100
  22. });
  23. canvas.addShape(childShape, rootShape);
  24. childShape2 = elementFactory.createShape({
  25. id: 'child2',
  26. x: 180, y: 110, width: 50, height: 100
  27. });
  28. canvas.addShape(childShape2, rootShape);
  29. childShape3 = elementFactory.createShape({
  30. id: 'child3',
  31. x: 240, y: 110, width: 50, height: 100
  32. });
  33. canvas.addShape(childShape3, rootShape);
  34. childShape4 = elementFactory.createShape({
  35. id: 'child4',
  36. x: 300, y: 110, width: 50, height: 100
  37. });
  38. canvas.addShape(childShape4, rootShape);
  39. }));
  40. describe('#select', function() {
  41. it('should select elements in bbox', inject(function(lassoTool, selection) {
  42. // given
  43. var elements = [childShape, childShape2, childShape3, childShape4];
  44. var bbox = {
  45. x: 175,
  46. y: 0,
  47. width: 120,
  48. height: 220
  49. };
  50. // when
  51. lassoTool.select(elements, bbox);
  52. // then
  53. var selectedElements = selection.get();
  54. expect(selectedElements.length).to.equal(2);
  55. expect(selectedElements[0]).to.equal(childShape2);
  56. expect(selectedElements[1]).to.equal(childShape3);
  57. }));
  58. });
  59. describe('visuals', function() {
  60. beforeEach(inject(function(dragging) {
  61. dragging.setOptions({ manual: true });
  62. }));
  63. it('should show lasso box', inject(function(lassoTool, canvas, dragging) {
  64. // when
  65. lassoTool.activateLasso(canvasEvent({ x: 100, y: 100 }));
  66. dragging.move(canvasEvent({ x: 200, y: 300 }));
  67. // then
  68. expect(canvas._svg.querySelector('.djs-lasso-overlay')).to.exist;
  69. }));
  70. it('should select after lasso', inject(function(lassoTool, dragging, selection, elementRegistry) {
  71. // when
  72. lassoTool.activateLasso(canvasEvent({ x: 100, y: 100 }));
  73. dragging.move(canvasEvent({ x: 200, y: 300 }));
  74. dragging.end();
  75. // then
  76. expect(selection.get()).to.eql([ elementRegistry.get('child') ]);
  77. }));
  78. });
  79. });