package classes
import (
"testing"
"git.golem15.com/golem15/summercms/modules/pact"
)
// TestParseContentFacts pins what a body says about itself: images with
// alt, decorative (alt present and empty) and size attributes (negative
// and invalid sizes 0), an img without src skipped; YouTube embeds of the
// editor's figure; the heading outline with collapsed text, inline tags
// joined, block children spaced, a no-break space collapsed like any
// other, a heading inside a heading read as part
// of the outer one.
func TestParseContentFacts(t *testing.T) {
f := parseContentFacts(`
Lwia grzywa
Dawkowanie i forma
Outer
inner
tail
`)
wantImages := []pact.ContentImage{
{URL: "/m/a.jpg", Alt: "Lion's mane", Width: 800},
{URL: "/m/line.png", Decorative: true},
{URL: "/m/b.jpg"},
}
if len(f.images) != len(wantImages) {
t.Fatalf("images = %+v", f.images)
}
for i, w := range wantImages {
if f.images[i] != w {
t.Errorf("image %d = %+v, want %+v", i, f.images[i], w)
}
}
if len(f.videos) != 1 || f.videos[0] != (pact.ContentVideo{Provider: "youtube", ID: "abc123"}) {
t.Fatalf("videos = %+v", f.videos)
}
wantHeadings := []pact.ContentHeading{{Level: 2, Text: "Lwia grzywa"}, {Level: 3, Text: "Dawkowanie i forma"}, {Level: 4, Text: "Outer inner tail"}, {Level: 2, Text: ""}}
if len(f.headings) != len(wantHeadings) {
t.Fatalf("headings = %+v", f.headings)
}
for i, w := range wantHeadings {
if f.headings[i] != w {
t.Errorf("heading %d = %+v, want %+v", i, f.headings[i], w)
}
}
}
// TestParseContentFactsEmpty pins an empty body and the category pillar
// text read the same way (headings only).
func TestParseContentFactsEmpty(t *testing.T) {
if f := parseContentFacts(" "); f.images != nil || f.videos != nil || f.headings != nil {
t.Fatalf("blank = %+v", f)
}
pillar := parseContentFacts("
Intro
Gatunki
Skipped
")
if len(pillar.headings) != 2 || pillar.headings[1].Level != 4 {
t.Fatalf("pillar = %+v", pillar.headings)
}
}
// TestTopHeading pins the record's highest heading level: 2 while the
// H1 setting turns body H1s into H2s, 0 (any) otherwise.
func TestTopHeading(t *testing.T) {
if topHeading(true) != 2 || topHeading(false) != 0 {
t.Fatal("topHeading is wrong")
}
if toolUpdatePost != "journal_update_post" || toolFixHeadings != "journal_fix_headings" || toolSetImageAlt != "journal_set_image_alt" {
t.Fatal("the descriptor's tool names changed")
}
}