-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(camunda-platform): clean up camunda:formData#values on type change
Closes #46 Related to bpmn-io/bpmn-properties-panel#2
- Loading branch information
1 parent
9d6dd49
commit b2d2665
Showing
4 changed files
with
208 additions
and
2 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
lib/camunda-platform/features/modeling/behavior/UserTaskGeneratedFormsBehavior.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor'; | ||
|
||
import { is } from 'bpmn-js/lib/util/ModelUtil'; | ||
|
||
|
||
/** | ||
* Camunda BPMN specific user task generated forms behavior removing camunda:FormField#values if camunda:FormField#type | ||
* is changed to something other than enum. | ||
*/ | ||
export default class UserTaskFormsBehavior extends CommandInterceptor { | ||
constructor(eventBus) { | ||
super(eventBus); | ||
|
||
this.preExecute([ | ||
'element.updateModdleProperties', | ||
'properties-panel.update-businessobject' | ||
], function(context) { | ||
let { | ||
businessObject, | ||
moddleElement, | ||
properties | ||
} = context; | ||
|
||
businessObject = businessObject || moddleElement; | ||
|
||
if (is(businessObject, 'camunda:FormField') | ||
&& 'camunda:type' in properties | ||
&& properties[ 'camunda:type' ] !== 'enum') { | ||
properties[ 'camunda:values' ] = undefined; | ||
} | ||
}, true); | ||
} | ||
} | ||
|
||
|
||
UserTaskFormsBehavior.$inject = [ 'eventBus' ]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
test/camunda-platform/features/modeling/UserTaskGeneratedFormsBehaviorSpec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { | ||
bootstrapCamundaPlatformModeler, | ||
inject | ||
} from 'test/TestHelper'; | ||
|
||
import { | ||
getBpmnJS | ||
} from 'bpmn-js/test/helper'; | ||
|
||
import coreModule from 'bpmn-js/lib/core'; | ||
|
||
import modelingModule from 'bpmn-js/lib/features/modeling'; | ||
|
||
import { | ||
getBusinessObject, | ||
is | ||
} from 'bpmn-js/lib/util/ModelUtil'; | ||
|
||
import camundaModdleExtensions from 'camunda-bpmn-moddle/resources/camunda'; | ||
|
||
import camundaPlatformModelingModules from 'lib/camunda-platform/features/modeling'; | ||
|
||
import propertiesPanelCommandHandler from 'bpmn-js-properties-panel/lib/cmd'; | ||
|
||
import diagramXML from './camunda-user-task-generated-forms-diagram.bpmn'; | ||
|
||
|
||
describe('camunda-platform/features/modeling - UserTaskGeneratedFormsBehavior', function() { | ||
|
||
const testModules = [ | ||
camundaPlatformModelingModules, | ||
coreModule, | ||
modelingModule, | ||
propertiesPanelCommandHandler | ||
]; | ||
|
||
const moddleExtensions = { | ||
camunda: camundaModdleExtensions | ||
}; | ||
|
||
beforeEach(bootstrapCamundaPlatformModeler(diagramXML, { | ||
modules: testModules, | ||
moddleExtensions | ||
})); | ||
|
||
function updateModdleProperties(element, moddleElement, properties) { | ||
getBpmnJS().invoke(function(modeling) { | ||
modeling.updateModdleProperties(element, moddleElement, properties); | ||
}); | ||
} | ||
|
||
function updateBusinessObject(element, businessObject, properties) { | ||
getBpmnJS().invoke(function(commandStack) { | ||
commandStack.execute('properties-panel.update-businessobject', { | ||
element, | ||
businessObject, | ||
properties | ||
}); | ||
}); | ||
} | ||
|
||
[ | ||
[ 'element.updateModdleProperties', updateModdleProperties ], | ||
[ 'properties-panel.update-businessobject', updateBusinessObject ] | ||
].forEach(([ command, fn ]) => { | ||
|
||
describe(command, function() { | ||
|
||
[ | ||
[ 'start event', 'StartEvent' ], | ||
[ 'user task', 'UserTask' ] | ||
].forEach(([ type, prefix ]) => { | ||
|
||
describe('setting camunda:FormField#type to boolean', function() { | ||
|
||
describe(type, function() { | ||
|
||
it('should delete camunda:FormField#values', inject(function(elementRegistry) { | ||
|
||
// when | ||
const element = elementRegistry.get(`${ prefix }_1`); | ||
|
||
const businessObject = getFormField(element); | ||
|
||
// when | ||
fn(element, businessObject, { 'camunda:type': 'boolean' }); | ||
|
||
// then | ||
expect(businessObject.get('camunda:values')).to.be.empty; | ||
})); | ||
|
||
|
||
it('should not delete camunda:FormField#values', inject(function(elementRegistry) { | ||
|
||
// when | ||
const element = elementRegistry.get(`${ prefix }_1`); | ||
|
||
const businessObject = getFormField(element); | ||
|
||
// when | ||
fn(element, businessObject, { 'camunda:type': 'enum' }); | ||
|
||
// then | ||
expect(businessObject.get('camunda:values')).not.to.be.empty; | ||
})); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
// helpers ////////// | ||
|
||
function getFormField(element, index = 0) { | ||
const businessObject = getBusinessObject(element); | ||
|
||
const extensionElements = businessObject.get('extensionElements'), | ||
values = extensionElements.get('values'); | ||
|
||
const formData = values.find((value) => { | ||
return is(value, 'camunda:FormData'); | ||
}); | ||
|
||
return formData.get('camunda:fields')[ index ]; | ||
} |
35 changes: 35 additions & 0 deletions
35
test/camunda-platform/features/modeling/camunda-user-task-generated-forms-diagram.bpmn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?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:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0fjxb6c" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.9.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0"> | ||
<bpmn:process id="Process_1" isExecutable="true"> | ||
<bpmn:startEvent id="StartEvent_1" camunda:formKey="embedded:deployment:FORM_NAME.html"> | ||
<bpmn:extensionElements> | ||
<camunda:formData> | ||
<camunda:formField id="FormField_1" type="enum"> | ||
<camunda:value id="Value_1" /> | ||
<camunda:value id="Value_2" /> | ||
</camunda:formField> | ||
</camunda:formData> | ||
</bpmn:extensionElements> | ||
</bpmn:startEvent> | ||
<bpmn:userTask id="UserTask_1" camunda:formKey="embedded:deployment:FORM_NAME.html"> | ||
<bpmn:extensionElements> | ||
<camunda:formData> | ||
<camunda:formField id="FormField_2" type="enum"> | ||
<camunda:value id="Value_3" /> | ||
<camunda:value id="Value_4" /> | ||
</camunda:formField> | ||
</camunda:formData> | ||
</bpmn:extensionElements> | ||
</bpmn:userTask> | ||
</bpmn:process> | ||
<bpmndi:BPMNDiagram id="BPMNDiagram_1"> | ||
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1"> | ||
<bpmndi:BPMNShape id="Event_0b9cna2_di" bpmnElement="StartEvent_1"> | ||
<dc:Bounds x="152" y="102" width="36" height="36" /> | ||
</bpmndi:BPMNShape> | ||
<bpmndi:BPMNShape id="Activity_0pn8rby_di" bpmnElement="UserTask_1"> | ||
<dc:Bounds x="260" y="80" width="100" height="80" /> | ||
</bpmndi:BPMNShape> | ||
</bpmndi:BPMNPlane> | ||
</bpmndi:BPMNDiagram> | ||
</bpmn:definitions> |