2022-07-11 17:09:25 +00:00
|
|
|
import { bootstrapPropertiesPanel } from './helpers';
|
2022-07-07 15:20:43 +00:00
|
|
|
import dataObjectInterceptor from '../../app/spiffworkflow/DataObject';
|
|
|
|
import { BpmnPropertiesPanelModule, BpmnPropertiesProviderModule } from 'bpmn-js-properties-panel';
|
|
|
|
import {
|
|
|
|
inject,
|
|
|
|
} from 'bpmn-js/test/helper';
|
2023-03-03 18:06:58 +00:00
|
|
|
import {
|
|
|
|
findDataObjects,
|
|
|
|
findDataObjectReferenceShapes,
|
|
|
|
idToHumanReadableName,
|
|
|
|
} from '../../app/spiffworkflow/DataObject/DataObjectHelpers';
|
2022-07-07 15:20:43 +00:00
|
|
|
|
|
|
|
describe('DataObject Interceptor', function() {
|
|
|
|
|
2022-07-11 15:00:19 +00:00
|
|
|
let xml = require('./bpmn/empty_diagram.bpmn').default;
|
2022-07-07 15:20:43 +00:00
|
|
|
|
|
|
|
beforeEach(bootstrapPropertiesPanel(xml, {
|
|
|
|
debounceInput: false,
|
|
|
|
additionalModules: [
|
|
|
|
dataObjectInterceptor,
|
|
|
|
BpmnPropertiesPanelModule,
|
|
|
|
BpmnPropertiesProviderModule,
|
|
|
|
]
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('New Data Object References should create a data object if none exist.', inject(function(canvas, modeling) {
|
|
|
|
|
|
|
|
// IF - a new dataObjectReference is created
|
|
|
|
let rootShape = canvas.getRootElement();
|
|
|
|
const dataObjectRefShape1 = modeling.createShape({ type: 'bpmn:DataObjectReference' },
|
|
|
|
{ x: 220, y: 220 }, rootShape);
|
|
|
|
|
|
|
|
// THEN - a new DataObject is also created.
|
|
|
|
const dataObjects = findDataObjects(rootShape.businessObject);
|
|
|
|
expect(dataObjects.length).to.equal(1);
|
|
|
|
expect(dataObjects[0]).to.equal(dataObjectRefShape1.businessObject.dataObjectRef);
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('New Data Object References should connect to the first available data Object if it exists', inject(function(canvas, modeling) {
|
|
|
|
|
|
|
|
// IF - two dataObjectReferences are created
|
|
|
|
let rootShape = canvas.getRootElement();
|
|
|
|
const dataObjectRefShape1 = modeling.createShape({ type: 'bpmn:DataObjectReference' },
|
|
|
|
{ x: 220, y: 220 }, rootShape);
|
|
|
|
const dataObjectRefShape2 = modeling.createShape({ type: 'bpmn:DataObjectReference' },
|
|
|
|
{ x: 320, y: 220 }, rootShape);
|
|
|
|
|
|
|
|
// THEN - only one new DataObject is created, and both references point to it..
|
|
|
|
const dataObjects = findDataObjects(rootShape.businessObject);
|
|
|
|
expect(dataObjects.length).to.equal(1);
|
|
|
|
expect(dataObjects[0]).to.equal(dataObjectRefShape1.businessObject.dataObjectRef);
|
|
|
|
expect(dataObjects[0]).to.equal(dataObjectRefShape2.businessObject.dataObjectRef);
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
2022-10-19 18:58:52 +00:00
|
|
|
it('Deleting a data object reference does not delete the data object, unless it is the last reference', inject(function(canvas, modeling) {
|
|
|
|
|
|
|
|
// IF - two dataObjectReferences are created
|
|
|
|
let rootShape = canvas.getRootElement();
|
|
|
|
const dataObjectRefShape1 = modeling.createShape({ type: 'bpmn:DataObjectReference' },
|
|
|
|
{ x: 220, y: 220 }, rootShape);
|
|
|
|
const dataObjectRefShape2 = modeling.createShape({ type: 'bpmn:DataObjectReference' },
|
|
|
|
{ x: 320, y: 220 }, rootShape);
|
|
|
|
|
|
|
|
// AND one is deleted
|
|
|
|
modeling.removeShape(dataObjectRefShape1)
|
|
|
|
|
|
|
|
// THEN - there is still a data object
|
|
|
|
const dataObjects = findDataObjects(rootShape.businessObject);
|
|
|
|
expect(dataObjects.length).to.equal(1);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('Deleting all the data references will also delete the data object', inject(function(canvas, modeling) {
|
|
|
|
|
|
|
|
// IF - two dataObjectReferences are created
|
|
|
|
let rootShape = canvas.getRootElement();
|
|
|
|
const dataObjectRefShape1 = modeling.createShape({ type: 'bpmn:DataObjectReference' },
|
|
|
|
{ x: 220, y: 220 }, rootShape);
|
|
|
|
const dataObjectRefShape2 = modeling.createShape({ type: 'bpmn:DataObjectReference' },
|
|
|
|
{ x: 320, y: 220 }, rootShape);
|
|
|
|
|
|
|
|
// AND both are deleted
|
|
|
|
modeling.removeShape(dataObjectRefShape1);
|
|
|
|
modeling.removeShape(dataObjectRefShape2);
|
|
|
|
|
|
|
|
// THEN - there is no data object
|
|
|
|
const dataObjects = findDataObjects(rootShape.businessObject);
|
|
|
|
expect(dataObjects.length).to.equal(0);
|
|
|
|
}));
|
|
|
|
|
2022-07-08 14:30:21 +00:00
|
|
|
it('Creating a new Reference will update the name to match the DataObject', inject(function(canvas, modeling) {
|
|
|
|
|
|
|
|
// IF - a Data Reference Exists
|
|
|
|
let rootShape = canvas.getRootElement();
|
|
|
|
const dataObjectRefShape1 = modeling.createShape({ type: 'bpmn:DataObjectReference' },
|
|
|
|
{ x: 220, y: 220 }, rootShape);
|
|
|
|
|
|
|
|
const dataObjects = findDataObjects(rootShape.businessObject);
|
2022-11-17 19:58:28 +00:00
|
|
|
const human_readable_name = idToHumanReadableName(dataObjects[0].id)
|
|
|
|
expect(dataObjectRefShape1.businessObject.name).to.equal(human_readable_name);
|
2022-07-08 14:30:21 +00:00
|
|
|
}));
|
|
|
|
|
2022-07-11 21:29:41 +00:00
|
|
|
it('should allow you to add a data object to a subprocess', inject(function(canvas, modeling, elementRegistry) {
|
2022-07-08 14:30:21 +00:00
|
|
|
|
2022-07-11 21:29:41 +00:00
|
|
|
// IF - A data object reference is added to a sup-process
|
|
|
|
let subProcessShape = elementRegistry.get('my_subprocess');
|
|
|
|
let subProcess = subProcessShape.businessObject;
|
|
|
|
let dataObjects = findDataObjects(subProcess);
|
|
|
|
expect(dataObjects.length).to.equal(0);
|
|
|
|
|
|
|
|
const dataObjectRefShape = modeling.createShape({ type: 'bpmn:DataObjectReference' },
|
|
|
|
{ x: 220, y: 220 }, subProcessShape);
|
|
|
|
|
|
|
|
// THEN - a new data object is visible in that SubProcess
|
|
|
|
dataObjects = findDataObjects(subProcess);
|
|
|
|
expect(dataObjects.length).to.equal(1);
|
|
|
|
}));
|
2022-07-08 14:30:21 +00:00
|
|
|
|
2023-03-03 18:06:58 +00:00
|
|
|
it('Data objects in a process should be visible in a subprocess', inject(function(canvas, modeling, elementRegistry) {
|
|
|
|
|
|
|
|
let subProcessShape = elementRegistry.get('my_subprocess');
|
|
|
|
let subProcess = subProcessShape.businessObject;
|
|
|
|
let dataObjects = findDataObjects(subProcess);
|
|
|
|
expect(dataObjects.length).to.equal(0);
|
|
|
|
|
|
|
|
let rootShape = canvas.getRootElement();
|
|
|
|
const dataObjectRefShape = modeling.createShape({ type: 'bpmn:DataObjectReference' },
|
|
|
|
{ x: 220, y: 220 }, rootShape);
|
|
|
|
|
|
|
|
dataObjects = findDataObjects(subProcess);
|
|
|
|
expect(dataObjects.length).to.equal(1);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('Data objects in a subprocess should not be visible in a process', inject(function(canvas, modeling, elementRegistry) {
|
|
|
|
|
|
|
|
let subProcessShape = elementRegistry.get('my_subprocess');
|
|
|
|
let subProcess = subProcessShape.businessObject;
|
|
|
|
const dataObjectRefShape = modeling.createShape({ type: 'bpmn:DataObjectReference' },
|
|
|
|
{ x: 220, y: 220 }, subProcessShape);
|
|
|
|
|
|
|
|
let dataObjects = findDataObjects(subProcess);
|
|
|
|
expect(dataObjects.length).to.equal(1);
|
|
|
|
|
|
|
|
let rootShape = canvas.getRootElement();
|
|
|
|
dataObjects = findDataObjects(rootShape);
|
|
|
|
expect(dataObjects.length).to.equal(0);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('References inside subprocesses should be visible in a process', inject(function(canvas, modeling, elementRegistry) {
|
|
|
|
|
|
|
|
let rootShape = canvas.getRootElement();
|
|
|
|
const refOne = modeling.createShape({ type: 'bpmn:DataObjectReference' },
|
|
|
|
{ x: 220, y: 220 }, rootShape);
|
|
|
|
|
|
|
|
let subProcessShape = elementRegistry.get('my_subprocess');
|
|
|
|
let subProcess = subProcessShape.businessObject;
|
|
|
|
const refTwo = modeling.createShape({ type: 'bpmn:DataObjectReference' },
|
|
|
|
{ x: 320, y: 220 }, subProcessShape);
|
|
|
|
|
|
|
|
let dataObjects = findDataObjects(subProcess);
|
|
|
|
expect(dataObjects.length).to.equal(1);
|
|
|
|
let references = findDataObjectReferenceShapes(rootShape.children, dataObjects[0].id);
|
|
|
|
expect(references.length).to.equal(2);
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
2022-07-07 15:20:43 +00:00
|
|
|
});
|