Skip to content
quarry Artifact [deabdd1e3a]
Login

Artifact [deabdd1e3a]

Artifact deabdd1e3ab3699384a3c5d63c5955de6aca3c9db1d5fa2d6e75d188fcb07956:


package web

import (
	"bytes"
	"strings"
	"testing"
)

// The title's pencil follows its last word inside the heading, and the
// title is edited in a text area, so a long title neither pushes the
// pencil onto a line of its own nor has to be read through one line.
func TestTheTitlePencilFollowsTheTitleAndEditsInATextArea(t *testing.T) {
	d := ticketDetail{ID: strings.Repeat("ef", 20), Fields: []ticketField{
		{Name: "title", Value: "a long title that wraps"}, {Name: "status", Value: "Open"}}}
	var buf bytes.Buffer
	if err := noHooks.template(ticketPage).ExecuteTemplate(&buf, "content", pageData{Repo: "tk", Ticket: d, CanWrite: true}); err != nil {
		t.Fatal(err)
	}
	html := buf.String()
	h1 := html[strings.Index(html, `<h1 class="t-title">`):]
	h1 = h1[:strings.Index(h1, "</h1>")]
	if !strings.Contains(h1, `class="t-pen"`) {
		t.Error("FAIL: the title's pencil is not inside the heading")
	}
	if strings.Index(h1, "wraps") > strings.Index(h1, `class="t-pen"`) {
		t.Error("FAIL: the pencil comes before the title's last word")
	}
	if !strings.Contains(html, `<textarea name="title"`) || strings.Contains(html, `<input name="title"`) {
		t.Error("FAIL: the title is not edited in a text area")
	}
	if !t.Failed() {
		t.Log("ok: pencil after the last word, text area to edit")
	}
}