-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gif block: refactor and add test coverage (#19066)
* Initial commit * Focusing forward ref input field * Added tests * Added @testing-library/react-hooks library to unit test custom hooks 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 * revert css change as it would be a UI regression * Removing previous version (kept it for reference while developing) * Add changelog * Here we are extracting getSelectedGiphyAttributes to utils. getSelectedGiphyAttributes is not referencing any props or state so we can use it in the useEffect hook and not reference it. * Using a regex to capture known giphy paths and extract the id. This is a little stricter than testing for the index of the domain.
- Loading branch information
Showing
19 changed files
with
788 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: compat | ||
|
||
Git block: Refactored class component into a functional one and added unit tests. No functional/UI changes. Changelog optional. |
37 changes: 37 additions & 0 deletions
37
projects/plugins/jetpack/extensions/blocks/gif/components/search-form.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { forwardRef } from '@wordpress/element'; | ||
import { Button } from '@wordpress/components'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
export function SearchForm( { onSubmit, onChange, value = '' }, ref ) { | ||
return ( | ||
<form | ||
className="wp-block-jetpack-gif_input-container" | ||
onSubmit={ onSubmit } | ||
> | ||
<input | ||
type="text" | ||
className="wp-block-jetpack-gif_input components-placeholder__input" | ||
placeholder={ __( 'Enter search terms, e.g. cat…', 'jetpack' ) } | ||
value={ value } | ||
onChange={ onChange } | ||
ref={ ref } | ||
aria-labelledby="wp-block-jetpack-gif_search-button" | ||
/> | ||
<Button id="wp-block-jetpack-gif_search-button" isSecondary type="submit"> | ||
{ __( 'Search', 'jetpack' ) } | ||
</Button> | ||
</form> | ||
); | ||
} | ||
|
||
export default forwardRef( SearchForm ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const GIPHY_API_KEY = 't1PkR1Vq0mzHueIFBvZSZErgFs9NBmYW'; |
19 changes: 19 additions & 0 deletions
19
projects/plugins/jetpack/extensions/blocks/gif/controls.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { PanelBody, Path, SVG } from '@wordpress/components'; | ||
import { InspectorControls } from '@wordpress/block-editor'; | ||
|
||
export default function Controls() { | ||
return ( | ||
<InspectorControls> | ||
<PanelBody className="components-panel__body-gif-branding"> | ||
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 202 22"> | ||
<Path d="M4.6 5.9H0v10h1.6v-3.1h3c4.8 0 4.8-6.9 0-6.9zm0 5.4h-3v-4h3c2.6.1 2.6 4 0 4zM51.2 12.3c2-.3 2.7-1.7 2.7-3.1 0-1.7-1.2-3.3-3.5-3.3h-4.6v10h1.6v-3.4h2.1l3 3.4h1.9l-.2-.3-3-3.3zM47.4 11V7.4h3c1.3 0 1.9.9 1.9 1.8s-.6 1.8-1.9 1.8h-3zM30.6 13.6L28 5.9h-1.1l-2.5 7.7-2.6-7.7H20l3.7 10H25l1.4-3.5L27.5 9l1.1 3.4 1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6zM127.4.6h5.9v20.8h-5.9zM147.6.6h-10.1v20.8h5.9v-5.6h4.2c5.6-.1 8.3-3.4 8.3-7.6.1-4.1-2.7-7.6-8.3-7.6zm0 10.2h-4.2V5.6h4.2c1.6 0 2.5 1.2 2.5 2.6 0 1.4-.9 2.6-2.5 2.6z" /> | ||
</SVG> | ||
</PanelBody> | ||
</InspectorControls> | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.