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_09_filetest.gno

1.81 Kb · 54 lines
 1// PKGPATH: gno.land/r/gnoland/boards2/v0/filetests/z_ui_thread_09_filetest
 2
 3// The flat "all comments" view (?flat=1) paginates ThreadMeta.AllReplies so
 4// every comment is reachable, unlike the recursive threaded view which
 5// truncates a large thread. Each flat page renders one <gno-foreign> block
 6// per comment, bounded by pageSizeFlat (50). With 60 comments the flat view
 7// spans 2 pages; the last comment is reachable via newest-first (desc page 1)
 8// and via page 2.
 9package z_ui_thread_09_filetest
10
11import (
12	"strings"
13	"testing"
14
15	"gno.land/p/gnoland/boards/v0"
16	"gno.land/p/nt/ufmt/v0"
17
18	boards2 "gno.land/r/gnoland/boards2/v0"
19)
20
21const owner address = "g1skl80cuz8zq3lul9pgz5pc35l2pfzgxgfpsqkx"
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	// pageSizeFlat is 50, so 60 comments span 2 flat pages.
33	for i := 0; i < 60; i++ {
34		boards2.CreateReply(cross(cur), bid, tid, 0, ufmt.Sprintf("comment-%d", i))
35	}
36}
37
38func main(cur realm) {
39	p1 := boards2.Render("test-board/1?flat=1")              // oldest first, page 1
40	desc := boards2.Render("test-board/1?flat=1&order=desc") // newest first, page 1
41	p2 := boards2.Render("test-board/1?flat=1&page=2")       // oldest first, page 2
42
43	ok := strings.Contains(p1, "All 60 comments") &&
44		strings.Contains(p1, "page 1 of 2") &&
45		strings.Contains(p1, "comment-0") && // first comment is on page 1
46		!strings.Contains(p1, "comment-59") && // last comment is NOT on oldest-first page 1
47		strings.Contains(desc, "comment-59") && // last comment reachable newest-first
48		strings.Contains(p2, "comment-59") && // and on the last page
49		strings.Contains(p2, "page 2 of 2")
50	println(ok)
51}
52
53// Output:
54// true