|
| 1 | +import TestContainer from 'mocha-test-container-support'; |
| 2 | + |
| 3 | +import { |
| 4 | + cleanup |
| 5 | +} from '@testing-library/preact/pure'; |
| 6 | + |
| 7 | +import { |
| 8 | + clearBpmnJS, |
| 9 | + setBpmnJS, |
| 10 | + insertCoreStyles, |
| 11 | + insertBpmnStyles, |
| 12 | + enableLogging |
| 13 | +} from 'test/TestHelper'; |
| 14 | + |
| 15 | +import { |
| 16 | + query as domQuery |
| 17 | +} from 'min-dom'; |
| 18 | + |
| 19 | +import Modeler from 'bpmn-js/lib/Modeler'; |
| 20 | +import NavigatedViewer from 'bpmn-js/lib/NavigatedViewer'; |
| 21 | + |
| 22 | +import BpmnPropertiesPanel from 'src/render'; |
| 23 | + |
| 24 | +import BpmnPropertiesProvider from 'src/provider/bpmn'; |
| 25 | +import ZeebePropertiesProvider from 'src/provider/zeebe'; |
| 26 | + |
| 27 | +import ZeebeModdle from 'zeebe-bpmn-moddle/resources/zeebe'; |
| 28 | + |
| 29 | +import TooltipProvider from 'src/contextProvider/zeebe/TooltipProvider'; |
| 30 | + |
| 31 | +import { |
| 32 | + insertCSS |
| 33 | +} from '../TestHelper'; |
| 34 | + |
| 35 | +insertCoreStyles(); |
| 36 | +insertBpmnStyles(); |
| 37 | + |
| 38 | +insertCSS('readonly-properties-panel', ` |
| 39 | + .bio-properties-panel-input, |
| 40 | + .bio-properties-panel-checkbox { |
| 41 | + pointer-events: none; |
| 42 | + } |
| 43 | +`); |
| 44 | + |
| 45 | + |
| 46 | +describe('<BpmnPropertiesPanelRenderer>', function() { |
| 47 | + |
| 48 | + afterEach(() => cleanup()); |
| 49 | + |
| 50 | + let modelerContainer; |
| 51 | + |
| 52 | + let propertiesContainer; |
| 53 | + |
| 54 | + let container; |
| 55 | + |
| 56 | + beforeEach(function() { |
| 57 | + modelerContainer = document.createElement('div'); |
| 58 | + modelerContainer.classList.add('modeler-container'); |
| 59 | + |
| 60 | + propertiesContainer = document.createElement('div'); |
| 61 | + propertiesContainer.classList.add('properties-container'); |
| 62 | + |
| 63 | + container = TestContainer.get(this); |
| 64 | + |
| 65 | + container.appendChild(modelerContainer); |
| 66 | + container.appendChild(propertiesContainer); |
| 67 | + }); |
| 68 | + |
| 69 | + async function createModeler(xml, options = {}, BpmnJS = Modeler) { |
| 70 | + const { |
| 71 | + shouldImport = true, |
| 72 | + additionalModules = [ |
| 73 | + BpmnPropertiesPanel, |
| 74 | + BpmnPropertiesProvider, |
| 75 | + ZeebePropertiesProvider |
| 76 | + ], |
| 77 | + moddleExtensions = { |
| 78 | + zeebe: ZeebeModdle |
| 79 | + }, |
| 80 | + description = {}, |
| 81 | + tooltip = {}, |
| 82 | + layout = {} |
| 83 | + } = options; |
| 84 | + |
| 85 | + clearBpmnJS(); |
| 86 | + |
| 87 | + const modeler = new BpmnJS({ |
| 88 | + container: modelerContainer, |
| 89 | + keyboard: { |
| 90 | + bindTo: document |
| 91 | + }, |
| 92 | + additionalModules, |
| 93 | + moddleExtensions, |
| 94 | + propertiesPanel: { |
| 95 | + parent: propertiesContainer, |
| 96 | + feelTooltipContainer: container, |
| 97 | + description, |
| 98 | + tooltip, |
| 99 | + layout |
| 100 | + }, |
| 101 | + ...options |
| 102 | + }); |
| 103 | + |
| 104 | + enableLogging && enableLogging(modeler); |
| 105 | + |
| 106 | + setBpmnJS(modeler); |
| 107 | + |
| 108 | + if (!shouldImport) { |
| 109 | + return { modeler }; |
| 110 | + } |
| 111 | + |
| 112 | + try { |
| 113 | + const result = await modeler.importXML(xml); |
| 114 | + |
| 115 | + return { error: null, warnings: result.warnings, modeler: modeler }; |
| 116 | + } catch (err) { |
| 117 | + return { error: err, warnings: err.warnings, modeler: modeler }; |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + |
| 122 | + it.only('should work with viewer', async function() { |
| 123 | + |
| 124 | + // given |
| 125 | + const diagramXml = require('test/fixtures/service-task.bpmn').default; |
| 126 | + |
| 127 | + const FakeModelingServicesModule = { |
| 128 | + commandStack: [ 'value', { |
| 129 | + registerHandler() { } |
| 130 | + } ], |
| 131 | + bpmnFactory: [ 'value', {} ], |
| 132 | + modeling: [ 'value', { |
| 133 | + updateProperties() { } |
| 134 | + } ] |
| 135 | + }; |
| 136 | + |
| 137 | + // when |
| 138 | + const result = await createModeler( |
| 139 | + diagramXml, |
| 140 | + { |
| 141 | + additionalModules: [ |
| 142 | + FakeModelingServicesModule, |
| 143 | + BpmnPropertiesPanel, |
| 144 | + BpmnPropertiesProvider, |
| 145 | + ZeebePropertiesProvider |
| 146 | + ], |
| 147 | + moddleExtensions: { |
| 148 | + zeebe: ZeebeModdle |
| 149 | + }, |
| 150 | + tooltip: TooltipProvider |
| 151 | + }, |
| 152 | + NavigatedViewer |
| 153 | + ); |
| 154 | + |
| 155 | + // then |
| 156 | + expect(result.error).not.to.exist; |
| 157 | + }); |
| 158 | + |
| 159 | +}); |
| 160 | + |
| 161 | + |
| 162 | +// helpers ///////////////////// |
| 163 | + |
| 164 | +// eslint-disable-next-line |
| 165 | +function getGroup(container, id) { |
| 166 | + return domQuery(`[data-group-id="group-${id}"`, container); |
| 167 | +} |
| 168 | + |
| 169 | +// eslint-disable-next-line |
| 170 | +function getHeaderName(container) { |
| 171 | + return domQuery('.bio-properties-panel-header-label', container).innerText; |
| 172 | +} |
| 173 | + |
| 174 | +// eslint-disable-next-line |
| 175 | +function getFeelPopup(container) { |
| 176 | + return domQuery('.bio-properties-panel-feel-popup', container); |
| 177 | +} |
| 178 | + |
| 179 | +// eslint-disable-next-line |
| 180 | +function getOpenFeelPopup(id, container) { |
| 181 | + return container.querySelector(`[data-entry-id="${id}"] .bio-properties-panel-open-feel-popup`); |
| 182 | +} |
0 commit comments