test(rules/Helper): accept actual elements
This commit is contained in:
parent
96c3f0f3a7
commit
8a6ab27b04
|
@ -2,18 +2,19 @@ import {
|
||||||
getBpmnJS
|
getBpmnJS
|
||||||
} from 'test/TestHelper';
|
} from 'test/TestHelper';
|
||||||
|
|
||||||
|
import {
|
||||||
|
isString
|
||||||
|
} from 'min-dash';
|
||||||
|
|
||||||
|
|
||||||
export function expectCanConnect(source, target, rules) {
|
export function expectCanConnect(source, target, rules) {
|
||||||
|
|
||||||
var results = {};
|
var results = {};
|
||||||
|
|
||||||
getBpmnJS().invoke(function(elementRegistry, bpmnRules) {
|
getBpmnJS().invoke(function(bpmnRules) {
|
||||||
|
|
||||||
source = elementRegistry.get(source);
|
source = get(source);
|
||||||
target = elementRegistry.get(target);
|
target = get(target);
|
||||||
|
|
||||||
expect(source).to.exist;
|
|
||||||
expect(target).to.exist;
|
|
||||||
|
|
||||||
if ('sequenceFlow' in rules) {
|
if ('sequenceFlow' in rules) {
|
||||||
results.sequenceFlow = bpmnRules.canConnectSequenceFlow(source, target);
|
results.sequenceFlow = bpmnRules.canConnectSequenceFlow(source, target);
|
||||||
|
@ -38,17 +39,8 @@ export function expectCanConnect(source, target, rules) {
|
||||||
|
|
||||||
export function expectCanDrop(element, target, expectedResult) {
|
export function expectCanDrop(element, target, expectedResult) {
|
||||||
|
|
||||||
var result;
|
var result = getBpmnJS().invoke(function(bpmnRules) {
|
||||||
|
return bpmnRules.canDrop(get(element), get(target));
|
||||||
getBpmnJS().invoke(function(elementRegistry, bpmnRules) {
|
|
||||||
|
|
||||||
element = elementRegistry.get(element);
|
|
||||||
target = elementRegistry.get(target);
|
|
||||||
|
|
||||||
expect(element).to.exist;
|
|
||||||
expect(target).to.exist;
|
|
||||||
|
|
||||||
result = bpmnRules.canDrop(element, target);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result).to.eql(expectedResult);
|
expect(result).to.eql(expectedResult);
|
||||||
|
@ -57,17 +49,8 @@ export function expectCanDrop(element, target, expectedResult) {
|
||||||
|
|
||||||
export function expectCanInsert(element, target, expectedResult) {
|
export function expectCanInsert(element, target, expectedResult) {
|
||||||
|
|
||||||
var result;
|
var result = getBpmnJS().invoke(function(bpmnRules) {
|
||||||
|
return bpmnRules.canInsert(get(element), get(target));
|
||||||
getBpmnJS().invoke(function(elementRegistry, bpmnRules) {
|
|
||||||
|
|
||||||
element = elementRegistry.get(element);
|
|
||||||
target = elementRegistry.get(target);
|
|
||||||
|
|
||||||
expect(element).to.exist;
|
|
||||||
expect(target).to.exist;
|
|
||||||
|
|
||||||
result = bpmnRules.canInsert(element, target);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result).to.eql(expectedResult);
|
expect(result).to.eql(expectedResult);
|
||||||
|
@ -78,9 +61,9 @@ export function expectCanMove(elements, target, rules) {
|
||||||
|
|
||||||
var results = {};
|
var results = {};
|
||||||
|
|
||||||
getBpmnJS().invoke(function(elementRegistry, bpmnRules) {
|
getBpmnJS().invoke(function(bpmnRules) {
|
||||||
|
|
||||||
target = elementRegistry.get(target);
|
target = get(target);
|
||||||
|
|
||||||
if ('attach' in rules) {
|
if ('attach' in rules) {
|
||||||
results.attach = bpmnRules.canAttach(elements, target);
|
results.attach = bpmnRules.canAttach(elements, target);
|
||||||
|
@ -93,3 +76,27 @@ export function expectCanMove(elements, target, rules) {
|
||||||
|
|
||||||
expect(results).to.eql(rules);
|
expect(results).to.eql(rules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
Loading…
Reference in New Issue