package guards import ( "os" "path/filepath" "regexp" "strings" "testing" "amadan.net/oficina/estilo.git/chrome" ) // TestTheAccountIsReachableOnNarrowScreens is the guard for a bug that // once removed sign-out from every phone. // // It used to pin rastrillo's topbar mechanics: [rst-shell-tail] is // display: none below 800px and only an [rst-shell-menu] immediately // before it could reveal it, so an app without that element had no // account menu — and no Sign out — on a phone. The bar is estilo's now // (shared chrome spec §5), and the same promise has a different shape: // below 800px the bar folds its nav and page actions into the Menu // sheet, and the account never folds at all. Sign out is two taps at // every width. // // Two assertions, because either alone is satisfiable while the bug is // back: the layout must render estilo's bar (and none of the old shell, // whose tail would hide an account put there), and estilo's narrow rule // must hide only the nav and the actions. func TestTheAccountIsReachableOnNarrowScreens(t *testing.T) { b, err := os.ReadFile(filepath.Join(repoRoot(t), "internal/sheets/templates/layout.html")) if err != nil { t.Fatal(err) } // Template comments are stripped FIRST: the layout explains the old // shell in prose, and a check over the raw file would pass on it. layout := regexp.MustCompile(`(?s)\{\{/\*.*?\*/\}\}`).ReplaceAllString(string(b), "") if !strings.Contains(layout, `{{template "estilo-bar" .Frame.Chrome}}`) { t.Fatal("layout.html does not render estilo's bar; whatever replaced it must keep the account reachable below 800px") } if strings.Contains(layout, "rst-shell-") { t.Fatal("layout.html still writes rastrillo's topbar shell, whose tail hides everything in it below 800px") } css := string(chrome.CSS()) narrow := regexp.MustCompile(`(?s)@media \(max-width: 799\.98px\)\s*\{(.*?)\n\}`).FindAllStringSubmatch(css, -1) if len(narrow) == 0 { t.Fatal("estilo's chrome.css has no narrow media query; this test is reading the wrong stylesheet") } for _, block := range narrow { for _, rule := range regexp.MustCompile(`([^{}]+)\{([^{}]*)\}`).FindAllStringSubmatch(block[1], -1) { if !strings.Contains(rule[2], "display: none") { continue } for _, part := range strings.Split(rule[1], ",") { sel := strings.TrimSpace(part) if strings.Contains(sel, "estilo-account") || strings.Contains(sel, "estilo-switcher") || strings.Contains(sel, "estilo-bar-end") { t.Errorf("estilo hides %q below 800px: the account (and Sign out) must never fold away", sel) } } } } }