Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

reactions_test.gno

1.86 Kb · 48 lines
 1package home
 2
 3import (
 4	"strings"
 5	"testing"
 6
 7	"gno.land/p/nt/uassert/v0"
 8)
 9
10// TestReactionBlockRenders exercises the cross-realm call itself, which is the
11// only thing that can find the failure mode this realm is exposed to: it is
12// private = true, and a private realm that hands one of its own objects to
13// another realm panics at RUNTIME with "cannot persist object from the private
14// realm", where gno lint sees nothing (AGENTS.md, ADR 0044). Only strings cross
15// here, in both directions, and this test is what says so.
16func TestReactionBlockRenders(t *testing.T) {
17	reset()
18	seed("layout", "# page\n\n:reactions:\n")
19
20	got := Render("")
21	uassert.True(t, strings.Contains(got, "(/r/moul/reactions/v0$help&func=React&"),
22		"the block's txlinks target the reactions realm")
23	uassert.True(t, strings.Contains(got, "page=gno.land%2Fr%2Fmoul%2Fhome"),
24		"keyed on this realm's path, which is what makes the tally this page's")
25	uassert.True(t, strings.Contains(got, "*no reactions yet*"))
26}
27
28// TestReactionsIsAReservedSlug: the placeholder is computed, so a slot may not
29// take its name and shadow it. gnohome refuses the same name off chain, before
30// the gas is spent (tools/gnohome/content.go).
31func TestReactionsIsAReservedSlug(cur realm, t *testing.T) {
32	reset()
33	testing.SetRealm(testing.NewUserRealm(admin))
34	uassert.AbortsWithMessage(t, cur,
35		"reserved slug: reactions is computed at render time", func() {
36			Set(cross(cur), "reactions", "nope")
37		})
38}
39
40// TestLayoutWithoutTheBlockCallsNothing is the property that makes the
41// placeholder free: dynreplacer only invokes a callback whose placeholder
42// occurs in the layout, so a layout that drops :reactions: does not reach into
43// the reactions realm at all.
44func TestLayoutWithoutTheBlockCallsNothing(t *testing.T) {
45	reset()
46	seed("layout", "# page\n\nnothing here\n")
47	uassert.Equal(t, "# page\n\nnothing here\n", Render(""))
48}