package web
import (
"path/filepath"
"strings"
"testing"
"craftdesign.group/quarry/internal/api"
"craftdesign.group/quarry/internal/artifact"
"craftdesign.group/quarry/internal/index"
"craftdesign.group/quarry/internal/ops"
)
// #383: a comment link whose target is a wiki page name links to the
// page, with its label when given, as fossil does; a page that does not
// exist stays as written.
func TestACommentLinksAWikiPageByName(t *testing.T) {
ix, err := index.Open(filepath.Join(t.TempDir(), "index.db"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { ix.Close() })
if err := ix.FoldNow([]index.Parsed{{Hash: strings.Repeat("d4", 20), Art: &artifact.Artifact{Type: artifact.Wiki,
WikiTitle: "RichProbePage", Date: "2026-10-29T12:00:00", User: "jva",
Mimetype: "text/x-markdown", Body: []byte("probe\n")}}}); err != nil {
t.Fatal(err)
}
if err := api.RegisterAll(ops.NewRegistry(), api.Deps{Version: "v",
Repos: api.NewRepos(map[string]*api.Repo{"wk": {Index: ix}})}); err != nil {
t.Fatal(err)
}
for in, want := range map[string]string{
"see [RichProbePage]": `<a href="/r/wk/wiki/RichProbePage">RichProbePage</a>`,
"see [RichProbePage|tight wiki]": `<a href="/r/wk/wiki/RichProbePage">tight wiki</a>`,
"see [RichProbePage | spaced wiki]": `<a href="/r/wk/wiki/RichProbePage">spaced wiki</a>`,
"see [NoSuchPageXyz|missing page]": `[NoSuchPageXyz|missing page]`,
} {
if got := string(commentHTML("wk", in)); !strings.Contains(got, want) {
t.Errorf("FAIL: %q rendered %q, want %q", in, got, want)
}
}
}