123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- import {
- bootstrapDiagram,
- inject
- } from 'test/TestHelper';
- import modelingModule from 'lib/features/modeling';
- describe('features/modeling - toggle collapsed', function() {
- beforeEach(bootstrapDiagram({
- modules: [
- modelingModule
- ]
- }));
- var rootShape;
- beforeEach(inject(function(elementFactory, canvas) {
- rootShape = elementFactory.createRoot({
- id: 'root'
- });
- canvas.setRootElement(rootShape);
- }));
- describe('expand', function() {
- var shapeToExpand,
- hiddenContainedChild;
- beforeEach(inject(function(elementFactory, canvas) {
- shapeToExpand = elementFactory.createShape({
- id: 'shapeToExpand',
- x: 100, y: 100, width: 300, height: 300,
- collapsed: true
- });
- canvas.addShape(shapeToExpand, rootShape);
- hiddenContainedChild = elementFactory.createShape({
- id: 'hiddenContainedChild',
- x: 150, y: 110, width: 100, height: 100,
- hidden: true
- });
- canvas.addShape(hiddenContainedChild, shapeToExpand);
- }));
- it('expand and should show children', inject(function(modeling) {
- // given
- var originalChildren = shapeToExpand.children.slice();
- // when
- modeling.toggleCollapse(shapeToExpand);
- // then
- expect(shapeToExpand.children).to.eql(originalChildren);
- expect(shapeToExpand.children).to.satisfy(allShown());
- }));
- describe('undo', function() {
- it('collapse and hide all children', inject(function(modeling, commandStack) {
- // given
- var originalChildren = shapeToExpand.children.slice();
- modeling.toggleCollapse(shapeToExpand);
- // when
- commandStack.undo();
- // then
- expect(shapeToExpand.collapsed).to.eql(true);
- expect(shapeToExpand.children).to.eql(originalChildren);
- expect(shapeToExpand.children).to.satisfy(allHidden());
- }));
- });
- });
- describe('collapse', function() {
- var shapeToCollapse,
- shownChildShape,
- hiddenChildShape;
- beforeEach(inject(function(elementFactory, canvas) {
- shapeToCollapse = elementFactory.createShape({
- id: 'shapeToCollapse',
- x: 100, y: 100, width: 300, height: 300,
- collapsed: false
- });
- canvas.addShape(shapeToCollapse, rootShape);
- shownChildShape = elementFactory.createShape({
- id: 'shownChildShape',
- x: 110, y: 110,
- width: 100, height: 100
- });
- canvas.addShape(shownChildShape, shapeToCollapse);
- hiddenChildShape = elementFactory.createShape({
- id: 'hiddenChildShape',
- x: 220, y: 110,
- width: 100, height: 100,
- hidden: true
- });
- canvas.addShape(hiddenChildShape, shapeToCollapse);
- }));
- it('collapse and hide children', inject(function(modeling) {
- // given
- var originalChildren = shapeToCollapse.children.slice();
- // when
- modeling.toggleCollapse(shapeToCollapse);
- // then
- expect(shapeToCollapse.collapsed).to.eql(true);
- expect(shapeToCollapse.children).to.eql(originalChildren);
- expect(shapeToCollapse.children).to.satisfy(allHidden());
- }));
- describe('undo', function() {
- it('expand and show children that were visible',
- inject(function(modeling, commandStack) {
- // given
- var originalChildren = shapeToCollapse.children.slice();
- modeling.toggleCollapse(shapeToCollapse);
- // when
- commandStack.undo();
- // then
- expect(shapeToCollapse.collapsed).to.eql(false);
- expect(shapeToCollapse.children).to.eql(originalChildren);
- expect(shownChildShape.hidden).not.to.eql(true);
- expect(hiddenChildShape.hidden).to.eql(true);
- })
- );
- });
- });
- });
- // helpers //////////////////////
- function allHidden() {
- return childrenHidden(true);
- }
- function allShown() {
- return childrenHidden(false);
- }
- function childrenHidden(hidden) {
- return function(children) {
- return children.every(function(c) {
- return c.hidden == hidden;
- });
- };
- }
|