oficina / slides Public

Clone
git clone https://amadan.net/oficina/slides

Plain git — no account needed to clone.

Download

Download this file

1package render_test
2
3// A clip block in HTML (scenes and clips spec §2; plan call R3): its
4// poster, described by the video's alt text, the video's address and
5// how it plays for the script that plays it, a press marked on a child
6// of its own so the poster is there from the slide's arrival, and an
7// empty frame wherever there is no video with a poster.
8
9import (
10 "strings"
11 "testing"
12
13 "amadan.net/oficina/slides/internal/slides/deck"
14 "amadan.net/oficina/slides/internal/slides/render"
15)
16
17func clipDeck(blocks ...deck.Block) *deck.Deck {
18 return &deck.Deck{
19 Meta: deck.Meta{Title: "Clips", Theme: "paper", Aspect: "16:9"},
20 Assets: map[string]deck.Asset{
21 "videoaaaaaaa": {Ref: "71de0001", Name: "demo.webm", Width: 1280, Height: 720, Alt: "Opening a deck", Poster: "905e0001", Duration: 4250},
22 "posteraaaaaa": {Ref: "905e0001", Name: "demo.webp", Width: 1280, Height: 720},
23 "nopostervidx": {Ref: "71de0002", Name: "lost.webm", Poster: "905e0009"},
24 },
25 Slides: []deck.Slide{{ID: "slideclip001", Layout: "flow", Template: "blank", Blocks: blocks}},
26 }
27}
28
29func clip(id, asset, play string) deck.Block {
30 return deck.Block{ID: id, Type: "clip", Region: "body", Props: map[string]any{"asset": asset, "play": play}}
31}
32
33func TestAClipIsItsPoster(t *testing.T) {
34 d := clipDeck(clip("clippress001", "videoaaaaaaa", "press"))
35 html, err := render.SlideWith(d, 0, render.Desktop, render.Options{AssetBase: "/d/x/assets"})
36 if err != nil {
37 t.Fatal(err)
38 }
39 want := `<figure slides-block data-block="clip" data-id="clippress001" data-clip="press" data-clip-src="/d/x/assets/71de0001" data-region="body">` +
40 "\n" + `<img src="/d/x/assets/905e0001" alt="Opening a deck" width="1280" height="720">` + "\n</figure>"
41 if !strings.Contains(string(html), want) {
42 t.Errorf("the clip is drawn as\n%s\nwant\n%s", html, want)
43 }
44 if got := render.AssetPaths(d, 0, "/p/s/assets"); strings.Join(got, " ") != "/p/s/assets/905e0001" {
45 t.Errorf("AssetPaths = %v, want the poster", got)
46 }
47 if got := render.ClipPaths(d, 0, "/p/s/assets"); strings.Join(got, " ") != "/p/s/assets/71de0001" {
48 t.Errorf("ClipPaths = %v, want the video", got)
49 }
50}
51
52func TestAClipsPressIsMarkedInsideIt(t *testing.T) {
53 looped := clip("cliploop0001", "videoaaaaaaa", "loop")
54 looped.Step = 1
55 d := clipDeck(clip("clippress001", "videoaaaaaaa", "press"), looped)
56 at := func(n int) string {
57 html, err := render.SlideWith(d, 0, render.Desktop, render.Options{AssetBase: "/a", Reveal: &n})
58 if err != nil {
59 t.Fatal(err)
60 }
61 return string(html)
62 }
63 zero := at(0)
64 for _, want := range []string{
65 `data-id="clippress001" data-clip="press" data-clip-src="/a/71de0001" data-region="body">`,
66 `<span data-clip-press data-press="1" data-waiting></span>`,
67 // A loop with a step arrives on it, whole, as any box does: the
68 // press after the clip's own.
69 `data-id="cliploop0001" data-clip="loop" data-clip-src="/a/71de0001" data-press="2" data-waiting data-region="body">`,
70 } {
71 if !strings.Contains(zero, want) {
72 t.Errorf("at press 0 the slide lacks %s:\n%s", want, zero)
73 }
74 }
75 if one := at(1); !strings.Contains(one, `<span data-clip-press data-press="1"></span>`) {
76 t.Errorf("at press 1 the clip is not pressed:\n%s", one)
77 }
78 if two := at(2); strings.Contains(two, "data-waiting") {
79 t.Errorf("at press 2 something still waits:\n%s", two)
80 }
81}
82
83func TestAClipWithNoVideoOrPosterIsAnEmptyFrame(t *testing.T) {
84 for _, b := range []deck.Block{
85 clip("clipnone0001", "", "press"),
86 clip("clipnone0002", "posteraaaaaa", "loop"), // a picture, not a video
87 clip("clipnone0003", "nopostervidx", "once"), // a poster the deck never registered
88 clip("clipnone0004", "goneaaaaaaaa", "once"),
89 } {
90 d := clipDeck(b)
91 html, err := render.SlideWith(d, 0, render.Desktop, render.Options{AssetBase: "/a"})
92 if err != nil {
93 t.Fatal(err)
94 }
95 if !strings.Contains(string(html), `data-missing-asset="true"`) || strings.Contains(string(html), "<img") || strings.Contains(string(html), "data-clip-src") {
96 t.Errorf("%s: drawn as\n%s", b.Props["asset"], html)
97 }
98 if got := render.ClipPaths(d, 0, "/a"); len(got) != 0 {
99 t.Errorf("%s: ClipPaths = %v", b.Props["asset"], got)
100 }
101 }
102 // No play is once.
103 d := clipDeck(deck.Block{ID: "clipplay0001", Type: "clip", Region: "body", Props: map[string]any{"asset": "videoaaaaaaa"}})
104 html, _ := render.SlideWith(d, 0, render.Desktop, render.Options{AssetBase: "/a"})
105 if !strings.Contains(string(html), `data-clip="once"`) {
106 t.Errorf("a clip with no play is drawn as\n%s", html)
107 }
108}
109