Skip to content

Commit 0384553

Browse files
committed
test: make more robust
Previously we relied on particular DOM queries that this commit factors out into dedicated helpers.
1 parent 3aa8e5e commit 0384553

File tree

1 file changed

+46
-29
lines changed

1 file changed

+46
-29
lines changed

test/spec/BpmnPropertiesPanelRenderer.spec.js

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
insertCoreStyles,
1313
insertBpmnStyles,
1414
withPropertiesPanel,
15-
enableLogging
15+
enableLogging,
16+
getBpmnJS
1617
} from 'test/TestHelper';
1718

1819
import {
@@ -697,9 +698,9 @@ describe('<BpmnPropertiesPanelRenderer>', function() {
697698
// then
698699
expect(spy).to.have.been.calledOnce;
699700
expect(spy).to.have.been.calledWith(sinon.match({ layout: newLayout }));
700-
701701
});
702702

703+
703704
describe('event emitting', function() {
704705

705706
it('should emit <propertiesPanel.attach>', async function() {
@@ -920,14 +921,10 @@ describe('<BpmnPropertiesPanelRenderer>', function() {
920921
selection.select(elementRegistry.get('ServiceTask_1'));
921922
});
922923

923-
const openPopupBtn = getOpenFeelPopup('ServiceTask_1-input-0-source', container);
924-
925924
// when
926-
await act(() => {
927-
openPopupBtn.click();
928-
});
925+
await triggerPopupOpen('ServiceTask_1-input-0-source', container);
929926

930-
const feelPopup = getFeelPopup(container);
927+
const feelPopup = getFeelPopupElement(container);
931928

932929
// then
933930
expect(feelPopup).to.exist;
@@ -966,18 +963,21 @@ describe('<BpmnPropertiesPanelRenderer>', function() {
966963
// given
967964
const spy = sinon.spy();
968965

969-
const openPopupBtn = getOpenFeelPopup('ServiceTask_1-input-0-source', container);
970-
971966
const eventBus = modeler.get('eventBus');
972967

968+
// assume
969+
eventBus.fire('propertiesPanel.showEntry', {
970+
id: 'ServiceTask_1-input-0-source'
971+
});
972+
973973
eventBus.on('feelPopup.opened', spy);
974974

975975
// when
976-
await act(() => {
977-
openPopupBtn.click();
978-
});
976+
await triggerPopupOpen('ServiceTask_1-input-0-source', container);
979977

980978
// then
979+
expect(getFeelPopupElement(container)).to.exist;
980+
981981
expect(spy).to.have.been.calledOnce;
982982
});
983983

@@ -987,23 +987,19 @@ describe('<BpmnPropertiesPanelRenderer>', function() {
987987
// given
988988
const spy = sinon.spy();
989989

990-
const openPopupBtn = getOpenFeelPopup('ServiceTask_1-input-0-source', container);
991-
992990
const eventBus = modeler.get('eventBus');
993991

994992
eventBus.on('feelPopup.closed', spy);
995993

996-
await act(() => {
997-
openPopupBtn.click();
998-
});
994+
// assume
995+
await showEntry('ServiceTask_1-input-0-source');
996+
997+
await triggerPopupOpen('ServiceTask_1-input-0-source', container);
999998

1000999
// assume
1001-
expect(getFeelPopup(container)).to.exist;
1000+
expect(getFeelPopupElement(container)).to.exist;
10021001

1003-
await act(() => {
1004-
const closeBtn = domQuery('.bio-properties-panel-feel-popup__close-btn', container);
1005-
closeBtn.click();
1006-
});
1002+
await triggerPopupClose(container);
10071003

10081004
// then
10091005
expect(spy).to.have.been.calledOnce;
@@ -1025,7 +1021,7 @@ describe('<BpmnPropertiesPanelRenderer>', function() {
10251021
});
10261022

10271023
// then
1028-
expect(getFeelPopup(container)).to.exist;
1024+
expect(getFeelPopupElement(container)).to.exist;
10291025
});
10301026

10311027

@@ -1043,15 +1039,15 @@ describe('<BpmnPropertiesPanelRenderer>', function() {
10431039
});
10441040

10451041
// assume
1046-
expect(getFeelPopup(container)).to.exist;
1042+
expect(getFeelPopupElement(container)).to.exist;
10471043

10481044
// when
10491045
await act(() => {
10501046
feelPopup.close();
10511047
});
10521048

10531049
// then
1054-
expect(getFeelPopup(container)).to.not.exist;
1050+
expect(getFeelPopupElement(container)).to.not.exist;
10551051
});
10561052

10571053

@@ -1169,10 +1165,31 @@ function getHeaderName(container) {
11691165
return domQuery('.bio-properties-panel-header-label', container).innerText;
11701166
}
11711167

1172-
function getFeelPopup(container) {
1168+
function getFeelPopupElement(container) {
11731169
return domQuery('.bio-properties-panel-feel-popup', container);
11741170
}
11751171

1176-
function getOpenFeelPopup(id, container) {
1177-
return container.querySelector(`[data-entry-id="${id}"] .bio-properties-panel-open-feel-popup`);
1172+
function triggerPopupOpen(id, container) {
1173+
const openButton = container.querySelector(`[data-entry-id="${id}"] .bio-properties-panel-open-feel-popup`);
1174+
1175+
expect(openButton, `<${id}> popup open el`).to.exist;
1176+
1177+
return act(() => openButton.click());
1178+
}
1179+
1180+
function triggerPopupClose(container) {
1181+
const closeButton = domQuery('.bio-properties-panel-feel-popup__close-btn', container);
1182+
1183+
expect(closeButton, 'popup close button').to.exist;
1184+
1185+
return act(() => closeButton.click());
11781186
}
1187+
1188+
function showEntry(id) {
1189+
1190+
return act(() => getBpmnJS().invoke(eventBus => {
1191+
eventBus.fire('propertiesPanel.showEntry', {
1192+
id
1193+
});
1194+
}));
1195+
}

0 commit comments

Comments
 (0)