fix(modeling): hide labels on element create

This commit is contained in:
Ricardo Matias 2015-10-06 16:12:40 +02:00
parent 08c2ebc78f
commit a0bfc29482
5 changed files with 67 additions and 37 deletions

View File

@ -30,6 +30,7 @@ function LabelSupport(eventBus, modeling, bpmnFactory) {
position = getExternalLabelMid(element); position = getExternalLabelMid(element);
modeling.createLabel(element, position, { modeling.createLabel(element, position, {
id: businessObject.id + '_label', id: businessObject.id + '_label',
hidden: true,
businessObject: businessObject businessObject: businessObject
}); });
} }

17
test/fixtures/bpmn/basic.bpmn vendored Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">
<bpmn:process id="Process_1" isExecutable="false">
<bpmn:startEvent id="StartEvent_1" />
<bpmn:task id="Task_1" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="173" y="102" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Task_1_di" bpmnElement="Task_1">
<dc:Bounds x="353" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -0,0 +1,37 @@
'use strict';
var TestHelper = require('../../../TestHelper');
/* global bootstrapModeler, inject */
var modelingModule = require('../../../../lib/features/modeling'),
coreModule = require('../../../../lib/core');
describe('features - bpmn-label-support', function() {
var diagramXML = require('../../../fixtures/bpmn/basic.bpmn');
var testModules = [ modelingModule, coreModule ];
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
describe('should not add a label on create', function() {
it('should not add a label on create', inject(function(elementFactory, elementRegistry, modeling, canvas) {
// when
var startEvent = elementRegistry.get('StartEvent_1'),
task = elementRegistry.get('Task_1');
modeling.connect(startEvent, task);
var labels = elementRegistry.filter(function(element) {
return element.type === 'label';
});
// then
expect(labels).to.have.length(2);
}));
});
});

View File

@ -39,7 +39,6 @@ describe('features/modeling/behavior - data objects -', function() {
expect(dataObject).to.exist; expect(dataObject).to.exist;
expect(is(dataObject, 'bpmn:DataObject')).to.be.true; expect(is(dataObject, 'bpmn:DataObject')).to.be.true;
expect(dataObject.id).to.exist; expect(dataObject.id).to.exist;
})); }));
@ -60,7 +59,6 @@ describe('features/modeling/behavior - data objects -', function() {
expect(dataObject2.$parent.id).to.equal(subProcess1.id); expect(dataObject2.$parent.id).to.equal(subProcess1.id);
expect(dataObjectRefShape2.parent.id).to.equal(subProcess1.id); expect(dataObjectRefShape2.parent.id).to.equal(subProcess1.id);
})); }));
}); });
@ -75,11 +73,9 @@ describe('features/modeling/behavior - data objects -', function() {
taskShape; taskShape;
beforeEach(inject(function(canvas, elementRegistry) { beforeEach(inject(function(canvas, elementRegistry) {
rootShape = canvas.getRootElement(); rootShape = canvas.getRootElement();
dataObjectRefShape1 = elementRegistry.get('DataObjectReference_1'); dataObjectRefShape1 = elementRegistry.get('DataObjectReference_1');
taskShape = elementRegistry.get('Task_1'); taskShape = elementRegistry.get('Task_1');
})); }));
describe('dataOutputAssociation', function() { describe('dataOutputAssociation', function() {
@ -95,7 +91,6 @@ describe('features/modeling/behavior - data objects -', function() {
expect(dataOutputAssociations[0].$parent).to.equal(taskShape.businessObject); expect(dataOutputAssociations[0].$parent).to.equal(taskShape.businessObject);
expect(dataOutputAssociations).to.include(outputAssociation.businessObject); expect(dataOutputAssociations).to.include(outputAssociation.businessObject);
expect(taskShape.businessObject.get('dataInputAssociations')).to.be.empty; expect(taskShape.businessObject.get('dataInputAssociations')).to.be.empty;
})); }));
@ -108,7 +103,6 @@ describe('features/modeling/behavior - data objects -', function() {
// then // then
expect(taskShape.businessObject.get('dataOutputAssociations')).to.be.empty; expect(taskShape.businessObject.get('dataOutputAssociations')).to.be.empty;
expect(taskShape.businessObject.get('dataInputAssociations')).to.be.empty; expect(taskShape.businessObject.get('dataInputAssociations')).to.be.empty;
})); }));
@ -125,7 +119,6 @@ describe('features/modeling/behavior - data objects -', function() {
expect(dataOutputAssociations[0].$parent).to.equal(taskShape.businessObject); expect(dataOutputAssociations[0].$parent).to.equal(taskShape.businessObject);
expect(dataOutputAssociations).to.include(outputAssociation.businessObject); expect(dataOutputAssociations).to.include(outputAssociation.businessObject);
expect(taskShape.businessObject.get('dataInputAssociations')).to.be.empty; expect(taskShape.businessObject.get('dataInputAssociations')).to.be.empty;
})); }));
}); });
@ -143,7 +136,6 @@ describe('features/modeling/behavior - data objects -', function() {
expect(dataInputAssociations[0].$parent).to.equal(taskShape.businessObject); expect(dataInputAssociations[0].$parent).to.equal(taskShape.businessObject);
expect(dataInputAssociations).to.include(inputAssociation.businessObject); expect(dataInputAssociations).to.include(inputAssociation.businessObject);
expect(taskShape.businessObject.get('dataOutputAssociations')).to.be.empty; expect(taskShape.businessObject.get('dataOutputAssociations')).to.be.empty;
})); }));
@ -156,7 +148,6 @@ describe('features/modeling/behavior - data objects -', function() {
// then // then
expect(taskShape.businessObject.get('dataOutputAssociations')).to.be.empty; expect(taskShape.businessObject.get('dataOutputAssociations')).to.be.empty;
expect(taskShape.businessObject.get('dataInputAssociations')).to.be.empty; expect(taskShape.businessObject.get('dataInputAssociations')).to.be.empty;
})); }));
@ -173,7 +164,6 @@ describe('features/modeling/behavior - data objects -', function() {
expect(dataInputAssociations[0].$parent).to.equal(taskShape.businessObject); expect(dataInputAssociations[0].$parent).to.equal(taskShape.businessObject);
expect(dataInputAssociations).to.include(inputAssociation.businessObject); expect(dataInputAssociations).to.include(inputAssociation.businessObject);
expect(taskShape.businessObject.get('dataOutputAssociations')).to.be.empty; expect(taskShape.businessObject.get('dataOutputAssociations')).to.be.empty;
})); }));
}); });
@ -192,13 +182,13 @@ describe('features/modeling/behavior - data objects -', function() {
inputAssociation; inputAssociation;
beforeEach(inject(function(canvas, elementRegistry) { beforeEach(inject(function(canvas, elementRegistry) {
rootShape = canvas.getRootElement(); rootShape = canvas.getRootElement();
task1Shape = elementRegistry.get('Task_1'); task1Shape = elementRegistry.get('Task_1');
task2Shape = elementRegistry.get('Task_2'); task2Shape = elementRegistry.get('Task_2');
outputAssociation = elementRegistry.get('DataOutputAssociation_1'); outputAssociation = elementRegistry.get('DataOutputAssociation_1');
inputAssociation = elementRegistry.get('DataInputAssociation_1'); inputAssociation = elementRegistry.get('DataInputAssociation_1');
})); }));
describe('DataOutputAssociation', function() { describe('DataOutputAssociation', function() {
@ -211,7 +201,6 @@ describe('features/modeling/behavior - data objects -', function() {
// then // then
expect(task1Shape.businessObject.get('dataOutputAssociations')).to.be.empty; expect(task1Shape.businessObject.get('dataOutputAssociations')).to.be.empty;
expect(task1Shape.businessObject.get('dataInputAssociations')).to.be.empty; expect(task1Shape.businessObject.get('dataInputAssociations')).to.be.empty;
})); }));
@ -219,6 +208,7 @@ describe('features/modeling/behavior - data objects -', function() {
// when // when
modeling.removeConnection(outputAssociation); modeling.removeConnection(outputAssociation);
commandStack.undo(); commandStack.undo();
var dataOutputAssociations = task1Shape.businessObject.get('dataOutputAssociations'); var dataOutputAssociations = task1Shape.businessObject.get('dataOutputAssociations');
@ -227,7 +217,6 @@ describe('features/modeling/behavior - data objects -', function() {
expect(dataOutputAssociations[0].$parent).to.equal(task1Shape.businessObject); expect(dataOutputAssociations[0].$parent).to.equal(task1Shape.businessObject);
expect(dataOutputAssociations).to.be.include(outputAssociation.businessObject); expect(dataOutputAssociations).to.be.include(outputAssociation.businessObject);
expect(task1Shape.businessObject.get('dataInputAssociations')).to.be.empty; expect(task1Shape.businessObject.get('dataInputAssociations')).to.be.empty;
})); }));
@ -235,13 +224,13 @@ describe('features/modeling/behavior - data objects -', function() {
// when // when
modeling.removeConnection(outputAssociation); modeling.removeConnection(outputAssociation);
commandStack.undo(); commandStack.undo();
commandStack.redo(); commandStack.redo();
// then // then
expect(task1Shape.businessObject.get('dataOutputAssociations')).to.be.empty; expect(task1Shape.businessObject.get('dataOutputAssociations')).to.be.empty;
expect(task1Shape.businessObject.get('dataInputAssociations')).to.be.empty; expect(task1Shape.businessObject.get('dataInputAssociations')).to.be.empty;
})); }));
}); });
@ -256,7 +245,6 @@ describe('features/modeling/behavior - data objects -', function() {
// then // then
expect(task2Shape.businessObject.get('dataInputAssociations')).to.be.empty; expect(task2Shape.businessObject.get('dataInputAssociations')).to.be.empty;
expect(task2Shape.businessObject.get('dataOutputAssociations')).to.be.empty; expect(task2Shape.businessObject.get('dataOutputAssociations')).to.be.empty;
})); }));
@ -264,6 +252,7 @@ describe('features/modeling/behavior - data objects -', function() {
// when // when
modeling.removeConnection(inputAssociation); modeling.removeConnection(inputAssociation);
commandStack.undo(); commandStack.undo();
var dataInputAssociations = task2Shape.businessObject.get('dataInputAssociations'); var dataInputAssociations = task2Shape.businessObject.get('dataInputAssociations');
@ -272,7 +261,6 @@ describe('features/modeling/behavior - data objects -', function() {
expect(dataInputAssociations[0].$parent).to.equal(task2Shape.businessObject); expect(dataInputAssociations[0].$parent).to.equal(task2Shape.businessObject);
expect(dataInputAssociations).to.include(inputAssociation.businessObject); expect(dataInputAssociations).to.include(inputAssociation.businessObject);
expect(task2Shape.businessObject.get('dataOutputAssociations')).to.be.empty; expect(task2Shape.businessObject.get('dataOutputAssociations')).to.be.empty;
})); }));
@ -280,21 +268,17 @@ describe('features/modeling/behavior - data objects -', function() {
// when // when
modeling.removeConnection(inputAssociation); modeling.removeConnection(inputAssociation);
commandStack.undo(); commandStack.undo();
commandStack.redo(); commandStack.redo();
// then // then
expect(task2Shape.businessObject.get('dataInputAssociations')).to.be.empty; expect(task2Shape.businessObject.get('dataInputAssociations')).to.be.empty;
expect(task2Shape.businessObject.get('dataOutputAssociations')).to.be.empty; expect(task2Shape.businessObject.get('dataOutputAssociations')).to.be.empty;
})); }));
}); });
}); });
describe('reconnect', function() {
});
}); });

View File

@ -54,14 +54,13 @@ describe('features/modeling - replace connection', function() {
var task4Shape = element('Task_4'); var task4Shape = element('Task_4');
var connection = element('SequenceFlow_1'); var connection = element('SequenceFlow_1');
var newWaypoints = [connection.waypoints[0], { x: task4Shape.x+30, y: task4Shape.y }]; var newWaypoints = [ connection.waypoints[0], { x: task4Shape.x + 30, y: task4Shape.y }];
// when // when
modeling.reconnectEnd(connection, task4Shape, newWaypoints); modeling.reconnectEnd(connection, task4Shape, newWaypoints);
// then // then
expectConnected(element('Task_2'), task4Shape, 'bpmn:MessageFlow'); expectConnected(element('Task_2'), task4Shape, 'bpmn:MessageFlow');
})); }));
@ -71,14 +70,13 @@ describe('features/modeling - replace connection', function() {
var task4Shape = element('Task_4'); var task4Shape = element('Task_4');
var connection = element('MessageFlow_1'); var connection = element('MessageFlow_1');
var newWaypoints = [connection.waypoints[0], { x: task4Shape.x, y: task4Shape.y+20 }]; var newWaypoints = [ connection.waypoints[0], { x: task4Shape.x, y: task4Shape.y + 20 } ];
// when // when
modeling.reconnectEnd(connection, task4Shape, newWaypoints); modeling.reconnectEnd(connection, task4Shape, newWaypoints);
// then // then
expectConnected(element('Task_3'), task4Shape, 'bpmn:SequenceFlow'); expectConnected(element('Task_3'), task4Shape, 'bpmn:SequenceFlow');
})); }));
@ -88,14 +86,13 @@ describe('features/modeling - replace connection', function() {
var participant2 = element('Participant_2'); var participant2 = element('Participant_2');
var connection = element('SequenceFlow_1'); var connection = element('SequenceFlow_1');
var newWaypoints = [connection.waypoints[0], { x: participant2.x, y: participant2.y }]; var newWaypoints = [ connection.waypoints[0], { x: participant2.x, y: participant2.y }];
// when // when
modeling.reconnectEnd(connection, participant2, newWaypoints); modeling.reconnectEnd(connection, participant2, newWaypoints);
// then // then
expectConnected(element('Task_2'), participant2, 'bpmn:MessageFlow'); expectConnected(element('Task_2'), participant2, 'bpmn:MessageFlow');
})); }));
@ -107,8 +104,8 @@ describe('features/modeling - replace connection', function() {
connection = element('SequenceFlow_1'); connection = element('SequenceFlow_1');
var newWaypoints = [ var newWaypoints = [
{ x: participant2.x+200 , y: participant2.y }, { x: participant2.x + 200, y: participant2.y },
{ x: subProcess1.x, y: subProcess1.y+50 } { x: subProcess1.x, y: subProcess1.y + 50 }
]; ];
// when // when
@ -116,7 +113,6 @@ describe('features/modeling - replace connection', function() {
// then // then
expectConnected(participant2, subProcess1, 'bpmn:MessageFlow'); expectConnected(participant2, subProcess1, 'bpmn:MessageFlow');
})); }));
}); });
@ -263,7 +259,6 @@ describe('features/modeling - replace connection', function() {
beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules })); beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules }));
var element; var element;
beforeEach(inject(function(elementRegistry) { beforeEach(inject(function(elementRegistry) {
@ -272,7 +267,6 @@ describe('features/modeling - replace connection', function() {
}; };
})); }));
describe('moving text-annotation to participant', function() { describe('moving text-annotation to participant', function() {
it('execute', inject(function(modeling, elementRegistry) { it('execute', inject(function(modeling, elementRegistry) {
@ -340,7 +334,6 @@ describe('features/modeling - replace connection', function() {
// then // then
expectNotConnected(boundaryEvent, taskShape2 ,sequenceFlow); expectNotConnected(boundaryEvent, taskShape2 ,sequenceFlow);
})); }));
@ -359,7 +352,6 @@ describe('features/modeling - replace connection', function() {
// then // then
expectConnected(boundaryEvent, taskShape2, sequenceFlow); expectConnected(boundaryEvent, taskShape2, sequenceFlow);
})); }));
@ -377,7 +369,6 @@ describe('features/modeling - replace connection', function() {
// then // then
expectNotConnected(taskShape, targetShape, sequenceFlow); expectNotConnected(taskShape, targetShape, sequenceFlow);
})); }));
}); });