|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { render, screen } from '@testing-library/react'; |
|
|
import React from 'react'; |
|
|
import { UserData } from 'calypso/lib/user/user'; |
|
|
import UserPosts from '../posts'; |
|
|
|
|
|
jest.mock( |
|
|
'calypso/reader/stream', |
|
|
() => |
|
|
( { |
|
|
streamKey, |
|
|
className, |
|
|
emptyContent, |
|
|
showFollowButton, |
|
|
showSiteNameOnCards, |
|
|
sidebarTabTitle, |
|
|
useCompactCards, |
|
|
} ) => ( |
|
|
<div data-testid="reader-stream" data-stream-key={ streamKey } className={ className }> |
|
|
<div data-testid="stream-props"> |
|
|
<span data-prop="showFollowButton">{ String( showFollowButton ) }</span> |
|
|
<span data-prop="showSiteNameOnCards">{ String( showSiteNameOnCards ) }</span> |
|
|
<span data-prop="sidebarTabTitle">{ sidebarTabTitle }</span> |
|
|
<span data-prop="useCompactCards">{ String( useCompactCards ) }</span> |
|
|
</div> |
|
|
{ emptyContent && <div data-testid="empty-content">{ emptyContent() }</div> } |
|
|
</div> |
|
|
) |
|
|
); |
|
|
|
|
|
jest.mock( 'calypso/components/empty-content', () => ( { icon, line } ) => ( |
|
|
<div data-testid="empty-content-component"> |
|
|
{ icon && <div data-testid="empty-content-icon">{ icon }</div> } |
|
|
{ line && <p data-testid="empty-content-line">{ line }</p> } |
|
|
</div> |
|
|
) ); |
|
|
|
|
|
describe( 'UserPosts', () => { |
|
|
const defaultUser: UserData = { |
|
|
ID: 123, |
|
|
user_login: 'testuser', |
|
|
display_name: 'Test User', |
|
|
avatar_URL: 'https://example.com/avatar.jpg', |
|
|
}; |
|
|
|
|
|
test( 'should render Stream component with correct props', () => { |
|
|
render( <UserPosts user={ defaultUser } /> ); |
|
|
|
|
|
|
|
|
const streamComponent = screen.getByTestId( 'reader-stream' ); |
|
|
expect( streamComponent ).toBeInTheDocument(); |
|
|
|
|
|
|
|
|
expect( streamComponent ).toHaveAttribute( 'data-stream-key', `user:${ defaultUser.ID }` ); |
|
|
|
|
|
|
|
|
expect( streamComponent ).toHaveClass( 'is-user-profile' ); |
|
|
|
|
|
|
|
|
const propsContainer = screen.getByTestId( 'stream-props' ); |
|
|
expect( propsContainer.querySelector( '[data-prop="showFollowButton"]' ) ).toHaveTextContent( |
|
|
'false' |
|
|
); |
|
|
expect( propsContainer.querySelector( '[data-prop="showSiteNameOnCards"]' ) ).toHaveTextContent( |
|
|
'true' |
|
|
); |
|
|
expect( propsContainer.querySelector( '[data-prop="sidebarTabTitle"]' ) ).toHaveTextContent( |
|
|
'Related' |
|
|
); |
|
|
|
|
|
expect( propsContainer.querySelector( '[data-prop="useCompactCards"]' ) ).toHaveTextContent( |
|
|
'true' |
|
|
); |
|
|
} ); |
|
|
|
|
|
test( 'should provide empty content function that renders correctly', () => { |
|
|
render( <UserPosts user={ defaultUser } /> ); |
|
|
|
|
|
|
|
|
const emptyContent = screen.getByTestId( 'empty-content' ); |
|
|
expect( emptyContent ).toBeInTheDocument(); |
|
|
|
|
|
|
|
|
expect( |
|
|
emptyContent.querySelector( '[data-testid="empty-content-component"]' ) |
|
|
).toBeInTheDocument(); |
|
|
|
|
|
|
|
|
expect( |
|
|
emptyContent.querySelector( '[data-testid="empty-content-icon"]' ) |
|
|
).toBeInTheDocument(); |
|
|
|
|
|
|
|
|
expect( emptyContent.querySelector( '[data-testid="empty-content-line"]' ) ).toHaveTextContent( |
|
|
'No posts yet.' |
|
|
); |
|
|
} ); |
|
|
} ); |
|
|
|