diff --git a/app/transitions/fly-to.js b/app/transitions/fly-to.js index 0ac41d91..6aaf41a6 100644 --- a/app/transitions/fly-to.js +++ b/app/transitions/fly-to.js @@ -14,8 +14,8 @@ export default function flyTo(opts={}) { var motion = { translateX: newOffset.left - oldOffset.left, translateY: newOffset.top - oldOffset.top, - width: this.newElement.width(), - height: this.newElement.height() + outerWidth: this.newElement.outerWidth(), + outerHeight: this.newElement.outerHeight() }; this.newElement.css({ visibility: 'hidden' }); diff --git a/tests/dummy/app/styles/_scenarios.scss b/tests/dummy/app/styles/_scenarios.scss index 1814d58d..12d54daa 100644 --- a/tests/dummy/app/styles/_scenarios.scss +++ b/tests/dummy/app/styles/_scenarios.scss @@ -87,6 +87,7 @@ td { margin: 20px; padding: 50px; box-sizing: content-box; + border: 1px solid purple; } .red-abs-box { @@ -99,6 +100,7 @@ td { margin: 30px; padding: 10px; box-sizing: content-box; + border: 1px solid purple; } .liquid-child { diff --git a/tests/integration/transitions/fly-to-test.js b/tests/integration/transitions/fly-to-test.js new file mode 100644 index 00000000..39b299a8 --- /dev/null +++ b/tests/integration/transitions/fly-to-test.js @@ -0,0 +1,144 @@ +/* global sinon */ +import Ember from "ember"; +import moduleForIntegration from "../../helpers/module-for-integration"; +import { test } from "ember-qunit"; +import QUnit from 'qunit'; + +moduleForIntegration('Integration: fly-to transition', { + teardown: function() { + QUnit.stop(); + var tmap = this.container.lookup('service:liquid-fire-transitions'); + tmap.waitUntilIdle().then(QUnit.start); + } +}); + +['border-box', 'content-box'].forEach(function(boxSizing) { + test(`it avoids a jump at end of animation, with absolutely positioned elements (${boxSizing})`, function(assert) { + expect(6); + this.container.lookup('service:liquid-fire-transitions').map(function() { + this.transition( + this.hasClass('fly-to-test'), + this.use('explode', { + pickOld: '.redbox', + pickNew: '.bluebox', + use: function() { + // sanity checks + assert.equal(this.oldElement && this.oldElement.length, 1, 'found old element'); + assert.equal(this.newElement && this.newElement.length, 1, 'found new element'); + assert.equal(this.oldElement && this.oldElement.css('background-color'), "rgb(255, 0, 0)"); + + return this.lookup('fly-to').call(this, { duration: 0 }).then(() => { + assert.deepEqual(this.newElement.offset(), this.oldElement.offset(), "element didn't jump"); + assert.equal(this.newElement.outerWidth(), this.oldElement.outerWidth(), "same width"); + assert.equal(this.newElement.outerHeight(), this.oldElement.outerHeight(), "same height"); + }); + } + }) + ); + }); + this.render(stylesheet(boxSizing) + ` + {{#liquid-if showBlue class="fly-to-test"}} +
+ {{else}} +
+ {{/liquid-if}} + `); + + this.set('showBlue', true); + }); + + test(`it avoids a jump at end of animation, with statically positioned elements (${boxSizing})`, function(assert) { + expect(6); + this.container.lookup('service:liquid-fire-transitions').map(function() { + this.transition( + this.hasClass('fly-to-test'), + this.use('explode', { + pickOld: '.greenbox', + pickNew: '.yellowbox', + use: function() { + // sanity checks + assert.equal(this.oldElement && this.oldElement.length, 1, 'found old element'); + assert.equal(this.newElement && this.newElement.length, 1, 'found new element'); + assert.equal(this.oldElement && this.oldElement.css('background-color'), "rgb(0, 128, 0)"); + + return this.lookup('fly-to').call(this, { duration: 0 }).then(() => { + assert.deepEqual(this.newElement.offset(), this.oldElement.offset(), "element didn't jump"); + assert.equal(this.newElement.outerWidth(), this.oldElement.outerWidth(), "same width"); + assert.equal(this.newElement.outerHeight(), this.oldElement.outerHeight(), "same height"); + }); + } + }) + ); + }); + this.render(stylesheet(boxSizing) + ` + {{#liquid-if showYellow class="fly-to-test"}} +
+ {{else}} +
+ {{/liquid-if}} + `); + + this.set('showYellow', true); + }); + + + + +}); + +function stylesheet(boxSizing) { + return ` + + + `; +}