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
3import (
4 "reflect"
5 "testing"
6
7 "amadan.net/oficina/slides/internal/slides/deck"
8 "amadan.net/oficina/slides/internal/slides/render"
9)
10
11func TestAssetPathsListsWhatTheSlideDraws(t *testing.T) {
12 img := func(id, asset string) deck.Block {
13 return deck.Block{ID: id, Type: "image", Props: map[string]any{"asset": asset}}
14 }
15 d := &deck.Deck{
16 Assets: map[string]deck.Asset{
17 "bg": {Ref: "aaaa1111"},
18 "one": {Ref: "bbbb2222"},
19 "two": {Ref: "cccc3333"},
20 "bad": {Ref: "has/slash"},
21 },
22 Slides: []deck.Slide{
23 {ID: "s", Background: deck.Background{Kind: "image", Value: "bg"}, Blocks: []deck.Block{
24 img("i1", "one"),
25 img("i2", "two"),
26 img("i3", "one"), // duplicate: listed once
27 img("i4", "missing"), // not registered
28 img("i5", "bad"), // ref that cannot go in a URL
29 img("i6", "../x"), // not an id
30 {ID: "t", Type: "text"},
31 }},
32 {ID: "plain", Background: deck.Background{Kind: "color", Value: "bg"}},
33 },
34 }
35 base := "/p/abc/assets"
36 want := []string{base + "/aaaa1111", base + "/bbbb2222", base + "/cccc3333"}
37 if got := render.AssetPaths(d, 0, base+"/"); !reflect.DeepEqual(got, want) {
38 t.Errorf("AssetPaths = %v, want %v", got, want)
39 }
40 if got := render.AssetPaths(d, 1, base); len(got) != 0 {
41 t.Errorf("a slide with no pictures: %v, want none", got)
42 }
43 if got := render.AssetPaths(d, 5, base); len(got) != 0 {
44 t.Errorf("out of range: %v, want none", got)
45 }
46}
47