From 36fedbc62d72bd1926a46ab13d322fa7a6d45015 Mon Sep 17 00:00:00 2001 From: Alex DiLiberto Date: Thu, 3 Jun 2021 12:07:04 -0400 Subject: [PATCH] add failing test for https://github.com/cibernox/ember-basic-dropdown/issues/614 --- .../components/basic-dropdown-test.js | 88 ++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/tests/integration/components/basic-dropdown-test.js b/tests/integration/components/basic-dropdown-test.js index 304a88e7..8f602af1 100644 --- a/tests/integration/components/basic-dropdown-test.js +++ b/tests/integration/components/basic-dropdown-test.js @@ -596,7 +596,7 @@ module('Integration | Component | basic-dropdown', function (hooks) { assert.dom('#is-disabled').doesNotExist('The select is enabled again'); }); - test('It can receive `@destination="id-of-elmnt"` to customize where `#-in-element` is going to render the content', async function (assert) { + test('It can receive `@destination="id-of-elmnt"` to customize where `#-in-element` is going to render the content (`id-of-elmnt` appears in dom order after BasicDropdown)', async function (assert) { assert.expect(1); await render(hbs` @@ -619,6 +619,92 @@ module('Integration | Component | basic-dropdown', function (hooks) { ); }); + test('It can receive `@destination="id-of-elmnt"` to customize where `#-in-element` is going to render the content (`id-of-elmnt` appears in dom order before BasicDropdown)', async function (assert) { + assert.expect(1); + + await render(hbs` +
+ + Click me + Hello + + `); + await click('.ember-basic-dropdown-trigger'); + + assert + .dom( + this.element.querySelector('.ember-basic-dropdown-content').parentNode + ) + .hasAttribute( + 'id', + 'id-of-elmnt', + 'The content has been rendered in an alternative destination' + ); + }); + + /** + FAILING TEST: + + ```ts + // addon/components/basic-dropdown-content.ts + + get destinationElement() { + return document.getElementById(this.args.destination); + } + ``` + + `document.getElementById(this.args.destination);` returns `null` in this scenario + */ + test('It can receive `@destination="id-of-elmnt"` to customize where `#-in-element` is going to render the content (`id-of-elmnt` appears in dom order after BasicDropdown) along with `@initiallyOpened={{true}}`', async function (assert) { + assert.expect(2); + + await render(hbs` + + Click me + + Hello + + +
+ `); + + assert.dom('#dropdown-is-opened').exists('The dropdown is opened'); + assert + .dom( + this.element.querySelector('.ember-basic-dropdown-content').parentNode + ) + .hasAttribute( + 'id', + 'id-of-elmnt', + 'The content has been rendered in an alternative destination' + ); + }); + + test('It can receive `@destination="id-of-elmnt"` to customize where `#-in-element` is going to render the content (`id-of-elmnt` appears in dom order before BasicDropdown) along with `@initiallyOpened={{true}}`', async function (assert) { + assert.expect(2); + + await render(hbs` +
+ + Click me + + Hello + + + `); + + assert.dom('#dropdown-is-opened').exists('The dropdown is opened'); + assert + .dom( + this.element.querySelector('.ember-basic-dropdown-content').parentNode + ) + .hasAttribute( + 'id', + 'id-of-elmnt', + 'The content has been rendered in an alternative destination' + ); + }); + // A11y test('By default, the `aria-owns` attribute of the trigger contains the id of the content', async function (assert) { assert.expect(1);