import React from 'react';
import { render, screen } from '@testing-library/react';
import Divider, { DividerProps } from './Divider';

describe('Divider', () => {
  const defaultProps: DividerProps = {
    testId: 'test-divider',
  };

  const renderDivider = (props: Partial<DividerProps> = {}) => {
    const utils = render(<Divider {...defaultProps} {...props} />);
    const rerender = (newProps: Partial<DividerProps> = {}) =>
      utils.rerender(<Divider {...defaultProps} {...newProps} />);
    return { ...utils, rerender };
  };

  it('should render the Divider component', () => {
    renderDivider();
    expect(screen.getByTestId('test-divider')).toBeInTheDocument();
    expect(screen.getByTestId('test-divider')).toHaveClass('wds-Divider');
  });

  it('should render as a semantic <hr> when `isContent` is true', () => {
    renderDivider({ isContent: true });
    expect(screen.getByTestId('test-divider')).not.toHaveAttribute('role', 'presentation');
  });

  it('should render as a non-semantic <div> when `isContent` is false', () => {
    renderDivider({ isContent: false });
    expect(screen.getByTestId('test-divider')).toHaveAttribute('role', 'presentation');
  });

  it('should apply custom class names when provided', () => {
    const { rerender } = renderDivider();
    expect(screen.getByTestId('test-divider')).not.toHaveClass('custom-class');

    // Re-render with updated props
    rerender({ className: 'custom-class' });
    expect(screen.getByTestId('test-divider')).toHaveClass('custom-class');
  });

  it('should apply the "content" level styling', () => {
    const { rerender } = renderDivider();
    expect(screen.getByTestId('test-divider')).not.toHaveClass('wds-Divider--content');

    rerender({ level: 'content' });
    expect(screen.getByTestId('test-divider')).toHaveClass('wds-Divider', 'wds-Divider--content');
  });

  it('should apply the "subsection" level styling', () => {
    const { rerender } = renderDivider();
    expect(screen.getByTestId('test-divider')).not.toHaveClass('wds-Divider--subsection');

    rerender({ level: 'subsection' });
    expect(screen.getByTestId('test-divider')).toHaveClass(
      'wds-Divider',
      'wds-Divider--subsection',
    );
  });
});
