File size: 2,002 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
/**
* @jest-environment jsdom
*/
import { render, screen } from '@testing-library/react';
import { Button, Icon } from '@wordpress/components';
import { cog } from '@wordpress/icons';
import { SectionHeader } from '..';
describe( 'SectionHeader', () => {
test( 'should render with title', () => {
render( <SectionHeader title="Test Title" /> );
expect( screen.getByRole( 'heading', { name: 'Test Title' } ) ).toBeVisible();
} );
test( 'should render with description', () => {
render( <SectionHeader title="Test Title" description="Test Description" /> );
expect( screen.getByText( 'Test Description' ) ).toBeVisible();
} );
test( 'should render with action buttons', () => {
render(
<SectionHeader
title="Test Title"
actions={
<>
<Button>Cancel</Button>
<Button>Save</Button>
</>
}
/>
);
expect( screen.getByRole( 'button', { name: 'Cancel' } ) ).toBeVisible();
expect( screen.getByRole( 'button', { name: 'Save' } ) ).toBeVisible();
} );
test( 'should render with decoration', () => {
render(
<SectionHeader
title="Test Title"
decoration={ <Icon data-testid="decoration" icon={ cog } /> }
/>
);
expect( screen.getByTestId( 'decoration' ) ).toBeVisible();
} );
test( 'should render with default level 2 heading', () => {
render( <SectionHeader title="Test Title" /> );
expect( screen.getByRole( 'heading', { name: 'Test Title' } ).tagName ).toBe( 'H2' );
} );
test( 'should render with different heading level when explicitly set', () => {
render( <SectionHeader title="Test Title" level={ 3 } /> );
expect( screen.getByRole( 'heading', { name: 'Test Title' } ).tagName ).toBe( 'H3' );
} );
test( 'should render with prefix content', () => {
render(
<SectionHeader
title="Test Title"
prefix={ <span data-testid="prefix">Prefix Content</span> }
/>
);
expect( screen.getByTestId( 'prefix' ) ).toBeVisible();
expect( screen.getByText( 'Prefix Content' ) ).toBeVisible();
} );
} );
|