- ConvertContentH1 and ConvertTranslationH1 for post bodies and category pillar text - SetImageAlt with several matches, repeated alt attributes and markup that only looks like an img - the content facts outline, images, decorative images and embeds - the related-posts mode and count
70 lines
2.8 KiB
Go
70 lines
2.8 KiB
Go
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(`<h2>Lwia <em>grzywa</em></h2>
|
|
<p><img src=" /m/a.jpg " alt=" Lion's mane " width="800" height="-1"><img src="/m/line.png" alt=""><img alt="no src"><img src="/m/b.jpg" width="x"></p>
|
|
<figure data-embed="youtube" data-id="abc123"></figure><figure data-embed="youtube"></figure><figure data-embed="vimeo" data-id="9"></figure>
|
|
<h3>Dawkowanie<br>i forma</h3><h4><span>Outer <h5>inner</h5> tail</span></h4><h2></h2>`)
|
|
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("<p>Intro</p><h2>Gatunki</h2><h4>Skipped</h4>")
|
|
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")
|
|
}
|
|
}
|