oficina / home Public

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

Plain git — no account needed to clone.

Download

Download this file

1package home
2
3import (
4 "fmt"
5 "regexp"
6 "strings"
7 "testing"
8
9 "amadan.net/oficina/home/internal/home/wisp"
10)
11
12// The front page as served: the drawing is in the page once, every
13// section heading carries its own wisp, every stretch points at a symbol
14// the drawing has — and no marker is left.
15func TestFrontPageWispsPointIntoTheDrawing(t *testing.T) {
16 f := newMountedChooser(t)
17 page := f.request("GET", "/", "", "", nil).Body.String()
18 if strings.Contains(page, "<!-- wisp:") {
19 t.Fatal("a wisp marker was not replaced")
20 }
21 if n := strings.Count(page, `<svg class="wisp-defs"`); n != 1 {
22 t.Fatalf("the wisps' drawing is in the page %d times, want once", n)
23 }
24 heads := regexp.MustCompile(`<h2 data-wisp="(\d+)">`).FindAllStringSubmatch(page, -1)
25 if len(heads) != wisp.Count {
26 t.Fatalf("%d headings carry a wisp, want one per variant (%d)", len(heads), wisp.Count)
27 }
28 uses := regexp.MustCompile(`<use href="#([^"]+)"/>`).FindAllStringSubmatch(page, -1)
29 if len(uses) != wisp.Count*wisp.Stretches {
30 t.Fatalf("%d wisp stretches on the page, want %d", len(uses), wisp.Count*wisp.Stretches)
31 }
32 for _, u := range uses {
33 if !strings.Contains(page, `<symbol id="`+u[1]+`"`) {
34 t.Errorf("a stretch points at %s, which the drawing lacks", u[1])
35 }
36 }
37}
38
39// home.css times each heading's wisp by its variant: the head starts it
40// declares are package wisp's, so the drawing and its timing cannot drift.
41func TestFrontPageWispTimingIsTheVariants(t *testing.T) {
42 css := string(siteAsset("home.css"))
43 for v := 0; v < wisp.Count; v++ {
44 want := fmt.Sprintf(`[data-wisp="%d"] { --wisp-d0: %gs; }`, v, wisp.Delay(v))
45 if !strings.Contains(css, want) {
46 t.Errorf("home.css lacks %s", want)
47 }
48 }
49 for i := 0; i < wisp.Stretches; i++ {
50 if want := fmt.Sprintf(".wisp:nth-of-type(%d) { --wisp-i: %d; }", i+1, i); !strings.Contains(css, want) {
51 t.Errorf("home.css lacks %s", want)
52 }
53 }
54 // Reduced motion and no scroll timelines both mean no wisp at all.
55 if !strings.Contains(css, ".wisp { display: none; }") || !strings.Contains(css, "@media (prefers-reduced-motion: no-preference)") {
56 t.Error("the wisp is not hidden by default and shown only where motion is welcome")
57 }
58}
59