2018-04-02 19:01:53 +00:00
|
|
|
/* global sinon */
|
2016-09-01 16:06:50 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
bootstrapModeler,
|
|
|
|
inject
|
|
|
|
} from 'test/TestHelper';
|
2016-09-01 16:06:50 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import Modeler from 'lib/Modeler';
|
|
|
|
|
|
|
|
import TestContainer from 'mocha-test-container-support';
|
2016-09-01 16:06:50 +00:00
|
|
|
|
2017-06-27 07:37:58 +00:00
|
|
|
var DELTA = 2;
|
|
|
|
|
2016-09-14 06:18:56 +00:00
|
|
|
|
2016-09-01 16:06:50 +00:00
|
|
|
describe('label bounds', function() {
|
|
|
|
|
|
|
|
function createModeler(xml, done) {
|
|
|
|
var modeler = new Modeler({ container: container });
|
|
|
|
|
|
|
|
modeler.importXML(xml, function(err, warnings) {
|
|
|
|
done(err, warnings, modeler);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var container;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
container = TestContainer.get(this);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('on import', function() {
|
|
|
|
|
|
|
|
it('should import simple label process', function(done) {
|
|
|
|
var xml = require('./LabelBoundsSpec.simple.bpmn');
|
|
|
|
createModeler(xml, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('on label change', function() {
|
|
|
|
|
|
|
|
var diagramXML = require('./LabelBoundsSpec.simple.bpmn');
|
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(diagramXML));
|
|
|
|
|
|
|
|
var updateLabel;
|
|
|
|
|
|
|
|
beforeEach(inject(function(directEditing) {
|
|
|
|
|
|
|
|
updateLabel = function(shape, text) {
|
|
|
|
directEditing.activate(shape);
|
|
|
|
directEditing._textbox.content.innerText = text;
|
|
|
|
directEditing.complete();
|
|
|
|
};
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('label dimensions', function() {
|
|
|
|
|
|
|
|
it('should expand width', inject(function(elementRegistry) {
|
|
|
|
|
|
|
|
// given
|
2016-10-26 09:26:58 +00:00
|
|
|
var shape = elementRegistry.get('StartEvent_1'),
|
|
|
|
oldLabelWidth = shape.label.width;
|
2016-09-01 16:06:50 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
updateLabel(shape, 'Foooooooooobar');
|
|
|
|
|
|
|
|
// then
|
2016-10-26 09:26:58 +00:00
|
|
|
expect(shape.label.width).to.be.above(oldLabelWidth);
|
2016-09-01 16:06:50 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should expand height', inject(function(elementRegistry) {
|
|
|
|
|
|
|
|
// given
|
2016-10-26 09:26:58 +00:00
|
|
|
var shape = elementRegistry.get('StartEvent_1'),
|
|
|
|
oldLabelHeight = shape.label.height;
|
2016-09-01 16:06:50 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
updateLabel(shape, 'Foo\nbar\nbaz');
|
|
|
|
|
|
|
|
// then
|
2016-10-26 09:26:58 +00:00
|
|
|
expect(shape.label.height).to.be.above(oldLabelHeight);
|
2016-09-01 16:06:50 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should reduce width', inject(function(elementRegistry) {
|
|
|
|
// given
|
2016-10-26 09:26:58 +00:00
|
|
|
var shape = elementRegistry.get('StartEvent_1'),
|
|
|
|
oldLabelWidth = shape.label.width;
|
2016-09-01 16:06:50 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
updateLabel(shape, 'i');
|
|
|
|
|
|
|
|
// then
|
2016-10-26 09:26:58 +00:00
|
|
|
expect(shape.label.width).to.be.below(oldLabelWidth);
|
2016-09-01 16:06:50 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should reduce height', inject(function(elementRegistry) {
|
|
|
|
// given
|
2016-10-26 09:26:58 +00:00
|
|
|
var shape = elementRegistry.get('StartEvent_3'),
|
|
|
|
oldLabelHeight = shape.label.height;
|
2016-09-01 16:06:50 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
updateLabel(shape, 'One line');
|
|
|
|
|
|
|
|
// then
|
2016-10-26 09:26:58 +00:00
|
|
|
expect(shape.label.height).to.be.below(oldLabelHeight);
|
2016-09-01 16:06:50 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('label position', function() {
|
|
|
|
|
|
|
|
var getExpectedX = function(shape) {
|
2017-02-13 12:47:00 +00:00
|
|
|
return Math.round(shape.x + shape.width / 2 - shape.label.width / 2);
|
2016-09-01 16:06:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
it('should shift to left', inject(function(elementRegistry) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var shape = elementRegistry.get('StartEvent_1');
|
|
|
|
|
|
|
|
// when
|
|
|
|
updateLabel(shape, 'Foooooooooobar');
|
|
|
|
|
|
|
|
// then
|
|
|
|
var expectedX = getExpectedX(shape);
|
|
|
|
|
2017-06-27 07:37:58 +00:00
|
|
|
expect(shape.label.x).to.be.closeTo(expectedX, DELTA);
|
2016-09-01 16:06:50 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should shift to right', inject(function(elementRegistry) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var shape = elementRegistry.get('StartEvent_1');
|
|
|
|
|
|
|
|
// when
|
|
|
|
updateLabel(shape, 'F');
|
|
|
|
|
|
|
|
// then
|
|
|
|
var expectedX = getExpectedX(shape);
|
|
|
|
|
2016-09-27 15:01:05 +00:00
|
|
|
expect(shape.label.x).to.equal(expectedX);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should remain the same', inject(function(elementRegistry) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var shape = elementRegistry.get('StartEvent_1');
|
|
|
|
|
|
|
|
// when
|
|
|
|
updateLabel(shape, 'FOOBAR');
|
|
|
|
|
|
|
|
// copy old horizontal label position
|
|
|
|
var oldX = shape.label.x + 0;
|
|
|
|
|
|
|
|
updateLabel(shape, 'FOOBAR\n1');
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(shape.label.x).to.equal(oldX);
|
2016-09-01 16:06:50 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('label outlines', function() {
|
|
|
|
|
|
|
|
it('should update after element bounds have been updated',
|
|
|
|
inject(function(outline, elementRegistry, bpmnRenderer) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var shape = elementRegistry.get('StartEvent_1');
|
|
|
|
|
|
|
|
var outlineSpy = sinon.spy(outline, 'updateShapeOutline');
|
|
|
|
var rendererSpy = sinon.spy(bpmnRenderer, 'drawShape');
|
|
|
|
|
|
|
|
// when
|
|
|
|
updateLabel(shape, 'Fooooobar');
|
|
|
|
|
|
|
|
// then
|
|
|
|
// expect the outline updating to happen after the renderer
|
|
|
|
// updated the elements bounds dimensions and position
|
|
|
|
sinon.assert.callOrder(
|
|
|
|
rendererSpy.withArgs(sinon.match.any, shape.label),
|
|
|
|
outlineSpy.withArgs(sinon.match.any, shape.label)
|
|
|
|
);
|
|
|
|
})
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('interaction events', function() {
|
|
|
|
|
|
|
|
it('should update bounds after element bounds have been updated',
|
2016-09-23 10:55:57 +00:00
|
|
|
inject(function(interactionEvents, elementRegistry, bpmnRenderer, graphicsFactory) {
|
2016-09-01 16:06:50 +00:00
|
|
|
|
|
|
|
// given
|
2016-09-23 10:55:57 +00:00
|
|
|
var shape = elementRegistry.get('StartEvent_1');
|
2016-09-01 16:06:50 +00:00
|
|
|
|
2016-09-23 10:55:57 +00:00
|
|
|
var graphicsFactorySpy = sinon.spy(graphicsFactory, 'update'),
|
2016-09-01 16:06:50 +00:00
|
|
|
rendererSpy = sinon.spy(bpmnRenderer, 'drawShape');
|
|
|
|
|
|
|
|
// when
|
|
|
|
updateLabel(shape, 'Fooooobar');
|
|
|
|
|
|
|
|
// then
|
|
|
|
// expect the interaction event bounds updating to happen after the renderer
|
|
|
|
// updated the elements bounds dimensions and position
|
|
|
|
sinon.assert.callOrder(
|
|
|
|
rendererSpy.withArgs(sinon.match.any, shape.label),
|
2016-09-23 10:55:57 +00:00
|
|
|
graphicsFactorySpy
|
2016-09-01 16:06:50 +00:00
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('on export', function() {
|
|
|
|
|
|
|
|
it('should create DI when label has changed', function(done) {
|
|
|
|
|
|
|
|
var xml = require('./LabelBoundsSpec.simple.bpmn');
|
|
|
|
|
|
|
|
createModeler(xml, function(err, warnings, modeler) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
var elementRegistry = modeler.get('elementRegistry'),
|
|
|
|
directEditing = modeler.get('directEditing');
|
|
|
|
|
|
|
|
var shape = elementRegistry.get('StartEvent_1');
|
|
|
|
|
|
|
|
directEditing.activate(shape);
|
|
|
|
directEditing._textbox.content.innerText = 'BARBAZ';
|
|
|
|
directEditing.complete();
|
|
|
|
|
|
|
|
modeler.saveXML({ format: true }, function(err, result) {
|
|
|
|
|
|
|
|
// strip spaces and line breaks after '>'
|
|
|
|
result = result.replace(/>\s+/g,'>');
|
|
|
|
|
|
|
|
// get label width and height from XML
|
|
|
|
var matches = result.match(/StartEvent_1_di.*?BPMNLabel.*?width="(\d*).*?height="(\d*)/);
|
|
|
|
|
|
|
|
var width = parseInt(matches[1]),
|
|
|
|
height = parseInt(matches[2]);
|
|
|
|
|
2016-10-26 09:26:58 +00:00
|
|
|
expect(width).to.equal(shape.label.width);
|
|
|
|
expect(height).to.equal(shape.label.height);
|
2016-09-01 16:06:50 +00:00
|
|
|
|
2017-12-04 21:27:32 +00:00
|
|
|
done(err);
|
2016-09-01 16:06:50 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should update existing DI when label has changed', function(done) {
|
|
|
|
|
|
|
|
var xml = require('./LabelBoundsSpec.simple.bpmn');
|
|
|
|
|
|
|
|
createModeler(xml, function(err, warnings, modeler) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
var elementRegistry = modeler.get('elementRegistry'),
|
|
|
|
directEditing = modeler.get('directEditing');
|
|
|
|
|
|
|
|
var shape = elementRegistry.get('StartEvent_3');
|
|
|
|
|
|
|
|
directEditing.activate(shape);
|
|
|
|
directEditing._textbox.content.innerText = 'BARBAZ';
|
|
|
|
directEditing.complete();
|
|
|
|
|
|
|
|
modeler.saveXML({ format: true }, function(err, result) {
|
|
|
|
|
|
|
|
// strip spaces and line breaks after '>'
|
|
|
|
result = result.replace(/>\s+/g,'>');
|
|
|
|
|
|
|
|
// get label width and height from XML
|
|
|
|
var matches = result.match(/StartEvent_3_di.*?BPMNLabel.*?width="(\d*).*?height="(\d*)/);
|
|
|
|
|
|
|
|
var width = parseInt(matches[1]),
|
|
|
|
height = parseInt(matches[2]);
|
|
|
|
|
2016-10-26 09:26:58 +00:00
|
|
|
expect(width).to.equal(shape.label.width);
|
|
|
|
expect(height).to.equal(shape.label.height);
|
2016-09-01 16:06:50 +00:00
|
|
|
|
2017-12-04 21:27:32 +00:00
|
|
|
done(err);
|
2016-09-01 16:06:50 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should not update DI of untouched labels', function(done) {
|
|
|
|
|
|
|
|
var xml = require('./LabelBoundsSpec.simple.bpmn');
|
|
|
|
|
2016-10-26 09:26:58 +00:00
|
|
|
// strip windows line breaks (if any)
|
|
|
|
xml = xml.replace(/\r/g, '');
|
|
|
|
|
2016-09-01 16:06:50 +00:00
|
|
|
createModeler(xml, function(err, warnings, modeler) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
modeler.saveXML({ format: true }, function(err, result) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(result).to.equal(xml);
|
|
|
|
|
2017-12-04 21:27:32 +00:00
|
|
|
done(err);
|
2016-09-01 16:06:50 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|