Skip to content

Commit

Permalink
FOOP
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Feb 16, 2024
1 parent b12664a commit 640a1d1
Show file tree
Hide file tree
Showing 5 changed files with 441 additions and 447 deletions.
99 changes: 18 additions & 81 deletions test/TestHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {
insertCSS
} from 'bpmn-js/test/helper';

import semver from 'semver';

import fileDrop from 'file-drops';

import download from 'downloadjs';
Expand All @@ -25,6 +23,16 @@ import zeebeModdle from 'zeebe-bpmn-moddle/resources/zeebe';

import propertiesPanelCSS from '@bpmn-io/properties-panel/dist/assets/properties-panel.css';

import elementTemplatesCSS from '../assets/element-templates.css';
import elementTemplateChooserCSS from '@bpmn-io/element-template-chooser/dist/element-template-chooser.css';
import lintingCSS from '@camunda/linting/assets/linting.css';

import testCSS from './test.css';

import diagramCSS from 'bpmn-js/dist/assets/diagram-js.css';
import bpmnJsCSS from 'bpmn-js/dist/assets/bpmn-js.css';
import bpmnFontCSS from 'bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css';


export * from 'bpmn-js/test/helper';

Expand Down Expand Up @@ -77,96 +85,25 @@ export function clickInput(input) {
}

export function insertCoreStyles() {
insertCSS(
'properties-panel.css',
require('@bpmn-io/properties-panel/dist/assets/properties-panel.css').default
);

insertCSS(
'element-templates.css',
require('../assets/element-templates.css').default
);

insertCSS(
'test.css',
require('./test.css').default
);

insertCSS(
'element-template-chooser.css',
require('@bpmn-io/element-template-chooser/dist/element-template-chooser.css').default
);

insertCSS('linting.css',
require('@camunda/linting/assets/linting.css').default
);
insertCSS('properties-panel.css', propertiesPanelCSS);
insertCSS('element-templates.css', elementTemplatesCSS);
insertCSS('element-template-chooser.css', elementTemplateChooserCSS);
insertCSS('linting.css', lintingCSS);

insertCSS('test.css', testCSS);
}

export function insertBpmnStyles() {
insertCSS(
'diagram.css',
require('bpmn-js/dist/assets/diagram-js.css').default
);

// @barmac: this fails before bpmn-js@9
if (bpmnJsSatisfies('>=9')) {
insertCSS(
'bpmn-js.css',
require('bpmn-js/dist/assets/bpmn-js.css').default
);
}
insertCSS('diagram.css', diagramCSS);

insertCSS(
'bpmn-font.css',
require('bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css').default
);
insertCSS('bpmn-js.css', bpmnJsCSS);
insertCSS('bpmn-font.css', bpmnFontCSS);
}

export function bootstrapModeler(diagram, options, locals) {
return bootstrapBpmnJS(Modeler, diagram, options, locals);
}

/**
* Execute test only if currently installed bpmn-js is of given version.
*
* @param {string} versionRange
* @param {boolean} only
*/
export function withBpmnJs(versionRange, only = false) {
if (bpmnJsSatisfies(versionRange)) {
return only ? it.only : it;
} else {
return it.skip;
}
}

function bpmnJsSatisfies(versionRange) {
const bpmnJsVersion = require('bpmn-js/package.json').version;

return semver.satisfies(bpmnJsVersion, versionRange, { includePrerelease: true });
}

/**
* Execute test only if currently installed @bpmn-io/properties-panel is of given version.
*
* @param {string} versionRange
* @param {boolean} only
*/
export function withPropertiesPanel(versionRange, only = false) {
if (propertiesPanelSatisfies(versionRange)) {
return only ? it.only : it;
} else {
return it.skip;
}
}

function propertiesPanelSatisfies(versionRange) {
const version = require('@bpmn-io/properties-panel/package.json').version;

return semver.satisfies(version, versionRange, { includePrerelease: true });
}

export async function setEditorValue(editor, value) {
await act(() => {
editor.textContent = value;
Expand Down
18 changes: 14 additions & 4 deletions test/spec/Example.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,19 @@ describe('<BpmnPropertiesPanelRenderer>', function() {
(singleStart === 'cloud-templates' ? it.only : it)('should import simple process (cloud-templates)', async function() {

// given
const diagramXml = require('test/spec/cloud-element-templates/fixtures/complex.bpmn').default;
const diagramXml = (await import('test/spec/cloud-element-templates/fixtures/complex.bpmn')).default;

const elementTemplateContext = require.context('test/spec/cloud-element-templates/fixtures', false, /\.json$/);
const elementTemplateContext = import.meta.webpackContext('test/spec/cloud-element-templates/fixtures', {
recursive: false,
regExp: /\.json$/
});

console.log(elementTemplateContext.keys());

const elementTemplates = elementTemplateContext.keys().map(key => elementTemplateContext(key)).flat();

console.log(elementTemplates);

// when
const result = await createModeler(
diagramXml,
Expand Down Expand Up @@ -273,9 +280,12 @@ describe('<BpmnPropertiesPanelRenderer>', function() {
(singleStart === 'templates' ? it.only : it)('should import simple process (templates)', async function() {

// given
const diagramXml = require('test/spec/element-templates/fixtures/complex.bpmn').default;
const diagramXml = (await import('test/spec/element-templates/fixtures/complex.bpmn')).default;

const elementTemplateContext = require.context('test/spec/element-templates/fixtures', false, /\.json$/);
const elementTemplateContext = import.meta.webpackContext('test/spec/element-templates/fixtures', {
recursive: false,
regExp: /\.json$/
});

const elementTemplates = elementTemplateContext.keys().map(key => elementTemplateContext(key)).flat();

Expand Down
Loading

0 comments on commit 640a1d1

Please sign in to comment.