internal/httpd/topics_test.go
34 lines · 1097 bytes
1package httpd
2
3import "testing"
4
5// Explore's column counts topics across the visible repositories, most
6// used first then by name, capped at twenty, each linking to ?q=<topic>
7// and the active one clearing the query (desktop layout spec).
8func TestTopicFacets(t *testing.T) {
9 repos := []describedRepo{
10 {Topics: []string{"cli", "git"}},
11 {Topics: []string{"git", "swift"}},
12 {Topics: []string{"git"}},
13 }
14 g := topicFacets(repos, "cli")
15 if g.Title != "Topics" || len(g.Items) != 3 {
16 t.Fatalf("group: %+v", g)
17 }
18 if g.Items[0].Label != "git" || g.Items[0].Count != 3 || g.Items[0].Href != "/explore?q=git" {
19 t.Errorf("git: %+v", g.Items[0])
20 }
21 if g.Items[1].Label != "cli" || !g.Items[1].Active || g.Items[1].Href != "/explore" {
22 t.Errorf("cli: %+v", g.Items[1])
23 }
24 if g.Items[2].Label != "swift" || g.Items[2].Count != 1 {
25 t.Errorf("swift: %+v", g.Items[2])
26 }
27 var many []describedRepo
28 for i := 0; i < 30; i++ {
29 many = append(many, describedRepo{Topics: []string{string(rune('a' + i))}})
30 }
31 if n := len(topicFacets(many, "").Items); n != 20 {
32 t.Errorf("cap: %d", n)
33 }
34}