-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(create-append-anything): move rules to dedicated module
- Loading branch information
Showing
5 changed files
with
158 additions
and
102 deletions.
There are no files selected for viewing
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,71 @@ | ||
import { | ||
find, | ||
} from 'min-dash'; | ||
|
||
import inherits from 'inherits-browser'; | ||
|
||
import { | ||
is, | ||
getBusinessObject | ||
} from '../../util/ModelUtil'; | ||
|
||
import { | ||
isAny | ||
} from '../modeling/util/ModelingUtil'; | ||
|
||
import RuleProvider from 'diagram-js/lib/features/rules/RuleProvider'; | ||
|
||
|
||
/** | ||
* Append anything modeling rules | ||
*/ | ||
export default function AppendRules(eventBus) { | ||
RuleProvider.call(this, eventBus); | ||
} | ||
|
||
inherits(AppendRules, RuleProvider); | ||
|
||
AppendRules.$inject = [ | ||
'eventBus' | ||
]; | ||
|
||
AppendRules.prototype.init = function() { | ||
this.addRule('shape.append', function(context) { | ||
|
||
var source = context.element; | ||
|
||
const businessObject = getBusinessObject(source); | ||
|
||
if (isAny(source, [ | ||
'bpmn:EndEvent', | ||
'bpmn:Group', | ||
'bpmn:TextAnnotation', | ||
'bpmn:SequenceFlow', | ||
'bpmn:Lane', | ||
'bpmn:Participant', | ||
'bpmn:DataStoreReference', | ||
'bpmn:DataObjectReference' | ||
])) { | ||
return false; | ||
} | ||
|
||
if (is(source, 'bpmn:IntermediateThrowEvent') && hasEventDefinition(source, 'bpmn:LinkEventDefinition')) { | ||
return false; | ||
} | ||
|
||
if (is(source, 'bpmn:SubProcess') && businessObject.triggeredByEvent) { | ||
return false; | ||
} | ||
}); | ||
|
||
}; | ||
|
||
|
||
// helpers ////////////// | ||
function hasEventDefinition(element, eventDefinition) { | ||
var bo = getBusinessObject(element); | ||
|
||
return !!find(bo.eventDefinitions || [], function(definition) { | ||
return is(definition, eventDefinition); | ||
}); | ||
} |
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
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
82 changes: 82 additions & 0 deletions
82
test/spec/features/create-append-anything/AppendRulesSpec.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,82 @@ | ||
import { | ||
bootstrapModeler, | ||
inject | ||
} from 'test/TestHelper'; | ||
|
||
import createAppendAnything from 'lib/features/create-append-anything'; | ||
import modelingModule from 'lib/features/modeling'; | ||
import coreModule from 'lib/core'; | ||
import rulesModule from 'diagram-js/lib/features/rules'; | ||
|
||
|
||
describe('features/create-append-anything - rules', function() { | ||
|
||
var testModules = [ modelingModule, coreModule, rulesModule, createAppendAnything ]; | ||
|
||
var testXML = require('./AppendMenuProvider.bpmn'); | ||
|
||
beforeEach(bootstrapModeler(testXML, { modules: testModules })); | ||
|
||
|
||
describe('element append', function() { | ||
|
||
it('should not allow for given element types', inject(function(elementFactory, rules) { | ||
|
||
// given | ||
var types = [ | ||
'bpmn:EndEvent', | ||
'bpmn:Group', | ||
'bpmn:TextAnnotation', | ||
'bpmn:SequenceFlow', | ||
'bpmn:Lane', | ||
'bpmn:Participant', | ||
'bpmn:DataStoreReference', | ||
'bpmn:DataObjectReference' | ||
]; | ||
|
||
// when | ||
|
||
var results = types.map(function(type) { | ||
var element = elementFactory.createShape({ type: type }); | ||
return rules.allowed('shape.append', { element }); | ||
}); | ||
|
||
// then | ||
results.forEach(function(result) { | ||
expect(result).to.be.false; | ||
}); | ||
})); | ||
|
||
|
||
it('should not allow for event subprocess', inject(function(elementFactory, rules) { | ||
|
||
// given | ||
var element = elementFactory.createShape({ type: 'bpmn:SubProcess', triggeredByEvent: true }); | ||
|
||
// when | ||
var result = rules.allowed('shape.append', { element }); | ||
|
||
// then | ||
expect(result).to.be.false; | ||
})); | ||
|
||
|
||
it('should not allow for link intermediate throw event', inject(function(elementFactory, rules) { | ||
|
||
// given | ||
var element = elementFactory.createShape({ | ||
type: 'bpmn:IntermediateThrowEvent', | ||
cancelActivity: false, | ||
eventDefinitionType: 'bpmn:LinkEventDefinition' | ||
}); | ||
|
||
// when | ||
var result = rules.allowed('shape.append', { element }); | ||
|
||
// then | ||
expect(result).to.be.false; | ||
})); | ||
|
||
}); | ||
|
||
}); |
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