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

Conversation

rohitpaulk
Copy link
Contributor

@rohitpaulk rohitpaulk commented Aug 7, 2024

Fixes #931.

I tried reading through the history of this to figure out why it was present, but nothing turned up. The commit that added the test-specific condition was 067ca88.

cc: @mkszepp in case you've got more context on why this was needed?

Reasoning behind removing this: If tests are using application.hbs, the component should work as-is. If tests aren't using application.hbs (component tests for example), the wormhole will need to be setup manually anyway + it'll still need to have the wormhole-specific ID, not ember-testing.

@rohitpaulk rohitpaulk force-pushed the fix-test-behaviour branch 2 times, most recently from 2f3fe4d to 7d74566 Compare August 7, 2024 16:46
@mkszepp
Copy link
Collaborator

mkszepp commented Aug 8, 2024

@rohitpaulk the code was added in this commit PR #743 ... i have only synced the code parts like it is in basic-dropdown, no specific condition.

_getDestinationId(): string {
// 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;
};
};
if (config.environment === 'test') {
// document doesn't exists in fastboot apps, for this reason we need this check
if (typeof document === 'undefined') {
return 'ember-basic-dropdown-wormhole';
}
const rootElement = config['APP']?.rootElement;
return (
document.querySelector(rootElement)?.id ??
'ember-basic-dropdown-wormhole'
);
}
return ((config['ember-basic-dropdown'] &&
config['ember-basic-dropdown'].destination) ||
'ember-basic-dropdown-wormhole') as string;
}

Can you add any test that we can see that it works fine also after this changes?

@rohitpaulk
Copy link
Contributor Author

@mkszepp thanks for the context! I've added tests for this.

The commit you linked to indeed only re-arranges stuff and doesn't alter logic. 067ca88 seems to be where the isTesting condition was added. That's the one I wasn't sure about - do you remember if there was a specific reason to add the isTesting check?

@rohitpaulk
Copy link
Contributor Author

Looks like there a shadow dom test failure, will check shortly!

@mkszepp
Copy link
Collaborator

mkszepp commented Aug 27, 2024

@rohitpaulk i have checked why the test fails and its not directly caused with you changes... its because we are adding for shadow dom tests already with a initializer the element (for tests unfortunately there is no better solution)

replacing your test dom('#custom-wormhole-destination') with dom('.ember-application #custom-wormhole-destination') solves the issue and test is also correct

const rootElement = document.createElement('div');
const wormhole = document.createElement('div');
wormhole.id = 'ember-basic-dropdown-wormhole';
hostElement.shadowRoot.appendChild(wormhole);
hostElement.shadowRoot.appendChild(rootElement);
targetElement.appendChild(hostElement);
config.APP.rootElement = '#ember-basic-dropdown-wormhole';
appInstance.set('rootElement', rootElement);
}

Unfortunately I have no rights to work on your branch, so I had to make a fork

Thanks for fixing the issue

@mkszepp mkszepp closed this Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove code that specifies different behaviour in tests inside of BasicDropdownWormhole
2 participants