| 1 | //go:build browser |
| 2 | |
| 3 | package home |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "testing" |
| 8 | "time" |
| 9 | |
| 10 | "amadan.net/rastrillo/fiesta/check/rhythm" |
| 11 | "amadan.net/rastrillo/rastrillo/harness" |
| 12 | "github.com/chromedp/chromedp" |
| 13 | ) |
| 14 | |
| 15 | // TestTheFrontPageKeepsTheRhythm: oficina.works, signed out, read by |
| 16 | // Fiesta's rhythm audit (Paul, 2026-11-22: "Can we somehow put |
| 17 | // something in place to avoid weird spacing issues like this in |
| 18 | // future?"). Every gap between two of the page's blocks is a step of |
| 19 | // the spacing scale, no text rests on a control, and every heading sits |
| 20 | // closer to its own content than to what comes before it, at a desktop |
| 21 | // width and a phone's. The product picture under the headline (.stage) |
| 22 | // is a drawing of the apps, spaced as they are, so the audit reads |
| 23 | // around it, as it reads around the wisps' drawing. |
| 24 | func TestTheFrontPageKeepsTheRhythm(t *testing.T) { |
| 25 | f := newMountedChooser(t) |
| 26 | useChrome(t) |
| 27 | rig := harness.New(t, asHost(directoryHost, f.p.directory.Router())) |
| 28 | for _, width := range []int64{1280, 390} { |
| 29 | ctx, cancel := context.WithTimeout(rig.Context(), 30*time.Second) |
| 30 | var found []rhythm.Finding |
| 31 | var step string |
| 32 | err := chromedp.Do(ctx, |
| 33 | chromedp.EmulateViewport(width, 900), |
| 34 | chromedp.Navigate(rig.Origin+"/"), |
| 35 | chromedp.WaitVisible(chromedp.CSS(`main`)), |
| 36 | harness.Into(&step, chromedp.Evaluate[string]( |
| 37 | `getComputedStyle(document.documentElement).getPropertyValue("--rst-sp-2").trim()`)), |
| 38 | harness.Into(&found, chromedp.Evaluate[[]rhythm.Finding]( |
| 39 | rhythm.Expression("main", rhythm.Options{Skip: []string{".stage", ".wisp-defs"}})))) |
| 40 | cancel() |
| 41 | if err != nil { |
| 42 | t.Fatalf("at %dpx: %v", width, err) |
| 43 | } |
| 44 | // A step the page never declares is no margin at all, and every |
| 45 | // gap it sets reads as 0, which is on the scale. |
| 46 | if step != "0.5rem" { |
| 47 | t.Fatalf("at %dpx: --rst-sp-2 is %q on the front page, want 0.5rem", width, step) |
| 48 | } |
| 49 | if len(found) > 0 { |
| 50 | t.Errorf("at %dpx: %s", width, rhythm.Report(found)) |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // TestTheDoorKeepsTheRhythm: id.*'s sign-in door is estilo's card |
| 56 | // (chrome.css, served from the pinned estilo), read by the same audit. |
| 57 | // It had 22px between the brand and the way in; estilo's card is now a |
| 58 | // stack on the scale. |
| 59 | func TestTheDoorKeepsTheRhythm(t *testing.T) { |
| 60 | f := newMountedChooser(t) |
| 61 | useChrome(t) |
| 62 | rig := harness.New(t, asHost(credentialHost, f.p.credential.Router())) |
| 63 | for _, width := range []int64{1280, 390} { |
| 64 | ctx, cancel := context.WithTimeout(rig.Context(), 30*time.Second) |
| 65 | var found []rhythm.Finding |
| 66 | err := chromedp.Do(ctx, |
| 67 | chromedp.EmulateViewport(width, 900), |
| 68 | chromedp.Navigate(rig.Origin+"/signin"), |
| 69 | chromedp.WaitVisible(chromedp.CSS(`[estilo-signin]`)), |
| 70 | harness.Into(&found, chromedp.Evaluate[[]rhythm.Finding]( |
| 71 | rhythm.Expression("main", rhythm.Options{})))) |
| 72 | cancel() |
| 73 | if err != nil { |
| 74 | t.Fatalf("at %dpx: %v", width, err) |
| 75 | } |
| 76 | if len(found) > 0 { |
| 77 | t.Errorf("at %dpx: %s", width, rhythm.Report(found)) |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |