mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-28 17:38:04 -08:00
The repositories moved from Neo-Desktop to the D-Modem GitHub organisation: D-Modem-RE is now D-Modem/D-Modem, pico-serial is D-Modem/hardware, modemmenu (PBX-Modem) is D-Modem/menu, bbs-sec is D-Modem/bbs and go3270-sec is D-Modem/go3270. Update links, module paths, submodule URLs and source-location strings to match. Copyright notices still name Neo-Desktop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRUwD2JJ5d6fgHmpVTw
120 lines
4.3 KiB
Go
120 lines
4.3 KiB
Go
package app
|
|
|
|
import (
|
|
"bytes"
|
|
"image"
|
|
"image/color"
|
|
"image/png"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/D-Modem/bbs/internal/imageboard"
|
|
"github.com/D-Modem/bbs/internal/store"
|
|
"github.com/D-Modem/bbs/internal/view"
|
|
)
|
|
|
|
// TestImageBoards: on a terminal, a thread started with an image sent by
|
|
// a transfer protocol, a reply quoting it, the posts read with their
|
|
// pictures, the image viewed whole.
|
|
func TestImageBoards(t *testing.T) {
|
|
b, alice, _ := setup(t)
|
|
set := imageboard.Defaults()
|
|
set.Dir, set.ThreadWait, set.ReplyWait = filepath.Join(t.TempDir(), "chan"), 0, 0
|
|
b.ImageBoards = &imageboard.Server{B: b, S: set}
|
|
bd, err := b.Store.CreateBoard(imageboard.NewBoard("b", "Random"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
img := image.NewRGBA(image.Rect(0, 0, 800, 400))
|
|
for x := 0; x < 800; x++ {
|
|
for y := 0; y < 400; y++ {
|
|
img.Set(x, y, color.RGBA{uint8(x), uint8(y), 99, 255})
|
|
}
|
|
}
|
|
var pngData bytes.Buffer
|
|
png.Encode(&pngData, img)
|
|
|
|
f := &fake{t: t, b: b, upload: pngData.Bytes(), script: []any{
|
|
"B", view.Choice{Action: view.Pick, Row: 0}, // /b/
|
|
view.Choice{Action: "new"}, false, map[string]string{"name": "Anon#tea", "options": "none"},
|
|
true, false, // an image, not a spoiler
|
|
draft{"", "Hello", []string{"first post"}},
|
|
view.Choice{Action: view.Pick, Row: 0}, // the thread
|
|
"reply", true, map[string]string{"options": "sage"}, false, draft{"", "", []string{">>1", "nice"}},
|
|
"prev", // from the reply to the first post
|
|
"view", view.Back,
|
|
view.Back, view.Choice{Action: view.Back}, view.Choice{Action: view.Back},
|
|
}}
|
|
if err := Run(b, alice, f); err != ErrLogoff {
|
|
t.Fatalf("Run: %v; shown %q", err, f.shown)
|
|
}
|
|
if len(f.script) > 0 {
|
|
t.Errorf("left of the script: %v; shown %q", f.script, f.shown)
|
|
}
|
|
has(t, "screens", f.shown, "menu Main menu")
|
|
has(t, "screens", f.shown, "table Image boards: /b/|Random|0|")
|
|
has(t, "said", f.said, "Posted: /b/ No.1.")
|
|
has(t, "said", f.said, "Posted: /b/ No.2.")
|
|
has(t, "screens", f.shown, "table /b/ - Random: 1|0|0|Hello")
|
|
has(t, "screens", f.shown, "message : >>1\nnice | from alice [signed]")
|
|
has(t, "screens", f.shown, "from Anon !WokonZwxw2 [member]")
|
|
has(t, "screens", f.shown, "message Hello: first post\n\nReplies: >>2")
|
|
// the thumbnail (250x125) fitted to 200x100, and the image whole
|
|
has(t, "screens", f.shown, "picture upload.png, 800x400, ")
|
|
has(t, "screens", f.shown, ": 200x100")
|
|
has(t, "screens", f.shown, "panel /b/ No.1")
|
|
|
|
op, _ := b.Store.ChanPost(bd.ID, 1)
|
|
reply, _ := b.Store.ChanPost(bd.ID, 2)
|
|
if op.Trip != "!WokonZwxw2" || op.Name != "Anon" || op.IP != "bbs:alice" || op.UserID != alice.User().ID ||
|
|
reply.Account != "alice" || reply.Name != "" || reply.Thread != 1 || reply.HasFile() {
|
|
t.Errorf("posts: %+v %+v", op, reply)
|
|
}
|
|
th, _ := b.Store.ChanThread(bd.ID, 1)
|
|
if !th.Bumped.Equal(op.Bumped) {
|
|
t.Error("sage bumped it")
|
|
}
|
|
}
|
|
|
|
// TestImageBoardArchive: a board's archive on a terminal, its threads
|
|
// read there, no reply offered.
|
|
func TestImageBoardArchive(t *testing.T) {
|
|
b, alice, _ := setup(t)
|
|
set := imageboard.Defaults()
|
|
set.Dir = filepath.Join(t.TempDir(), "chan")
|
|
b.ImageBoards = &imageboard.Server{B: b, S: set}
|
|
bd, err := b.Store.CreateBoard(imageboard.NewBoard("b", "Random"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, sub := range []string{"Old one", "New one"} {
|
|
if err := b.Store.AddPost(&store.BoardPost{BoardID: bd.ID, Subject: sub, Comment: "about " + sub, IP: "x"}, true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if _, err := b.Store.PruneChanThreads(bd.ID, 1, true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
f := &fake{t: t, b: b, script: []any{
|
|
"B", view.Choice{Action: view.Pick, Row: 0}, // /b/
|
|
view.Choice{Action: "archive"},
|
|
view.Choice{Action: view.Pick, Row: 0}, // the archived thread
|
|
view.Back,
|
|
view.Choice{Action: view.Back}, view.Choice{Action: view.Back}, view.Choice{Action: view.Back},
|
|
}}
|
|
if err := Run(b, alice, f); err != ErrLogoff {
|
|
t.Fatalf("Run: %v; shown %q", err, f.shown)
|
|
}
|
|
if len(f.script) > 0 {
|
|
t.Errorf("left of the script: %v; shown %q", f.script, f.shown)
|
|
}
|
|
has(t, "screens", f.shown, "table /b/ - Random: 2|0|0|New one")
|
|
has(t, "screens", f.shown, "table /b/ - archive: 1|0|Old one|")
|
|
has(t, "screens", f.shown, "message Old one: about Old one")
|
|
op, _ := b.Store.ChanThread(bd.ID, 1)
|
|
s := &Session{B: b, User: alice.User()}
|
|
if s.mayPost(bd, op) || !s.mayPost(bd, nil) {
|
|
t.Error("an archived thread may be replied to")
|
|
}
|
|
}
|