// tools/generate-tests/generators/hypermedia-generator-b.ts — Language-specific test generators
// SPEC-043: Split from hypermedia-generator.ts for SOLID compliance.
// === Language-specific test file generators ===
function generatePythonHttpxTest(title) {
    const slug = title.toLowerCase().replace(/\s+/g, '_');
    return `"""Integration tests for ${title} — HTMX hypermedia endpoints."""
import pytest
from httpx import AsyncClient
from bs4 import BeautifulSoup


@pytest.mark.anyio
async def test_${slug}_returns_html_fragment(client: AsyncClient) -> None:
    """GET endpoint returns 200 with Content-Type: text/html."""
    response = await client.get("/your-endpoint")
    assert response.status_code == 200
    assert "text/html" in response.headers.get("content-type", "")


@pytest.mark.anyio
async def test_${slug}_html_contains_expected_elements(client: AsyncClient) -> None:
    """Response HTML fragment contains the expected DOM elements."""
    response = await client.get("/your-endpoint")
    soup = BeautifulSoup(response.text, "html.parser")
    assert soup.find(id="your-element-id") is not None


@pytest.mark.anyio
async def test_${slug}_hx_request_header(client: AsyncClient) -> None:
    """Fragment endpoint validates HX-Request header."""
    response = await client.get(
        "/your-endpoint/fragment",
        headers={"HX-Request": "true"},
    )
    assert response.status_code == 200


@pytest.mark.anyio
async def test_${slug}_post_mutation_via_hx_post(client: AsyncClient) -> None:
    """Mutation via hx-post returns updated HTML fragment."""
    response = await client.post(
        "/your-action",
        headers={"HX-Request": "true"},
        data={"field": "value"},
    )
    assert response.status_code == 200
    assert "text/html" in response.headers.get("content-type", "")
`;
}
function generateGoHttptestTest(title) {
    const pkg = title.toLowerCase().replace(/\s+/g, '_');
    return `// Integration tests for ${title} — HTMX hypermedia endpoints.
package ${pkg}_test

import (
\t"net/http"
\t"net/http/httptest"
\t"strings"
\t"testing"

\t"github.com/PuerkitoBio/goquery"
)

func TestGetEndpointReturnsHTMLFragment(t *testing.T) {
\treq := httptest.NewRequest(http.MethodGet, "/your-endpoint", nil)
\trw := httptest.NewRecorder()
\t// handler.ServeHTTP(rw, req) — replace with your handler
\t_ = rw // remove this line when handler is wired

\tif rw.Code != http.StatusOK {
\t\tt.Errorf("expected 200, got %d", rw.Code)
\t}
\tif !strings.Contains(rw.Header().Get("Content-Type"), "text/html") {
\t\tt.Errorf("expected text/html content-type, got %s", rw.Header().Get("Content-Type"))
\t}
\t_ = req
}

func TestGetEndpointHTMLContainsExpectedElements(t *testing.T) {
\treq := httptest.NewRequest(http.MethodGet, "/your-endpoint", nil)
\trw := httptest.NewRecorder()
\t// handler.ServeHTTP(rw, req)

\tdoc, err := goquery.NewDocumentFromReader(rw.Body)
\tif err != nil {
\t\tt.Fatalf("failed to parse HTML: %v", err)
\t}
\tif doc.Find("#your-element-id").Length() == 0 {
\t\tt.Error("expected #your-element-id element in response HTML")
\t}
\t_ = req
}

func TestHxRequestHeaderValidation(t *testing.T) {
\treq := httptest.NewRequest(http.MethodGet, "/your-endpoint/fragment", nil)
\treq.Header.Set("HX-Request", "true")
\trw := httptest.NewRecorder()
\t// handler.ServeHTTP(rw, req)

\tif rw.Code != http.StatusOK {
\t\tt.Errorf("expected 200, got %d", rw.Code)
\t}
}
`;
}
function generateRubyRackTest(title) {
    return `# Integration tests for ${title} — HTMX hypermedia endpoints.
require 'rails_helper'

RSpec.describe '${title}', type: :request do
  describe 'GET /your-endpoint' do
    it 'returns 200 with text/html content type' do
      get '/your-endpoint'
      expect(response).to have_http_status(:ok)
      expect(response.content_type).to include('text/html')
    end

    it 'returns HTML fragment with expected elements' do
      get '/your-endpoint'
      expect(response.body).to include('id="your-element-id"')
    end

    context 'with HX-Request header' do
      it 'returns fragment response' do
        get '/your-endpoint/fragment', headers: { 'HX-Request' => 'true' }
        expect(response).to have_http_status(:ok)
        expect(response.content_type).to include('text/html')
      end
    end
  end

  describe 'POST /your-action' do
    it 'mutates via hx-post and returns updated fragment' do
      post '/your-action',
           params: { field: 'value' },
           headers: { 'HX-Request' => 'true' }
      expect(response).to have_http_status(:ok)
      expect(response.content_type).to include('text/html')
    end
  end
end
`;
}
function generateLaravelHttpTest(title) {
    return `<?php

// Integration tests for ${title} — HTMX hypermedia endpoints.
namespace Tests\\Feature;

use Tests\\TestCase;

class ${title.replace(/\s+/g, '')}Test extends TestCase
{
    public function test_get_endpoint_returns_html_fragment(): void
    {
        $response = $this->get('/your-endpoint');
        $response->assertStatus(200);
        $response->assertHeader('content-type', 'text/html; charset=UTF-8');
    }

    public function test_html_contains_expected_elements(): void
    {
        $response = $this->get('/your-endpoint');
        $response->assertSee('id="your-element-id"', false);
    }

    public function test_hx_request_header_returns_fragment(): void
    {
        $response = $this->withHeaders([
            'HX-Request' => 'true',
        ])->get('/your-endpoint/fragment');
        $response->assertStatus(200);
    }

    public function test_post_mutation_via_hx_post(): void
    {
        $response = $this->withHeaders([
            'HX-Request' => 'true',
        ])->post('/your-action', ['field' => 'value']);
        $response->assertStatus(200);
        $response->assertHeader('content-type', 'text/html; charset=UTF-8');
    }
}
`;
}
function generateJavaSpringTest(title) {
    const cls = title.replace(/\s+/g, '');
    return `// Integration tests for ${title} — HTMX hypermedia endpoints.
package com.example.tests;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@SpringBootTest
@AutoConfigureMockMvc
class ${cls}IntegrationTest {

    @Autowired
    private MockMvc mockMvc;

    @Test
    void getEndpointReturnsHtmlFragment() throws Exception {
        mockMvc.perform(get("/your-endpoint"))
               .andExpect(status().isOk())
               .andExpect(content().contentTypeCompatibleWith("text/html"));
    }

    @Test
    void htmlContainsExpectedElements() throws Exception {
        mockMvc.perform(get("/your-endpoint"))
               .andExpect(status().isOk())
               .andExpect(content().string(org.hamcrest.Matchers.containsString("your-element-id")));
    }

    @Test
    void hxRequestHeaderReturnsFragment() throws Exception {
        mockMvc.perform(get("/your-endpoint/fragment")
               .header("HX-Request", "true"))
               .andExpect(status().isOk());
    }
}
`;
}
function generateNodePlaywrightTest(title) {
    return `// Integration tests for ${title} — HTMX hypermedia endpoints (Playwright SSR).
import { test, expect } from '@playwright/test';

test.describe('${title} — hypermedia endpoints', () => {
  test('GET endpoint returns 200 and HTML fragment', async ({ request }) => {
    const response = await request.get('/your-endpoint');
    expect(response.status()).toBe(200);
    expect(response.headers()['content-type']).toContain('text/html');
  });

  test('HTML fragment contains expected elements', async ({ page }) => {
    await page.goto('/your-endpoint');
    await expect(page.locator('#your-element-id')).toBeVisible();
  });

  test('HX-Request header returns fragment response', async ({ request }) => {
    const response = await request.get('/your-endpoint/fragment', {
      headers: { 'HX-Request': 'true' },
    });
    expect(response.status()).toBe(200);
  });

  test('hx-post mutation updates HTML fragment', async ({ request }) => {
    const response = await request.post('/your-action', {
      headers: { 'HX-Request': 'true' },
      form: { field: 'value' },
    });
    expect(response.status()).toBe(200);
    expect(response.headers()['content-type']).toContain('text/html');
  });
});
`;
}
export function getFileExtension(language) {
    const exts = {
        python: 'py',
        go: 'go',
        ruby: 'rb',
        php: 'php',
        java: 'java',
        javascript: 'spec.ts',
        typescript: 'spec.ts',
    };
    return exts[language] ?? 'test.ts';
}
export function selectTestFramework(language) {
    const frameworks = {
        python: 'pytest-httpx',
        go: 'net-http-httptest',
        ruby: 'rack-test',
        php: 'laravel-http',
        java: 'spring-mvc-test',
        javascript: 'playwright-ssr',
        typescript: 'playwright-ssr',
    };
    return frameworks[language] ?? 'playwright-ssr';
}
export function generateTestContent(title, language) {
    switch (language) {
        case 'python':
            return generatePythonHttpxTest(title);
        case 'go':
            return generateGoHttptestTest(title);
        case 'ruby':
            return generateRubyRackTest(title);
        case 'php':
            return generateLaravelHttpTest(title);
        case 'java':
            return generateJavaSpringTest(title);
        default:
            return generateNodePlaywrightTest(title);
    }
}
/**
 * Generate hypermedia integration test files for the given spec and knowledge.
 */
export function generateHypermediaTestFiles(spec, testDir, language, autoGenerate) {
    const slug = spec.id.toLowerCase().replace(/[^a-z0-9]/g, '-');
    const ext = getFileExtension(language);
    const framework = selectTestFramework(language);
    const content = generateTestContent(spec.title, language);
    return [
        {
            path: `${testDir}/integration/${slug}.hypermedia.${ext}`,
            framework,
            content,
            ready: autoGenerate,
        },
    ];
}
//# sourceMappingURL=hypermedia-generator-b.js.map