rastrillo / fiesta Public

Clone
git clone https://amadan.net/rastrillo/fiesta

Plain git — no account needed to clone.

Download

Download this file

1package check
2
3import (
4 "slices"
5 "strings"
6 "testing"
7
8 xhtml "golang.org/x/net/html"
9
10 "amadan.net/rastrillo/fiesta"
11 "amadan.net/rastrillo/fiesta/internal/markup"
12 "amadan.net/rastrillo/fiesta/internal/rowrule"
13)
14
15// The Row Rule: a dropdown never sits on a line of its own. It sits in
16// a row beside what it acts on. A menu alone on a line reads as a
17// control for nothing in particular, and one above a page's title
18// pushes the title down and reads as the page's first action. DESIGN.md
19// states the rule, and internal/rowrule is its check, shared with the
20// site's landing page. This test holds every example to it, so a
21// gallery page can never teach the placement the rule forbids.
22
23// TestEveryDropdownSitsInARow: every state of every example, bodies and
24// layouts whole, keeps the Row Rule. The gallery is where a reader
25// learns where a menu goes, so a state that shows one alone teaches the
26// placement the rule forbids.
27func TestEveryDropdownSitsInARow(t *testing.T) {
28 states := everyState(t, fiesta.FS())
29 menus := 0
30 for _, s := range states {
31 if strings.Contains(s.Markup, "rst-dropdown") {
32 menus++
33 }
34 respelled, _ := markup.Respell([]byte(s.Markup))
35 doc, err := xhtml.Parse(strings.NewReader(string(respelled)))
36 if err != nil {
37 t.Errorf("%s/%s: the markup does not parse: %v", s.Name, s.State, err)
38 continue
39 }
40 for _, msg := range rowrule.Breaches(doc, nil) {
41 t.Errorf("%s/%s: %s", s.Name, s.State, msg)
42 }
43 }
44 // A walk that finds no menus passes whatever the rule says.
45 if menus < 10 {
46 t.Fatalf("%d states hold a dropdown, want at least 10; the walk is reading the wrong markup", menus)
47 }
48 if t.Failed() {
49 var rows []string
50 for row, why := range rowrule.Rows {
51 rows = append(rows, row+" ("+why+")")
52 }
53 slices.Sort(rows)
54 t.Logf("put each menu in one of these rows: %s", strings.Join(rows, ", "))
55 }
56}
57