import { describe, expect, it } from 'vitest'
import {
  buildPublicRobotsTxt,
  buildPublicSitemapXml,
  crawlablePublicRoutes,
  footerLinks,
  marketingNavLinks,
  publicCrawlerDisallowPaths,
  publicRouteRegistry,
} from '../public-route-registry'

describe('public route registry', () => {
  it('keeps unique route definitions for the public shell', () => {
    const uniquePaths = new Set(publicRouteRegistry.map((route) => route.path))

    expect(uniquePaths.size).toBe(publicRouteRegistry.length)
  })

  it('exposes the intended primary navigation and footer surfaces', () => {
    expect(marketingNavLinks).toEqual([
      { to: '/', label: 'Home' },
      { to: '/browser', label: 'Browser' },
      { to: '/features', label: 'Features' },
      { to: '/about', label: 'About' },
      { to: '/help', label: 'Help Center' },
      { to: '/pricing', label: 'Pricing' },
      { to: '/download', label: 'Download' },
    ])

    expect(footerLinks).toContainEqual({
      to: '/open-source-notices',
      label: 'Open Source Notices',
    })
    expect(footerLinks).toContainEqual({
      to: '/contact',
      label: 'Contact',
    })
  })

  it('keeps auth routes out of crawlable sitemap posture', () => {
    expect(crawlablePublicRoutes.map((route) => route.path)).not.toContain('/login')
    expect(crawlablePublicRoutes.map((route) => route.path)).not.toContain('/register')
    expect(crawlablePublicRoutes.map((route) => route.path)).toContain('/browser')
    expect(crawlablePublicRoutes.map((route) => route.path)).toContain('/help')
    expect(crawlablePublicRoutes.map((route) => route.path)).toContain('/getting-started')
    expect(crawlablePublicRoutes.map((route) => route.path)).toContain('/launch-status')
  })

  it('keeps protected runtime and auth boundaries out of crawler posture', () => {
    expect(publicCrawlerDisallowPaths).toEqual([
      '/app',
      '/api/',
      '/auth',
      '/health',
      '/login',
      '/register',
    ])
  })

  it('carries non-empty loader metadata for every shared public-shell route', () => {
    for (const route of publicRouteRegistry) {
      expect(route.loaderTitle.trim().length).toBeGreaterThan(0)
      expect((route.loaderDescription || '').trim().length).toBeGreaterThan(0)
      expect((route.loaderEyebrow || '').trim().length).toBeGreaterThan(0)
    }
  })

  it('renders sitemap XML from the shared crawlable route registry', () => {
    const xml = buildPublicSitemapXml()

    expect(xml).toContain('<loc>https://hypertwist.app/</loc>')
    expect(xml).toContain('<loc>https://hypertwist.app/browser</loc>')
    expect(xml).toContain('<loc>https://hypertwist.app/features</loc>')
    expect(xml).toContain('<loc>https://hypertwist.app/help</loc>')
    expect(xml).toContain('<loc>https://hypertwist.app/getting-started</loc>')
    expect(xml).toContain('<loc>https://hypertwist.app/launch-status</loc>')
    expect(xml).not.toContain('/login')
    expect(xml).not.toContain('/register')
  })

  it('renders robots.txt from the shared crawler policy and route registry', () => {
    const robots = buildPublicRobotsTxt()

    expect(robots).toContain('User-agent: *')
    expect(robots).toContain('Allow: /')
    expect(robots).toContain('Disallow: /app')
    expect(robots).toContain('Disallow: /api/')
    expect(robots).toContain('Disallow: /auth')
    expect(robots).toContain('Disallow: /health')
    expect(robots).toContain('Disallow: /login')
    expect(robots).toContain('Disallow: /register')
    expect(robots).toContain('Sitemap: https://hypertwist.app/sitemap.xml')
    expect(robots).not.toContain('Disallow: /features')
  })
})
