Skip to content

Commit

Permalink
test: add integration test for variables suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
barmac committed Oct 12, 2023
1 parent 306ce43 commit 293ffea
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { bootstrapModeler, inject, act } from 'test/helper';

import { query as domQuery } from 'min-dom';

import { DmnVariableResolverModule } from '@bpmn-io/dmn-variable-resolver';

import { triggerInputEvent } from 'dmn-js-shared/test/util/EventUtil';

import { queryEditor } from 'dmn-js-shared/test/util/EditorUtil';
Expand Down Expand Up @@ -367,6 +369,44 @@ describe('features/decision-rules', function() {

});


describe('integration', function() {

beforeEach(bootstrapModeler(emptyRuleXML, {
modules: [
CoreModule,
ModelingModule,
DecisionRulesModule,
DecisionRulesEditorModule,
DmnVariableResolverModule
],
debounceInput: false
}));


it('should pass variables to editor', async function() {

// given
const editor = queryEditor('[data-element-id="unaryTest_1"]', testContainer);

await act(() => editor.focus());

// when
await changeInput(document.activeElement, 'Var');

// then
await expectEventually(() => {
const options = testContainer.querySelectorAll('[role="option"]');

expect(options).to.exist;
expect(options).to.satisfy(options => {
const result = Array.from(options).some(
option => option.textContent === 'Variable');
return result;
});
});
});
});
});

// helpers //////////////////
Expand All @@ -390,4 +430,19 @@ function isFirefox() {

function skipFF() {
return isFirefox() ? it.only : it;
}
}

async function expectEventually(fn) {
for (let i = 0; i < 10; i++) {
try {
await act(() => {});
await fn();
return;
} catch (e) {

// wait
}
}

return fn();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" id="definitions_1y78itg" name="definitions" namespace="http://camunda.org/schema/1.0/dmn" exporter="dmn-js (https://demo.bpmn.io/dmn)" exporterVersion="7.4.1">
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/" id="definitions_1y78itg" name="definitions" namespace="http://camunda.org/schema/1.0/dmn" exporter="Camunda Modeler" exporterVersion="5.11.0">
<decision id="decision_1" name="decision_1">
<informationRequirement id="InformationRequirement_1rlyhoa">
<requiredInput href="#InputData_0kmeexs" />
</informationRequirement>
<decisionTable id="decisionTable_1">
<input id="input1" label="">
<inputExpression id="inputExpression1" typeRef="string">
Expand All @@ -18,4 +21,20 @@
</rule>
</decisionTable>
</decision>
<inputData id="InputData_0kmeexs" name="Variable" />
<dmndi:DMNDI>
<dmndi:DMNDiagram id="DMNDiagram_1s7fwgc">
<dmndi:DMNShape id="DMNShape_0p7qsmy" dmnElementRef="decision_1">
<dc:Bounds height="80" width="180" x="150" y="80" />
</dmndi:DMNShape>
<dmndi:DMNShape id="DMNShape_0ow358g" dmnElementRef="InputData_0kmeexs">
<dc:Bounds height="45" width="125" x="177" y="217" />
</dmndi:DMNShape>
<dmndi:DMNEdge id="DMNEdge_07npi6i" dmnElementRef="InformationRequirement_1rlyhoa">
<di:waypoint x="240" y="217" />
<di:waypoint x="240" y="180" />
<di:waypoint x="240" y="160" />
</dmndi:DMNEdge>
</dmndi:DMNDiagram>
</dmndi:DMNDI>
</definitions>
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:camunda="http://camunda.org/schema/1.0/dmn" id="definitions" name="definitions" namespace="http://camunda.org/schema/1.0/dmn">
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:camunda="http://camunda.org/schema/1.0/dmn" xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/" id="definitions" name="definitions" namespace="http://camunda.org/schema/1.0/dmn" exporter="Camunda Modeler" exporterVersion="5.11.0">
<decision id="decision" name="Check Order">
<informationRequirement id="InformationRequirement_1klmiyt">
<requiredInput href="#InputData_1j8tsl1" />
</informationRequirement>
<decisionTable id="decisionTable">
<input id="input1" label="Customer Status" camunda:inputVariable="">
<inputExpression id="inputExpression1" typeRef="string" expressionLanguage="">
Expand Down Expand Up @@ -86,4 +89,20 @@ else
</rule>
</decisionTable>
</decision>
<inputData id="InputData_1j8tsl1" name="Variable" />
<dmndi:DMNDI>
<dmndi:DMNDiagram id="DMNDiagram_1ibs1io">
<dmndi:DMNShape id="DMNShape_0ce24mr" dmnElementRef="decision">
<dc:Bounds height="80" width="180" x="150" y="80" />
</dmndi:DMNShape>
<dmndi:DMNShape id="DMNShape_1t81hpb" dmnElementRef="InputData_1j8tsl1">
<dc:Bounds height="45" width="125" x="177" y="317" />
</dmndi:DMNShape>
<dmndi:DMNEdge id="DMNEdge_01a9t3u" dmnElementRef="InformationRequirement_1klmiyt">
<di:waypoint x="240" y="317" />
<di:waypoint x="240" y="180" />
<di:waypoint x="240" y="160" />
</dmndi:DMNEdge>
</dmndi:DMNDiagram>
</dmndi:DMNDI>
</definitions>
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { bootstrapModeler, inject } from 'test/helper';
import { bootstrapModeler, inject, act } from 'test/helper';

import {
triggerInputEvent,
triggerMouseEvent
} from 'dmn-js-shared/test/util/EventUtil';

import { DmnVariableResolverModule } from '@bpmn-io/dmn-variable-resolver';

import { query as domQuery } from 'min-dom';

import TestContainer from 'mocha-test-container-support';
Expand All @@ -26,7 +28,8 @@ describe('decision-table-head/editor - input', function() {
DecisionTableHeadModule,
DecisionTableHeadEditorModule,
ModelingModule,
KeyboardModule
KeyboardModule,
DmnVariableResolverModule
],
debounceInput: false
}));
Expand Down Expand Up @@ -182,6 +185,32 @@ describe('decision-table-head/editor - input', function() {
expect(inputBo.inputExpression.text).to.equal('foo');
}));
});


describe('integration', function() {

it('should pass variables to editor', async function() {

// given
const editorEl = openEditor('input2');
const input = getControl('.ref-text [role="textbox"]', editorEl);

// when
await changeInput(input, 'Var');

// then
await expectEventually(() => {
const options = testContainer.querySelectorAll('[role="option"]');

expect(options).to.exist;
expect(options).to.satisfy(options => {
const result = Array.from(options).some(
option => option.textContent === 'Variable');
return result;
});
});
});
});
});


Expand Down Expand Up @@ -240,11 +269,22 @@ function getControl(selector, parent) {
* @param {string} value
*/
function changeInput(input, value) {
input.textContent = value;

return new Promise(resolve => {
requestAnimationFrame(() => {
resolve();
});
return act(() => {
input.textContent = value;
});
}

async function expectEventually(fn) {
for (let i = 0; i < 10; i++) {
try {
await act(() => {});
await fn();
return;
} catch (e) {

// wait
}
}

return fn();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { bootstrapModeler, inject } from 'test/helper';

import { query as domQuery } from 'min-dom';

import { DmnVariableResolverModule } from '@bpmn-io/dmn-variable-resolver';

import { queryEditor } from 'dmn-js-shared/test/util/EditorUtil';

import ExpressionLanguagesModule from 'dmn-js-shared/lib/features/expression-languages';
Expand All @@ -26,7 +28,8 @@ describe('textarea editor', function() {
CoreModule,
TextareaEditorModule,
ModelingModule,
ExpressionLanguagesModule
ExpressionLanguagesModule,
DmnVariableResolverModule
],
debounceInput: false
}));
Expand Down Expand Up @@ -75,6 +78,33 @@ describe('textarea editor', function() {
expect(viewer.getDecision().decisionLogic.text).to.equal('foo');
}));


describe('integration', function() {

it('should pass variables to editor', inject(async function(viewer) {

// given
const editor = queryEditor('.textarea', testContainer);

await act(() => editor.focus());

// when
await changeInput(document.activeElement, 'Var');

// then
await expectEventually(() => {
const options = testContainer.querySelectorAll('[role="option"]');

expect(options).to.exist;
expect(options).to.satisfy(options => {
const result = Array.from(options).some(
option => option.textContent === 'Variable');
return result;
});
});
}));
});

});

// helpers //////////
Expand All @@ -87,11 +117,26 @@ function changeInput(input, value) {
return act(() => input.textContent = value);
}

function act(fn) {
fn();
async function act(fn) {
await fn();
return new Promise(resolve => {
requestAnimationFrame(() => {
resolve();
});
});
}

async function expectEventually(fn) {
for (let i = 0; i < 10; i++) {
try {
await act(() => {});
await fn();
return;
} catch (e) {

// wait
}
}

return fn();
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" xmlns:camunda="http://camunda.org/schema/1.0/dmn" id="dish" name="Desired Dish" namespace="party">
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/" id="dish" name="Desired Dish" namespace="party" exporter="Camunda Modeler" exporterVersion="5.11.0">
<decision id="season" name="Season">
<variable id="InformationItem_16229yj" name="season" typeRef="string" />
<informationRequirement id="InformationRequirement_13flr3u">
<requiredInput href="#InputData_0wikdil" />
</informationRequirement>
<literalExpression id="LiteralExpression_0hs8xyn">
<text>calendar.getSeason(date)</text>
</literalExpression>
</decision>
<inputData id="InputData_0wikdil" name="Variable" />
<dmndi:DMNDI>
<dmndi:DMNDiagram>
<dmndi:DMNShape dmnElementRef="season">
<dc:Bounds height="55" width="100" x="150" y="10" />
<dc:Bounds height="55" width="100" x="150" y="80" />
</dmndi:DMNShape>
<dmndi:DMNShape id="DMNShape_1ds1jom" dmnElementRef="InputData_0wikdil">
<dc:Bounds height="45" width="125" x="138" y="198" />
</dmndi:DMNShape>
<dmndi:DMNEdge id="DMNEdge_0qwszuo" dmnElementRef="InformationRequirement_13flr3u">
<di:waypoint x="201" y="198" />
<di:waypoint x="200" y="155" />
<di:waypoint x="200" y="135" />
</dmndi:DMNEdge>
</dmndi:DMNDiagram>
</dmndi:DMNDI>
</definitions>

0 comments on commit 293ffea

Please sign in to comment.