/** * @jest-environment jsdom */ // @ts-nocheck - TODO: Fix TypeScript issues import { render, screen } from '@testing-library/react'; import React from 'react'; import { UserData } from 'calypso/lib/user/user'; import UserProfileHeader from '../index'; jest.mock( '@wordpress/icons', () => ( { external: 'mock-external-icon', Icon: ( { icon } ) => { icon }, } ) ); jest.mock( 'calypso/blocks/reader-avatar', () => ( { author, iconSize } ) => (
{ author.avatar_URL && avatar }
) ); jest.mock( 'calypso/components/section-nav', () => ( { children } ) => (
{ children }
) ); jest.mock( 'calypso/components/section-nav/tabs', () => ( { children } ) => (
{ children }
) ); jest.mock( 'calypso/components/section-nav/item', () => ( { children, path, selected } ) => ( { children } ) ); describe( 'UserProfileHeader', () => { const defaultUser: UserData = { ID: 123, user_login: 'testuser', display_name: 'Test User', avatar_URL: 'https://example.com/avatar.jpg', profile_URL: 'https://wordpress.com/testuser', bio: undefined, }; beforeEach( () => { jest.clearAllMocks(); } ); test( 'should render the avatar with correct user information', () => { render( ); const avatars = screen.getAllByTestId( 'reader-avatar' ); expect( avatars[ 0 ] ).toBeInTheDocument(); expect( avatars[ 0 ] ).toHaveAttribute( 'data-author-id', defaultUser.ID.toString() ); // Test that desktop and mobile versions are properly rendered const desktopAvatar = screen.getByTestId( 'desktop-avatar' ); expect( desktopAvatar ).toBeInTheDocument(); const mobileAvatar = screen.getByTestId( 'mobile-avatar' ); expect( mobileAvatar ).toBeInTheDocument(); } ); test( 'should render the user display name', () => { render( ); // Check if display name is rendered const displayNameEl = screen.getByText( defaultUser.display_name ?? '' ); // @ts-expect-error -- jest-dom matchers are available globally expect( displayNameEl ).toBeInTheDocument(); } ); test( 'should render navigation tabs with Posts, Lists, and Recommended Blogs options', () => { render( ); // Check if navigation section is rendered expect( screen.getByTestId( 'section-nav' ) ).toBeInTheDocument(); expect( screen.getByTestId( 'nav-tabs' ) ).toBeInTheDocument(); // Check for navigation items const navItems = screen.getAllByTestId( 'nav-item' ); expect( navItems.length ).toBe( 3 ); // Posts, Lists, and Recommended Blogs // Check nav item content - should have Posts, Lists, and Recommended Blogs const navTexts = navItems.map( ( item ) => item.textContent ); expect( navTexts ).toContain( 'Posts' ); expect( navTexts ).toContain( 'Lists' ); expect( navTexts ).toContain( 'Recommended Blogs' ); } ); test( 'should not render bio section when user has no bio', () => { render( ); // Bio section should not be present const bioSection = document.querySelector( '.user-profile-header__bio' ); expect( bioSection ).not.toBeInTheDocument(); } ); test( 'should render bio section when user has a bio', () => { const userWithBio = { ...defaultUser, bio: 'This is my test biography that describes me as a test user.', }; render( ); // Bio section should be present const bioText = screen.getByText( userWithBio.bio ); expect( bioText ).toBeInTheDocument(); } ); } );