From 1bce4f08772ef02dae737774bc9c1220fdd9d553 Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Sun, 18 Nov 2018 20:09:59 -0800 Subject: [PATCH] Add back event tests. --- lib/legacy/polymer.dom.js | 20 +++++++++- test/unit/polymer-dom-nopatch.html | 60 +++++++++++++++--------------- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/lib/legacy/polymer.dom.js b/lib/legacy/polymer.dom.js index dd5d961ee1..8462873421 100644 --- a/lib/legacy/polymer.dom.js +++ b/lib/legacy/polymer.dom.js @@ -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]; } /** @@ -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, [ diff --git a/test/unit/polymer-dom-nopatch.html b/test/unit/polymer-dom-nopatch.html index d08c1eb527..d5c87afb6b 100644 --- a/test/unit/polymer-dom-nopatch.html +++ b/test/unit/polymer-dom-nopatch.html @@ -14,7 +14,7 @@ - + @@ -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() {