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

1.30 Kb · 44 lines
 1// PKGPATH: gno.land/r/gnoland/boards2/v0/filetests/z_ui_board_05_filetest
 2
 3// An invalid ?page= (out of range, zero, negative, or non-numeric) clamps to
 4// the last valid page instead of aborting the render or echoing a broken
 5// "page N of M" picker (see newClampedPager). Notably a NEGATIVE page is not
 6// rejected by pager.New, so it must be caught by the clamp.
 7package z_ui_board_05_filetest
 8
 9import (
10	"strings"
11	"testing"
12
13	boards2 "gno.land/r/gnoland/boards2/v0"
14)
15
16const (
17	owner     address = "g1skl80cuz8zq3lul9pgz5pc35l2pfzgxgfpsqkx"
18	boardName         = "test-board"
19)
20
21func init(cur realm) {
22	testing.SetRealm(testing.NewUserRealm(owner))
23	boardID := boards2.CreateBoard(cross(cur), boardName, false, false)
24	// pageSizeDefault is 6, so 7 threads span 2 pages; the last page is 2.
25	for i := 0; i < 7; i++ {
26		boards2.CreateThread(cross(cur), boardID, "T", "Body")
27	}
28}
29
30func main() {
31	// Each value is invalid: too high, zero, negative, non-numeric. All must
32	// clamp to the last page ("page 2 of 2"); if any slipped through, the
33	// picker would echo the bad number (e.g. "page -5 of 2") and this fails.
34	ok := true
35	for _, q := range []string{"?page=99", "?page=0", "?page=-5", "?page=abc"} {
36		if !strings.Contains(boards2.Render(boardName+q), "page 2 of 2") {
37			ok = false
38		}
39	}
40	println(ok)
41}
42
43// Output:
44// true