From 98e1dcf990cfdbd9e9a105a392c0442a4aa5fe58 Mon Sep 17 00:00:00 2001 From: Jan Tagscherer Date: Sat, 27 Oct 2018 20:13:36 +0200 Subject: [PATCH 1/3] Always keep animation end listener active, fixes #132 --- paper-tooltip.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paper-tooltip.js b/paper-tooltip.js index 9476bc8..6568bfb 100644 --- a/paper-tooltip.js +++ b/paper-tooltip.js @@ -339,6 +339,7 @@ Polymer({ */ attached: function() { this._findTarget(); + this.listen(this.$.tooltip, 'animationend', '_onAnimationEnd'); }, /** @@ -347,6 +348,7 @@ Polymer({ detached: function() { if (!this.manualMode) this._removeListeners(); + this.unlisten(this.$.tooltip, 'animationend', '_onAnimationEnd'); }, /** @@ -496,7 +498,6 @@ Polymer({ this.listen(this._target, 'blur', 'hide'); this.listen(this._target, 'tap', 'hide'); } - this.listen(this.$.tooltip, 'animationend', '_onAnimationEnd'); this.listen(this, 'mouseenter', 'hide'); }, @@ -582,7 +583,6 @@ Polymer({ this.unlisten(this._target, 'blur', 'hide'); this.unlisten(this._target, 'tap', 'hide'); } - this.unlisten(this.$.tooltip, 'animationend', '_onAnimationEnd'); this.unlisten(this, 'mouseenter', 'hide'); } }); From b28c3541fb69b9a15ff7925514a947a268daa318 Mon Sep 17 00:00:00 2001 From: Jan Tagscherer Date: Sat, 27 Oct 2018 20:14:33 +0200 Subject: [PATCH 2/3] Add unit test for animation playback state in manual mode --- test/basic.html | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/basic.html b/test/basic.html index fe86f40..cdc7274 100644 --- a/test/basic.html +++ b/test/basic.html @@ -476,6 +476,29 @@ expect(tooltip._addListeners.callCount).to.be.equal(1); expect(tooltip._removeListeners.callCount).to.be.equal(1); }); + + test('animation state is updated in manual-mode', function() { + var f = fixture('manual-mode'); + + var tooltip = f.querySelector('paper-tooltip'); + assert.isTrue(tooltip.manualMode); + sinon.spy(tooltip, '_onAnimationEnd'); + + // Manually set the animation state for testing purposes + tooltip._animationPlaying = true; + assert.isTrue(tooltip._animationPlaying); + + // Select the inner tooltip div and use it to simulate the end of its + // animation + var tooltipContainer = tooltip.shadowRoot.querySelector('#tooltip'); + + // Dispatch an event simulating the end of a tooltip animation and make + // sure that the callback has been executed and that the animation + // state has been updated + tooltipContainer.dispatchEvent(new CustomEvent('animationend')); + expect(tooltip._onAnimationEnd.callCount).to.be.equal(1); + assert.isFalse(tooltip._animationPlaying); + }); test('changing for= re-targets event listeners', function() { var f = fixture('dynamic'); From 08df7bedf839bf6141c55bbe50434614ae3db8b1 Mon Sep 17 00:00:00 2001 From: Jan Tagscherer Date: Sat, 27 Oct 2018 20:50:21 +0200 Subject: [PATCH 3/3] Formatting --- test/basic.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/basic.html b/test/basic.html index cdc7274..e893af9 100644 --- a/test/basic.html +++ b/test/basic.html @@ -476,24 +476,24 @@ expect(tooltip._addListeners.callCount).to.be.equal(1); expect(tooltip._removeListeners.callCount).to.be.equal(1); }); - + test('animation state is updated in manual-mode', function() { var f = fixture('manual-mode'); var tooltip = f.querySelector('paper-tooltip'); assert.isTrue(tooltip.manualMode); sinon.spy(tooltip, '_onAnimationEnd'); - + // Manually set the animation state for testing purposes tooltip._animationPlaying = true; assert.isTrue(tooltip._animationPlaying); - - // Select the inner tooltip div and use it to simulate the end of its + + // Select the inner tooltip div and use it to simulate the end of its // animation var tooltipContainer = tooltip.shadowRoot.querySelector('#tooltip'); - - // Dispatch an event simulating the end of a tooltip animation and make - // sure that the callback has been executed and that the animation + + // Dispatch an event simulating the end of a tooltip animation and make + // sure that the callback has been executed and that the animation // state has been updated tooltipContainer.dispatchEvent(new CustomEvent('animationend')); expect(tooltip._onAnimationEnd.callCount).to.be.equal(1);