package web
import (
"bytes"
"strings"
"testing"
)
// me.feed has computed the caller's own work all along — cross-repo,
// newest-first — and the page dropped it. This pins that it reaches the
// template, because a field decoded and never rendered is invisible in
// every other way: it compiles, it round-trips, and no test notices.
func TestDashboardShowsYourOwnWork(t *testing.T) {
d := dashData{User: "dmestas", Mine: []dashEvent{
{Kind: "f", Repo: "quarry", Ref: "abc", Comment: "a forum post I wrote",
Date: "2026-09-07T10:00:00Z"},
}}
var buf bytes.Buffer
if err := dashboardPage.ExecuteTemplate(&buf, "content",
pageData{Dash: &d, User: "dmestas"}); err != nil {
t.Fatal(err)
}
got := buf.String()
if !strings.Contains(got, "a forum post I wrote") {
t.Error("the caller's own work is computed and still not rendered")
}
// It is the reader's own list, so repeating their name on every row
// says nothing; the feed's rows carry an author, these must not.
mine := got[strings.Index(got, "dash-mine-h"):]
if i := strings.Index(mine, "dash-feed"); i > 0 {
mine = mine[:i]
}
if strings.Count(mine, "dmestas") > 1 {
t.Error("the sidebar repeats the reader's own name on its rows")
}
}
// Empty has two causes and the page must not claim the first: you wrote
// nothing recently, OR your artifacts carry an author name that is not
// this login (me.feed matches the two by string equality). Saying "you
// have written nothing" would be a guess presented as a fact.
func TestEmptyOwnWorkDoesNotClaimYouWroteNothing(t *testing.T) {
d := dashData{User: "dmestas"}
var buf bytes.Buffer
if err := dashboardPage.ExecuteTemplate(&buf, "content",
pageData{Dash: &d, User: "dmestas"}); err != nil {
t.Fatal(err)
}
if !strings.Contains(buf.String(), "author name") {
t.Error("the empty state does not admit that a name mismatch looks identical to silence")
}
}