bpmn-js-properties-panel
Version:
A simple properties panel for bpmn-js
363 lines (229 loc) • 8.77 kB
JavaScript
;
var TestHelper = require('../../../TestHelper');
var TestContainer = require('mocha-test-container-support');
/* global bootstrapModeler, inject */
var propertiesPanelModule = require('../../../../lib'),
coreModule = require('bpmn-js/lib/core'),
selectionModule = require('diagram-js/lib/features/selection'),
modelingModule = require('bpmn-js/lib/features/modeling'),
propertiesProviderModule = require('../../../../lib/provider/camunda'),
camundaModdlePackage = require('camunda-bpmn-moddle/resources/camunda');
var ModelUtil = require('bpmn-js/lib/util/ModelUtil'),
is = ModelUtil.is,
getBusinessObject = ModelUtil.getBusinessObject;
var extensionElementsHelper = require('../../../../lib/helper/ExtensionElementsHelper');
var domQuery = require('min-dom/lib/query');
// MODEL HELPER
function getElements(bo, type, prop) {
var elems = extensionElementsHelper.getExtensionElements(bo, type) || [];
return !prop ? elems : (elems[0] || {})[prop] || [];
}
function getInputParameters(bo) {
return getParameters(bo, 'inputParameters');
}
function getParameters(bo, prop) {
return getElements(bo, 'camunda:InputOutput', prop);
}
// DOM HELPER
function getInputOutputTab(container) {
return domQuery('div[data-tab="input-output"]', container);
}
function getParameterTypeSelect(container) {
return domQuery('select[id="camunda-parameterType-select"]', getInputOutputTab(container));
}
// input parameter
function getInputParameterSelect(container) {
return getSelect('inputs', container);
}
function selectInputParameter(idx, container) {
var selectBox = getInputParameterSelect(container);
selectBox.options[idx].selected = 'selected';
TestHelper.triggerEvent(selectBox, 'change');
}
// helper
function getSelect(suffix, container) {
return domQuery('select[id=cam-extensionElements-' + suffix + ']', getInputOutputTab(container));
}
describe('input-output-parameterType-script', function() {
var diagramXML = require('./InputOutput.bpmn');
var testModules = [
coreModule, selectionModule, modelingModule,
propertiesPanelModule,
propertiesProviderModule
];
var container;
beforeEach(function() {
container = TestContainer.get(this);
});
beforeEach(bootstrapModeler(diagramXML, {
modules: testModules,
moddleExtensions: { camunda: camundaModdlePackage }
}));
beforeEach(inject(function(commandStack, propertiesPanel) {
var undoButton = document.createElement('button');
undoButton.textContent = 'UNDO';
undoButton.addEventListener('click', function() {
commandStack.undo();
});
container.appendChild(undoButton);
propertiesPanel.attachTo(container);
}));
describe('change parameter type script ', function(propertiesPanel) {
var parameter,
parameterTypeSelect;
beforeEach(inject(function(propertiesPanel, elementRegistry, selection) {
// given
var container = propertiesPanel._container;
var shape = elementRegistry.get('WITH_INPUT_OUTPUT_PARAMS');
selection.select(shape);
// select first parameter
selectInputParameter(1, container);
parameter = getInputParameters(getBusinessObject(shape))[1];
parameterTypeSelect = getParameterTypeSelect(container);
}));
describe('to text', function() {
beforeEach(function() {
// when
parameterTypeSelect.options[0].selected = 'selected';
TestHelper.triggerEvent(parameterTypeSelect, 'change');
});
describe('in the DOM', function() {
it('should execute', function() {
// then
expect(parameterTypeSelect.value).to.equal('text');
});
it('should undo', inject(function(commandStack) {
// when
commandStack.undo();
// then
expect(parameterTypeSelect.value).to.equal('script');
}));
it('should redo', inject(function(commandStack) {
// when
commandStack.undo();
commandStack.redo();
// then
expect(parameterTypeSelect.value).to.equal('text');
}));
});
describe('on the business object', function() {
it('should execute', function() {
// then
expect(parameter.value).to.be.undefined;
expect(parameter.definition).to.be.undefined;
});
it('should undo', inject(function(commandStack) {
// when
commandStack.undo();
// then
expect(parameter.value).to.be.undefined;
expect(is(parameter.definition, 'camunda:Script')).to.be.true;
}));
it('should redo', inject(function(commandStack) {
// when
commandStack.undo();
commandStack.redo();
// then
expect(parameter.value).to.be.undefined;
expect(parameter.definition).to.be.undefined;
}));
});
});
describe('to list', function() {
beforeEach(function() {
// when
parameterTypeSelect.options[2].selected = 'selected';
TestHelper.triggerEvent(parameterTypeSelect, 'change');
});
describe('in the DOM', function() {
it('should execute', function() {
// then
expect(parameterTypeSelect.value).to.equal('list');
});
it('should undo', inject(function(commandStack) {
// when
commandStack.undo();
// then
expect(parameterTypeSelect.value).to.equal('script');
}));
it('should redo', inject(function(commandStack) {
// when
commandStack.undo();
commandStack.redo();
// then
expect(parameterTypeSelect.value).to.equal('list');
}));
});
describe('on the business object', function() {
it('should execute', function() {
// then
expect(parameter.value).to.be.undefined;
expect(is(parameter.definition, 'camunda:List')).to.be.true;
});
it('should undo', inject(function(commandStack) {
// when
commandStack.undo();
// then
expect(parameter.value).to.be.undefined;
expect(is(parameter.definition, 'camunda:Script')).to.be.true;
}));
it('should redo', inject(function(commandStack) {
// when
commandStack.undo();
commandStack.redo();
// then
expect(parameter.value).to.be.undefined;
expect(is(parameter.definition, 'camunda:List')).to.be.true;
}));
});
});
describe('to map', function() {
beforeEach(function() {
// when
parameterTypeSelect.options[3].selected = 'selected';
TestHelper.triggerEvent(parameterTypeSelect, 'change');
});
describe('in the DOM', function() {
it('should execute', function() {
// then
expect(parameterTypeSelect.value).to.equal('map');
});
it('should undo', inject(function(commandStack) {
// when
commandStack.undo();
// then
expect(parameterTypeSelect.value).to.equal('script');
}));
it('should redo', inject(function(commandStack) {
// when
commandStack.undo();
commandStack.redo();
// then
expect(parameterTypeSelect.value).to.equal('map');
}));
});
describe('on the business object', function() {
it('should execute', function() {
// then
expect(parameter.value).to.be.undefined;
expect(is(parameter.definition, 'camunda:Map')).to.be.true;
});
it('should undo', inject(function(commandStack) {
// when
commandStack.undo();
// then
expect(parameter.value).to.be.undefined;
expect(is(parameter.definition, 'camunda:Script')).to.be.true;
}));
it('should redo', inject(function(commandStack) {
// when
commandStack.undo();
commandStack.redo();
// then
expect(parameter.value).to.be.undefined;
expect(is(parameter.definition, 'camunda:Map')).to.be.true;
}));
});
});
});
});