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

fix: setFocus methods should wait for the component to be loaded #5749

Merged
merged 18 commits into from
Nov 19, 2022

Conversation

driskull
Copy link
Member

@driskull driskull commented Nov 15, 2022

fix: setFocus methods should wait for the component to be loaded

@driskull
Copy link
Member Author

@jcfranco what about something like this to fix #5369?

@driskull driskull changed the title Prototype: setFocus waiting for component to be loaded Prototype: setFocus should wait for component to be loaded Nov 15, 2022
@driskull driskull changed the title Prototype: setFocus should wait for component to be loaded fix: setFocus should wait for component to be loaded Nov 15, 2022
Copy link
Member

@jcfranco jcfranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶
🕶😎🕶🕶🕶🕶😎😎🕶🕶🕶😎😎🕶🕶😎🕶🕶😎🕶😎😎😎🕶😎🕶🕶🕶😎🕶😎😎😎😎🕶
🕶😎🕶🕶🕶😎🕶🕶😎🕶😎🕶🕶😎🕶😎🕶😎🕶🕶🕶😎🕶🕶😎😎🕶🕶😎🕶😎🕶🕶🕶🕶
🕶😎🕶🕶🕶😎🕶🕶😎🕶😎🕶🕶😎🕶😎😎🕶🕶🕶🕶😎🕶🕶😎🕶😎🕶😎🕶😎🕶😎😎🕶
🕶😎🕶🕶🕶😎🕶🕶😎🕶😎🕶🕶😎🕶😎🕶😎🕶🕶🕶😎🕶🕶😎🕶🕶😎😎🕶😎🕶🕶😎🕶
🕶😎😎😎🕶🕶😎😎🕶🕶🕶😎😎🕶🕶😎🕶🕶😎🕶😎😎😎🕶😎🕶🕶🕶😎🕶😎😎😎😎🕶
🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶

🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶
🕶😎😎😎😎🕶🕶😎😎🕶🕶🕶😎😎🕶🕶😎😎😎🕶🕶😎🕶
🕶😎🕶🕶🕶🕶😎🕶🕶😎🕶😎🕶🕶😎🕶😎🕶🕶😎🕶😎🕶
🕶😎🕶😎😎🕶😎🕶🕶😎🕶😎🕶🕶😎🕶😎🕶🕶😎🕶😎🕶
🕶😎🕶🕶😎🕶😎🕶🕶😎🕶😎🕶🕶😎🕶😎🕶🕶😎🕶🕶🕶
🕶😎😎😎😎🕶🕶😎😎🕶🕶🕶😎😎🕶🕶😎😎😎🕶🕶😎🕶
🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶🕶

src/utils/loadable.ts Outdated Show resolved Hide resolved
src/utils/loadable.ts Outdated Show resolved Hide resolved
src/utils/focusable.ts Outdated Show resolved Hide resolved
src/utils/loadable.ts Show resolved Hide resolved
src/utils/loadable.ts Show resolved Hide resolved
src/utils/loadable.ts Outdated Show resolved Hide resolved
src/components/flow-item/flow-item.tsx Show resolved Hide resolved
@github-actions github-actions bot added the bug Bug reports for broken functionality. Issues should include a reproduction of the bug. label Nov 15, 2022
@driskull driskull marked this pull request as ready for review November 16, 2022 21:24
@driskull driskull requested a review from a team as a code owner November 16, 2022 21:24
@driskull driskull changed the title fix: setFocus should wait for component to be loaded fix: setFocus should wait for components to be loaded Nov 16, 2022
@driskull driskull changed the title fix: setFocus should wait for components to be loaded fix: setFocus methods should wait for the component to be loaded Nov 16, 2022
@driskull driskull added the pr ready for visual snapshots Adding this label will run visual snapshot testing. label Nov 17, 2022
Copy link
Member

@jcfranco jcfranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀
👀👓👓👓👓👀👀👓👓👀👀👀👓👓👓👀👓👀👀👀👓👀👀👓👓👓👀👓👀
👀👓👀👀👀👀👓👀👀👓👀👓👀👀👀👀👓👀👀👀👓👀👓👀👀👀👀👓👀
👀👓👓👓👀👀👓👀👀👓👀👓👀👀👀👀👓👀👀👀👓👀👀👓👓👀👀👓👀
👀👓👀👀👀👀👓👀👀👓👀👓👀👀👀👀👓👀👀👀👓👀👀👀👀👓👀👀👀
👀👓👀👀👀👀👀👓👓👀👀👀👓👓👓👀👀👓👓👓👀👀👓👓👓👀👀👓👀
👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀

Awesome!

WRT components using setFocus, as long as we have a follow-up issue and convention note to ensure we use the loadable util consistently, I think it's fine for the focusable test helper to not cover it since it's a Stencil lifecycle bug. It'd be really complex to test it consistently and would be out of scope regarding our test coverage.

src/utils/loadable.spec.ts Outdated Show resolved Hide resolved
src/utils/loadable.ts Show resolved Hide resolved
src/utils/loadable.spec.ts Show resolved Hide resolved
loaded: false,
promise: null
};
const fakeComponent: any = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like how this test is showing how the modules work together. If not too complex, we could do the same for other spec tests.

From that perspective, I think we could simplify the test and have it focus on its use case:

const afterDidLoad = fakeComponent.resolvesAfterDidLoad();

// assert afterDidLoad not resolved

fakeComponent.componentWillLoad();

// assert afterDidLoad not resolved

fakeComponent.componentDidLoad();

// assert afterDidLoad resolved

Alternatively, the individual utils could be tested as well:

// assert componentLoaded(fakeComponent) not resolved

setUpLoadableComponent(fakeComponent);
// assert componentLoaded(fakeComponent) not resolved

componentLoaded(fakeComponent);
// assert componentLoaded(fakeComponent) resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like how this test is showing how the modules work together. If not too complex, we could do the same for other spec tests.

Can we get a followup issue for this? 👍

// assert afterDidLoad not resolved

How can I assert the promise is not resolved? There's not a property on the promise. Is there some util for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's one, untested, idea:

const afterLoad = jest.fn();
const load = componentLoaded(fakeComponent).then(afterLoad);

await waitForAnimationFrame();
assert(afterLoad).not.toHaveBeenCalled();

setUpLoadableComponent(fakeComponent);
await waitForAnimationFrame();
assert(afterLoad).not.toHaveBeenCalled();

componentLoaded(fakeComponent);
await waitForAnimationFrame();
assert(afterLoad).toHaveBeenCalled();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

@driskull
Copy link
Member Author

@jcfranco this one good to merge?

@driskull driskull added pr ready for visual snapshots Adding this label will run visual snapshot testing. and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. labels Nov 19, 2022
@driskull driskull merged commit 06d4767 into master Nov 19, 2022
@driskull driskull deleted the dris0000/component-loadable branch November 19, 2022 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug reports for broken functionality. Issues should include a reproduction of the bug. pr ready for visual snapshots Adding this label will run visual snapshot testing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants