From e79c0b20ad9e3562428bfa9ea952c44fde6653e6 Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 16 Sep 2022 16:02:35 +0200 Subject: [PATCH] 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..853a4c2 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'); + await clock.tickAsync(300); - 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 ] }); + + await clock.tickAsync(300); + + // 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() {