Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

z_ui_thread_10_filetest.gno

1.86 Kb · 48 lines
 1// PKGPATH: gno.land/r/gnoland/boards2/v0/filetests/z_ui_thread_10_filetest
 2
 3// No post or comment renders more than pageSizeReplies (10) direct children
 4// inline. A comment with more shows the cap inline plus a "View all N replies"
 5// link to its re-rooted view, which paginates the children on its own ?page=
 6// (a distinct path from the thread, so no pager collision).
 7package z_ui_thread_10_filetest
 8
 9import (
10	"strings"
11	"testing"
12
13	"gno.land/p/nt/ufmt/v0"
14
15	boards2 "gno.land/r/gnoland/boards2/v0"
16)
17
18const owner address = "g1skl80cuz8zq3lul9pgz5pc35l2pfzgxgfpsqkx"
19
20func init(cur realm) {
21	testing.SetRealm(testing.NewUserRealm(owner))
22	bid := boards2.CreateBoard(cross(cur), "test-board", false, false)
23	tid := boards2.CreateThread(cross(cur), bid, "Foo", "OP body")
24	cid := boards2.CreateReply(cross(cur), bid, tid, 0, "parent comment") // reply #2
25	// 12 direct children under the comment — past the inline cap of 10.
26	for i := 0; i < 12; i++ {
27		boards2.CreateReply(cross(cur), bid, tid, cid, ufmt.Sprintf("child-%d", i))
28	}
29}
30
31func main(cur realm) {
32	thread := boards2.Render("test-board/1")           // threaded view
33	reroot := boards2.Render("test-board/1/2")         // re-root at the comment, page 1
34	reroot2 := boards2.Render("test-board/1/2?page=2") // re-root, page 2
35	threadDesc := boards2.Render("test-board/1?order=desc")
36
37	ok := strings.Contains(thread, "View all 12 replies") && // breadth cap inline + link
38		strings.Contains(reroot, "page 1 of 2") && // re-root paginates the children
39		strings.Contains(reroot2, "page 2 of 2") && // and advances to the tail
40		// In a desc thread the "View all" link carries the order so the
41		// re-root opens newest-first too; in the default (asc) view it doesn't.
42		strings.Contains(threadDesc, "/r/gnoland/boards2/v0:test-board/1/2?order=desc") &&
43		!strings.Contains(thread, "test-board/1/2?order=desc")
44	println(ok)
45}
46
47// Output:
48// true