internal/httpd/emptystates_test.go
78 lines · 2133 bytes
2 symbols in this file
1package httpd
2
3import (
4 "html/template"
5 "strings"
6 "testing"
7
8 "gitbay.org/gitbay/internal/store"
9 "gitbay.org/gitbay/internal/web"
10)
11
12// A signed-in viewer with zero issues gets a link to open one; a
13// signed-out visitor gets only the fact, and no CLI command either way
14// (#270).
15func TestIssuesEmptyStateOffersOpenLinkForViewer(t *testing.T) {
16 render := func(viewer string) string {
17 var sb strings.Builder
18 p := testRepoPage()
19 p.Viewer = viewer
20 if err := web.Render(&sb, "issues.html", struct {
21 repoPage
22 State string
23 Label string
24 Query string
25 Filters []listFilter
26 Facets []facetGroup
27 Issues []store.Issue
28 LabelColors map[string]template.CSS
29 Older string
30 }{repoPage: p, State: "open"}); err != nil {
31 t.Fatalf("render: %v", err)
32 }
33 return sb.String()
34 }
35
36 anon := render("")
37 if !strings.Contains(anon, "no open issues") {
38 t.Errorf("missing empty-state fact:\n%s", anon)
39 }
40 if strings.Contains(anon, "issues/new") {
41 t.Error("signed-out visitor should not see an open-issue link")
42 }
43 if strings.Contains(anon, "gitbay issue create") {
44 t.Error("empty state should not name a CLI command")
45 }
46
47 viewer := render("alice")
48 if !strings.Contains(viewer, `href="/krz/gitbay/issues/new"`) {
49 t.Errorf("signed-in viewer missing the open-issue link:\n%s", viewer)
50 }
51}
52
53// An empty release list states the fact without a CLI command; the page
54// already offers the create form above when the viewer can write and a
55// tag is free to release (#270).
56func TestReleasesEmptyStateHasNoCLICommand(t *testing.T) {
57 var sb strings.Builder
58 if err := web.Render(&sb, "releases.html", struct {
59 repoPage
60 Releases []struct {
61 store.Release
62 NotesHTML template.HTML
63 }
64 FreeTags []string
65 CanWrite bool
66 Notice string
67 Draft *draft
68 }{repoPage: testRepoPage()}); err != nil {
69 t.Fatalf("render: %v", err)
70 }
71 out := sb.String()
72 if !strings.Contains(out, "no releases yet") {
73 t.Errorf("missing empty-state fact:\n%s", out)
74 }
75 if strings.Contains(out, "gitbay release create") {
76 t.Error("empty state should not name a CLI command")
77 }
78}