z_ui_board_05_filetest.gno
1.30 Kb · 44 lines
1// PKGPATH: gno.land/r/gnoland/boards2/v1/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/v1"
14)
15
16const (
17 owner address = "g1rp7cmetn27eqlpjpc4vuusf8kaj746tysc0qgh"
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