DefaultRendererSpec.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import {
  2. bootstrapDiagram,
  3. inject
  4. } from 'test/TestHelper';
  5. import drawModule from 'lib/draw';
  6. describe('draw - DefaultRenderer', function() {
  7. beforeEach(bootstrapDiagram({ modules: [ drawModule ] }));
  8. describe('#getShapePath', function() {
  9. it('should return rectangular shape path', inject(function(canvas, elementFactory, graphicsFactory) {
  10. // given
  11. var shape = canvas.addShape(elementFactory.createShape({
  12. id: 'shapeA',
  13. x: 100, y: 100, width: 100, height: 100
  14. }));
  15. // when
  16. var path = graphicsFactory.getShapePath(shape);
  17. // then
  18. expect(path).to.eql('M100,100l100,0l0,100l-100,0z');
  19. }));
  20. });
  21. describe('#getConnectionPath', function() {
  22. it('should return line segments connection path', inject(function(canvas, graphicsFactory) {
  23. // given
  24. var shapeA = canvas.addShape({
  25. id: 'shapeA',
  26. x: 100, y: 100, width: 100, height: 100
  27. });
  28. var shapeB = canvas.addShape({
  29. id: 'shapeB',
  30. x: 300, y: 250, width: 100, height: 100
  31. });
  32. var connection = canvas.addConnection({
  33. id: 'connection',
  34. waypoints: [ { x: 150, y: 150 }, { x: 200, y: 200 }, { x: 350, y: 300 }],
  35. source: shapeA,
  36. target: shapeB
  37. });
  38. // when
  39. var path = graphicsFactory.getConnectionPath(connection);
  40. // then
  41. expect(path).to.eql('M150,150L200,200L350,300');
  42. }));
  43. it('should take invisible dockings into account', inject(function(canvas, graphicsFactory) {
  44. // given
  45. var shapeA = canvas.addShape({
  46. id: 'shapeA',
  47. x: 100, y: 100, width: 100, height: 100
  48. });
  49. var shapeB = canvas.addShape({
  50. id: 'shapeB',
  51. x: 300, y: 250, width: 100, height: 100
  52. });
  53. var connection = canvas.addConnection({
  54. id: 'connection',
  55. waypoints: [ { x: 150, y: 150, original: { x: 130, y: 130 } }, { x: 200, y: 200 }, { x: 350, y: 300 }],
  56. source: shapeA,
  57. target: shapeB
  58. });
  59. // when
  60. var path = graphicsFactory.getConnectionPath(connection);
  61. // then
  62. expect(path).to.eql('M130,130L200,200L350,300');
  63. }));
  64. });
  65. });