import { render, screen } from '@testing-library/svelte';
import { describe, expect, it } from 'vitest';
import SlugPage from './+page.svelte';
import { createStaticRouteData } from '../../test/fixtures';

describe('static slug route page', () => {
  it.each([
    ['pack-walks', 'Join our Tiny Gang!'],
    ['dog-walking', 'Walks for larger breeds, too!'],
    ['puppy-visits', 'Introducing Puppy Visits: Building strong foundations for our pack walks!'],
    ['our-pricing', 'Simple, transparent pricing — no lock-in contracts.'],
    ['about', 'Who we are'],
    ['contact-us', "Fill in the form below and we'll be in touch to arrange a free introduction."],
    ['terms-and-conditions', '1. Application of Terms'],
    ['privacy-policy', 'How we collect your information']
  ] as const)('renders the %s page branch', (slug, expectedText) => {
    render(SlugPage, {
      data: createStaticRouteData(slug)
    });

    expect(screen.getByText(expectedText)).toBeInTheDocument();
  });

  it('sets SEO metadata for rendered slug pages', () => {
    render(SlugPage, {
      data: createStaticRouteData('about')
    });

    expect(document.title).toBe('About Us | Dog Walkers | Goodwalk');
    expect(document.head.innerHTML).toContain('AboutPage');
  });

  it.each(['terms-and-conditions', 'privacy-policy'] as const)(
    'does not render booking or testimonial sections on %s',
    (slug) => {
      render(SlugPage, {
        data: createStaticRouteData(slug)
      });

      expect(
        screen.queryByText("Fill in the form below and we'll be in touch to arrange a free introduction.")
      ).not.toBeInTheDocument();
      expect(screen.queryByText('Why people choose us!')).not.toBeInTheDocument();
    }
  );

  it('shows the general enquiry option on the contact page only', () => {
    const { rerender } = render(SlugPage, {
      data: {
        ...createStaticRouteData('contact-us'),
        generalEnquiryEnabled: true
      }
    });

    expect(screen.getByLabelText(/General enquiry/i)).toBeInTheDocument();

    rerender({
      data: createStaticRouteData('pack-walks')
    });

    expect(screen.queryByLabelText(/General enquiry/i)).not.toBeInTheDocument();
  });
});
