este-library-oldschool
Version:
Library for github.com/steida/este.git
130 lines • 5.56 kB
JavaScript
// Generated by github.com/steida/coffee2closure 900.1.18
suite('este.events.EventHandler', function() {
var EventHandler, el, handler;
EventHandler = este.events.EventHandler;
handler = null;
el = null;
setup(function() {
handler = new EventHandler;
return el = document.createElement('div');
});
teardown(function() {
return EventHandler.handlers = {};
});
suite('constructor', function() {
return test('should work', function() {
return assert.instanceOf(handler, EventHandler);
});
});
suite('EventHandler.getHandlerClass', function() {
test('should return null for non element', function() {
return assert.isNull(EventHandler.getHandlerClass({}, 'foo'));
});
test('should return GestureHandler class for tap', function() {
var handlerClass;
handlerClass = EventHandler.getHandlerClass(el, 'tap');
return assert.equal(handlerClass, este.events.GestureHandler);
});
test('should return SubmitHandler class for submit', function() {
var handlerClass;
handlerClass = EventHandler.getHandlerClass(el, 'submit');
return assert.equal(handlerClass, este.events.SubmitHandler);
});
test('should return FocusHandler class for focusin', function() {
var handlerClass;
handlerClass = EventHandler.getHandlerClass(el, 'focusin');
return assert.equal(handlerClass, goog.events.FocusHandler);
});
test('should return FocusHandler class for focusout', function() {
var handlerClass;
handlerClass = EventHandler.getHandlerClass(el, 'focusout');
return assert.equal(handlerClass, goog.events.FocusHandler);
});
test('should return InputHandler class for input', function() {
var handlerClass;
handlerClass = EventHandler.getHandlerClass(el, 'input');
return assert.equal(handlerClass, goog.events.InputHandler);
});
test('should return KeyHandler class for key', function() {
var handlerClass;
handlerClass = EventHandler.getHandlerClass(el, 'key');
return assert.equal(handlerClass, goog.events.KeyHandler);
});
return test('should return MouseWheelHandler class for mousewheel', function() {
var handlerClass;
handlerClass = EventHandler.getHandlerClass(el, 'mousewheel');
return assert.equal(handlerClass, goog.events.MouseWheelHandler);
});
});
suite('listen', function() {
test('should return instance for one type', function() {
var result;
result = handler.listen(el, 'focusin', function() {});
return assert.equal(result, handler);
});
test('should return instance for more types', function() {
var result;
result = handler.listen(el, ['focusin', 'focusout'], function() {});
return assert.equal(result, handler);
});
suite('focusin and focusout on the same element', function() {
return test('should create only one FocusHandler instance', function() {
var count, instance;
handler.listen(el, 'focusin', function() {});
handler.listen(el, 'focusout', function() {});
count = goog.object.getCount(este.events.EventHandler.handlers);
assert.equal(count, 1);
instance = goog.object.getAnyValue(este.events.EventHandler.handlers);
return assert.instanceOf(instance, goog.events.FocusHandler);
});
});
suite('focusin and focusout on the same element with type as array', function() {
return test('should create only one FocusHandler instance', function() {
var count, instance;
handler.listen(el, ['focusin', 'focusout'], function() {});
count = goog.object.getCount(este.events.EventHandler.handlers);
assert.equal(count, 1);
instance = goog.object.getAnyValue(este.events.EventHandler.handlers);
return assert.instanceOf(instance, goog.events.FocusHandler);
});
});
return suite('focusin and focusout on different elements', function() {
return test('should create two FocusHandler instances', function() {
var count;
handler.listen(el, 'focusin', function() {});
handler.listen(document.createElement('div'), 'focusout', function() {});
count = goog.object.getCount(este.events.EventHandler.handlers);
return assert.equal(count, 2);
});
});
});
suite('unlisten focusin, focusout', function() {
return test('should dispose FocusHander', function(done) {
var focusHandler, onIn, onOut;
onIn = function() {};
onOut = function() {};
handler.listen(el, 'focusin', onIn);
handler.listen(el, 'focusout', onOut);
focusHandler = goog.object.getAnyValue(este.events.EventHandler.handlers);
focusHandler.dispose = function() {
assert.isTrue(goog.object.isEmpty(este.events.EventHandler.handlers));
return done();
};
handler.unlisten(el, 'focusin', onIn);
return handler.unlisten(el, 'focusout', onOut);
});
});
return suite('removeAll', function() {
return test('should work', function() {
handler.listen(el, 'submit', function() {});
handler.listen(el, 'focusin', function() {});
handler.listen(el, 'focusout', function() {});
handler.listen(el, 'input', function() {});
handler.listen(el, 'key', function() {});
handler.listen(el, 'mousewheel', function() {});
handler.listen(el, 'click', function() {});
handler.removeAll();
return assert.isTrue(goog.object.isEmpty(este.events.EventHandler.handlers));
});
});
});