Skip to content

Commit 607d192

Browse files
abdul99ahadbarmac
authored andcommitted
test: add integration tests for trimming
- support text field, optional feel and textareas - trimming should happen if there exists trailing spaces - input should not be propogated to other element Related to camunda/web-modeler#13599
1 parent eed2239 commit 607d192

File tree

2 files changed

+280
-3
lines changed

2 files changed

+280
-3
lines changed

test/fixtures/integration.bpmn

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1k9gocq" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.34.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.7.0">
3+
<bpmn:process id="Process_0bjswkx" isExecutable="true">
4+
<bpmn:task id="Task_1" name="Task 1" />
5+
<bpmn:task id="Task_2" name="Task 2" />
6+
<bpmn:serviceTask id="ServiceTask_1" name="Service Task 1">
7+
<bpmn:extensionElements>
8+
<zeebe:taskDefinition type="foo" />
9+
</bpmn:extensionElements>
10+
</bpmn:serviceTask>
11+
<bpmn:serviceTask id="ServiceTask_2" name="Service Task 2">
12+
<bpmn:extensionElements>
13+
<zeebe:taskDefinition type="bar" />
14+
</bpmn:extensionElements>
15+
</bpmn:serviceTask>
16+
<bpmn:intermediateCatchEvent id="LinkEvent_1" name="Link Event 1">
17+
<bpmn:linkEventDefinition name="name" />
18+
</bpmn:intermediateCatchEvent>
19+
<bpmn:intermediateThrowEvent id="LinkEvent_2" name="Link Event 2">
20+
<bpmn:linkEventDefinition name="name" />
21+
</bpmn:intermediateThrowEvent>
22+
</bpmn:process>
23+
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
24+
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0bjswkx">
25+
<bpmndi:BPMNShape id="Activity_1xnx3pj_di" bpmnElement="Task_1">
26+
<dc:Bounds x="160" y="240" width="100" height="80" />
27+
<bpmndi:BPMNLabel />
28+
</bpmndi:BPMNShape>
29+
<bpmndi:BPMNShape id="BPMNShape_13ftmyc" bpmnElement="Task_2">
30+
<dc:Bounds x="360" y="240" width="100" height="80" />
31+
<bpmndi:BPMNLabel />
32+
</bpmndi:BPMNShape>
33+
<bpmndi:BPMNShape id="Activity_1tf1eey_di" bpmnElement="ServiceTask_1">
34+
<dc:Bounds x="160" y="80" width="100" height="80" />
35+
</bpmndi:BPMNShape>
36+
<bpmndi:BPMNShape id="Activity_012sk28_di" bpmnElement="ServiceTask_2">
37+
<dc:Bounds x="360" y="80" width="100" height="80" />
38+
</bpmndi:BPMNShape>
39+
<bpmndi:BPMNShape id="LinkEvent_1_di" bpmnElement="LinkEvent_1">
40+
<dc:Bounds x="160" y="400" width="36" height="36" />
41+
</bpmndi:BPMNShape>
42+
<bpmndi:BPMNShape id="LinkEvent_2_di" bpmnElement="LinkEvent_2">
43+
<dc:Bounds x="360" y="400" width="36" height="36" />
44+
</bpmndi:BPMNShape>
45+
</bpmndi:BPMNPlane>
46+
</bpmndi:BPMNDiagram>
47+
</bpmn:definitions>

test/spec/BpmnPropertiesPanelRenderer.spec.js

Lines changed: 233 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import TestContainer from 'mocha-test-container-support';
22

33
import {
44
act,
5-
cleanup
5+
cleanup,
6+
waitFor
67
} from '@testing-library/preact/pure';
78

89
import {
@@ -13,7 +14,8 @@ import {
1314
insertBpmnStyles,
1415
withPropertiesPanel,
1516
enableLogging,
16-
getBpmnJS
17+
getBpmnJS,
18+
changeInput
1719
} from 'test/TestHelper';
1820

1921
import {
@@ -54,6 +56,10 @@ import ExamplePropertiesProvider from './extension/ExamplePropertiesProvider';
5456
import ZeebeTooltipProvider from 'src/contextProvider/zeebe/TooltipProvider';
5557
import CamundaPlatformTooltipProvider from 'src/contextProvider/camunda-platform/TooltipProvider';
5658

59+
import { getExtensionElementsList } from 'src/utils/ExtensionElementsUtil';
60+
61+
import { getBusinessObject } from 'bpmn-js/lib/util/ModelUtil';
62+
5763
const singleStart = window.__env__ && window.__env__.SINGLE_START;
5864

5965
insertCoreStyles();
@@ -501,6 +507,209 @@ describe('<BpmnPropertiesPanelRenderer>', function() {
501507
expect(getHeaderName(propertiesContainer)).to.eql('start');
502508
});
503509

510+
describe('input', function() {
511+
512+
let modeler;
513+
const diagramXml = require('test/fixtures/integration.bpmn').default;
514+
515+
beforeEach(function() {
516+
return act(async () => {
517+
({ modeler } = await createModeler(diagramXml, {
518+
propertiesPanel: {
519+
parent: propertiesContainer,
520+
layout: {
521+
groups: {
522+
'general': { open: true },
523+
'taskDefinition': { open: true },
524+
'link': { open: true }
525+
}
526+
}
527+
}
528+
}));
529+
});
530+
});
531+
532+
533+
describe('feel (optional)', function() {
534+
535+
const OPTIONAL_FEEL_SELECTOR = '[name=taskDefinitionType]';
536+
537+
it('should trim value', async function() {
538+
539+
// given
540+
const elementRegistry = modeler.get('elementRegistry'),
541+
selection = modeler.get('selection'),
542+
serviceTask = elementRegistry.get('ServiceTask_1');
543+
await act(() => {
544+
selection.select(serviceTask);
545+
});
546+
547+
// when
548+
const input = domQuery(OPTIONAL_FEEL_SELECTOR, container);
549+
input.focus();
550+
changeInput(input, ' bar ');
551+
input.blur();
552+
553+
// then
554+
await waitFor(() => {
555+
expect(getTaskDefinition(serviceTask).get('type')).to.eql('bar');
556+
});
557+
});
558+
559+
560+
it('should not propagate input to other element', async function() {
561+
562+
// given
563+
const elementRegistry = modeler.get('elementRegistry'),
564+
selection = modeler.get('selection'),
565+
serviceTask = elementRegistry.get('ServiceTask_1'),
566+
anotherServiceTask = elementRegistry.get('ServiceTask_2');
567+
const originalValueOfAnotherServiceTask = getTaskDefinition(anotherServiceTask).get('type');
568+
await act(() => {
569+
selection.select(serviceTask);
570+
});
571+
572+
// when
573+
const input = domQuery(OPTIONAL_FEEL_SELECTOR, container);
574+
input.focus();
575+
changeInput(input, 'newValue');
576+
input.blur();
577+
578+
await act(() => {
579+
selection.select(anotherServiceTask);
580+
});
581+
582+
// and when
583+
const input2 = domQuery(OPTIONAL_FEEL_SELECTOR, container);
584+
input2.focus();
585+
586+
// then
587+
expect(input2.value).to.eql(originalValueOfAnotherServiceTask);
588+
expect(getTaskDefinition(anotherServiceTask).get('type')).to.eql(originalValueOfAnotherServiceTask);
589+
});
590+
});
591+
592+
593+
describe('text area', function() {
594+
595+
const TEXT_AREA_SELECTOR = '[name=name]';
596+
597+
it('should trim value', async function() {
598+
599+
// given
600+
const elementRegistry = modeler.get('elementRegistry'),
601+
selection = modeler.get('selection'),
602+
serviceTask = elementRegistry.get('ServiceTask_1');
603+
await act(() => {
604+
selection.select(serviceTask);
605+
});
606+
607+
// when
608+
const input = domQuery(TEXT_AREA_SELECTOR, container);
609+
input.focus();
610+
changeInput(input, ' bar ');
611+
input.blur();
612+
613+
// then
614+
await waitFor(() => {
615+
expect(getName(serviceTask)).to.eql('bar');
616+
});
617+
});
618+
619+
620+
it('should not propagate input to other element', async function() {
621+
622+
// given
623+
const elementRegistry = modeler.get('elementRegistry'),
624+
selection = modeler.get('selection'),
625+
serviceTask = elementRegistry.get('ServiceTask_1'),
626+
anotherServiceTask = elementRegistry.get('ServiceTask_2');
627+
const originalValueOfAnotherServiceTask = getName(anotherServiceTask);
628+
await act(() => {
629+
selection.select(serviceTask);
630+
});
631+
632+
// when
633+
const input = domQuery(TEXT_AREA_SELECTOR, container);
634+
input.focus();
635+
changeInput(input, 'newValue');
636+
input.blur();
637+
638+
await act(() => {
639+
selection.select(anotherServiceTask);
640+
});
641+
642+
// and when
643+
const input2 = domQuery(TEXT_AREA_SELECTOR, container);
644+
input2.focus();
645+
646+
// then
647+
expect(input2.value).to.eql(originalValueOfAnotherServiceTask);
648+
expect(getName(anotherServiceTask)).to.eql(originalValueOfAnotherServiceTask);
649+
});
650+
});
651+
652+
653+
describe('text field', function() {
654+
655+
const TEXT_FIELD_SELECTOR = '[name=linkName]';
656+
657+
it('should trim value', async function() {
658+
659+
// given
660+
const elementRegistry = modeler.get('elementRegistry'),
661+
selection = modeler.get('selection'),
662+
linkEvent = elementRegistry.get('LinkEvent_1');
663+
await act(() => {
664+
selection.select(linkEvent);
665+
});
666+
667+
// when
668+
const input = domQuery(TEXT_FIELD_SELECTOR, container);
669+
input.focus();
670+
changeInput(input, ' bar ');
671+
input.blur();
672+
673+
// then
674+
await waitFor(() => {
675+
expect(getLinkName(linkEvent)).to.eql('bar');
676+
});
677+
});
678+
679+
680+
it('should not propagate input to other element', async function() {
681+
682+
// given
683+
const elementRegistry = modeler.get('elementRegistry'),
684+
selection = modeler.get('selection'),
685+
linkEvent = elementRegistry.get('LinkEvent_1'),
686+
anotherLinkName = elementRegistry.get('LinkEvent_2');
687+
const originalValueOfAnotherLinkEvent = getLinkName(anotherLinkName);
688+
await act(() => {
689+
selection.select(linkEvent);
690+
});
691+
692+
// when
693+
const input = domQuery(TEXT_FIELD_SELECTOR, container);
694+
input.focus();
695+
changeInput(input, 'newValue');
696+
input.blur();
697+
698+
await act(() => {
699+
selection.select(anotherLinkName);
700+
});
701+
702+
// and when
703+
const input2 = domQuery(TEXT_FIELD_SELECTOR, container);
704+
input2.focus();
705+
706+
// then
707+
expect(input2.value).to.eql(originalValueOfAnotherLinkEvent);
708+
expect(getLinkName(anotherLinkName)).to.eql(originalValueOfAnotherLinkEvent);
709+
});
710+
});
711+
});
712+
504713

505714
withPropertiesPanel('>=0.16')('should show error', async function() {
506715

@@ -813,6 +1022,7 @@ describe('<BpmnPropertiesPanelRenderer>', function() {
8131022
});
8141023
});
8151024

1025+
8161026
// then
8171027
expect(document.activeElement).to.exist;
8181028
expect(document.activeElement.closest('.bio-properties-panel-entry')).to.exist;
@@ -1223,4 +1433,24 @@ function showEntry(id) {
12231433
id
12241434
});
12251435
}));
1226-
}
1436+
}
1437+
1438+
// helper //////////////////
1439+
1440+
function getTaskDefinition(element) {
1441+
const businessObject = getBusinessObject(element);
1442+
1443+
return getExtensionElementsList(businessObject, 'zeebe:TaskDefinition')[0];
1444+
}
1445+
1446+
function getName(element) {
1447+
const businessObject = getBusinessObject(element);
1448+
1449+
return businessObject.get('name');
1450+
}
1451+
1452+
function getLinkName(element) {
1453+
const businessObject = getBusinessObject(element);
1454+
1455+
return businessObject.get('eventDefinitions')[0].get('name');
1456+
}

0 commit comments

Comments
 (0)