import '@testing-library/jest-dom'; import { Address } from '@/identity/components/Address'; import { Avatar } from '@/identity/components/Avatar'; import { EthBalance } from '@/identity/components/EthBalance'; import { IdentityLayout } from '@/identity/components/IdentityLayout'; import { Name } from '@/identity/components/Name'; import { Socials } from '@/identity/components/Socials'; import { render, screen } from '@testing-library/react'; import { describe, expect, it, vi } from 'vitest'; vi.mock('@/identity/components/Avatar', () => ({ Avatar: vi.fn(() =>
Avatar
), })); vi.mock('@/identity/components/Name', () => ({ Name: vi.fn(() =>
Name
), })); vi.mock('@/identity/components/Address', () => ({ Address: vi.fn(() =>
Address
), })); vi.mock('@/identity/components/EthBalance', () => ({ EthBalance: vi.fn(() =>
EthBalance
), })); vi.mock('@/identity/components/Socials', () => ({ Socials: vi.fn(() =>
Socials
), })); const renderComponent = (props = {}) => { return render(
, ); }; describe('IdentityLayout', () => { it('should render all children components when present', () => { renderComponent(); expect(screen.getByText('Avatar')).toBeInTheDocument(); expect(screen.getByText('Name')).toBeInTheDocument(); expect(screen.getByText('Address')).toBeInTheDocument(); expect(screen.getByText('EthBalance')).toBeInTheDocument(); expect(screen.getByText('Socials')).toBeInTheDocument(); }); it('should render with custom class', () => { renderComponent(); expect(screen.getByTestId('ockIdentityLayout_container')).toHaveClass( 'custom-class', ); }); it('should render correctly without Address component', () => { render( , ); expect(screen.getByText('Avatar')).toBeInTheDocument(); expect(screen.getByText('Name')).toBeInTheDocument(); expect(screen.getByText('EthBalance')).toBeInTheDocument(); expect(screen.queryByText('Address')).not.toBeInTheDocument(); }); it('should render correctly without EthBalance component', () => { render(
, ); expect(screen.getByText('Avatar')).toBeInTheDocument(); expect(screen.getByText('Name')).toBeInTheDocument(); expect(screen.getByText('Address')).toBeInTheDocument(); expect(screen.queryByText('EthBalance')).not.toBeInTheDocument(); }); it('should render correctly without Socials component', () => { render(
, ); expect(screen.getByText('Avatar')).toBeInTheDocument(); expect(screen.getByText('Name')).toBeInTheDocument(); expect(screen.getByText('Address')).toBeInTheDocument(); expect(screen.getByText('EthBalance')).toBeInTheDocument(); expect(screen.queryByText('Socials')).not.toBeInTheDocument(); }); it('should render correctly with only required components', () => { render( , ); expect(screen.getByText('Avatar')).toBeInTheDocument(); expect(screen.getByText('Name')).toBeInTheDocument(); expect(screen.queryByText('Address')).not.toBeInTheDocument(); expect(screen.queryByText('EthBalance')).not.toBeInTheDocument(); expect(screen.queryByText('Socials')).not.toBeInTheDocument(); }); it('should pass hasCopyAddressOnClick prop correctly to Address component', () => { render(
, ); expect(Address).toHaveBeenCalledWith( expect.objectContaining({ hasCopyAddressOnClick: true }), undefined, ); }); it('should pass undefined hasCopyAddressOnClick when prop is not provided', () => { render(
, ); expect(Address).toHaveBeenCalledWith( expect.objectContaining({ hasCopyAddressOnClick: undefined }), undefined, ); }); });