Skip to content
quarry Artifact [30d48b5c55]
Login

Artifact [30d48b5c55]

Artifact 30d48b5c55a76819c3f3ef45664fe6ef9ab7f3e3be7a2353fee05dd7e587685e:


package web

import (
	"strings"
	"testing"
)

// A feed row must link to the thing it names. Landing rows had no
// branch in the template's chain, so they fell through to the empty
// else and linked to /r/{repo} — the repository's files, for a row
// whose title says "Landing:". A comment on a landing goes to the same
// record: the record is where the conversation is.
func TestFeedRowsLinkToTheThingTheyName(t *testing.T) {
	row := func(kind string) string {
		t.Helper()
		var sb strings.Builder
		err := noHooks.template(dashboardPage).ExecuteTemplate(&sb, "dash-event", dashEvent{
			Repo: "alpha", Kind: kind, Ref: strings.Repeat("b", 40),
			Hash: strings.Repeat("a", 64), Date: "2026-09-05T12:00:00Z",
			User: "dan", Comment: "Landing: something",
		})
		if err != nil {
			t.Fatal(err)
		}
		return sb.String()
	}

	for kind, want := range map[string]string{
		"l":  "/r/alpha/landing/bbbbbbbbbbbb",
		"lc": "/r/alpha/landing/bbbbbbbbbbbb",
		"t":  "/r/alpha/ticket/",
		"w":  "/r/alpha/wiki/",
		"ci": "/r/alpha/checkin/",
	} {
		got := row(kind)
		if !strings.Contains(got, `href="`+want) {
			t.Errorf("kind %q does not link to %q", kind, want)
		}
	}

	// And a landing carries the pull-request glyph, not the folder the
	// unmatched default hands out.
	if got := row("l"); !strings.Contains(got, "#i-landing") {
		t.Error("a landing row does not carry the landing glyph")
	}
	if got := row("l"); strings.Contains(got, "#i-dir") {
		t.Error("a landing row still falls through to the folder icon")
	}
}