oficina / slides Public

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

Plain git — no account needed to clone.

Download

Download this file

1package layout_test
2
3import (
4 "encoding/json"
5 "strings"
6 "testing"
7
8 "amadan.net/oficina/slides/internal/slides/deck"
9 "amadan.net/oficina/slides/internal/slides/layout"
10)
11
12// Codex 7: two columns blocks naming each other used to leave the
13// paint list with nothing from either — every member was claimed, so
14// no traversal started. The engine now draws what nothing reached after
15// the rest and says so with a warning, on both layouts, and the page
16// (render) does the same.
17func cyclic(layout string) *deck.Deck {
18 blocks := []deck.Block{
19 {ID: "intro", Type: "text", Region: "body", Text: txt("Reached")},
20 {ID: "one", Type: "columns", Region: "body",
21 Props: map[string]any{"children": []any{"two", "kid"}}},
22 {ID: "two", Type: "columns", Region: "body",
23 Props: map[string]any{"children": []any{"one"}}},
24 {ID: "kid", Type: "text", Region: "body", Text: txt("Under the cycle")},
25 }
26 if layout == "canvas" {
27 for i := range blocks {
28 blocks[i].Region = ""
29 blocks[i].Box = box(0.1, 0.1+0.2*float64(i), 0.8, 0.15)
30 blocks[i].Z = i
31 }
32 }
33 return &deck.Deck{
34 Meta: deck.Meta{Theme: "paper"},
35 Slides: []deck.Slide{{ID: "s", Layout: layout, Template: "blank", Blocks: blocks}},
36 }
37}
38
39func TestBlocksNothingReachesAreDrawnAndReported(t *testing.T) {
40 for _, l := range []string{"flow", "canvas"} {
41 t.Run(l, func(t *testing.T) {
42 p, warnings, err := layout.Layout(cyclic(l), 0)
43 if err != nil {
44 t.Fatal(err)
45 }
46 raw, err := json.Marshal(p)
47 if err != nil {
48 t.Fatal(err)
49 }
50 s := string(raw)
51 for _, word := range []string{"Reached", "Under the cycle"} {
52 if !strings.Contains(s, word) {
53 t.Errorf("the paint list lost %q:\n%s", word, s)
54 }
55 }
56 if strings.Index(s, "Reached") > strings.Index(s, "Under the cycle") {
57 t.Errorf("the unreached content is drawn before the reached content")
58 }
59 var unreached []string
60 for _, w := range warnings {
61 if w.Kind == layout.WarnUnreached {
62 unreached = append(unreached, w.Block)
63 if w.Slide != "s" {
64 t.Errorf("warning does not name the slide: %+v", w)
65 }
66 }
67 }
68 if strings.Join(unreached, ",") != "one,two,kid" {
69 t.Errorf("unreached warnings name %v, want one, two, kid", unreached)
70 }
71 })
72 }
73}
74
75// A well-formed deck reports nothing unreached: the fixture is every
76// template and both layouts.
77func TestAWellFormedDeckHasNothingUnreached(t *testing.T) {
78 d := fixture()
79 for i := range d.Slides {
80 _, warnings, err := layout.Layout(d, i)
81 if err != nil {
82 t.Fatal(err)
83 }
84 for _, w := range warnings {
85 if w.Kind == layout.WarnUnreached {
86 t.Errorf("slide %d: %+v", i, w)
87 }
88 }
89 }
90}
91