Skip to content

Commit

Permalink
feat(contextPad): fire contextPad.trigger event
Browse files Browse the repository at this point in the history
  • Loading branch information
smbea committed Apr 5, 2023
1 parent 7da8ba8 commit d4dfedb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/features/context-pad/ContextPad.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ ContextPad.prototype.triggerEntry = function(entryId, action, event, autoActivat

var handler = entry.action;

this._eventBus.fire('contextPad.trigger', { event });

// simple action (via callback function)
if (isFunction(handler)) {
if (action === 'click') {
Expand Down
16 changes: 14 additions & 2 deletions test/spec/features/context-pad/ContextPadSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,14 +774,22 @@ describe('features/context-pad', function() {

describe('event handling', function() {

const triggerSpy = sinon.spy();

beforeEach(bootstrapDiagram({ modules: [ contextPadModule, providerModule ] }));

afterEach(function() {
triggerSpy.resetHistory();
});


it('should handle click event', inject(function(canvas, contextPad) {
it('should handle click event', inject(function(canvas, contextPad, eventBus) {

// given
var shape = canvas.addShape({ id: 's1', width: 100, height: 100, x: 10, y: 10 });

eventBus.on('contextPad.trigger', triggerSpy);

contextPad.open(shape);

var pad = contextPad.getPad(shape),
Expand All @@ -794,6 +802,7 @@ describe('features/context-pad', function() {
contextPad.trigger('click', event);

// then
expect(triggerSpy).to.have.been.calledOnce;
expect(event.__handled).to.be.true;
}));

Expand All @@ -819,7 +828,7 @@ describe('features/context-pad', function() {
}));


it('should handle drag event', inject(function(canvas, contextPad) {
it('should handle drag event', inject(function(canvas, contextPad, eventBus) {

// given
var shape = canvas.addShape({
Expand All @@ -829,6 +838,8 @@ describe('features/context-pad', function() {
type: 'drag'
});

eventBus.on('contextPad.trigger', triggerSpy);

contextPad.open(shape);

var pad = contextPad.getPad(shape),
Expand All @@ -841,6 +852,7 @@ describe('features/context-pad', function() {
contextPad.trigger('dragstart', event);

// then
expect(triggerSpy).to.have.been.calledOnce;
expect(event.__handled).to.be.true;
}));

Expand Down

0 comments on commit d4dfedb

Please sign in to comment.