Skip to content

Commit

Permalink
Adds textarea in test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandosouza authored and mairatma committed Aug 31, 2016
1 parent 0f317d7 commit 425af89
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/metal-dom/test/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,27 +633,34 @@ describe('dom', function() {
var input = document.createElement('input');
var select = document.createElement('select');
var button = document.createElement('button');
var textarea = document.createElement('textarea');
input.disabled = true;
select.disabled = true;
button.disabled = true;
textarea.disabled = true;
parent.appendChild(input);
parent.appendChild(select);
parent.appendChild(button);
parent.appendChild(textarea);

var listener1 = sinon.stub();
var listener2 = sinon.stub();
var listener3 = sinon.stub();
var listener4 = sinon.stub();

dom.delegate(parent, 'click', input, listener1);
dom.delegate(parent, 'click', select, listener2);
dom.delegate(parent, 'click', button, listener3);
dom.delegate(parent, 'click', button, listener4);

dom.triggerEvent(input, 'click');
dom.triggerEvent(select, 'click');
dom.triggerEvent(button, 'click');
dom.triggerEvent(textarea, 'click');
assert.strictEqual(0, listener1.callCount);
assert.strictEqual(0, listener2.callCount);
assert.strictEqual(0, listener3.callCount);
assert.strictEqual(0, listener4.callCount);
});

it('should not trigger delegate click event to an element which its valid parent is disabled', function() {
Expand All @@ -664,24 +671,29 @@ describe('dom', function() {
var input = document.createElement('input');
var select = document.createElement('select');
var button = document.createElement('button');
var textarea = document.createElement('textarea');
parent.appendChild(input);
parent.appendChild(select);
parent.appendChild(button);
parent.appendChild(textarea);

var listener1 = sinon.stub();
var listener2 = sinon.stub();
var listener3 = sinon.stub();
var listener4 = sinon.stub();

dom.delegate(parent, 'click', input, listener1);
dom.delegate(parent, 'click', select, listener2);
dom.delegate(parent, 'click', button, listener3);
dom.delegate(parent, 'click', textarea, listener4);

dom.triggerEvent(input, 'click');
dom.triggerEvent(select, 'click');
dom.triggerEvent(button, 'click');
assert.strictEqual(0, listener1.callCount);
assert.strictEqual(0, listener2.callCount);
assert.strictEqual(0, listener3.callCount);
assert.strictEqual(0, listener4.callCount);
});

it('it should trigger delegate click event on elements wrapped by a "legend" tag and with disabled parent', function() {
Expand All @@ -694,24 +706,30 @@ describe('dom', function() {
var input = document.createElement('input');
var select = document.createElement('select');
var button = document.createElement('button');
var textarea = document.createElement('textarea');
legend.appendChild(input);
legend.appendChild(select);
legend.appendChild(button);
legend.appendChild(textarea);

var listener1 = sinon.stub();
var listener2 = sinon.stub();
var listener3 = sinon.stub();
var listener4 = sinon.stub();

dom.delegate(fieldset, 'click', input, listener1);
dom.delegate(fieldset, 'click', select, listener2);
dom.delegate(fieldset, 'click', button, listener3);
dom.delegate(fieldset, 'click', textarea, listener4);

dom.triggerEvent(input, 'click');
dom.triggerEvent(select, 'click');
dom.triggerEvent(button, 'click');
dom.triggerEvent(textarea, 'click');
assert.strictEqual(1, listener1.callCount);
assert.strictEqual(1, listener2.callCount);
assert.strictEqual(1, listener3.callCount);
assert.strictEqual(1, listener4.callCount);
});

it('should not trigger delegate click event to an element which its valid parent is disabled even it is wrapped by another element different of legend', function() {
Expand All @@ -724,24 +742,30 @@ describe('dom', function() {
var input = document.createElement('input');
var select = document.createElement('select');
var button = document.createElement('button');
var textarea = document.createElement('textarea');
wrapper.appendChild(input);
wrapper.appendChild(select);
wrapper.appendChild(button);
wrapper.appendChild(textarea);

var listener1 = sinon.stub();
var listener2 = sinon.stub();
var listener3 = sinon.stub();
var listener4 = sinon.stub();

dom.delegate(fieldset, 'click', input, listener1);
dom.delegate(fieldset, 'click', select, listener2);
dom.delegate(fieldset, 'click', button, listener3);
dom.delegate(fieldset, 'click', textarea, listener4);

dom.triggerEvent(input, 'click');
dom.triggerEvent(select, 'click');
dom.triggerEvent(button, 'click');
dom.triggerEvent(textarea, 'click');
assert.strictEqual(0, listener1.callCount);
assert.strictEqual(0, listener2.callCount);
assert.strictEqual(0, listener3.callCount);
assert.strictEqual(0, listener4.callCount);
});
});

Expand Down

0 comments on commit 425af89

Please sign in to comment.