53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestPageImagesCarryTheirSize(t *testing.T) {
|
|
for _, path := range []string{
|
|
"/doc/prism-slides",
|
|
"/doc/prism-slides/pages",
|
|
"/doc/prism-slides/versions/lemonde",
|
|
"/doc/prism-slides/versions/lemonde/pages",
|
|
} {
|
|
body := get(t, path).Body.String()
|
|
if n := strings.Count(body, `page-1.jpg" width="4" height="3"`); n < 2 {
|
|
t.Errorf("%s: %d page-1 images with their size, want the page and its full-screen view", path, n)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAssemblySlidesCarryTheirSize(t *testing.T) {
|
|
root := assemblyCorpus(t, `[{"id": "sized", "title": "Sized", "slides": [{"doc": "deck", "pages": "1"}]}]`)
|
|
withCorpus(t, root)
|
|
for _, path := range []string{"/explore/assemblies", "/explore/assemblies/sized"} {
|
|
if body := get(t, path).Body.String(); !strings.Contains(body, `page-1.jpg" width="4" height="3"`) {
|
|
t.Errorf("%s: slide image without its size", path)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestUnreadablePageImageWarns(t *testing.T) {
|
|
root := assemblyCorpus(t, "")
|
|
writeAssemblyDoc(t, root, "broken", map[string]interface{}{"title": "Broken"}, []string{"page-1.jpg"}, nil)
|
|
writeFixtureFile(t, filepath.Join(root, "broken", "images", "page-1.jpg"), "not an image")
|
|
var logged bytes.Buffer
|
|
log.SetOutput(&logged)
|
|
withCorpus(t, root)
|
|
log.SetOutput(os.Stderr)
|
|
|
|
if !strings.Contains(logged.String(), "page image unreadable, served without its size: broken/images/page-1.jpg") {
|
|
t.Errorf("no warning for the unreadable image:\n%s", logged.String())
|
|
}
|
|
body := get(t, "/doc/broken").Body.String()
|
|
if !strings.Contains(body, `<img src="/files/broken/images/page-1.jpg"
|
|
`) || strings.Contains(body, `page-1.jpg" width=`) {
|
|
t.Errorf("unreadable image: want it served without width/height")
|
|
}
|
|
}
|