diff --git a/addon/components/ember-tether.js b/addon/components/ember-tether.js index 4614550..142554e 100644 --- a/addon/components/ember-tether.js +++ b/addon/components/ember-tether.js @@ -20,6 +20,10 @@ export default class EmberTetherComponent extends Component { } get bodyElement() { + if (this.args.bodyElement) { + return document.getElementById(this.args.bodyElement); + } + let config = this.emberTetherConfig; if (config && config.bodyElementId) { return document.getElementById(config.bodyElementId); diff --git a/tests/acceptance/tether-test.js b/tests/acceptance/tether-test.js index 7502382..257c0cb 100644 --- a/tests/acceptance/tether-test.js +++ b/tests/acceptance/tether-test.js @@ -60,6 +60,16 @@ module('Acceptance | tether test', function (hooks) { ); }; + assert.parentHasId = function (thingSelector, parentId) { + let thing = document.querySelector(thingSelector); + let parent = thing.parentElement; + assert.equal( + parent.id, + parentId, + `${thingSelector}'s parent has id ${parentId}`, + ); + }; + test('tethering a thing to a target', async function (assert) { await visit('/'); @@ -67,6 +77,8 @@ module('Acceptance | tether test', function (hooks) { assert.rightOf('.tethered-thing', '#tether-target-1'); assert.topAligned('.another-tethered-thing', '#tether-target-3'); assert.leftOf('.another-tethered-thing', '#tether-target-3'); + + assert.parentHasId('.tethered-thing', 'ember-testing'); }); test('tethering to an Ember Component', async function (assert) { @@ -150,4 +162,16 @@ module('Acceptance | tether test', function (hooks) { ); }); }); + + test('bodyElement', async function (assert) { + await visit('/'); + + assert.topAligned( + '.a-tethered-thing-with-body-element', + '#tether-target-8', + ); + assert.rightOf('.a-tethered-thing-with-body-element', '#tether-target-8'); + + assert.parentHasId('.a-tethered-thing-with-body-element', 'body-element'); + }); }); diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs index 7578ec1..65704ac 100644 --- a/tests/dummy/app/templates/application.hbs +++ b/tests/dummy/app/templates/application.hbs @@ -52,6 +52,9 @@
5
6
7
+
8
+ +
+ + Another tethered thing with bodyElement + +