From dfc0e30ba37fdf8b15b47387f1056fe002928fcd Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 16 Sep 2022 16:02:35 +0200 Subject: [PATCH 1/3] fix: use setTimeout to work around properties panel focus issue Related to https://github.com/camunda/camunda-modeler/issues/3127 --- lib/modeler/Linting.js | 7 +- test/spec/modeler/Linting.spec.js | 129 +++++++++++++++++------------- 2 files changed, 79 insertions(+), 57 deletions(-) diff --git a/lib/modeler/Linting.js b/lib/modeler/Linting.js index 6e2bacc..9efc147 100644 --- a/lib/modeler/Linting.js +++ b/lib/modeler/Linting.js @@ -32,8 +32,11 @@ export default class Linting { const { entryId } = propertiesPanel; - this._eventBus.fire('propertiesPanel.showEntry', { - id: entryId + // TODO(philippfromme): remove timeout once properties panel is fixed + setTimeout(() => { + this._eventBus.fire('propertiesPanel.showEntry', { + id: entryId + }); }); } diff --git a/test/spec/modeler/Linting.spec.js b/test/spec/modeler/Linting.spec.js index 6a4c4ec..e8bcff7 100644 --- a/test/spec/modeler/Linting.spec.js +++ b/test/spec/modeler/Linting.spec.js @@ -110,7 +110,7 @@ describe('Linting', function() { })); - (singleStart ? it.only : it)('example', inject(function(bpmnjs, canvas, eventBus, linting, modeling, propertiesPanel) { + (singleStart ? it.only : it.skip)('example', inject(function(bpmnjs, canvas, eventBus, linting, modeling, propertiesPanel) { // given const linter = new Linter(); @@ -363,88 +363,107 @@ describe('Linting', function() { )); - it('should show error', inject( - async function(bpmnjs, elementRegistry, eventBus, linting, selection) { + describe('show error', function() { - // given - const serviceTask = elementRegistry.get('ServiceTask_1'); + let clock; - const reports = await linter.lint(bpmnjs.getDefinitions()); + beforeEach(function() { + clock = sinon.useFakeTimers(); + }); - // assume - expect(reports).to.have.length(1); + afterEach(function() { + clock.restore(); + }); - linting.setErrors(reports); - linting.activate(); + it('should show error', inject( + async function(bpmnjs, elementRegistry, eventBus, linting, selection) { - const propertiesPanelSetErrorSpy = sinon.spy(); + // given + const serviceTask = elementRegistry.get('ServiceTask_1'); - eventBus.on('propertiesPanel.setErrors', propertiesPanelSetErrorSpy); + const reports = await linter.lint(bpmnjs.getDefinitions()); - const propertiesPanelShowEntrySpy = sinon.spy(); + // assume + expect(reports).to.have.length(1); - eventBus.on('propertiesPanel.showEntry', propertiesPanelShowEntrySpy); + linting.setErrors(reports); - // when - linting.showError(reports[ 0 ]); + linting.activate(); - // then - expect(selection.get()).to.eql([ serviceTask ]); + const propertiesPanelSetErrorSpy = sinon.spy(); - expect(propertiesPanelSetErrorSpy).to.have.been.calledOnce; - expect(propertiesPanelSetErrorSpy).to.have.been.calledWithMatch({ - errors: getErrors(reports, serviceTask) - }); + eventBus.on('propertiesPanel.setErrors', propertiesPanelSetErrorSpy); - expect(propertiesPanelShowEntrySpy).to.have.been.calledOnce; - expect(propertiesPanelShowEntrySpy).to.have.been.calledWithMatch({ - id: 'taskDefinitionType' - }); - } - )); + const propertiesPanelShowEntrySpy = sinon.spy(); + eventBus.on('propertiesPanel.showEntry', propertiesPanelShowEntrySpy); - it('should show error on lintingAnnotations.click', inject( - async function(bpmnjs, elementRegistry, eventBus, linting, selection) { + // when + linting.showError(reports[ 0 ]); - // given - const serviceTask = elementRegistry.get('ServiceTask_1'); + clock.tick(); - const reports = await linter.lint(bpmnjs.getDefinitions()); + // then + expect(selection.get()).to.eql([ serviceTask ]); - // assume - expect(reports).to.have.length(1); + expect(propertiesPanelSetErrorSpy).to.have.been.calledOnce; + expect(propertiesPanelSetErrorSpy).to.have.been.calledWithMatch({ + errors: getErrors(reports, serviceTask) + }); - linting.setErrors(reports); + expect(propertiesPanelShowEntrySpy).to.have.been.calledOnce; + expect(propertiesPanelShowEntrySpy).to.have.been.calledWithMatch({ + id: 'taskDefinitionType' + }); + } + )); - linting.activate(); - const propertiesPanelSetErrorSpy = sinon.spy(); + it('should show error on lintingAnnotations.click', inject( + async function(bpmnjs, elementRegistry, eventBus, linting, selection) { - eventBus.on('propertiesPanel.setErrors', propertiesPanelSetErrorSpy); + // given + const serviceTask = elementRegistry.get('ServiceTask_1'); - const propertiesPanelShowEntrySpy = sinon.spy(); + const reports = await linter.lint(bpmnjs.getDefinitions()); - eventBus.on('propertiesPanel.showEntry', propertiesPanelShowEntrySpy); + // assume + expect(reports).to.have.length(1); - // when - eventBus.fire('lintingAnnotations.click', { report: reports[ 0 ] }); + linting.setErrors(reports); - // then - expect(selection.get()).to.eql([ serviceTask ]); + linting.activate(); - expect(propertiesPanelSetErrorSpy).to.have.been.calledOnce; - expect(propertiesPanelSetErrorSpy).to.have.been.calledWithMatch({ - errors: getErrors(reports, serviceTask) - }); + const propertiesPanelSetErrorSpy = sinon.spy(); - expect(propertiesPanelShowEntrySpy).to.have.been.calledOnce; - expect(propertiesPanelShowEntrySpy).to.have.been.calledWithMatch({ - id: 'taskDefinitionType' - }); - } - )); + eventBus.on('propertiesPanel.setErrors', propertiesPanelSetErrorSpy); + + const propertiesPanelShowEntrySpy = sinon.spy(); + + eventBus.on('propertiesPanel.showEntry', propertiesPanelShowEntrySpy); + + // when + eventBus.fire('lintingAnnotations.click', { report: reports[ 0 ] }); + + clock.tick(); + + // then + expect(selection.get()).to.eql([ serviceTask ]); + + expect(propertiesPanelSetErrorSpy).to.have.been.calledOnce; + expect(propertiesPanelSetErrorSpy).to.have.been.calledWithMatch({ + errors: getErrors(reports, serviceTask) + }); + + expect(propertiesPanelShowEntrySpy).to.have.been.calledOnce; + expect(propertiesPanelShowEntrySpy).to.have.been.calledWithMatch({ + id: 'taskDefinitionType' + }); + } + )); + + }); describe('canvas scrolling', function() { From b948c109066eafaff7536707b3fbe83e821acbfe Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Fri, 23 Sep 2022 08:45:43 +0200 Subject: [PATCH 2/3] test: add TODO --- test/spec/modeler/Linting.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/spec/modeler/Linting.spec.js b/test/spec/modeler/Linting.spec.js index e8bcff7..3c5fcd0 100644 --- a/test/spec/modeler/Linting.spec.js +++ b/test/spec/modeler/Linting.spec.js @@ -446,6 +446,7 @@ describe('Linting', function() { // when eventBus.fire('lintingAnnotations.click', { report: reports[ 0 ] }); + // TODO(philippfromme): remove timeout once properties panel is fixed clock.tick(); // then From 3e59e22d21ce0f9007d8d8e81243a95b3bbc907e Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Fri, 23 Sep 2022 08:46:25 +0200 Subject: [PATCH 3/3] test: remove `skip` --- test/spec/modeler/Linting.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/modeler/Linting.spec.js b/test/spec/modeler/Linting.spec.js index 3c5fcd0..38cb73f 100644 --- a/test/spec/modeler/Linting.spec.js +++ b/test/spec/modeler/Linting.spec.js @@ -110,7 +110,7 @@ describe('Linting', function() { })); - (singleStart ? it.only : it.skip)('example', inject(function(bpmnjs, canvas, eventBus, linting, modeling, propertiesPanel) { + (singleStart ? it.only : it)('example', inject(function(bpmnjs, canvas, eventBus, linting, modeling, propertiesPanel) { // given const linter = new Linter();