| | |
| | |
| | |
| | |
| |
|
| | import { render, screen } from '@testing-library/react'; |
| | import React from 'react'; |
| | import { UserData } from 'calypso/lib/user/user'; |
| | import { List } from 'calypso/reader/list-manage/types'; |
| | import { UserLists } from '../lists'; |
| |
|
| | jest.mock( 'calypso/components/empty-content', () => ( { icon, line } ) => ( |
| | <div data-testid="empty-content"> |
| | { icon && <div data-testid="empty-content-icon">{ icon }</div> } |
| | { line && <p data-testid="empty-content-line">{ line }</p> } |
| | </div> |
| | ) ); |
| |
|
| | describe( 'UserLists', () => { |
| | const defaultUser: UserData = { |
| | ID: 123, |
| | user_login: 'testuser', |
| | display_name: 'Test User', |
| | avatar_URL: 'https://example.com/avatar.jpg', |
| | }; |
| |
|
| | const mockRequestUserLists = jest.fn(); |
| |
|
| | test( 'should render empty content when user has no lists', () => { |
| | render( |
| | <UserLists |
| | user={ defaultUser } |
| | requestUserLists={ mockRequestUserLists } |
| | lists={ [] } |
| | isLoading={ false } |
| | /> |
| | ); |
| |
|
| | |
| | expect( screen.getByTestId( 'empty-content' ) ).toBeInTheDocument(); |
| |
|
| | |
| | expect( screen.getByTestId( 'empty-content-icon' ) ).toBeInTheDocument(); |
| |
|
| | |
| | expect( screen.getByTestId( 'empty-content-line' ) ).toHaveTextContent( 'No lists yet.' ); |
| |
|
| | |
| | expect( mockRequestUserLists ).toHaveBeenCalledWith( defaultUser.user_login ); |
| | } ); |
| |
|
| | test( 'should render nothing when in loading state', () => { |
| | const { container } = render( |
| | <UserLists user={ defaultUser } requestUserLists={ mockRequestUserLists } isLoading /> |
| | ); |
| |
|
| | |
| | expect( container ).toBeEmptyDOMElement(); |
| | } ); |
| |
|
| | test( 'should render lists when user has lists', () => { |
| | const mockLists: List[] = [ |
| | { |
| | ID: 1, |
| | title: 'Test List 1', |
| | description: 'This is test list 1', |
| | slug: 'test-list-1', |
| | owner: 'testuser', |
| | is_public: true, |
| | is_owner: true, |
| | }, |
| | { |
| | ID: 2, |
| | title: 'Test List 2', |
| | description: 'This is test list 2', |
| | slug: 'test-list-2', |
| | owner: 'testuser', |
| | is_public: true, |
| | is_owner: true, |
| | }, |
| | ]; |
| |
|
| | render( |
| | <UserLists |
| | user={ defaultUser } |
| | requestUserLists={ mockRequestUserLists } |
| | lists={ mockLists } |
| | isLoading={ false } |
| | /> |
| | ); |
| |
|
| | const listsContainer = document.querySelector( '.user-profile__lists-body' ); |
| | expect( listsContainer ).toBeInTheDocument(); |
| |
|
| | |
| | expect( screen.getByText( 'Test List 1' ) ).toBeInTheDocument(); |
| | expect( screen.getByText( 'Test List 2' ) ).toBeInTheDocument(); |
| |
|
| | |
| | expect( screen.getByText( 'This is test list 1' ) ).toBeInTheDocument(); |
| | expect( screen.getByText( 'This is test list 2' ) ).toBeInTheDocument(); |
| |
|
| | |
| | const links = Array.from( document.querySelectorAll( 'a.user-profile__lists-body-link' ) ); |
| | expect( links ).toHaveLength( 2 ); |
| | expect( links[ 0 ].getAttribute( 'href' ) ).toBe( |
| | `/reader/list/${ defaultUser.user_login }/test-list-1` |
| | ); |
| | expect( links[ 1 ].getAttribute( 'href' ) ).toBe( |
| | `/reader/list/${ defaultUser.user_login }/test-list-2` |
| | ); |
| | } ); |
| | } ); |
| |
|