Skip to content
quarry Artifact [93fe97685d]
Login

Artifact [93fe97685d]

Artifact 93fe97685d8a4d82c25f757008e6ed44b10b2f27844e904cefe53891a01feeb2:


package web

import (
	"strings"
	"testing"

	"craftdesign.group/quarry/internal/oltp"
)

// The add-a-person field completes against the forge's accounts, and
// not only through a datalist: Safari suppresses that popup on a field
// that also says autocomplete="off", so a phone saw no completion at
// all. The list quarry renders itself is the one that shows.
// jsPath is a rendered Datastar expression with its JS string escaping
// undone, so a test can assert the URL it names.
//
// A path built by repoURL lands inside a single-quoted JS string, where
// html/template escapes the slashes: '\/r\/alpha/people.frag'. That is
// the same string to JavaScript and the same request on the wire, and a
// test that pinned the backslashes would be pinning the escaper rather
// than the behaviour.
func jsPath(s string) string { return strings.ReplaceAll(s, `\/`, "/") }

func TestRosterAddFieldCompletes(t *testing.T) {
	var b strings.Builder
	if err := noHooks.template(settingsPage).ExecuteTemplate(&b, "content", pageData{
		Repo: "alpha", IsAdmin: true, Logins: []string{"calionauta", "dmestas"},
		Roster: &rosterPanel{Presets: []oltp.Preset{{Name: "Developer"}}},
	}); err != nil {
		t.Fatal(err)
	}
	got := b.String()
	for _, want := range []string{
		`id="roster-suggest"`,
		"/r/alpha/people.frag",
		`<datalist id="logins">`,
	} {
		if !strings.Contains(jsPath(got), want) {
			t.Errorf("FAIL: the add field has no completion: missing %s", want)
		}
	}
	t.Log("ok: the field completes through a list quarry renders, with the datalist as the floor")
}