package web
import (
"strings"
"testing"
"craftdesign.group/quarry/internal/artifact"
"craftdesign.group/quarry/internal/index"
)
// #265: a landing shows its branch's design note, the wiki page
// branch/<branch>, with an edit link; a branch without one offers "Add a
// design note" that opens the editor on that page. (This server has no
// auth plane, so every viewer may write; who may read the note is
// landing.get's gate, tested in internal/api.)
func TestLandingShowsTheBranchDesignNote(t *testing.T) {
const page = "/r/alpha/landing/" + "a1a1a1a1a1a1a1a1"
ix := landingIndex(t, false)
none := landingGet(t, landingServer(t, ix, "ok"), page)
if !strings.Contains(none, `data-hook="landing-note-add"`) || strings.Contains(none, `data-hook="landing-note"`) {
t.Errorf("FAIL: a branch with no note does not offer one to a wiki writer")
}
if !strings.Contains(none, `/wiki/branch%2Ffossil-caps/edit`) {
t.Errorf("FAIL: the add link does not open branch/fossil-caps in the editor")
}
if err := ix.FoldNow([]index.Parsed{{Hash: strings.Repeat("d4", 20), Art: &artifact.Artifact{Type: artifact.Wiki,
WikiTitle: "branch/fossil-caps", Date: "2026-08-20T12:00:00", User: "eve",
Mimetype: "text/x-markdown", Body: []byte("Phases one to five; phase six waits on RFC 0004.\n")}}}); err != nil {
t.Fatal(err)
}
with := landingGet(t, landingServer(t, ix, "ok"), page)
note := with[strings.Index(with, `data-hook="landing-note"`):]
if !strings.Contains(with, `data-hook="landing-note"`) || !strings.Contains(note, "phase six waits") {
t.Fatalf("FAIL: the branch's note is not on its landing")
}
if !strings.Contains(note, `data-hook="landing-note-edit"`) || strings.Contains(with, `data-hook="landing-note-add"`) {
t.Errorf("FAIL: a written note has no edit link, or still offers to add one")
}
}