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 b8db000 commit eabfa1d
Show file tree
Hide file tree
Showing 2 changed files with 43 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
39 changes: 39 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,45 @@ describe('features/context-pad', function() {
});


describe('event integration', function() {

const triggerSpy = sinon.spy();

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

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


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 });

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 eabfa1d

Please sign in to comment.