internal/web/widths_test.go

9df917e73a67d15adecc3f45976690f6fcd4e47a
gitbay/internal/web/widths_test.go history · blame · raw

51 lines · 2045 bytes

 1package web
 2
 3import (
 4	"regexp"
 5	"strings"
 6	"testing"
 7)
 8
 9// List pages and the dashboard render at the container width; text pages
10// keep the reading cap (desktop layout spec).
11func TestListPagesAreWide(t *testing.T) {
12	wide := []string{"dashboard.html", "issues.html", "mrs.html", "explore.html", "notifications.html", "globalsearch.html", "builds.html"}
13	for _, name := range wide {
14		src, err := templateFS.ReadFile("templates/" + name)
15		if err != nil {
16			t.Fatal(err)
17		}
18		if !strings.HasPrefix(string(src), `{{define "width"}}wide{{end}}`) {
19			t.Errorf("%s does not declare width wide", name)
20		}
21	}
22	for _, name := range []string{"issue.html", "wiki.html", "owner.html"} {
23		src, _ := templateFS.ReadFile("templates/" + name)
24		if strings.Contains(string(src), `{{define "width"}}wide{{end}}`) {
25			t.Errorf("%s is a text page and must not be wide", name)
26		}
27	}
28	for _, name := range []string{"issues.html", "mrs.html", "notifications.html", "globalsearch.html", "dashboard.html"} {
29		src, _ := templateFS.ReadFile("templates/" + name)
30		if !strings.Contains(string(src), `<ul class="issuelist rows">`) {
31			t.Errorf("%s does not use one-line rows", name)
32		}
33	}
34	if src, _ := templateFS.ReadFile("templates/explore.html"); !strings.Contains(string(src), `<ul class="repolist rows">`) {
35		t.Error("explore.html does not use one-line rows")
36	}
37	// Settings pages carry a section column: every section id has a link
38	// in the column, and the page is wide with the narrow grid.
39	for _, name := range []string{"settings.html", "account.html", "admin.html"} {
40		src, _ := templateFS.ReadFile("templates/" + name)
41		s := string(src)
42		if !strings.HasPrefix(s, `{{define "width"}}wide{{end}}`) || !strings.Contains(s, `<div class="withcol narrow">`) {
43			t.Errorf("%s lacks the narrow column layout", name)
44		}
45		for _, m := range regexp.MustCompile(`<section id="([a-z]+)"`).FindAllStringSubmatch(s, -1) {
46			if !strings.Contains(s, `href="#`+m[1]+`"`) {
47				t.Errorf("%s: section %q has no link in the column", name, m[1])
48			}
49		}
50	}
51}