2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
getBpmnJS
|
|
|
|
} from 'test/TestHelper';
|
2015-07-30 08:48:17 +00:00
|
|
|
|
2018-08-22 08:51:07 +00:00
|
|
|
import {
|
|
|
|
isString
|
|
|
|
} from 'min-dash';
|
|
|
|
|
2015-07-30 08:48:17 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export function expectCanConnect(source, target, rules) {
|
2015-07-30 08:48:17 +00:00
|
|
|
|
|
|
|
var results = {};
|
|
|
|
|
2018-08-22 08:51:07 +00:00
|
|
|
getBpmnJS().invoke(function(bpmnRules) {
|
2015-07-30 08:48:17 +00:00
|
|
|
|
2018-08-22 08:51:07 +00:00
|
|
|
source = get(source);
|
|
|
|
target = get(target);
|
2015-07-30 08:48:17 +00:00
|
|
|
|
|
|
|
if ('sequenceFlow' in rules) {
|
|
|
|
results.sequenceFlow = bpmnRules.canConnectSequenceFlow(source, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('messageFlow' in rules) {
|
|
|
|
results.messageFlow = bpmnRules.canConnectMessageFlow(source, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('association' in rules) {
|
|
|
|
results.association = bpmnRules.canConnectAssociation(source, target);
|
|
|
|
}
|
2015-10-06 10:33:21 +00:00
|
|
|
|
|
|
|
if ('dataAssociation' in rules) {
|
|
|
|
results.dataAssociation = bpmnRules.canConnectDataAssociation(source, target);
|
|
|
|
}
|
2015-07-30 08:48:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(results).to.eql(rules);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export function expectCanDrop(element, target, expectedResult) {
|
2015-07-30 08:48:17 +00:00
|
|
|
|
2018-08-22 08:51:07 +00:00
|
|
|
var result = getBpmnJS().invoke(function(bpmnRules) {
|
|
|
|
return bpmnRules.canDrop(get(element), get(target));
|
2015-07-30 08:48:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(result).to.eql(expectedResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-24 14:16:53 +00:00
|
|
|
export function expectCanInsert(element, target, expectedResult) {
|
|
|
|
|
2018-08-22 08:51:07 +00:00
|
|
|
var result = getBpmnJS().invoke(function(bpmnRules) {
|
|
|
|
return bpmnRules.canInsert(get(element), get(target));
|
2018-07-24 14:16:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(result).to.eql(expectedResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export function expectCanMove(elements, target, rules) {
|
2015-07-30 08:48:17 +00:00
|
|
|
|
|
|
|
var results = {};
|
|
|
|
|
2019-03-29 10:20:45 +00:00
|
|
|
elements = elements.map(get);
|
|
|
|
|
2018-08-22 08:51:07 +00:00
|
|
|
getBpmnJS().invoke(function(bpmnRules) {
|
2015-07-30 08:48:17 +00:00
|
|
|
|
2018-08-22 08:51:07 +00:00
|
|
|
target = get(target);
|
2015-07-30 08:48:17 +00:00
|
|
|
|
|
|
|
if ('attach' in rules) {
|
|
|
|
results.attach = bpmnRules.canAttach(elements, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('move' in rules) {
|
|
|
|
results.move = bpmnRules.canMove(elements, target);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(results).to.eql(rules);
|
2018-08-22 08:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve element, resolving an ID with
|
|
|
|
* the actual element.
|
|
|
|
*/
|
|
|
|
function get(element) {
|
|
|
|
|
|
|
|
var actualElement;
|
|
|
|
|
|
|
|
if (isString(element)) {
|
|
|
|
actualElement = getBpmnJS().invoke(function(elementRegistry) {
|
|
|
|
return elementRegistry.get(element);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!actualElement) {
|
|
|
|
throw new Error('element #' + element + ' not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
return actualElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
return element;
|
2018-04-02 19:01:53 +00:00
|
|
|
}
|