import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect'; // for additional matchers
import SeeMore from '.';

describe('SeeMore Component', () => {
  test('renders external link when type is external', () => {
    const module = {
      see_more_link: {
        path: 'https://example.com',
        value: 1,
        title: 'External Link',
        type: 'external',
      },
    };

    render(<SeeMore module={module} showMoreLink />);

    const externalLink = screen.getByRole('link', { name: /External Link/i });
    expect(externalLink).toHaveAttribute('href', 'https://example.com');
  });

  test('renders internal link when type is page', () => {
    const module = {
      see_more_link: {
        path: '/internal-page',
        value: 2,
        title: 'Internal Link',
        type: 'page',
      },
    };

    render(<SeeMore module={module} showMoreLink />);

    const internalLink = screen.getByRole('link', { name: /Internal Link/i });
    expect(internalLink).toHaveAttribute('href', '/internal-page');
  });

  test('does not render link when showMoreLink is false', () => {
    const module = {
      see_more_link: {
        path: '/should-not-render',
        value: 3,
        title: 'Should Not Render',
        type: 'page',
      },
    };

    render(<SeeMore module={module} showMoreLink={false} />);

    const link = screen.queryByRole('link', { name: /Should Not Render/i });
    expect(link).not.toBeInTheDocument();
  });
});
