Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove test-specific behaviour for BasicDropdownWormhole #933

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,41 @@ 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('#custom-wormhole-destination', this.element.getRootNode())
.exists('custom destination is used');

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

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