Skip to content

Instantly share code, notes, and snippets.

@adamsilverstein
Created August 17, 2020 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamsilverstein/4ca24e203b1d3143d0a9fcbd50afb0d3 to your computer and use it in GitHub Desktop.
Save adamsilverstein/4ca24e203b1d3143d0a9fcbd50afb0d3 to your computer and use it in GitHub Desktop.
diff --git a/packages/editor/src/components/post-author/index.js b/packages/editor/src/components/post-author/index.js
index bdd9c30596..623a0ad82b 100644
--- a/packages/editor/src/components/post-author/index.js
+++ b/packages/editor/src/components/post-author/index.js
@@ -17,8 +17,7 @@ import { compose, withInstanceId } from '@wordpress/compose';
*/
import PostAuthorCheck from './check';
-function PostAuthor( { authors, postAuthor, onUpdateAuthor } ) {
-
+export function PostAuthor( { authors, postAuthor, onUpdateAuthor } ) {
const authorsForField = useMemo( () => {
return authors.map( ( author ) => {
return {
@@ -62,6 +61,8 @@ function PostAuthor( { authors, postAuthor, onUpdateAuthor } ) {
setFieldValue( inputValue );
};
+ let isLoading;
+
const availableAuthors = useSelect(
( select ) => {
if (
@@ -87,7 +88,7 @@ function PostAuthor( { authors, postAuthor, onUpdateAuthor } ) {
[ fieldValue, postAuthor, isLoading ]
);
- const isLoading = useSelect(
+ isLoading = useSelect(
( select ) => {
return select( 'core/data' ).isResolving( 'core', 'getAuthors', [
{ search: fieldValue },
diff --git a/packages/editor/src/components/post-author/test/index.js b/packages/editor/src/components/post-author/test/index.js
index 368be4fda7..3387a8b095 100644
--- a/packages/editor/src/components/post-author/test/index.js
+++ b/packages/editor/src/components/post-author/test/index.js
@@ -1,3 +1,13 @@
+
+/**
+ * WordPress dependencies
+ */
+import {
+ select as dataSelect,
+ createRegistry,
+ registerGenericStore,
+} from '@wordpress/data';
+
/**
* External dependencies
*/
@@ -41,18 +51,58 @@ describe( 'PostAuthor', () => {
},
};
+ const postAuthor = {
+ id: 1,
+ name: 'admin',
+ };
+
describe( '#render()', () => {
it( 'should update author', () => {
const onUpdateAuthor = jest.fn();
+
+ registerGenericStore( 'core/data', {
+ getActions: () => ( { foo: 'bar' } ),
+ subscribe: () => ( { foo: 'bar' } ),
+ getSelectors: () => {
+ return { 'isResolving': () => false };
+ },
+ } );
+
+ registerGenericStore( 'core', {
+ getActions: () => ( { foo: 'bar' } ),
+ subscribe: () => ( { foo: 'bar' } ),
+ getSelectors: () => {
+ return {
+ 'getAuthors': () => authors,
+ 'getAuthor': () => authors[ 0 ],
+ };
+ },
+ } );
+
+ registerGenericStore( 'core/editor', {
+ getActions: () => ( { editPost: () => {} } ),
+ subscribe: () => ( { foo: 'bar' } ),
+ getSelectors: () => {
+ return {
+ 'getCurrentPost': () => {},
+ 'getCurrentPostType': () => {},
+ 'getEditedPostAttribute': () => {},
+ };
+ },
+ } );
+
const wrapper = shallow(
<PostAuthor
authors={ authors }
user={ user }
onUpdateAuthor={ onUpdateAuthor }
+ postAuthor={ postAuthor }
/>
);
- wrapper.find( 'select' ).simulate( 'change', {
+ expect( onUpdateAuthor ).toHaveBeenCalledWith( ["fieldValue", "admin"] );
+
+ wrapper.find( 'input' ).simulate( 'change', {
target: {
value: '3',
},
@@ -62,3 +112,4 @@ describe( 'PostAuthor', () => {
} );
} );
} );
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment