oficina / sheets Public

Clone
git clone https://amadan.net/oficina/sheets

Plain git — no account needed to clone.

Download

Download this file

1package guards
2
3import (
4 "os"
5 "path/filepath"
6 "regexp"
7 "strings"
8 "testing"
9
10 "amadan.net/oficina/estilo.git/chrome"
11)
12
13// TestTheAccountIsReachableOnNarrowScreens is the guard for a bug that
14// once removed sign-out from every phone.
15//
16// It used to pin rastrillo's topbar mechanics: [rst-shell-tail] is
17// display: none below 800px and only an [rst-shell-menu] immediately
18// before it could reveal it, so an app without that element had no
19// account menu — and no Sign out — on a phone. The bar is estilo's now
20// (shared chrome spec §5), and the same promise has a different shape:
21// below 800px the bar folds its nav and page actions into the Menu
22// sheet, and the account never folds at all. Sign out is two taps at
23// every width.
24//
25// Two assertions, because either alone is satisfiable while the bug is
26// back: the layout must render estilo's bar (and none of the old shell,
27// whose tail would hide an account put there), and estilo's narrow rule
28// must hide only the nav and the actions.
29func TestTheAccountIsReachableOnNarrowScreens(t *testing.T) {
30 b, err := os.ReadFile(filepath.Join(repoRoot(t), "internal/sheets/templates/layout.html"))
31 if err != nil {
32 t.Fatal(err)
33 }
34 // Template comments are stripped FIRST: the layout explains the old
35 // shell in prose, and a check over the raw file would pass on it.
36 layout := regexp.MustCompile(`(?s)\{\{/\*.*?\*/\}\}`).ReplaceAllString(string(b), "")
37 if !strings.Contains(layout, `{{template "estilo-bar" .Frame.Chrome}}`) {
38 t.Fatal("layout.html does not render estilo's bar; whatever replaced it must keep the account reachable below 800px")
39 }
40 if strings.Contains(layout, "rst-shell-") {
41 t.Fatal("layout.html still writes rastrillo's topbar shell, whose tail hides everything in it below 800px")
42 }
43
44 css := string(chrome.CSS())
45 narrow := regexp.MustCompile(`(?s)@media \(max-width: 799\.98px\)\s*\{(.*?)\n\}`).FindAllStringSubmatch(css, -1)
46 if len(narrow) == 0 {
47 t.Fatal("estilo's chrome.css has no narrow media query; this test is reading the wrong stylesheet")
48 }
49 for _, block := range narrow {
50 for _, rule := range regexp.MustCompile(`([^{}]+)\{([^{}]*)\}`).FindAllStringSubmatch(block[1], -1) {
51 if !strings.Contains(rule[2], "display: none") {
52 continue
53 }
54 for _, part := range strings.Split(rule[1], ",") {
55 sel := strings.TrimSpace(part)
56 if strings.Contains(sel, "estilo-account") || strings.Contains(sel, "estilo-switcher") || strings.Contains(sel, "estilo-bar-end") {
57 t.Errorf("estilo hides %q below 800px: the account (and Sign out) must never fold away", sel)
58 }
59 }
60 }
61 }
62}
63