-
Notifications
You must be signed in to change notification settings - Fork 798
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
Gif block: refactor and add test coverage #19066
Conversation
Caution: This PR has changes that must be merged to WordPress.com |
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 If you are an automattician, once your PR is ready for review add the "[Status] Needs Team review" label and ask someone from your team review the code. jetpack plugin:
|
ff5684f
to
cd0a1b9
Compare
expect( container.querySelector( 'figure' ) ).toBeInTheDocument(); | ||
expect( container.querySelector( 'figcaption' ) ).toBeInTheDocument(); | ||
expect( container.querySelector( '.wp-block-jetpack-gif-wrapper iframe' ) ).toBeInTheDocument(); | ||
expect( container.querySelectorAll( '.wp-block-jetpack-gif_thumbnail-container' ) ).toHaveLength( 2 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually wondering if I should just to a toMatchSnapShot()
here... 🤔
1a5786b
to
e0326e5
Compare
searchText | ||
) }&api_key=${ encodeURIComponent( GIPHY_API_KEY ) }&limit=10`; | ||
}; | ||
}, [ giphyData ] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm aware of the missing function dependency.
Here we only care about the currency of giphyData
, which changes after every API update. Otherwise it won't fire.
setSelectedGiphy
is used here and when we select a new thumbnail in the results so it's going to change the function reference.
As it is, the state is only updated once and when we desire it.
We could wrap it in a useCallback
, I've tried this but I think it's an optimisation we can leave for later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you then add an eslint-disable and a quick explanation in the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @jeherve
I've had a change of heart and decided to appease the linter, and have extracted the method that does reference state/props. Reference: https://reactjs.org/docs/hooks-faq.html#is-it-safe-to-omit-functions-from-the-list-of-dependencies
It might save us some bugs in the future if this block is further developed :D
searchText | ||
) }&api_key=${ encodeURIComponent( GIPHY_API_KEY ) }&limit=10`; | ||
}; | ||
}, [ giphyData ] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you then add an eslint-disable and a quick explanation in the code?
7cefa79
to
97738c9
Compare
Importing regenerator runtime to polyfill transpiled generator functions for react hooks testing library Added custom hook to fetch api data Added tests for custom hook and updated tests for edit.js
…edGiphyAttributes is not referencing any props or state so we can use it in the useEffect hook and not reference it.
7b74cdf
to
dcdb32d
Compare
…s a little stricter than testing for the index of the domain.
dcdb32d
to
575a94e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests well for me, nice rework! 🚢
Great news! One last step: head over to your WordPress.com diff, D58239-code, and commit it. Thank you! |
r222722-wpcom |
Changes proposed in this Pull Request:
After trying to add test coverage to the Gif block in #19019, we thought we'd preserve some sanity by refactoring the block in order to:
Jetpack product discussion
p1HpG7-b3G-p2
Does this pull request change what data or activity we track or use?
Nope.
Testing instructions:
Make sure there are no visual or functional regressions in the editor or the save versions. Nothing should change in this respect.
Check that:
Run the unit tests:
Proposed changelog entry for your changes:
Not sure if a changelog is required for a refactor and tests. No functionality/UI has changed.