77 lines
2.3 KiB
Go
77 lines
2.3 KiB
Go
package seo
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"seo-optimizer/pkg/models"
|
|
)
|
|
|
|
func TestHasFAQBlock(t *testing.T) {
|
|
builder := NewContentBuilder(nil)
|
|
content := `<!-- wp:rank-math/faq-block {"questions":[]} --><div class="wp-block-rank-math-faq-block"></div><!-- /wp:rank-math/faq-block -->`
|
|
if !builder.hasFAQBlock(content) {
|
|
t.Fatalf("expected FAQ block to be detected")
|
|
}
|
|
}
|
|
|
|
func TestBuildOptimizedContentSkipsExistingFAQ(t *testing.T) {
|
|
builder := NewContentBuilder(nil)
|
|
original := `<!-- wp:rank-math/faq-block {"questions":[]} --><div class="wp-block-rank-math-faq-block"></div><!-- /wp:rank-math/faq-block -->`
|
|
|
|
optimization := &models.OptimizationResponse{
|
|
SEOMeta: models.SEOMeta{},
|
|
ContentOptimization: models.ContentOptimization{
|
|
Changes: []models.ContentChange{},
|
|
InternalLinks: []models.InternalLink{},
|
|
},
|
|
FAQBlock: models.FAQBlock{
|
|
ShouldCreate: true,
|
|
Questions: []models.FAQQuestion{
|
|
{ID: "faq-question-1", Title: "Q1", Content: "A1", Visible: true},
|
|
},
|
|
},
|
|
Validation: models.Validation{},
|
|
Summary: "",
|
|
}
|
|
|
|
result, err := builder.BuildOptimizedContent(original, optimization)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if strings.Count(result, "wp:rank-math/faq-block") != 2 {
|
|
t.Fatalf("expected single FAQ block markers, got %d", strings.Count(result, "wp:rank-math/faq-block"))
|
|
}
|
|
}
|
|
|
|
func TestWrapInGutenbergBlocks(t *testing.T) {
|
|
builder := NewContentBuilder(nil)
|
|
content := "Hello world\n\nSecond paragraph"
|
|
wrapped := builder.wrapInGutenbergBlocks(content)
|
|
|
|
if !strings.Contains(wrapped, "<!-- wp:paragraph -->") {
|
|
t.Fatalf("expected paragraph blocks to be added")
|
|
}
|
|
|
|
if count := strings.Count(wrapped, "<!-- wp:paragraph -->"); count != 2 {
|
|
t.Fatalf("expected 2 paragraph blocks, got %d", count)
|
|
}
|
|
}
|
|
|
|
func TestWrapInGutenbergBlocksHandlesHeadingsAndLists(t *testing.T) {
|
|
builder := NewContentBuilder(nil)
|
|
content := "<h2>Title</h2>\n\n<ul><li>One</li><li>Two</li></ul>\n\n<p>Para</p>"
|
|
wrapped := builder.wrapInGutenbergBlocks(content)
|
|
|
|
if !strings.Contains(wrapped, "<!-- wp:heading {\"level\":2} -->") {
|
|
t.Fatalf("expected heading block wrapper")
|
|
}
|
|
if !strings.Contains(wrapped, "<!-- wp:list -->") {
|
|
t.Fatalf("expected list block wrapper")
|
|
}
|
|
if count := strings.Count(wrapped, "<!-- wp:paragraph -->"); count != 1 {
|
|
t.Fatalf("expected 1 paragraph block, got %d", count)
|
|
}
|
|
}
|