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 20fe558 commit de0f0fe
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/features/context-pad/ContextPad.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ ContextPad.prototype.triggerEntry = function(entryId, action, event, autoActivat

var handler = entry.action;

if (this._eventBus.fire('contextPad.trigger', { entry, event }) === false) {
return;
}

// simple action (via callback function)
if (isFunction(handler)) {
if (action === 'click') {
Expand Down
33 changes: 33 additions & 0 deletions test/spec/features/context-pad/ContextPadSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,39 @@ describe('features/context-pad', function() {
});


describe('event integration', function() {

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

it('should fire "contextPad.trigger"', inject(function(canvas, contextPad, eventBus) {

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

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

contextPad.open(shape);

var pad = contextPad.getPad(shape),
html = pad.html,
target = domQuery('[data-action="action.c"]', html);

var event = globalEvent(target, { x: 0, y: 0 });

// when
contextPad.trigger('click', event);

// then
const entry = contextPad._current.entries['action.c'];

expect(triggerSpy).to.have.been.calledOnce;
expect(triggerSpy.getCall(0).args[1]).to.eql({ entry, event });
}));

});


describe('scaling', function() {

var NUM_REGEX = /([+-]?\d*[.]?\d+)(?=,|\))/g;
Expand Down

0 comments on commit de0f0fe

Please sign in to comment.