z_ui_thread_08_filetest.gno
1.84 Kb · 54 lines
1// PKGPATH: gno.land/r/gnoland/boards2/v1/filetests/z_ui_thread_08_filetest
2
3// A thread large enough to exceed the foreign-block render budget
4// degrades gracefully: rendering stops before gnoweb's per-render
5// foreign-block cap would blank comments, and a "More replies — view
6// full thread" notice is shown instead (see maxRenderedBodies). The
7// reply count and assertion are derived from MaxBlocksPerRender so this
8// stays a truncation test if the cap changes.
9package z_ui_thread_08_filetest
10
11import (
12 "strings"
13 "testing"
14
15 "gno.land/p/gnoland/boards"
16 "gno.land/p/nt/markdown/foreign/v0"
17
18 boards2 "gno.land/r/gnoland/boards2/v1"
19)
20
21const owner address = "g1rp7cmetn27eqlpjpc4vuusf8kaj746tysc0qgh"
22
23var (
24 bid boards.ID
25 tid boards.ID
26)
27
28func init(cur realm) {
29 testing.SetRealm(testing.NewUserRealm(owner))
30 bid = boards2.CreateBoard(cross(cur), "test-board", false, false)
31 tid = boards2.CreateThread(cross(cur), bid, "Foo", "OP body")
32
33 // One top-level comment with many direct sub-replies (sub-replies
34 // are not paginated, so they consume the shared render budget).
35 // Create MaxBlocksPerRender of them — strictly more than the budget
36 // (cap minus a margin) — so rendering must truncate.
37 rid := boards2.CreateReply(cross(cur), bid, tid, 0, "top comment")
38 for i := 0; i < foreign.MaxBlocksPerRender(); i++ {
39 boards2.CreateReply(cross(cur), bid, tid, rid, "sub reply")
40 }
41}
42
43func main(cur realm) {
44 content := boards2.Render("test-board/1")
45 n := strings.Count(content, "<gno-foreign>")
46 // The top comment's many sub-replies are capped inline at pageSizeReplies
47 // (so n stays well under the foreign-block budget); the rest are reachable
48 // via the comment's paginated re-rooted view ("View all N replies").
49 capped := n > 0 && n < foreign.MaxBlocksPerRender()/4
50 println(capped && strings.Contains(content, "View all 256 replies"))
51}
52
53// Output:
54// true