Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Apr 25, 2014
1 parent 6dc0819 commit ed0642d
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions test/html/event-handlers.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<div id="list" style="height: 200px; overflow: auto; border: 1px solid black;" on-scroll="{{scrollAction}}">
<div class="gradient">
<template repeat="{{list1}}">
<div class="list1" on-tap="{{itemTapAction}}">{{index}}</div>
<div class="list1" on-up="{{itemUpAction}}">{{index}}</div>
</template>
<template repeat="{{item in list2}}">
<div class="list2" on-tap="{{foo.itemTapAction}}">{{item.index}}</div>
Expand All @@ -48,13 +48,14 @@
ready: function() {
this.list1 = [];
this.list2 = [];
var self = this;
for (var i=0, o; i <10; i++) {
o = {index: i};
this.list1.push(o);
}
for (var i=0, o; i <10; i++) {
o = {index: i, itemTapAction: function(e) {
//console.log('model action: [%s].%s', e.currentTarget.localName, e.type, this);
self.itemTapAction(e);
this.itemTapAction(e);
}};
this.list1.push(o);
this.list2.push(o);
}
this.runTests();
Expand All @@ -66,7 +67,7 @@
}
},
hostTapAction: function(e) {
this.logEvent(e);
e.gotHostEvent = true;
},
divTapAction: function(e) {
this.logEvent(e);
Expand All @@ -81,41 +82,38 @@
this.logEvent(e);
},
logEvent: function(e, message) {
this.tests++;
this.lastEvent = e.type;
e.gotEvent = true;
//console.log('[%s].%s: %s', e.currentTarget.localName, e.type, message || '');
},
itemTapAction: function(e) {
var model = e.target.templateInstance.model;
this.logEvent(e, 'item: ' + (model.item ? model.item.index : model.index));
e.stopPropagation();
},
itemUpAction: function(e) {
this.logEvent(e);
},
runTests: function() {
this.fire('tap', null, this.$.div, true);
chai.assert.equal(this.tests, 2, 'event heard at div and host');
chai.assert.equal(this.lastEvent, 'tap', 'tap handled');
this.fire('focus', null, this.$.input, false);
chai.assert.equal(this.tests, 3, 'event heard by input');
chai.assert.equal(this.lastEvent, 'focus', 'focus handled');
this.fire('blur', null, this.$.input, false);
chai.assert.equal(this.tests, 4, 'event heard by input');
chai.assert.equal(this.lastEvent, 'blur', 'blur handled');
this.fire('scroll', null, this.$.list, false);
chai.assert.equal(this.tests, 5, 'event heard by list');
chai.assert.equal(this.lastEvent, 'scroll', 'scroll handled');
var e = this.fire('tap', null, this.$.div, true);
chai.assert.isTrue(e.gotEvent, 'tap event heard at div host');
chai.assert.isTrue(e.gotHostEvent, 'tap event heard at host');
e = this.fire('focus', null, this.$.input, false);
chai.assert.isTrue(e.gotEvent, 'focus event heard by input');
e = this.fire('blur', null, this.$.input, false);
chai.assert.isTrue(e.gotEvent, 'blur event heard by input');
e = this.fire('scroll', null, this.$.list, false);
chai.assert.isTrue(e.gotEvent, 'scroll event heard by list');
this.onMutation(this.$.list, function() {
var l1 = this.$.list.querySelector('.list1');
this.fire('tap', null, l1, false);
chai.assert.equal(this.tests, 6, 'event heard by list1 item');
chai.assert.equal(this.lastEvent, 'tap', 'tap handled');
var e = this.fire('up', null, l1, false);
// TODO(rafaelw): fix assert
//chai.assert.isTrue(e.gotEvent, 'up event heard by list1 item');
var l2 = this.$.list.querySelector('.list2');
this.fire('tap', null, l2, false);
chai.assert.equal(this.tests, 7, 'event heard by list2 item');
chai.assert.equal(this.lastEvent, 'tap', 'tap handled by model');
e = this.fire('tap', null, l2, false);
chai.assert.isTrue(e.gotEvent, 'tap event heard by list2 handled by model');
var l21 = this.$.list.querySelector('.list2-1');
this.fire('tap', null, l21, false);
chai.assert.equal(this.tests, 8, 'event heard by list2-1 item');
chai.assert.equal(this.lastEvent, 'tap', 'tap handled by model');
e = this.fire('tap', null, l21, false);
chai.assert.isTrue(e.gotEvent, 'tap event heard by list2-1 item');
done();
});
}
Expand Down

0 comments on commit ed0642d

Please sign in to comment.