85 lines
3.0 KiB
Go
85 lines
3.0 KiB
Go
package aiprompts
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestSEOProductHTMLAllLocales(t *testing.T) {
|
|
for _, lang := range OfflinePromptLanguages() {
|
|
prompt, err := OfflineDefaultPrompt(lang)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
body := DescriptionSectionInstructions(prompt)
|
|
if strings.Count(body, "<p>{") != 2 || strings.Count(body, "<h2>{") != 2 || strings.Count(body, "<ul><li>{") != 1 {
|
|
t.Fatalf("%s invalid HTML: %s", lang, body)
|
|
}
|
|
formula := DeriveDescriptionFormulaFromLegacyParts(LegacyEnhanceParts{DescriptionRules: body, WasLegacy: true})
|
|
if len(formula.Sections) != 5 {
|
|
t.Fatalf("%s got %d sections; want 5: %+v", lang, len(formula.Sections), formula.Sections)
|
|
}
|
|
got := []string{}
|
|
for _, section := range formula.Sections {
|
|
got = append(got, section.Type)
|
|
}
|
|
if strings.Join(got, ",") != "p,h2,p,h2,ul" {
|
|
t.Fatalf("%s wrong sections %v", lang, got)
|
|
}
|
|
if !formula.Sections[3].Optional || !formula.Sections[4].Optional {
|
|
t.Fatalf("%s missing optional flags", lang)
|
|
}
|
|
if strings.Contains(body, "<h1>") || strings.Contains(body, "<b>") {
|
|
t.Fatalf("%s non-semantic HTML", lang)
|
|
}
|
|
if strings.Contains(body, "five distinct H2") || strings.Contains(body, "pet različitih naslova H2") {
|
|
t.Fatalf("%s repetitive formula", lang)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSEOEnglishMetaSplit(t *testing.T) {
|
|
parts := ParseLegacyCombinedEnhancePrompt(GenericDefaultCategoryPrompt)
|
|
if !parts.WasLegacy {
|
|
t.Fatal("English default not parsed")
|
|
}
|
|
meta := DeriveDescriptionFormulaFromLegacyParts(parts)
|
|
if !strings.HasPrefix(meta.MetaTitle, "Create a distinct") {
|
|
t.Fatalf("metaTitle=%s", meta.MetaTitle)
|
|
}
|
|
if !strings.HasPrefix(meta.MetaDescription, "Summarize what") {
|
|
t.Fatalf("metaDescription=%s", meta.MetaDescription)
|
|
}
|
|
if strings.Contains(meta.MetaDescription, "meta_title:") {
|
|
t.Fatal("title rule leaked into description")
|
|
}
|
|
}
|
|
|
|
func TestSEOUpgradeHasPreviousVersionAndDifferentHashSource(t *testing.T) {
|
|
for _, name := range []string{"Televisions", "Grohe mixers", "High chairs"} {
|
|
old := PriorDefaultCategoryFormula("", name)
|
|
now := DefaultCategoryFormula("", name)
|
|
if old.Overlay == "" || now.Overlay == "" || old.Overlay == now.Overlay {
|
|
t.Fatalf("%s migration source missing", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestEveryLocalizedDefaultUsesDistinctBracedMetaFields(t *testing.T) {
|
|
for _, lang := range OfflinePromptLanguages() {
|
|
prompt, err := OfflineDefaultPrompt(lang)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
meta := ExtractEnhanceSectionBody(prompt, SectionMetaStart, SectionMetaEnd)
|
|
if strings.Count(meta, "{meta_title:") != 1 || strings.Count(meta, "{meta_description:") != 1 || strings.Count(meta, "}") != 2 {
|
|
t.Fatalf("%s SEO meta has inconsistent brace structure: %s", lang, meta)
|
|
}
|
|
parts := LegacyEnhanceParts{MetaRules: meta, WasLegacy: true}
|
|
result := DeriveDescriptionFormulaFromLegacyParts(parts)
|
|
if result.MetaTitle == "" || result.MetaDescription == "" || strings.Contains(result.MetaTitle, "meta_description:") {
|
|
t.Fatalf("%s metadata parser lost a field: %+v", lang, result)
|
|
}
|
|
}
|
|
}
|