Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Oct 23, 2013
1 parent fea8d34 commit f28f584
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
45 changes: 35 additions & 10 deletions test/html/event-handlers.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,37 @@
}
</style>

<div on-tap="{{divTapAction}}">Tap me!
<div id="div" on-tap="{{divTapAction}}">Tap me!
<content></content>
</div>
<input id="input" on-focus="{{focusAction}}" on-blur="{{blurAction}}">focusy</input>
<div style="height: 200px; overflow: auto; border: 1px solid black;" on-scroll="{{scrollAction}}">
<div id="list" style="height: 200px; overflow: auto; border: 1px solid black;" on-scroll="{{scrollAction}}">
<div class="gradient">
<template repeat="{{list1}}">
<div on-tap="{{itemTapAction}}">{{index}}</div>
<div class="list1" on-tap="{{itemTapAction}}">{{index}}</div>
</template>
<template repeat="{{item in list2}}">
<div on-tap="{{@item.itemTapAction}}">{{item.index}}</div>
<div class="list2" on-tap="{{@item.itemTapAction}}">{{item.index}}</div>
</template>
</div>
</div>
</template>
<script>
Polymer('x-test', {
tests: 0,
ready: function() {
this.list1 = [];
this.list2 = [];
var self = this;
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);
self.itemTapAction(e);
}};
this.list1.push(o);
this.list2.push(o);
}
this.runTests();
},
hostTapAction: function(e) {
this.logEvent(e);
Expand All @@ -71,21 +75,42 @@
this.logEvent(e);
},
logEvent: function(e, message) {
this.tests++;
this.lastEvent = e.type;
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();
},
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');
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 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');
done();
});
}
});
</script>
</polymer-element>


<script>
document.addEventListener('WebComponentsReady', function() {
})
</script>
</body>
</html>
22 changes: 1 addition & 21 deletions test/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,10 @@ suite('events', function() {
done();
}, 0);
});

/*test('host events order', function() {
createTestElement('x-foo');
createTestElement('x-bar', '<x-foo></x-foo>');
var bar = document.createElement('x-bar');
work.appendChild(bar);
// click on x-foo
bar.webkitShadowRoot.childNodes[0].click();
assert.equal(results.textContent, 'x-foox-bar');
});
test('host events order more', function() {
createTestElement('x-foo');
createTestElement('x-bar', '<x-foo></x-foo>');
createTestElement('x-zot', '<x-bar></x-bar>');
var zot = document.createElement('x-zot');
work.appendChild(zot);
// click on x-foo
zot.webkitShadowRoot.childNodes[0].webkitShadowRoot.childNodes[0].click();
assert.equal(results.textContent, 'x-foox-barx-zot');
});*/
});

htmlSuite('events-declarative', function() {
htmlTest('html/event-handlers.html');
htmlTest('html/event-path.html');
htmlTest('html/event-path-declarative.html');
});

0 comments on commit f28f584

Please sign in to comment.