aboutsummaryrefslogtreecommitdiffstats
path: root/internal/web/web_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/web/web_test.go')
-rw-r--r--internal/web/web_test.go66
1 files changed, 61 insertions, 5 deletions
diff --git a/internal/web/web_test.go b/internal/web/web_test.go
index 9520953..5ab8219 100644
--- a/internal/web/web_test.go
+++ b/internal/web/web_test.go
@@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"regexp"
+ "strconv"
"strings"
"testing"
"time"
@@ -73,7 +74,7 @@ func TestRootRoutePrecedence(t *testing.T) {
t.Errorf("%s: got %d, want %d", path, rec.Code, want)
}
}
- for _, slug := range []string{"webadmin", "admin", "b", "media", "feed.xml", "favicon.ico"} {
+ for _, slug := range []string{"webadmin", "admin", "b", "media", "feed.xml", "favicon.ico", "tag"} {
if !reservedPageSlugs[slug] {
t.Errorf("page slug %q should be reserved", slug)
}
@@ -146,15 +147,15 @@ func TestLayoutTheme(t *testing.T) {
func TestBuildLayout(t *testing.T) {
mods := []store.Module{{ID: 1, Area: "header", Kind: "title"}, {ID: 2, Area: "left", Kind: "recent", Count: 3}, {ID: 3, Area: "right", Kind: "recent", Count: 8},
- {ID: 4, Area: "right", Kind: "archive"}, {ID: 5, Area: "footer", Kind: "rss"}, {ID: 6, Area: "above", Kind: "html"}}
+ {ID: 4, Area: "right", Kind: "archive"}, {ID: 5, Area: "footer", Kind: "rss"}, {ID: 6, Area: "above", Kind: "html"}, {ID: 7, Area: "right", Kind: "tagcloud"}}
th := DefaultTheme()
l := buildLayout(th, mods)
- if !l.HasLeft || !l.HasRight || len(l.Header) != 1 || len(l.Footer) != 1 || len(l.Above) != 1 || l.MaxRecent() != 8 || !l.NeedsArchive() {
+ if !l.HasLeft || !l.HasRight || len(l.Header) != 1 || len(l.Footer) != 1 || len(l.Above) != 1 || l.MaxRecent() != 8 || !l.NeedsArchive() || !l.NeedsTags() {
t.Errorf("layout: %+v", l)
}
th.RightOn, th.FooterOn = false, false
l = buildLayout(th, mods)
- if l.HasRight || len(l.Footer) != 0 || l.MaxRecent() != 3 || l.NeedsArchive() {
+ if l.HasRight || len(l.Footer) != 0 || l.MaxRecent() != 3 || l.NeedsArchive() || l.NeedsTags() {
t.Errorf("switched-off areas should drop their modules: %+v", l)
}
if buildLayout(th, nil).HasLeft {
@@ -206,6 +207,61 @@ func TestModuleKinds(t *testing.T) {
if got := moduleSummary("en", store.Module{Kind: "menu"}); got != "" {
t.Errorf("menu summary: %q", got)
}
+ if got := moduleSummary("en", store.Module{Kind: "tags", Count: 8}); got != "8 tags" {
+ t.Errorf("tags summary: %q", got)
+ }
+ if got := moduleSummary("en", store.Module{Kind: "tags"}); got != "all tags" {
+ t.Errorf("all-tags summary: %q", got)
+ }
+}
+
+func TestParseTags(t *testing.T) {
+ tags, ok := parseTags([]string{" Go ", "go", "GO", "", "tomatoes plants", "!!!", "Ντομάτες"})
+ if !ok || len(tags) != 3 {
+ t.Fatalf("parseTags: ok=%v %+v", ok, tags)
+ }
+ for i, want := range []store.Tag{{Name: "Go", Slug: "go"}, {Name: "tomatoes plants", Slug: "tomatoes-plants"}, {Name: "Ντομάτες", Slug: "ntomates"}} {
+ if tags[i] != want {
+ t.Errorf("tag %d = %+v, want %+v", i, tags[i], want)
+ }
+ }
+ if tags, ok := parseTags(nil); !ok || len(tags) != 0 {
+ t.Errorf("no tags: ok=%v %+v", ok, tags)
+ }
+ if _, ok := parseTags([]string{strings.Repeat("α", 41)}); ok {
+ t.Error("41 runes should be too long")
+ }
+ if _, ok := parseTags([]string{strings.Repeat("α", 40)}); !ok {
+ t.Error("40 runes are fine")
+ }
+ many := make([]string, 21)
+ for i := range many {
+ many[i] = "t" + strconv.Itoa(i)
+ }
+ if _, ok := parseTags(many); ok {
+ t.Error("21 tags should be too many")
+ }
+ if !tagSet(tags)["ntomates"] || tagSet(tags)["nope"] {
+ t.Error("tagSet")
+ }
+}
+
+func TestCloudSizes(t *testing.T) {
+ if got := cloudSizes(nil); len(got) != 0 {
+ t.Errorf("empty: %+v", got)
+ }
+ same := cloudSizes([]store.TagCount{{Name: "a", Count: 1}, {Name: "b", Count: 1}})
+ if same[0].Size != 3 || same[1].Size != 3 {
+ t.Errorf("equal counts get the middle size: %+v", same)
+ }
+ spread := cloudSizes([]store.TagCount{{Name: "a", Count: 1}, {Name: "b", Count: 5}, {Name: "c", Count: 9}})
+ if spread[0].Size != 1 || spread[1].Size != 3 || spread[2].Size != 5 || spread[0].Name != "a" {
+ t.Errorf("spread: %+v", spread)
+ }
+ top := topTags([]store.TagCount{{Name: "a", Count: 1}, {Name: "b", Count: 5}, {Name: "c", Count: 5}})
+ if top[0].Name != "b" || top[1].Name != "c" || top[2].Name != "a" {
+ t.Errorf("topTags: %+v", top)
+ }
}
func TestValidLinkURL(t *testing.T) {
@@ -323,7 +379,7 @@ func TestAllTemplatesParse(t *testing.T) {
for _, name := range []string{"auth/login.html", "dashboard/overview.html", "dashboard/pages.html", "dashboard/page_form.html",
"dashboard/posts.html", "dashboard/post_form.html", "dashboard/design.html", "dashboard/files.html", "dashboard/settings.html",
"dashboard/password.html", "dashboard/confirm.html", "dashboard/sections.html", "dashboard/section_form.html", "dashboard/layout.html", "dashboard/module_form.html", "admin/index.html", "admin/new_user.html", "admin/delete_user.html",
- "blog/page.html", "blog/post.html", "blog/404.html"} {
+ "blog/page.html", "blog/post.html", "blog/tag.html", "blog/404.html"} {
for _, l := range i18n.Languages() {
if _, err := tpl.get(l.Code, name); err != nil {
t.Errorf("%s (%s): %v", name, l.Code, err)