/* eslint-disable @typescript-eslint/no-explicit-any */

import React from 'react'
import { render, screen } from '@testing-library/react'
import Topper from './index'

describe('Topper component', () => {
  const topper = {
    __typename: 'OpinionTopper',
    headline: 'Test headline',
    backgroundColour: 'paper',
    columnists: [
      {
        prefLabel: 'Jane Doe',
      },
    ],
    headshot:
      'https://www.ft.com/__origami/service/image/v2/images/raw/test-headshot.jpg',
  }

  it('renders with byline (shows columnist and headshot)', () => {
    const { asFragment } = render(
      <Topper
        content={
          {
            __typename: 'Article',
            title: 'Test headline',
            topper,
            byline: 'Jane Doe',
          } as any
        }
      />
    )

    expect(asFragment()).toMatchSnapshot()
  })

  it('hides columnist and headshot when byline is missing', () => {
    const { asFragment } = render(
      <Topper
        content={
          {
            __typename: 'Article',
            title: 'Test headline',
            topper,
            // no byline
          } as any
        }
      />
    )

    expect(asFragment()).toMatchSnapshot()
  })

  it('does not render topic tags or follow controls when partner topper concepts are suppressed', () => {
    const FollowButtonSlot = jest.fn(() => <button>Follow topic</button>)
    const partnerContent = {
      __typename: 'Article',
      title: 'Partner content headline',
      clientName: 'Partner client',
      topper: {
        __typename: 'BasicTopper',
        headline: 'Partner content headline',
        backgroundColour: 'paper',
        displayConcept: null,
        genreConcept: null,
        headerSlot: { type: 'partner-content' },
      },
    }

    const { container, queryByText } = render(
      <Topper
        content={partnerContent as any}
        followButtonSlot={FollowButtonSlot}
      />
    )

    expect(screen.getByText('Partner Content')).toBeTruthy()
    expect(container.querySelector('.o-topper__topic')).toBeNull()
    expect(queryByText('Follow topic')).toBeNull()
    expect(FollowButtonSlot).not.toHaveBeenCalled()
  })
})
