//go:build browser // The door's rhythm, measured: Fiesta's rhythm audit (its check/rhythm, // v1.7.0, copied into testdata/rhythm.js because estilo does not require // Fiesta; see the Makefile's test-spacing) over the card of every door // page, the Colophon and the Google Drive chooser, in real engines, on a // desktop and a phone. It reports two blocks whose gap is not a step of // the spacing scale, text and a control less than --rst-sp-2 apart, a // heading no closer to its content than to what comes before it, and a // stack (rst-stack) bent out of its column or holding a fixed or // absolute child it does not pass over; none of these pages is an // rst-stack, so the last two have nothing to find here. It does not read // past a closed
' summary, nor into a list (a text block), so // an open Colophon entry is audited from its own root. // // Not part of `make test`: it needs Node 22+ and Playwright // (ESTILO_PLAYWRIGHT, ESTILO_BROWSERS as for the title check). // ESTILO_SHOTS= saves each page there to look at. package chrome import ( "bytes" "encoding/json" "fmt" "html/template" "net/http" "net/http/httptest" "os" "os/exec" "strings" "testing" "amadan.net/oficina/estilo.git/base" "amadan.net/oficina/estilo.git/credits" "amadan.net/oficina/estilo.git/googleimport" "amadan.net/oficina/estilo.git/theme" "github.com/carlosframework/rastrillo/ui" ) const doorPage = `
%s
` type doorRhythm struct { Engine string `json:"engine"` Version string `json:"version"` Error string `json:"error"` Pages []struct { Page string `json:"page"` Viewport int `json:"viewport"` Sizes map[string][]float64 `json:"sizes"` Gaps map[string]*float64 `json:"gaps"` Findings []struct { Kind string `json:"kind"` Gap float64 `json:"gap"` Before string `json:"before"` After string `json:"after"` Message string `json:"message"` } `json:"findings"` } `json:"pages"` } func openCard(t *testing.T) string { t.Helper() open := render(t, "estilo-door-open", SignIn{Icon: "/i.svg", App: "Calendar"}) body := `

Join your team

Calendar keeps your team's schedule in one place.

Your details

Shown to your team.

Your work address.

We never show it to anyone outside the team.

Notifications

After a hidden block, still close to its heading.

We'll email you when someone invites you.

A section of the card's own.

` return open + body + render(t, "estilo-door-close", nil) } // openGaps is the table, in the open card: the space above each block, // in CSS pixels at a 16px root. var openGaps = map[string]float64{ "#g-h1": 24, // after the brand "#g-lede": 8, // after a heading "#g-h2": 24, // before an h2 "#g-label": 8, // after a heading "#g-input": 8, // an input after its label "#g-hint": 12, // anything else "#g-field-hint": 12, // anything else "#g-hinted": 8, // an input after its hint "#g-after-hint": 8, // a hint after its input "#g-h3": 16, // before an h3 "#g-past-hidden": 8, // after a heading, past a hidden block: the gap "#g-section": 24, // a section "#door-img": 12, // anything else "#g-after-img": 12, // anything else "#door-button": 16, // before a button } // colophon renders estilo's Colophon (credits) with two entries, one // with its source and notices; open, every entry is open, as a reader // who opened them sees it. Closed, the page also carries an app's own // margin on the heading, which must not reach it. func colophon(t *testing.T, open bool) string { t.Helper() tpl := template.Must(template.ParseFS(credits.Templates(), "templates/*.html")) var out bytes.Buffer data := credits.PageData{Title: "Open source", MissingNoticeLabel: "No notice was found.", Components: []credits.Component{ {Name: "example.org/first", Version: "v1.2.3", SourceURL: "https://example.org/first", Notices: []credits.Notice{{Name: "LICENSE", Text: "Copyright the authors.\nPermission is granted."}, {Name: "NOTICE", Text: "Built with care."}}}, {Name: "example.org/second"}, }} if err := tpl.ExecuteTemplate(&out, "estilo/credits", data); err != nil { t.Fatal(err) } html := out.String() if !open { // An app's own rule on the heading, as Mapa's frame.css wrote // one before estilo spaced the Colophon: the stack outweighs it. html = `` + html } if open { html = strings.ReplaceAll(html, "
", "
") } return html } // colophonGaps is the space above each of the Colophon's blocks: the // list --rst-sp-2 under its heading, and in an open entry its source // --rst-sp-3 under the summary, a notice's name --rst-sp-3 under what // is above it, and the notice's text --rst-sp-2 under its name. var colophonGaps = map[string]float64{ "[estilo-credits] > ul": 8, "[estilo-credits] li:first-child details > p": 12, "[estilo-credits] li:first-child details > pre": 8, "[estilo-credits] li:first-child details > p + pre + p": 12, } // chooser renders the Google Drive chooser as its script leaves it: // ready, the Choose button shown and the status empty; idle, the status // saying something under Choose (a refusal, or what was imported); // busy, Cancel under Choose and the status saying what is happening. func chooser(t *testing.T, state string) string { t.Helper() tpl := template.Must(template.New("root").Parse(googleimport.Template())) var out bytes.Buffer view := googleimport.View{Config: googleimport.Config{ClientID: "123456789-client.apps.googleusercontent.com", APIKey: "AIzaPublicBrowserKey123456789", AppID: "123456789"}, Kind: googleimport.Docs, FormID: "upload", InputID: "file", Labels: googleimport.Text("en")} if err := tpl.ExecuteTemplate(&out, "estilo-google-import", view); err != nil { t.Fatal(err) } html := strings.Replace(out.String(), "