import { render } from '@testing-library/react'
import { MemoryRouter } from 'react-router-dom'
import { describe, expect, it } from 'vitest'
import { SiteMetadata } from '../components/seo/SiteMetadata'
import { ROUTER_FUTURE_FLAGS } from '../router/router-future'

describe('SiteMetadata', () => {
  it('applies route-aware title, canonical, og, twitter, and robots metadata', () => {
    render(
      <MemoryRouter initialEntries={['/pricing?preview=true']} future={ROUTER_FUTURE_FLAGS}>
        <SiteMetadata
          title="HyperTwist pricing"
          description="Pricing metadata description."
          canonicalPath="/pricing"
        />
      </MemoryRouter>,
    )

    expect(document.title).toBe('HyperTwist pricing | HyperTwist')
    expect(document.head.querySelector('meta[name="description"]')?.getAttribute('content')).toBe('Pricing metadata description.')
    expect(document.head.querySelector('meta[name="robots"]')?.getAttribute('content')).toBe('index,follow')
    expect(document.head.querySelector('meta[property="og:url"]')?.getAttribute('content')).toBe('https://hypertwist.app/pricing')
    expect(document.head.querySelector('meta[name="twitter:title"]')?.getAttribute('content')).toBe('HyperTwist pricing | HyperTwist')
    expect(document.head.querySelector('link[rel="canonical"]')?.getAttribute('href')).toBe('https://hypertwist.app/pricing')
  })

  it('supports noindex protected-route posture', () => {
    render(
      <MemoryRouter initialEntries={['/app/downloads?platform=windows']} future={ROUTER_FUTURE_FLAGS}>
        <SiteMetadata
          title="HyperTwist downloads"
          description="Protected download lane."
          canonicalPath="/app/downloads"
          robots="noindex,nofollow"
        />
      </MemoryRouter>,
    )

    expect(document.title).toBe('HyperTwist downloads | HyperTwist')
    expect(document.head.querySelector('meta[name="robots"]')?.getAttribute('content')).toBe('noindex,nofollow')
    expect(document.head.querySelector('link[rel="canonical"]')?.getAttribute('href')).toBe('https://hypertwist.app/app/downloads')
  })
})
