Skip to content

Commit

Permalink
Remove test-specific behaviour for BasicDropdownWormhole (#937)
Browse files Browse the repository at this point in the history
* use consistent BasicDropdownWormhole behaviour in tests

* Fix test

---------

Co-authored-by: Paul Kuruvilla <[email protected]>
  • Loading branch information
mkszepp and rohitpaulk authored Aug 27, 2024
1 parent d816d19 commit 6d619d7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
17 changes: 2 additions & 15 deletions ember-basic-dropdown/src/components/basic-dropdown-wormhole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,11 @@ export default class BasicDropdownWormholeComponent extends Component<BasicDropd
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const config = getOwner(this).resolveRegistration('config:environment') as {
environment: string;
APP: {
rootElement: string;
};
'ember-basic-dropdown': {
destination: string;
'ember-basic-dropdown'?: {
destination?: string;
};
};

if (config.environment === 'test') {
// document doesn't exists in fastboot apps, for this reason we need this check
if (typeof document === 'undefined') {
return '';
}
const rootElement = config['APP']?.rootElement;
return document.querySelector(rootElement)?.id ?? '';
}

return ((config['ember-basic-dropdown'] &&
config['ember-basic-dropdown'].destination) ||
'ember-basic-dropdown-wormhole') as string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,47 @@ import config from 'test-app/config/environment';
module('Integration | Component | basic-dropdown-wormhole', function (hooks) {
setupRenderingTest(hooks);

hooks.beforeEach(async function () {
// Duplicate config to avoid mutating global config
this.originalConfig = JSON.parse(
JSON.stringify(config['ember-basic-dropdown'] || {}),
);
});

hooks.afterEach(async function () {
config['ember-basic-dropdown'] = this.originalConfig;
});

test('Is present', async function (assert) {
await render(hbs`
<BasicDropdownWormhole />
`);

let id = '#ember-testing';
if (config.APP.shadowDom) {
id = '#ember-basic-dropdown-wormhole';
}
assert
.dom('#ember-basic-dropdown-wormhole', this.element.getRootNode())
.exists('wormhole is present');
});

assert.dom(id, this.element.getRootNode()).exists('wormhole is present');
test('Uses custom destination from config if present', async function (assert) {
config['ember-basic-dropdown'] = {
destination: 'custom-wormhole-destination',
};

await render(hbs`<BasicDropdownWormhole />`);

assert
.dom(
'.ember-application #custom-wormhole-destination',
this.element.getRootNode(),
)
.exists('custom destination is used');

assert
.dom(
'.ember-application #ember-basic-dropdown-wormhole',
this.element.getRootNode(),
)
.doesNotExist('default destination is not used');
});

test('Has class my-custom-class', async function (assert) {
Expand Down

0 comments on commit 6d619d7

Please sign in to comment.