Skip to content
quarry Artifact [e08a6d760d]
Login

Artifact [e08a6d760d]

Artifact e08a6d760d4240e9539d51c63cf14d84e79d59744fa0a8ec1d5a641b627d8cc8:


package web

import (
	"strings"
	"testing"
)

// A landing draws its own files.
//
// A landing is a forum thread, so an upload aimed at its id was always
// accepted, always stored and always listed by attachment.list — it
// was the one object whose own page had no attachments section, and
// whose own op did not return them. The result was a file you could
// put on a record and then not see: ten screenshots went onto today's
// landings before anybody noticed they rendered nowhere.
func TestALandingDrawsItsAttachments(t *testing.T) {
	d := pageData{
		Repo: "quarry", Title: "Landing",
		AttachTarget: "b1c49d85f52b",
		AttachCards: []attachCard{
			{Name: "before.png", Hash: strings.Repeat("a", 64), External: true},
			{Name: "after.png", Hash: strings.Repeat("b", 64), External: true},
		},
		Landing: &landingDetail{landingRow: landingRow{
			ID: "b1c49d85f52b", Branch: "x", Target: "trunk", State: "open"}},
	}
	var out strings.Builder
	if err := landingPage.Execute(&out, d); err != nil {
		t.Fatal(err)
	}
	body := out.String()
	for _, name := range []string{"before.png", "after.png"} {
		if !strings.Contains(body, name) {
			t.Errorf("FAIL: the record does not draw %s, so a file put on it is reachable "+
				"only through the API", name)
		}
	}
	// And the section is the shared one, not a hand-rolled copy: the
	// same partial the ticket, wiki, technote and forum pages use.
	if !strings.Contains(body, "attach") {
		t.Error("FAIL: no attachments section at all on the record")
	}
}

// A record with no files says nothing rather than drawing an empty box.
func TestALandingWithNoFilesDrawsNoSection(t *testing.T) {
	d := pageData{
		Repo: "quarry", Title: "Landing", AttachTarget: "b1c49d85f52b",
		Landing: &landingDetail{landingRow: landingRow{
			ID: "b1c49d85f52b", Branch: "x", Target: "trunk", State: "open"}},
	}
	var out strings.Builder
	if err := landingPage.Execute(&out, d); err != nil {
		t.Fatal(err)
	}
	if strings.Contains(out.String(), "before.png") {
		t.Error("FAIL: a record with no files drew one anyway")
	}
}