Skip to content
quarry Artifact [b35a72f587]
Login

Artifact [b35a72f587]

Artifact b35a72f587cdca45bec78d077d66951143428e5ea6e64c1ac990833bf37c2621:


package web

import (
	"strings"
	"testing"
)

// An audit row's token id is drawn as a data hook carrying the id, with
// the id kept in the title; a person's own change draws nothing.
func TestViaDrawsTheTokenAChangeCameInOn(t *testing.T) {
	h := &handlerHooks{tokenLabel: func(id string) string {
		if id == "tok1" {
			return "workflow, run r1, started by dan"
		}
		return ""
	}}
	if got := string(h.via("")); got != "" {
		t.Errorf("FAIL: a person's change drew %q", got)
	}
	got := string(h.via("tok1"))
	for _, want := range []string{`data-hook="via"`, `data-token="tok1"`, `title="token tok1"`, "workflow, run r1, started by dan"} {
		if !strings.Contains(got, want) {
			t.Errorf("FAIL: via(tok1) lacks %s: %s", want, got)
		}
	}
	if got := string(h.via("gone")); !strings.Contains(got, `data-token="gone"`) {
		t.Errorf("FAIL: an unresolved id drew no hook: %s", got)
	}
	if got := string((&handlerHooks{}).via("x<y")); strings.Contains(got, "x<y") {
		t.Errorf("FAIL: the id was not escaped: %s", got)
	}
}