spiff-arena/test/spec/UserTaskPropsSpec.js

164 lines
6.2 KiB
JavaScript
Raw Normal View History

import {
BpmnPropertiesPanelModule,
BpmnPropertiesProviderModule,
} from 'bpmn-js-properties-panel';
import { getBpmnJS } from 'bpmn-js/test/helper';
import { getBusinessObject } from 'bpmn-js/lib/util/ModelUtil';
import TestContainer from 'mocha-test-container-support';
import spiffModdleExtension from '../../app/spiffworkflow/moddle/spiffworkflow.json';
import {getExtensionProperty, getExtensionValue} from '../../app/spiffworkflow/extensions/extensionHelpers';
import {
bootstrapPropertiesPanel,
changeInput,
expectSelected, findButton,
findEntry,
findGroupEntry,
findInput,
findSelect, pressButton,
} from './helpers';
import extensions from '../../app/spiffworkflow/extensions';
import {query as domQuery} from 'min-dom';
Squashed 'bpmn-js-spiffworkflow/' changes from 9dcca6c80..6007a770a 6007a770a fix typo aa524120b Merge pull request #47 from sartography/dependabot/github_actions/crazy-max/ghaction-github-labeler-5.0.0 75556c020 Bump crazy-max/ghaction-github-labeler from 4.2.0 to 5.0.0 9a5c333de Merge pull request #46 from sartography/feature/better_form_nav c6c955284 Merge pull request #43 from sartography/bugfix/update-data-input-output-specs 094c573e0 fixing a test. 5fcb47125 Assume established naming conventions over requiring a form schema and ui schema each time as separate inputs. Making this one dropdown for the user form instead of two. 53f45dbaa Merge pull request #45 from sartography/dependabot/github_actions/actions/checkout-4 67765a994 Bump actions/checkout from 3 to 4 dbcd66942 Merge pull request #44 from sartography/dependabot/github_actions/crazy-max/ghaction-github-labeler-4.2.0 b8be0e335 Bump crazy-max/ghaction-github-labeler from 4.1.0 to 4.2.0 7743372d2 update iospec to include refs in input/output sets 6e17bda37 use same version of bpmn-js as arena 2c7fca88f missed a type in spiffworkflow.json d62f021e3 Merge pull request #42 from sartography/bugfix/lowercase-overridden-tags c625980c5 update extension names e92ae2f5a make sure tags with extensions are written to xml correctly eb37b6d29 Merge pull request #41 from sartography/feature/guest_form_submission 1b390c46c added panel extensions for guest access to human tasks w/ burnettk f01bece04 Merge pull request #40 from sartography/feature/multiinstance-improvements b8179146b allow attaching pre/post scripts to MI task or instance tasks git-subtree-dir: bpmn-js-spiffworkflow git-subtree-split: 6007a770a5938c993173001a013116cedfc80359
2023-10-14 12:30:16 -04:00
describe('Properties Panel for User Tasks', function () {
const user_form_xml = require('./bpmn/user_form.bpmn').default;
const diagram_xml = require('./bpmn/diagram.bpmn').default;
let container;
beforeEach(function () {
container = TestContainer.get(this);
});
function addOptionsToEventBus(bpmnModeler) {
Squashed 'bpmn-js-spiffworkflow/' changes from 9dcca6c80..6007a770a 6007a770a fix typo aa524120b Merge pull request #47 from sartography/dependabot/github_actions/crazy-max/ghaction-github-labeler-5.0.0 75556c020 Bump crazy-max/ghaction-github-labeler from 4.2.0 to 5.0.0 9a5c333de Merge pull request #46 from sartography/feature/better_form_nav c6c955284 Merge pull request #43 from sartography/bugfix/update-data-input-output-specs 094c573e0 fixing a test. 5fcb47125 Assume established naming conventions over requiring a form schema and ui schema each time as separate inputs. Making this one dropdown for the user form instead of two. 53f45dbaa Merge pull request #45 from sartography/dependabot/github_actions/actions/checkout-4 67765a994 Bump actions/checkout from 3 to 4 dbcd66942 Merge pull request #44 from sartography/dependabot/github_actions/crazy-max/ghaction-github-labeler-4.2.0 b8be0e335 Bump crazy-max/ghaction-github-labeler from 4.1.0 to 4.2.0 7743372d2 update iospec to include refs in input/output sets 6e17bda37 use same version of bpmn-js as arena 2c7fca88f missed a type in spiffworkflow.json d62f021e3 Merge pull request #42 from sartography/bugfix/lowercase-overridden-tags c625980c5 update extension names e92ae2f5a make sure tags with extensions are written to xml correctly eb37b6d29 Merge pull request #41 from sartography/feature/guest_form_submission 1b390c46c added panel extensions for guest access to human tasks w/ burnettk f01bece04 Merge pull request #40 from sartography/feature/multiinstance-improvements b8179146b allow attaching pre/post scripts to MI task or instance tasks git-subtree-dir: bpmn-js-spiffworkflow git-subtree-split: 6007a770a5938c993173001a013116cedfc80359
2023-10-14 12:30:16 -04:00
bpmnModeler.on('spiff.json_schema_files.requested', (event) => {
event.eventBus.fire('spiff.json_schema_files.returned', {
options: [
{ label: 'pizza_form.json', value: 'pizza_form.json' },
{ label: 'credit_card_form.json', value: 'credit_card_form.json' },
{ label: 'give_me_a_number_form.json', value: 'give_me_a_number_form.json' },
{ label: 'number_form_schema.json', value: 'number_form_schema.json' },
],
});
});
}
function preparePropertiesPanelWithXml(xml) {
return bootstrapPropertiesPanel(xml, {
container,
debounceInput: false,
additionalModules: [
extensions,
BpmnPropertiesPanelModule,
BpmnPropertiesProviderModule,
],
moddleExtensions: {
spiffworkflow: spiffModdleExtension,
},
});
}
it('should display a panel for setting the web form properties', async function () {
await preparePropertiesPanelWithXml(user_form_xml)();
// IF - you select a user task
const userTask = await expectSelected('my_user_task');
expect(userTask).to.exist;
// THEN - a property panel exists with a section for editing web forms
const group = findGroupEntry('user_task_properties', container);
expect(group).to.exist;
});
it('should allow you to select a json file.', async function () {
await preparePropertiesPanelWithXml(user_form_xml)();
const modeler = getBpmnJS();
addOptionsToEventBus(modeler);
// IF - you select a user task and change the formJsonSchemaFilename text field
const userTask = await expectSelected('my_user_task');
const group = findGroupEntry('user_task_properties', container);
const entry = findEntry('extension_formJsonSchemaFilename', group);
const selectList = findSelect(entry);
expect(selectList).to.exist;
Squashed 'bpmn-js-spiffworkflow/' changes from 9dcca6c80..6007a770a 6007a770a fix typo aa524120b Merge pull request #47 from sartography/dependabot/github_actions/crazy-max/ghaction-github-labeler-5.0.0 75556c020 Bump crazy-max/ghaction-github-labeler from 4.2.0 to 5.0.0 9a5c333de Merge pull request #46 from sartography/feature/better_form_nav c6c955284 Merge pull request #43 from sartography/bugfix/update-data-input-output-specs 094c573e0 fixing a test. 5fcb47125 Assume established naming conventions over requiring a form schema and ui schema each time as separate inputs. Making this one dropdown for the user form instead of two. 53f45dbaa Merge pull request #45 from sartography/dependabot/github_actions/actions/checkout-4 67765a994 Bump actions/checkout from 3 to 4 dbcd66942 Merge pull request #44 from sartography/dependabot/github_actions/crazy-max/ghaction-github-labeler-4.2.0 b8be0e335 Bump crazy-max/ghaction-github-labeler from 4.1.0 to 4.2.0 7743372d2 update iospec to include refs in input/output sets 6e17bda37 use same version of bpmn-js as arena 2c7fca88f missed a type in spiffworkflow.json d62f021e3 Merge pull request #42 from sartography/bugfix/lowercase-overridden-tags c625980c5 update extension names e92ae2f5a make sure tags with extensions are written to xml correctly eb37b6d29 Merge pull request #41 from sartography/feature/guest_form_submission 1b390c46c added panel extensions for guest access to human tasks w/ burnettk f01bece04 Merge pull request #40 from sartography/feature/multiinstance-improvements b8179146b allow attaching pre/post scripts to MI task or instance tasks git-subtree-dir: bpmn-js-spiffworkflow git-subtree-split: 6007a770a5938c993173001a013116cedfc80359
2023-10-14 12:30:16 -04:00
expect(selectList.options.length).to.equal(5); // including the empty option
expect(selectList.options[0].label).to.equal('');
expect(selectList.options[1].label).to.equal('pizza_form.json');
expect(selectList.options[2].label).to.equal('credit_card_form.json');
changeInput(selectList, 'pizza_form.json');
// THEN - the input is updated.
const businessObject = getBusinessObject(userTask);
expect(businessObject.extensionElements).to.exist;
const properties = businessObject.extensionElements.values[1];
expect(properties.properties).to.exist;
const property = properties.properties[0];
expect(property.value).to.equal('pizza_form.json');
expect(property.name).to.equal('formJsonSchemaFilename');
});
it('should parse the spiffworkflow:properties tag when you open an existing file', async function () {
await preparePropertiesPanelWithXml(diagram_xml)();
const modeler = getBpmnJS();
addOptionsToEventBus(modeler);
// IF - a user tag is selected, and you change the script in the properties panel
await expectSelected('task_confirm');
const group = findGroupEntry('user_task_properties', container);
const formJsonSchemaFilenameEntry = findEntry('extension_formJsonSchemaFilename', group);
const formJsonSchemaFilenameInput = findSelect(formJsonSchemaFilenameEntry);
expect(formJsonSchemaFilenameInput.value).to.equal('give_me_a_number_form.json');
Squashed 'bpmn-js-spiffworkflow/' changes from 9dcca6c80..6007a770a 6007a770a fix typo aa524120b Merge pull request #47 from sartography/dependabot/github_actions/crazy-max/ghaction-github-labeler-5.0.0 75556c020 Bump crazy-max/ghaction-github-labeler from 4.2.0 to 5.0.0 9a5c333de Merge pull request #46 from sartography/feature/better_form_nav c6c955284 Merge pull request #43 from sartography/bugfix/update-data-input-output-specs 094c573e0 fixing a test. 5fcb47125 Assume established naming conventions over requiring a form schema and ui schema each time as separate inputs. Making this one dropdown for the user form instead of two. 53f45dbaa Merge pull request #45 from sartography/dependabot/github_actions/actions/checkout-4 67765a994 Bump actions/checkout from 3 to 4 dbcd66942 Merge pull request #44 from sartography/dependabot/github_actions/crazy-max/ghaction-github-labeler-4.2.0 b8be0e335 Bump crazy-max/ghaction-github-labeler from 4.1.0 to 4.2.0 7743372d2 update iospec to include refs in input/output sets 6e17bda37 use same version of bpmn-js as arena 2c7fca88f missed a type in spiffworkflow.json d62f021e3 Merge pull request #42 from sartography/bugfix/lowercase-overridden-tags c625980c5 update extension names e92ae2f5a make sure tags with extensions are written to xml correctly eb37b6d29 Merge pull request #41 from sartography/feature/guest_form_submission 1b390c46c added panel extensions for guest access to human tasks w/ burnettk f01bece04 Merge pull request #40 from sartography/feature/multiinstance-improvements b8179146b allow attaching pre/post scripts to MI task or instance tasks git-subtree-dir: bpmn-js-spiffworkflow git-subtree-split: 6007a770a5938c993173001a013116cedfc80359
2023-10-14 12:30:16 -04:00
});
it('should update both the json and ui extensions if the json file is set', async function () {
await preparePropertiesPanelWithXml(diagram_xml)();
const modeler = getBpmnJS();
addOptionsToEventBus(modeler);
const userElement = await expectSelected('task_confirm');
const group = findGroupEntry('user_task_properties', container);
const button = findButton(
'launch_editor_button_formJsonSchemaFilename',
group
);
expect(button).to.exist;
let launchEvent;
let eventBus = modeler.get('eventBus');
eventBus.on('spiff.file.edit', function (event) {
launchEvent = event;
});
await pressButton(button);
expect(launchEvent.value).to.exist;
eventBus.fire('spiff.jsonSchema.update', {
value: 'new-schema.json',
});
const jsonFile = getExtensionValue(userElement, 'formJsonSchemaFilename');
const uiFile = getExtensionValue(userElement, 'formUiSchemaFilename');
expect(jsonFile).to.equal('new-schema.json');
expect(uiFile).to.equal('new-uischema.json');
});
it('should allow you to change the instructions to the end user', async function () {
// If a user task is selected
await preparePropertiesPanelWithXml(diagram_xml)();
const modeler = getBpmnJS();
addOptionsToEventBus(modeler);
// AND the value of the instructions is changed
const userElement = await expectSelected('task_confirm');
const group = findGroupEntry('instructions', container);
const input = domQuery('textarea', group);
changeInput(input, '#Hello!');
// THEN - the script tag in the BPMN Business object / XML is updated as well.
const businessObject = getBusinessObject(userElement);
// The change is reflected in the business object
let instructions = getExtensionValue(
userElement,
Squashed 'bpmn-js-spiffworkflow/' changes from 9dcca6c80..6007a770a 6007a770a fix typo aa524120b Merge pull request #47 from sartography/dependabot/github_actions/crazy-max/ghaction-github-labeler-5.0.0 75556c020 Bump crazy-max/ghaction-github-labeler from 4.2.0 to 5.0.0 9a5c333de Merge pull request #46 from sartography/feature/better_form_nav c6c955284 Merge pull request #43 from sartography/bugfix/update-data-input-output-specs 094c573e0 fixing a test. 5fcb47125 Assume established naming conventions over requiring a form schema and ui schema each time as separate inputs. Making this one dropdown for the user form instead of two. 53f45dbaa Merge pull request #45 from sartography/dependabot/github_actions/actions/checkout-4 67765a994 Bump actions/checkout from 3 to 4 dbcd66942 Merge pull request #44 from sartography/dependabot/github_actions/crazy-max/ghaction-github-labeler-4.2.0 b8be0e335 Bump crazy-max/ghaction-github-labeler from 4.1.0 to 4.2.0 7743372d2 update iospec to include refs in input/output sets 6e17bda37 use same version of bpmn-js as arena 2c7fca88f missed a type in spiffworkflow.json d62f021e3 Merge pull request #42 from sartography/bugfix/lowercase-overridden-tags c625980c5 update extension names e92ae2f5a make sure tags with extensions are written to xml correctly eb37b6d29 Merge pull request #41 from sartography/feature/guest_form_submission 1b390c46c added panel extensions for guest access to human tasks w/ burnettk f01bece04 Merge pull request #40 from sartography/feature/multiinstance-improvements b8179146b allow attaching pre/post scripts to MI task or instance tasks git-subtree-dir: bpmn-js-spiffworkflow git-subtree-split: 6007a770a5938c993173001a013116cedfc80359
2023-10-14 12:30:16 -04:00
'spiffworkflow:InstructionsForEndUser'
);
expect(instructions).to.equal('#Hello!');
});
});