2022-08-30 18:31:50 +00:00
|
|
|
import { query as domQuery } from 'min-dom';
|
2022-07-01 17:01:52 +00:00
|
|
|
import { act, fireEvent } from '@testing-library/preact';
|
2022-06-30 18:02:38 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
getBpmnJS,
|
2022-08-30 18:31:50 +00:00
|
|
|
bootstrapBpmnJS,
|
|
|
|
inject,
|
|
|
|
insertCSS,
|
2022-06-30 18:02:38 +00:00
|
|
|
} from 'bpmn-js/test/helper';
|
|
|
|
import Modeler from 'bpmn-js/lib/Modeler';
|
|
|
|
import TestContainer from 'mocha-test-container-support';
|
2022-08-30 18:31:50 +00:00
|
|
|
import { getBusinessObject } from 'bpmn-js/lib/util/ModelUtil';
|
|
|
|
import { createMoveEvent } from 'diagram-js/lib/features/mouse/Mouse';
|
2022-06-30 18:02:38 +00:00
|
|
|
|
2022-08-08 20:08:44 +00:00
|
|
|
export let PROPERTIES_PANEL_CONTAINER;
|
|
|
|
export let CONTAINER;
|
2022-06-30 18:02:38 +00:00
|
|
|
|
|
|
|
export function bootstrapPropertiesPanel(diagram, options, locals) {
|
2022-08-30 18:31:50 +00:00
|
|
|
return async function () {
|
|
|
|
let { container } = options;
|
2022-07-13 16:29:35 +00:00
|
|
|
if (!container) {
|
|
|
|
container = TestContainer.get(this);
|
|
|
|
}
|
2022-08-30 18:31:50 +00:00
|
|
|
CONTAINER = container;
|
2022-06-30 18:02:38 +00:00
|
|
|
|
|
|
|
insertBpmnStyles();
|
|
|
|
insertCoreStyles();
|
|
|
|
const createModeler = bootstrapBpmnJS(Modeler, diagram, options, locals);
|
|
|
|
await act(() => createModeler.call(this));
|
|
|
|
|
|
|
|
// (2) clean-up properties panel
|
|
|
|
clearPropertiesPanelContainer();
|
|
|
|
|
|
|
|
// (3) attach properties panel
|
2022-08-30 18:31:50 +00:00
|
|
|
const attachPropertiesPanel = inject(function (propertiesPanel) {
|
2022-06-30 18:02:38 +00:00
|
|
|
PROPERTIES_PANEL_CONTAINER = document.createElement('div');
|
|
|
|
PROPERTIES_PANEL_CONTAINER.classList.add('properties-container');
|
|
|
|
|
2022-07-01 17:01:52 +00:00
|
|
|
container.appendChild(PROPERTIES_PANEL_CONTAINER);
|
2022-06-30 18:02:38 +00:00
|
|
|
|
|
|
|
return act(() => propertiesPanel.attachTo(PROPERTIES_PANEL_CONTAINER));
|
|
|
|
});
|
|
|
|
await attachPropertiesPanel();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function clearPropertiesPanelContainer() {
|
|
|
|
if (PROPERTIES_PANEL_CONTAINER) {
|
|
|
|
PROPERTIES_PANEL_CONTAINER.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function insertCoreStyles() {
|
|
|
|
insertCSS(
|
|
|
|
'properties-panel.css',
|
|
|
|
require('bpmn-js-properties-panel/dist/assets/properties-panel.css').default
|
|
|
|
);
|
2022-08-30 18:31:50 +00:00
|
|
|
insertCSS('test.css', require('./test.css').default);
|
2022-06-30 18:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function insertBpmnStyles() {
|
|
|
|
insertCSS(
|
|
|
|
'diagram.css',
|
|
|
|
require('bpmn-js/dist/assets/diagram-js.css').default
|
|
|
|
);
|
|
|
|
|
|
|
|
// @barmac: this fails before bpmn-js@9
|
2022-08-30 18:31:50 +00:00
|
|
|
insertCSS('bpmn-js.css', require('bpmn-js/dist/assets/bpmn-js.css').default);
|
2022-06-30 18:02:38 +00:00
|
|
|
|
|
|
|
insertCSS(
|
|
|
|
'bpmn-font.css',
|
|
|
|
require('bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css').default
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function expectSelected(id) {
|
2022-08-30 18:31:50 +00:00
|
|
|
return getBpmnJS().invoke(async function (elementRegistry, selection) {
|
2022-06-30 18:02:38 +00:00
|
|
|
const element = elementRegistry.get(id);
|
|
|
|
|
|
|
|
await act(() => {
|
|
|
|
selection.select(element);
|
|
|
|
});
|
|
|
|
|
|
|
|
return element;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-01 17:01:52 +00:00
|
|
|
export function getPropertiesPanel() {
|
|
|
|
return PROPERTIES_PANEL_CONTAINER;
|
|
|
|
}
|
|
|
|
|
2022-06-30 18:02:38 +00:00
|
|
|
export function findEntry(id, container) {
|
2022-08-30 18:31:50 +00:00
|
|
|
return domQuery(`[data-entry-id='${id}']`, container);
|
2022-06-30 18:02:38 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 17:44:02 +00:00
|
|
|
export function findGroupEntry(id, container) {
|
2022-08-30 18:31:50 +00:00
|
|
|
return domQuery(`[data-group-id='group-${id}']`, container);
|
2022-07-05 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 18:02:38 +00:00
|
|
|
export function findInput(type, container) {
|
2022-08-30 18:31:50 +00:00
|
|
|
return domQuery(`input[type='${type}']`, container);
|
2022-06-30 18:02:38 +00:00
|
|
|
}
|
|
|
|
|
2022-08-09 17:56:12 +00:00
|
|
|
export function findTextarea(id, container) {
|
2022-08-30 18:31:50 +00:00
|
|
|
return domQuery(`textarea[id='${id}']`, container);
|
2022-08-09 17:56:12 +00:00
|
|
|
}
|
|
|
|
|
2022-07-06 17:25:53 +00:00
|
|
|
export function findButton(id, container) {
|
2022-08-30 18:31:50 +00:00
|
|
|
return domQuery(`button[id='${id}']`, container);
|
2022-07-06 17:25:53 +00:00
|
|
|
}
|
|
|
|
|
2022-08-16 15:11:16 +00:00
|
|
|
export function findButtonByClass(buttonClass, container) {
|
2022-08-30 18:31:50 +00:00
|
|
|
return domQuery(`button[class='${buttonClass}']`, container);
|
2022-08-16 15:11:16 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 18:02:38 +00:00
|
|
|
export function findSelect(container) {
|
|
|
|
return domQuery('select', container);
|
|
|
|
}
|
|
|
|
|
2022-07-01 17:01:52 +00:00
|
|
|
export function changeInput(input, value) {
|
|
|
|
fireEvent.input(input, { target: { value } });
|
|
|
|
}
|
|
|
|
|
2022-07-06 17:25:53 +00:00
|
|
|
export function pressButton(button) {
|
|
|
|
fireEvent.click(button);
|
|
|
|
}
|
2022-07-01 17:01:52 +00:00
|
|
|
|
2022-08-16 15:11:16 +00:00
|
|
|
export function findDivByClass(divClass, container) {
|
2022-08-30 18:31:50 +00:00
|
|
|
return domQuery(`div[class='${divClass}']`, container);
|
2022-08-16 15:11:16 +00:00
|
|
|
}
|
|
|
|
|
2022-07-07 15:20:43 +00:00
|
|
|
/**
|
|
|
|
* Drags an element from the palette onto the canvas.
|
|
|
|
* @param id
|
|
|
|
*/
|
|
|
|
export function triggerPaletteEntry(id) {
|
2022-08-30 18:31:50 +00:00
|
|
|
getBpmnJS().invoke(function (palette) {
|
|
|
|
const entry = palette.getEntries()[id];
|
2022-07-07 15:20:43 +00:00
|
|
|
|
|
|
|
if (entry && entry.action && entry.action.click) {
|
|
|
|
entry.action.click(createMoveEvent(0, 0));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|