Skip to content
quarry Artifact [62b2975064]
Login

Artifact [62b2975064]

Artifact 62b2975064ff76122ae7509b045278ec506ac9d41c42f7ce4ae3d38d525d1075:


package web

import (
	"strings"
	"testing"

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

// The set of searchable kinds is written down in four places: the
// index's SearchKinds, the ops validator's `oneof`, this package's
// scope chips, and hitOf's switch. Adding "doc" to the index left the
// validator behind, so the chip existed, the rows existed, the FTS
// matched — and every doc search returned nothing, because the op
// refused the kind before it reached the query.
//
// hitOf is covered by TestEverySearchKindLinksSomewhere; this covers
// the chips, which are the other half of "a reader can actually reach
// this kind".
func TestScopeChipsCoverEverySearchKind(t *testing.T) {
	have := map[string]bool{}
	for _, s := range searchScopes {
		have[s.Kind] = true
	}
	if !have[""] {
		t.Error(`searchScopes lost the "everything" chip`)
	}
	for _, kind := range index.SearchKinds {
		if !have[kind] {
			t.Errorf("index searches %q but no scope chip offers it — "+
				"the kind is unreachable from the UI", kind)
		}
	}
	for kind := range have {
		if kind == "" {
			continue
		}
		if !strings.Contains(strings.Join(index.SearchKinds, ","), kind) {
			t.Errorf("scope chip %q is not a kind the index files — "+
				"it can only ever return nothing", kind)
		}
	}
}