Skip to content
quarry Artifact [fd0c8df43f]
Login

Artifact [fd0c8df43f]

Artifact fd0c8df43f6af0c6ee67ef28755d79e10361efd281f6ed3e4bc1a0f25e7db2f1:


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", struct {
			Repo, Kind, Ref, Hash, Date, User, Comment string
		}{
			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")
	}
}