diff --git a/editor/sidebar/post-author/index.js b/editor/sidebar/post-author/index.js index 5ab46f48f4e3f3..9c7df7aca114c8 100644 --- a/editor/sidebar/post-author/index.js +++ b/editor/sidebar/post-author/index.js @@ -18,7 +18,7 @@ import './style.scss'; import { getEditedPostAttribute } from '../../selectors'; import { editPost } from '../../actions'; -class PostAuthor extends Component { +export class PostAuthor extends Component { constructor() { super( ...arguments ); diff --git a/editor/sidebar/post-author/test/index.js b/editor/sidebar/post-author/test/index.js new file mode 100644 index 00000000000000..5214fb79924b71 --- /dev/null +++ b/editor/sidebar/post-author/test/index.js @@ -0,0 +1,102 @@ +/** + * External dependencies + */ +import { shallow } from 'enzyme'; + +/** + * Internal dependencies + */ +import { PostAuthor } from '../'; + +describe( 'PostAuthor', () => { + const users = { + data: [ + { + id: 1, + name: 'admin', + capabilities: { + level_1: true, + }, + }, + { + id: 2, + name: 'subscriber', + capabilities: { + level_0: true, + }, + }, + { + id: 3, + name: 'andrew', + capabilities: { + level_1: true, + }, + }, + ], + }; + + describe( '#getAuthors()', () => { + it( 'returns empty array on unknown users', () => { + const wrapper = shallow( ); + + const authors = wrapper.instance().getAuthors(); + + expect( authors ).toEqual( [] ); + } ); + + it( 'filters users to authors', () => { + const wrapper = shallow( ); + + const authors = wrapper.instance().getAuthors(); + + expect( authors.map( ( author ) => author.id ).sort() ).toEqual( [ 1, 3 ] ); + } ); + } ); + + describe( '#render()', () => { + it( 'should not render anything if users unknown', () => { + const wrapper = shallow( ); + + expect( wrapper.type() ).toBe( null ); + } ); + + it( 'should not render anything if single user', () => { + const wrapper = shallow( + + ); + + expect( wrapper.type() ).toBe( null ); + } ); + + it( 'should not render anything if single filtered user', () => { + const wrapper = shallow( + + ); + + expect( wrapper.type() ).toBe( null ); + } ); + + it( 'should render select control', () => { + const wrapper = shallow( ); + + expect( wrapper.find( 'select' ).length ).not.toBe( 0 ); + } ); + + it( 'should update author', () => { + const onUpdateAuthor = jest.fn(); + const wrapper = shallow( + + ); + + wrapper.find( 'select' ).simulate( 'change', { + target: { + value: '3', + }, + } ); + + expect( onUpdateAuthor ).toHaveBeenCalledWith( 3 ); + } ); + } ); +} );