| 1 | package home |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "html" |
| 6 | "os" |
| 7 | "regexp" |
| 8 | "strings" |
| 9 | "testing" |
| 10 | |
| 11 | "amadan.net/oficina/estilo.git/sky" |
| 12 | ) |
| 13 | |
| 14 | // TestFrontPageLineBreaksKeepTheirSpace: an earlier hero hid its <br> on |
| 15 | // narrow screens, so a <br> glued to words on both sides ran them together |
| 16 | // — "Open your newoffice suite." on every phone (polish audit, round 1). |
| 17 | // The Calma hero wraps by itself and has no <br>; this stays so the next |
| 18 | // one to come back keeps whitespace on at least one side. |
| 19 | func TestFrontPageLineBreaksKeepTheirSpace(t *testing.T) { |
| 20 | if glued := regexp.MustCompile(`\S<br\s*/?>\S`).FindAll(indexPage, -1); len(glued) > 0 { |
| 21 | t.Fatalf("front page has <br> with no whitespace beside it: %q", glued) |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | // The front page renders its sky from estilo's template: every layer the |
| 26 | // pinned estilo draws, the inline placeholders included, and the marker |
| 27 | // gone. |
| 28 | func TestFrontPageRendersEstilosSky(t *testing.T) { |
| 29 | if !bytes.Contains(indexPage, []byte(skyMarker)) { |
| 30 | t.Fatal("index.html has no sky marker") |
| 31 | } |
| 32 | // Attribute values are HTML-escaped (html/template writes "+" as |
| 33 | // "+"); the browser reads them unescaped, so compare that. |
| 34 | page := []byte(html.UnescapeString(string(withSky(indexPage)))) |
| 35 | if bytes.Contains(page, []byte(skyMarker)) { |
| 36 | t.Fatal("the sky marker was not replaced") |
| 37 | } |
| 38 | for _, layer := range sky.For(sky.SuiteSeed).Layers { |
| 39 | want := layer.Src |
| 40 | if want == "" { |
| 41 | want = string(layer.Inline) |
| 42 | } |
| 43 | if !bytes.Contains(page, []byte(`src="`+want+`"`)) { |
| 44 | t.Errorf("front page lacks the %s layer (%s)", layer.Name, layer.Tone) |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // TestTheFrontPagesScaleIsFiestas: the front page links no tokens.css, |
| 50 | // so home.css states the spacing scale itself; it must be the scale the |
| 51 | // vendored tokens.css carries, step for step, or the page drifts from |
| 52 | // every other page the suite draws. |
| 53 | func TestTheFrontPagesScaleIsFiestas(t *testing.T) { |
| 54 | step := regexp.MustCompile(`--rst-sp-([1-6]):\s*([^;]+);`) |
| 55 | read := func(css []byte) map[string]string { |
| 56 | out := map[string]string{} |
| 57 | for _, m := range step.FindAllSubmatch(css, -1) { |
| 58 | if _, seen := out[string(m[1])]; !seen { |
| 59 | out[string(m[1])] = strings.TrimSpace(string(m[2])) |
| 60 | } |
| 61 | } |
| 62 | return out |
| 63 | } |
| 64 | tokens, err := os.ReadFile("static/tokens.css") |
| 65 | if err != nil { |
| 66 | t.Fatal(err) |
| 67 | } |
| 68 | want, got := read(tokens), read(siteAsset("home.css")) |
| 69 | if len(want) != 6 { |
| 70 | t.Fatalf("read %d steps from tokens.css, want 6", len(want)) |
| 71 | } |
| 72 | for n, v := range want { |
| 73 | if got[n] != v { |
| 74 | t.Errorf("home.css --rst-sp-%s is %q, tokens.css says %q", n, got[n], v) |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |