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 {
|
2019-08-06 16:57:30 +00:00
|
|
|
isArray,
|
|
|
|
isString,
|
|
|
|
map
|
2018-08-22 08:51:07 +00:00
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-06 16:57:30 +00:00
|
|
|
export function expectCanCreate(shape, target, expectedResult) {
|
2019-07-22 11:53:45 +00:00
|
|
|
|
2019-08-06 16:57:30 +00:00
|
|
|
var result = getBpmnJS().invoke(function(rules) {
|
|
|
|
|
|
|
|
if (isArray(shape)) {
|
|
|
|
return rules.allowed('elements.create', {
|
|
|
|
elements: get(shape),
|
|
|
|
target: get(target)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return rules.allowed('shape.create', {
|
|
|
|
shape: get(shape),
|
|
|
|
target: get(target)
|
|
|
|
});
|
2019-07-22 11:53:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(result).to.eql(expectedResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-08 08:50:05 +00:00
|
|
|
export function expectCanCopy(element, elements, expectedResult) {
|
|
|
|
|
|
|
|
var result = getBpmnJS().invoke(function(rules) {
|
|
|
|
return rules.allowed('element.copy', {
|
|
|
|
element: element,
|
|
|
|
elements: elements
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2019-08-06 16:57:30 +00:00
|
|
|
function get(elementId) {
|
|
|
|
|
|
|
|
if (isArray(elementId)) {
|
|
|
|
return map(elementId, get);
|
|
|
|
}
|
2018-08-22 08:51:07 +00:00
|
|
|
|
2019-08-06 16:57:30 +00:00
|
|
|
var element;
|
2018-08-22 08:51:07 +00:00
|
|
|
|
2019-08-06 16:57:30 +00:00
|
|
|
if (isString(elementId)) {
|
|
|
|
element = getBpmnJS().invoke(function(elementRegistry) {
|
|
|
|
return elementRegistry.get(elementId);
|
2018-08-22 08:51:07 +00:00
|
|
|
});
|
|
|
|
|
2019-08-06 16:57:30 +00:00
|
|
|
if (!element) {
|
|
|
|
throw new Error('element #' + elementId + ' not found');
|
2018-08-22 08:51:07 +00:00
|
|
|
}
|
|
|
|
|
2019-08-06 16:57:30 +00:00
|
|
|
return element;
|
2018-08-22 08:51:07 +00:00
|
|
|
}
|
|
|
|
|
2019-08-06 16:57:30 +00:00
|
|
|
return elementId;
|
2018-04-02 19:01:53 +00:00
|
|
|
}
|