it('triggers node handlers and returns last value', function() {
            var eventBaton = 0;

            Events.init(plotDiv);

            plotDiv.on('ping', function() {
                eventBaton++;
                return 'ping';
            });

            plotDiv.on('ping', function() {
                eventBaton++;
                return 'ping';
            });

            plotDiv.on('ping', function() {
                eventBaton++;
                return 'pong';
            });

            var result = Events.triggerHandler(plotDiv, 'ping');

            expect(eventBaton).toBe(3);
            expect(result).toBe('pong');
        });
        it('triggers jQuery handlers when no matching node events bound', function() {
            var eventBaton = 0;

            Events.init(plotDiv);

            jQuery(plotDiv).bind('ping', function() {
                eventBaton++;
                return 'ping';
            });

            /*
             * This will not be called
             */
            plotDiv.on('pong', function() {
                eventBaton++;
                return 'ping';
            });

            jQuery(plotDiv).bind('ping', function() {
                eventBaton++;
                return 'pong';
            });

            var result = Events.triggerHandler(plotDiv, 'ping');

            expect(eventBaton).toBe(2);
            expect(result).toBe('pong');
        });
        it('does *not* mirror triggerHandler events on the internal handler', function() {
            var eventBaton = 0;
            var internalEventBaton = 0;

            Events.init(plotDiv);

            plotDiv.on('ping', function() {
                eventBaton++;
                return 'ping';
            });

            plotDiv._internalOn('ping', function() {
                internalEventBaton++;
                return 'foo';
            });

            plotDiv.on('ping', function() {
                eventBaton++;
                return 'pong';
            });

            var result = Events.triggerHandler(plotDiv, 'ping');

            expect(eventBaton).toBe(2);
            expect(internalEventBaton).toBe(0);
            expect(result).toBe('pong');
        });
Example #4
0
        it('maps function onto incoming plot object', function() {
            Events.init(plotObj);

            expect(typeof plotObj.on).toBe('function');
            expect(typeof plotObj.once).toBe('function');
            expect(typeof plotObj.removeListener).toBe('function');
            expect(typeof plotObj.removeAllListeners).toBe('function');
        });
Example #5
0
        it('triggers node style events', function(done) {
            Events.init(plotObj);

            plotObj.on('ping', function(data) {
                expect(data).toBe('pong');
                done();
            });

            setTimeout(function() {
                plotObj.emit('ping', 'pong');
            });
        });
        it('mirrors events on an internal handler', function(done) {
            Events.init(plotDiv);

            plotDiv._internalOn('ping', function(data) {
                expect(data).toBe('pong');
                done();
            });

            setTimeout(function() {
                plotDiv.emit('ping', 'pong');
            });
        });
        it('triggers jquery events', function(done) {
            Events.init(plotDiv);

            $(plotDiv).bind('ping', function(event, data) {
                expect(data).toBe('pong');
                done();
            });

            setTimeout(function() {
                $(plotDiv).trigger('ping', 'pong');
            });
        });
Example #8
0
    beforeEach(function(done) {
        gd = createGraphDiv();

        // bump event max listeners to remove console warnings
        Events.init(gd);
        gd._internalEv.setMaxListeners(20);

        // move update menu #2 to click on them separately
        var mockCopy = Lib.extendDeep({}, mock);
        mockCopy.layout.updatemenus[1].x = 1;

        allMenus = mockCopy.layout.updatemenus;
        buttonMenus = allMenus.filter(function(opts) { return opts.type === 'buttons'; });
        dropdownMenus = allMenus.filter(function(opts) { return opts.type !== 'buttons'; });

        Plotly.plot(gd, mockCopy.data, mockCopy.layout)
        .catch(failTest)
        .then(done);
    });
Example #9
0
 it('instantiates an emitter on incoming plot object', function() {
     expect(plotObj._ev).not.toBeDefined();
     expect(Events.init(plotObj)._ev).toBeDefined();
 });
        it('should remove all method from the plotObj', function() {
            Events.init(plotObj);
            Events.purge(plotObj);

            expect(plotObj).toEqual({});
        });