ToggleShapeCollapseSpec.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import {
  2. bootstrapDiagram,
  3. inject
  4. } from 'test/TestHelper';
  5. import modelingModule from 'lib/features/modeling';
  6. describe('features/modeling - toggle collapsed', function() {
  7. beforeEach(bootstrapDiagram({
  8. modules: [
  9. modelingModule
  10. ]
  11. }));
  12. var rootShape;
  13. beforeEach(inject(function(elementFactory, canvas) {
  14. rootShape = elementFactory.createRoot({
  15. id: 'root'
  16. });
  17. canvas.setRootElement(rootShape);
  18. }));
  19. describe('expand', function() {
  20. var shapeToExpand,
  21. hiddenContainedChild;
  22. beforeEach(inject(function(elementFactory, canvas) {
  23. shapeToExpand = elementFactory.createShape({
  24. id: 'shapeToExpand',
  25. x: 100, y: 100, width: 300, height: 300,
  26. collapsed: true
  27. });
  28. canvas.addShape(shapeToExpand, rootShape);
  29. hiddenContainedChild = elementFactory.createShape({
  30. id: 'hiddenContainedChild',
  31. x: 150, y: 110, width: 100, height: 100,
  32. hidden: true
  33. });
  34. canvas.addShape(hiddenContainedChild, shapeToExpand);
  35. }));
  36. it('expand and should show children', inject(function(modeling) {
  37. // given
  38. var originalChildren = shapeToExpand.children.slice();
  39. // when
  40. modeling.toggleCollapse(shapeToExpand);
  41. // then
  42. expect(shapeToExpand.children).to.eql(originalChildren);
  43. expect(shapeToExpand.children).to.satisfy(allShown());
  44. }));
  45. describe('undo', function() {
  46. it('collapse and hide all children', inject(function(modeling, commandStack) {
  47. // given
  48. var originalChildren = shapeToExpand.children.slice();
  49. modeling.toggleCollapse(shapeToExpand);
  50. // when
  51. commandStack.undo();
  52. // then
  53. expect(shapeToExpand.collapsed).to.eql(true);
  54. expect(shapeToExpand.children).to.eql(originalChildren);
  55. expect(shapeToExpand.children).to.satisfy(allHidden());
  56. }));
  57. });
  58. });
  59. describe('collapse', function() {
  60. var shapeToCollapse,
  61. shownChildShape,
  62. hiddenChildShape;
  63. beforeEach(inject(function(elementFactory, canvas) {
  64. shapeToCollapse = elementFactory.createShape({
  65. id: 'shapeToCollapse',
  66. x: 100, y: 100, width: 300, height: 300,
  67. collapsed: false
  68. });
  69. canvas.addShape(shapeToCollapse, rootShape);
  70. shownChildShape = elementFactory.createShape({
  71. id: 'shownChildShape',
  72. x: 110, y: 110,
  73. width: 100, height: 100
  74. });
  75. canvas.addShape(shownChildShape, shapeToCollapse);
  76. hiddenChildShape = elementFactory.createShape({
  77. id: 'hiddenChildShape',
  78. x: 220, y: 110,
  79. width: 100, height: 100,
  80. hidden: true
  81. });
  82. canvas.addShape(hiddenChildShape, shapeToCollapse);
  83. }));
  84. it('collapse and hide children', inject(function(modeling) {
  85. // given
  86. var originalChildren = shapeToCollapse.children.slice();
  87. // when
  88. modeling.toggleCollapse(shapeToCollapse);
  89. // then
  90. expect(shapeToCollapse.collapsed).to.eql(true);
  91. expect(shapeToCollapse.children).to.eql(originalChildren);
  92. expect(shapeToCollapse.children).to.satisfy(allHidden());
  93. }));
  94. describe('undo', function() {
  95. it('expand and show children that were visible',
  96. inject(function(modeling, commandStack) {
  97. // given
  98. var originalChildren = shapeToCollapse.children.slice();
  99. modeling.toggleCollapse(shapeToCollapse);
  100. // when
  101. commandStack.undo();
  102. // then
  103. expect(shapeToCollapse.collapsed).to.eql(false);
  104. expect(shapeToCollapse.children).to.eql(originalChildren);
  105. expect(shownChildShape.hidden).not.to.eql(true);
  106. expect(hiddenChildShape.hidden).to.eql(true);
  107. })
  108. );
  109. });
  110. });
  111. });
  112. // helpers //////////////////////
  113. function allHidden() {
  114. return childrenHidden(true);
  115. }
  116. function allShown() {
  117. return childrenHidden(false);
  118. }
  119. function childrenHidden(hidden) {
  120. return function(children) {
  121. return children.every(function(c) {
  122. return c.hidden == hidden;
  123. });
  124. };
  125. }