2026-04-24 08:38:00 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2026-07-14 17:05:31 +03:00
|
|
|
import { SectionPanel } from './SectionPanel';
|
2026-04-19 08:27:08 +03:00
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
|
number: '01',
|
|
|
|
|
title: 'About',
|
|
|
|
|
id: 'about',
|
|
|
|
|
isActive: false,
|
2026-05-07 12:46:31 +03:00
|
|
|
href: '/about',
|
2026-04-19 08:27:08 +03:00
|
|
|
children: <p>Content here</p>,
|
2026-04-24 08:38:00 +03:00
|
|
|
};
|
2026-04-19 08:27:08 +03:00
|
|
|
|
2026-07-14 17:05:31 +03:00
|
|
|
describe('SectionPanel', () => {
|
2026-04-19 08:27:08 +03:00
|
|
|
describe('collapsed state (isActive=false)', () => {
|
|
|
|
|
it('renders a section element with the given id', () => {
|
2026-07-14 17:05:31 +03:00
|
|
|
const { container } = render(<SectionPanel {...defaultProps} />);
|
2026-04-24 08:38:00 +03:00
|
|
|
expect(container.querySelector('section#about')).toBeInTheDocument();
|
|
|
|
|
});
|
2026-05-07 12:46:31 +03:00
|
|
|
|
|
|
|
|
it('renders a link with number and title', () => {
|
2026-07-14 17:05:31 +03:00
|
|
|
render(<SectionPanel {...defaultProps} />);
|
2026-05-07 12:46:31 +03:00
|
|
|
expect(screen.getByRole('link', { name: /01.*About/i })).toBeInTheDocument();
|
2026-04-24 08:38:00 +03:00
|
|
|
});
|
2026-05-07 12:46:31 +03:00
|
|
|
|
|
|
|
|
it('link points to the correct href', () => {
|
2026-07-14 17:05:31 +03:00
|
|
|
render(<SectionPanel {...defaultProps} />);
|
2026-05-07 12:46:31 +03:00
|
|
|
expect(screen.getByRole('link', { name: /01.*About/i })).toHaveAttribute('href', '/about');
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-19 08:27:08 +03:00
|
|
|
it('does not render children', () => {
|
2026-07-14 17:05:31 +03:00
|
|
|
render(<SectionPanel {...defaultProps} />);
|
2026-04-24 08:38:00 +03:00
|
|
|
expect(screen.queryByText('Content here')).not.toBeInTheDocument();
|
|
|
|
|
});
|
2026-05-07 12:46:31 +03:00
|
|
|
|
|
|
|
|
it('does not render a button', () => {
|
2026-07-14 17:05:31 +03:00
|
|
|
render(<SectionPanel {...defaultProps} />);
|
2026-05-07 12:46:31 +03:00
|
|
|
expect(screen.queryByRole('button')).not.toBeInTheDocument();
|
2026-04-24 08:38:00 +03:00
|
|
|
});
|
|
|
|
|
});
|
2026-04-19 08:27:08 +03:00
|
|
|
|
|
|
|
|
describe('active state (isActive=true)', () => {
|
2026-04-24 08:38:00 +03:00
|
|
|
const activeProps = { ...defaultProps, isActive: true };
|
2026-04-19 08:27:08 +03:00
|
|
|
|
|
|
|
|
it('renders an h1 with number and title', () => {
|
2026-07-14 17:05:31 +03:00
|
|
|
render(<SectionPanel {...activeProps} />);
|
2026-04-24 08:38:00 +03:00
|
|
|
expect(screen.getByRole('heading', { level: 1, name: /01.*About/i })).toBeInTheDocument();
|
|
|
|
|
});
|
2026-05-07 12:46:31 +03:00
|
|
|
|
2026-04-19 08:27:08 +03:00
|
|
|
it('renders children', () => {
|
2026-07-14 17:05:31 +03:00
|
|
|
render(<SectionPanel {...activeProps} />);
|
2026-04-24 08:38:00 +03:00
|
|
|
expect(screen.getByText('Content here')).toBeInTheDocument();
|
|
|
|
|
});
|
2026-05-07 12:46:31 +03:00
|
|
|
|
|
|
|
|
it('does not render a link', () => {
|
2026-07-14 17:05:31 +03:00
|
|
|
render(<SectionPanel {...activeProps} />);
|
2026-05-07 12:46:31 +03:00
|
|
|
expect(screen.queryByRole('link')).not.toBeInTheDocument();
|
2026-04-24 08:38:00 +03:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|