import { describe, it, expect } from 'vitest'
import { render, screen } from '@testing-library/react'
import { BrowserRouter } from 'react-router-dom'
import { UpgradePrompt } from '../UpgradePrompt'

function renderWithRouter(ui: React.ReactElement) {
  return render(<BrowserRouter>{ui}</BrowserRouter>)
}

describe('UpgradePrompt', () => {
  it('renders display name and required plan from catalog', () => {
    renderWithRouter(<UpgradePrompt feature="psa_integration" />)
    expect(
      screen.getByText(/PSA Integration is available on Pro/i),
    ).toBeInTheDocument()
  })

  it('CTA navigates to /account/billing/select-plan', () => {
    renderWithRouter(<UpgradePrompt feature="psa_integration" />)
    const cta = screen.getByRole('link', { name: /Upgrade to Pro/i })
    expect(cta).toHaveAttribute('href', '/account/billing/select-plan')
  })

  it('humanizes unknown feature keys and falls back to Pro', () => {
    renderWithRouter(<UpgradePrompt feature="some_new_feature" />)
    expect(
      screen.getByText(/Some New Feature is available on Pro/i),
    ).toBeInTheDocument()
  })
})
