DiagramSpec.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import Diagram from '../..';
  2. describe('Diagram', function() {
  3. var container;
  4. beforeEach(function() {
  5. container = document.createElement('div');
  6. document.body.appendChild(container);
  7. });
  8. afterEach(function() {
  9. container.parentNode.removeChild(container);
  10. });
  11. describe('runtime', function() {
  12. it('should bootstrap', function() {
  13. new Diagram({
  14. canvas: {
  15. container: container,
  16. width: 700,
  17. height: 500
  18. }
  19. });
  20. });
  21. it('should offer #destroy method', function() {
  22. // when
  23. var diagram = new Diagram({
  24. canvas: {
  25. container: container,
  26. width: 700,
  27. height: 500
  28. }
  29. });
  30. // then
  31. expect(diagram.destroy).to.be.an('function');
  32. });
  33. describe('should expose diagram services', function() {
  34. it('via #get', function() {
  35. // when
  36. var diagram = new Diagram({
  37. canvas: {
  38. container: container,
  39. width: 700,
  40. height: 500
  41. }
  42. });
  43. // then
  44. expect(diagram.get('canvas')).to.be.an('object');
  45. });
  46. it('via #get / non-existing service', function() {
  47. // when
  48. var diagram = new Diagram({
  49. canvas: {
  50. container: container,
  51. width: 700,
  52. height: 500
  53. }
  54. });
  55. // then
  56. expect(function() {
  57. diagram.get('foobar');
  58. }).to.throw('No provider for "foobar"! (Resolving: foobar)');
  59. });
  60. it('via #get / non-existing optional service', function() {
  61. // when
  62. var diagram = new Diagram({
  63. canvas: {
  64. container: container,
  65. width: 700,
  66. height: 500
  67. }
  68. });
  69. // then
  70. expect(diagram.get('foobar', false)).to.be.null;
  71. });
  72. it('via #invoke', function() {
  73. // when
  74. var diagram = new Diagram({
  75. canvas: {
  76. container: container,
  77. width: 700,
  78. height: 500
  79. }
  80. });
  81. diagram.invoke([ 'canvas', function(canvas) {
  82. canvas.addShape({ id: 's1', x: 10, y: 10, width: 30, height: 30 });
  83. canvas.addShape({ id: 's2', x: 100, y: 100, width: 30, height: 30 });
  84. canvas.addConnection({ id: 'c1', waypoints: [ { x: 25, y: 25 }, { x: 115, y: 115 } ] });
  85. }]);
  86. });
  87. });
  88. });
  89. });