Skip to content

Commit

Permalink
fix: use setTimeout to work around properties panel focus issue
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Sep 19, 2022
1 parent fc4c4f6 commit e79c0b2
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 57 deletions.
7 changes: 5 additions & 2 deletions lib/modeler/Linting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});
}

Expand Down
129 changes: 74 additions & 55 deletions test/spec/modeler/Linting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit e79c0b2

Please sign in to comment.