Skip to content

Commit

Permalink
Merge pull request #11606 from Automattic/fix/comment-link-on-streams
Browse files Browse the repository at this point in the history
Accept comments argument in showSelectedPost
  • Loading branch information
blowery authored Feb 27, 2017
2 parents 300b5ae + 6f88c28 commit cd64141
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
4 changes: 2 additions & 2 deletions client/reader/search-stream/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ const SearchCardAdapter = ( isRecommendations ) => class extends Component {

onCardClick = ( post ) => {
recordTrackForPost( 'calypso_reader_searchcard_clicked', post );
this.props.handleClick( { post } );
this.props.handleClick();
}

onCommentClick = () => {
this.props.handleClick( this.props.post, { comments: true } );
this.props.handleClick( { comments: true } );
}

render() {
Expand Down
51 changes: 51 additions & 0 deletions client/reader/test/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* External dependencies
*/
import sinon from 'sinon';
import { expect } from 'chai';

/**
* Internal dependencies
*/
import useFakeDom from 'test/helpers/use-fake-dom';
import useMockery from 'test/helpers/use-mockery';

describe( 'reader utils', () => {
const pageSpy = sinon.spy();

beforeEach( () => {
pageSpy.reset();
} );

describe( '#showSelectedPost', () => {
let showSelectedPost;
useFakeDom();
useMockery( ( mockery ) => {
mockery.registerMock( 'page', {
show: pageSpy,
} );
mockery.registerMock( 'lib/feed-stream-store/actions', {
selectItem: sinon.stub(),
} );
mockery.registerMock( 'reader/controller-helper', {
setLastStoreId: sinon.stub(),
} );
showSelectedPost = require( '../utils' ).showSelectedPost;
} );

it( 'does not do anything if postKey argument is missing', () => {
showSelectedPost( {} );
expect( pageSpy ).to.have.not.been.called;
} );

it( 'redirects if passed a post key', () => {
showSelectedPost( { postKey: { feedId: 1, postId: 5 } } );
expect( pageSpy ).to.have.been.calledOnce;
} );

it( 'redirects to a #comments URL if we passed comments argument', () => {
showSelectedPost( { postKey: { feedId: 1, postId: 5 }, comments: true } );
expect( pageSpy ).to.have.been.calledWithMatch('#comments');
} );
} );
} );
3 changes: 2 additions & 1 deletion client/reader/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function isPostNotFound( post ) {
return post.statusCode === 404;
}

export function showSelectedPost( { store, replaceHistory, selectedGap, postKey, index } ) {
export function showSelectedPost( { store, replaceHistory, selectedGap, postKey, index, comments } ) {
if ( ! postKey ) {
return;
}
Expand Down Expand Up @@ -119,6 +119,7 @@ export function showSelectedPost( { store, replaceHistory, selectedGap, postKey,
showFullPost( {
post: mappedPost,
replaceHistory,
comments
} );
}

Expand Down

0 comments on commit cd64141

Please sign in to comment.