internal/web/widths_test.go

545ba0bcdea3b534903bd78c918c0c025a97eda7
gitbay/internal/web/widths_test.go

57 lines · 2244 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. admin.html spans full width so queue tables fill the container.
41	for _, name := range []string{"settings.html", "account.html", "admin.html"} {
42		src, _ := templateFS.ReadFile("templates/" + name)
43		s := string(src)
44		wantCol := `<div class="withcol narrow">`
45		if name == "admin.html" {
46			wantCol = `<div class="withcol">`
47		}
48		if !strings.HasPrefix(s, `{{define "width"}}wide{{end}}`) || !strings.Contains(s, wantCol) {
49			t.Errorf("%s lacks the expected column layout (%s)", name, wantCol)
50		}
51		for _, m := range regexp.MustCompile(`<section id="([a-z]+)"`).FindAllStringSubmatch(s, -1) {
52			if !strings.Contains(s, `href="#`+m[1]+`"`) {
53				t.Errorf("%s: section %q has no link in the column", name, m[1])
54			}
55		}
56	}
57}