OutlineSpec.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import {
  2. bootstrapDiagram,
  3. inject
  4. } from 'test/TestHelper';
  5. import selectionModule from 'lib/features/selection';
  6. import {
  7. query as domQuery
  8. } from 'min-dom';
  9. import {
  10. classes as svgClasses
  11. } from 'tiny-svg';
  12. describe('features/outline/Outline', function() {
  13. beforeEach(bootstrapDiagram({ modules: [ selectionModule ] }));
  14. it('should expose API', inject(function(outline) {
  15. expect(outline).to.exist;
  16. expect(outline.updateShapeOutline).to.exist;
  17. expect(outline.updateConnectionOutline).to.exist;
  18. }));
  19. describe('select', function() {
  20. it('should add outline to shape', inject(function(selection, canvas, elementRegistry) {
  21. // given
  22. var shape = canvas.addShape({
  23. id: 'test',
  24. x: 10,
  25. y: 10,
  26. width: 100,
  27. height: 100
  28. });
  29. // when
  30. selection.select(shape);
  31. // then
  32. var gfx = elementRegistry.getGraphics(shape);
  33. var outline = domQuery('.djs-outline', gfx);
  34. expect(outline).to.exist;
  35. expect(svgClasses(gfx).has('selected')).to.be.true; // Outline class is set
  36. }));
  37. it('should add outline to connection', inject(function(selection, canvas, elementRegistry) {
  38. // given
  39. var connection = canvas.addConnection({ id: 'select1', waypoints: [ { x: 25, y: 25 }, { x: 115, y: 115 } ] });
  40. // when
  41. selection.select(connection);
  42. // then
  43. var gfx = elementRegistry.getGraphics(connection);
  44. var outline = domQuery('.djs-outline', gfx);
  45. expect(outline).to.exist;
  46. expect(svgClasses(gfx).has('selected')).to.be.true; // Outline class is set
  47. }));
  48. });
  49. describe('deselect', function() {
  50. it('should remove outline class from shape', inject(function(selection, canvas, elementRegistry) {
  51. // given
  52. var shape = canvas.addShape({
  53. id: 'test',
  54. x: 10,
  55. y: 10,
  56. width: 100,
  57. height: 100
  58. });
  59. // when
  60. selection.select(shape);
  61. selection.deselect(shape);
  62. // then
  63. var gfx = elementRegistry.getGraphics(shape);
  64. var outline = domQuery('.djs-outline', gfx);
  65. expect(outline).to.exist;
  66. expect(svgClasses(gfx).has('selected')).to.be.false; // Outline class is not set
  67. }));
  68. it('should remove outline class from connection', inject(function(selection, canvas, elementRegistry) {
  69. // given
  70. var connection = canvas.addConnection({ id: 'select3', waypoints: [ { x: 25, y: 25 }, { x: 115, y: 115 } ] });
  71. // when
  72. selection.select(connection);
  73. selection.deselect(connection);
  74. // then
  75. var gfx = elementRegistry.getGraphics(connection);
  76. var outline = domQuery('.djs-outline', gfx);
  77. expect(outline).to.exist;
  78. expect(svgClasses(gfx).has('selected')).to.be.false; // Outline class is not set
  79. }));
  80. });
  81. });