internal/web/widths_test.go
53 lines · 2117 bytes
1 symbol in this file
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 for _, name := range []string{"explore.html", "owner.html"} {
35 if src, _ := templateFS.ReadFile("templates/" + name); !strings.Contains(string(src), `<ul class="repolist rows">`) {
36 t.Errorf("%s does not use one-line repository rows", name)
37 }
38 }
39 // Settings pages carry a section column: every section id has a link
40 // in the column, and the page is wide with the narrow grid.
41 for _, name := range []string{"settings.html", "account.html", "admin.html"} {
42 src, _ := templateFS.ReadFile("templates/" + name)
43 s := string(src)
44 if !strings.HasPrefix(s, `{{define "width"}}wide{{end}}`) || !strings.Contains(s, `<div class="withcol narrow">`) {
45 t.Errorf("%s lacks the narrow column layout", name)
46 }
47 for _, m := range regexp.MustCompile(`<section id="([a-z]+)"`).FindAllStringSubmatch(s, -1) {
48 if !strings.Contains(s, `href="#`+m[1]+`"`) {
49 t.Errorf("%s: section %q has no link in the column", name, m[1])
50 }
51 }
52 }
53}