Skip to content

Commit

Permalink
Add back event tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Nov 19, 2018
1 parent b211436 commit 1bce4f0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 30 deletions.
20 changes: 19 additions & 1 deletion lib/legacy/polymer.dom.js
Expand Up @@ -259,7 +259,7 @@ export class EventApi {
* @return {!EventTarget} The node this event was dispatched to
*/
get rootTarget() {
return this.event.composedPath()[0];
return this.path[0];
}

/**
Expand Down Expand Up @@ -446,6 +446,24 @@ if (window.ShadyDOM && window.ShadyDOM.inUse && window.ShadyDOM.noPatch) {
}

DomApi = Wrapper;

Object.defineProperties(EventApi.prototype, {

localTarget: {
get() {
return window.ShadyDOM && window.ShadyDOM.noPatch ? this.event.currentTarget : this.event.target;
},
configurable: true
},

path: {
get() {
return ShadyDOM.composedPath(this.event);
},
configurable: true
}
});

} else {

forwardMethods(DomApi.prototype, [
Expand Down
60 changes: 31 additions & 29 deletions test/unit/polymer-dom-nopatch.html
Expand Up @@ -14,7 +14,7 @@
<script>
ShadyDOM = {force: true, noPatch: true};
</script>
<script src="../../node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
<script src="wct-browser-config.js"></script>
<script src="../../node_modules/wct-browser-legacy/browser.js"></script>
<script type="module" src="../../polymer-legacy.js"></script>
Expand Down Expand Up @@ -156,37 +156,39 @@
});
});

// suite('events', function() {
suite('events', function() {

// test('localTarget, rootTarget, path', function(done) {
// var el = fixture('scoped');
// el.addEventListener('composed', function(e) {
// assert.equal(dom(e).rootTarget, el.$.scoped);
// assert.equal(dom(e).localTarget, el);
// let nodes = [];
// let p = el.$.scoped;
// while (p) {
// nodes.push(p);
// p = p.parentNode || p.host;
// }
// nodes.push(window);
// assert.deepEqual(Array.from(dom(e).path), nodes);
// done();
// });
// el.fireComposed();
// });
test('localTarget, rootTarget, path', function(done) {
var el = fixture('scoped');
el.addEventListener('composed', function(e) {
assert.equal(dom(e).rootTarget, el.$.scoped);
assert.equal(dom(e).localTarget, el);
let nodes = [];
let p = el.$.scoped;
while (p) {
nodes.push(p);
p = dom(p).parentNode || dom(p).host;
}
nodes.push(window);
const path = dom(e).path;
assert.deepEqual(path, nodes);
done();
});
ShadyDOM.flush();
el.fireComposed();
});

// });
});

// suite('activeElement getter', function() {
// test('Retrieves `_activeElement` (ShadyDOM) or `activeElement`.', function() {
// var focusableInShadow = fixture('focusableInShadow');
// focusableInShadow.$.focusable.focus();
// var rootNode = focusableInShadow.getRootNode();
// assert.equal(dom(rootNode).activeElement, focusableInShadow);
// assert.equal(dom(focusableInShadow.shadowRoot).activeElement, focusableInShadow.$.focusable);
// });
// });
suite('activeElement getter', function() {
test('Retrieves `activeElement`', function() {
var focusableInShadow = fixture('focusableInShadow');
focusableInShadow.$.focusable.focus();
var rootNode = dom(focusableInShadow).getRootNode();
assert.equal(dom(rootNode).activeElement, focusableInShadow);
assert.equal(dom(dom(focusableInShadow).shadowRoot).activeElement, focusableInShadow.$.focusable);
});
});

suite('legacy api', function() {
test('getEffectiveChildNodes', function() {
Expand Down

0 comments on commit 1bce4f0

Please sign in to comment.