UNPKG

este-library-oldschool

Version:

Library for github.com/steida/este.git

198 lines 6.12 kB
// Generated by github.com/steida/coffee2closure 900.1.18 suite('este.events.Delegation', function() { var Delegation, delegation, element; Delegation = este.events.Delegation; element = null; delegation = null; setup(function() { element = document.createElement('div'); delegation = new Delegation(element, ['click', 'mouseover', 'mouseout']); delegation.targetFilter = function(el) { return el.className === 'target'; }; return delegation.targetParentFilter = function(el) { return el.className === 'parent'; }; }); suite('Delegation.create', function() { return test('should return delegation', function() { delegation = new Delegation(element, ['click', 'mouseover', 'mouseout']); return assert.instanceOf(delegation, Delegation); }); }); suite('should dispatch click', function() { test('on element with className .target and with parent className .parent', function(done) { goog.events.listen(delegation, 'click', function() { return done(); }); return goog.events.fireListeners(element, 'click', false, { type: 'click', target: { className: 'target', nodeType: 1, parentNode: { className: 'parent' } } }); }); test('on element with className .target and without parent', function(done) { delete delegation.targetParentFilter; goog.events.listen(delegation, 'click', function() { return done(); }); return goog.events.fireListeners(element, 'click', false, { type: 'click', target: { nodeType: 1, className: 'target' } }); }); return test('on element inside el with className .target and with parent className .parent', function(done) { var target; target = { nodeType: 1, className: 'target', parentNode: { nodeType: 1, className: 'parent' } }; goog.events.listen(delegation, 'click', function(e) { assert.equal(e.target, target, 'target should be updated'); return done(); }); return goog.events.fireListeners(element, 'click', false, { type: 'click', target: { nodeType: 1, parentNode: target } }); }); }); suite('should not dispatch click', function() { test('on element without className .target', function() { var called; called = false; goog.events.listen(delegation, 'click', function() { return called = true; }); goog.events.fireListeners(element, 'click', false, { type: 'click', target: {} }); return assert.isFalse(called); }); return test('on element with className .target and without parent className .parent', function() { var called; called = false; goog.events.listen(delegation, 'click', function() { return called = true; }); goog.events.fireListeners(element, 'click', false, { type: 'click', target: { className: 'target', parentNode: {} } }); return assert.isFalse(called); }); }); suite('should not dispatch mouseover', function() { return test('on element inside target', function() { var called, target; called = false; target = { className: 'target', parentNode: { className: 'parent' } }; goog.events.listen(delegation, 'mouseover', function() { return called = true; }); goog.events.fireListeners(element, 'mouseover', false, { type: 'mouseover', relatedTarget: target, target: { parentNode: target } }); return assert.isFalse(called); }); }); suite('should not dispatch mouseout', function() { return test('on element inside target', function() { var called, target; called = false; target = { className: 'target', parentNode: { className: 'parent' } }; goog.events.listen(delegation, 'mouseout', function() { return called = true; }); goog.events.fireListeners(element, 'mouseout', false, { type: 'mouseout', relatedTarget: target, target: { parentNode: target } }); return assert.isFalse(called); }); }); suite('w3c', function() { suite('focus', function() { return test('should call addEventListener', function(done) { element.addEventListener = function(type, fn, capture) { assert.equal(type, 'focus'); assert.isFunction(fn); assert.isTrue(capture); return done(); }; return delegation = new Delegation(element, 'focus'); }); }); return suite('blur', function() { return test('should call addEventListener', function(done) { element.addEventListener = function(type, fn, capture) { assert.equal(type, 'blur'); assert.isFunction(fn); assert.isTrue(capture); return done(); }; return delegation = new Delegation(element, 'blur'); }); }); }); return suite('ie', function() { suite('focus', function() { return test('should call addEventListener', function(done) { element.addEventListener = function(type, fn, capture) { assert.equal(type, 'focusin'); assert.isFunction(fn); assert.isFalse(capture); return done(); }; return delegation = new Delegation(element, 'focus', true); }); }); return suite('blur', function() { return test('should call addEventListener', function(done) { element.addEventListener = function(type, fn, capture) { assert.equal(type, 'focusout'); assert.isFunction(fn); assert.isFalse(capture); return done(); }; return delegation = new Delegation(element, 'blur', true); }); }); }); });