Render: a test of AssetPaths, red against a stub then green
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 file changed,
+46
−0
internal/slides/render/asset_paths_test.go+46 −0
diff --git a/internal/slides/render/asset_paths_test.go b/internal/slides/render/asset_paths_test.go| new file mode 100644 |
| index 0000000..ae7b07f |
| --- /dev/null |
| +++ b/internal/slides/render/asset_paths_test.go |
| @@ -0,0 +1,46 @@ |
| +package render_test |
| + |
| +import ( |
| + "reflect" |
| + "testing" |
| + |
| + "amadan.net/oficina/slides/internal/slides/deck" |
| + "amadan.net/oficina/slides/internal/slides/render" |
| +) |
| + |
| +func TestAssetPathsListsWhatTheSlideDraws(t *testing.T) { |
| + img := func(id, asset string) deck.Block { |
| + return deck.Block{ID: id, Type: "image", Props: map[string]any{"asset": asset}} |
| + } |
| + d := &deck.Deck{ |
| + Assets: map[string]deck.Asset{ |
| + "bg": {Ref: "aaaa1111"}, |
| + "one": {Ref: "bbbb2222"}, |
| + "two": {Ref: "cccc3333"}, |
| + "bad": {Ref: "has/slash"}, |
| + }, |
| + Slides: []deck.Slide{ |
| + {ID: "s", Background: deck.Background{Kind: "image", Value: "bg"}, Blocks: []deck.Block{ |
| + img("i1", "one"), |
| + img("i2", "two"), |
| + img("i3", "one"), // duplicate: listed once |
| + img("i4", "missing"), // not registered |
| + img("i5", "bad"), // ref that cannot go in a URL |
| + img("i6", "../x"), // not an id |
| + {ID: "t", Type: "text"}, |
| + }}, |
| + {ID: "plain", Background: deck.Background{Kind: "color", Value: "bg"}}, |
| + }, |
| + } |
| + base := "/p/abc/assets" |
| + want := []string{base + "/aaaa1111", base + "/bbbb2222", base + "/cccc3333"} |
| + if got := render.AssetPaths(d, 0, base+"/"); !reflect.DeepEqual(got, want) { |
| + t.Errorf("AssetPaths = %v, want %v", got, want) |
| + } |
| + if got := render.AssetPaths(d, 1, base); len(got) != 0 { |
| + t.Errorf("a slide with no pictures: %v, want none", got) |
| + } |
| + if got := render.AssetPaths(d, 5, base); len(got) != 0 { |
| + t.Errorf("out of range: %v, want none", got) |
| + } |
| +} |