fix(modeling): strip all namespaces for semantic id generation
Related to #108
This commit is contained in:
parent
b8db4322ab
commit
86d5c20f07
|
@ -22,7 +22,9 @@ BpmnFactory.prototype._needsId = function(element) {
|
||||||
|
|
||||||
BpmnFactory.prototype._ensureId = function(element) {
|
BpmnFactory.prototype._ensureId = function(element) {
|
||||||
|
|
||||||
var prefix = (element.$type || '').replace(/^\s*bpmn:/g, '') + '_';
|
// generate semantic ids for elements
|
||||||
|
// bpmn:SequenceFlow -> SequenceFlow_ID
|
||||||
|
var prefix = (element.$type || '').replace(/^[^:]*:/g, '') + '_';
|
||||||
|
|
||||||
if (!element.id && this._needsId(element)) {
|
if (!element.id && this._needsId(element)) {
|
||||||
element.id = this._model.ids.nextPrefixed(prefix, element);
|
element.id = this._model.ids.nextPrefixed(prefix, element);
|
||||||
|
|
|
@ -22,18 +22,32 @@ describe('features - bpmn-factory', function() {
|
||||||
|
|
||||||
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
||||||
|
|
||||||
describe('create element', function() {
|
|
||||||
it('element should be created', inject(function(bpmnFactory) {
|
|
||||||
var task = bpmnFactory.create('bpmn:Task');
|
|
||||||
expect(task).toBeDefined();
|
|
||||||
expect(task.$type).toEqual('bpmn:Task');
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('element id should have semantic prefix', inject(function(bpmnFactory) {
|
describe('create element', function() {
|
||||||
|
|
||||||
|
it('should return instance', inject(function(bpmnFactory) {
|
||||||
|
|
||||||
|
var task = bpmnFactory.create('bpmn:Task');
|
||||||
|
expect(task).toBeDefined();
|
||||||
|
expect(task.$type).toEqual('bpmn:Task');
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
it('should assign id (with semantic prefix)', inject(function(bpmnFactory) {
|
||||||
var task = bpmnFactory.create('bpmn:ServiceTask');
|
var task = bpmnFactory.create('bpmn:ServiceTask');
|
||||||
|
|
||||||
expect(task.$type).toEqual('bpmn:ServiceTask');
|
expect(task.$type).toEqual('bpmn:ServiceTask');
|
||||||
expect(task.id).toMatch(/^ServiceTask_/g);
|
expect(task.id).toMatch(/^ServiceTask_/g);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
it('should assign id (with semantic prefix)', inject(function(bpmnFactory) {
|
||||||
|
var plane = bpmnFactory.create('bpmndi:BPMNPlane');
|
||||||
|
|
||||||
|
expect(plane.$type).toEqual('bpmndi:BPMNPlane');
|
||||||
|
expect(plane.id).toMatch(/^BPMNPlane_/g);
|
||||||
|
}));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue