rastrillo / fiesta Public

Clone
git clone https://amadan.net/rastrillo/fiesta

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3package check
4
5import (
6 "context"
7 "testing"
8 "time"
9
10 "github.com/chromedp/chromedp"
11
12 "amadan.net/rastrillo/fiesta"
13 "amadan.net/rastrillo/fiesta/internal/harness"
14)
15
16// TestLightJSOnAnOldThemeWritesOntoNothingItPaints: with the new
17// tokens.css, light.js and the v0.28 day theme, every property the
18// script writes lands on a token the old theme never painted, so the
19// pixels are the old pair's after a pointer move too, and the harness
20// sees no console error.
21func TestLightJSOnAnOldThemeWritesOntoNothingItPaints(t *testing.T) {
22 oldTokens, oldTheme := legacyFile(t, "tokens-v028.css"), legacyFile(t, "day-v028.css")
23 rig := legacyRig(t, oldTokens, oldTheme, fiesta.TokensCSS(), oldTheme, true)
24 ctx, cancel := context.WithTimeout(rig.Context(), 120*time.Second)
25 defer cancel()
26 shots := map[string][2][]byte{}
27 for i, dir := range []string{"/old/", "/new/"} {
28 mustRun(t, ctx, chromedp.EmulateViewport(1280, 1400), chromedp.Navigate(rig.Origin+dir), chromedp.WaitVisible("#field", chromedp.ByQuery),
29 chromedp.Evaluate(`new Promise(r => addEventListener("load", r, {once: true}) || document.readyState === "complete" && r())`, nil, awaitPromise))
30 bx, by, _, _ := rect(t, ctx, "#box")
31 move(t, ctx, 1270, 400)
32 move(t, ctx, bx+40, by+20)
33 time.Sleep(1200 * time.Millisecond)
34 still(t, ctx)
35 for _, sel := range []string{"#box", "#card", "#b-primary", "#b-plain", "#sw"} {
36 s := shots[sel]
37 s[i] = snap(t, ctx, sel)
38 shots[sel] = s
39 }
40 }
41 for sel, s := range shots {
42 if ok, why := samePixels(t, s[0], s[1]); !ok {
43 t.Errorf("%s renders differently with light.js on the old theme: %s", sel, why)
44 }
45 }
46}
47
48// TestOldTokensWithANewThemeStillRenders (C16's reverse pair): an app
49// that re-copied theme.css and kept its v0.28 tokens.css renders with
50// the old rules and the new colours: the primary button is the new
51// accent under white, the card a plain hairline, no console error (the
52// harness fails one), in both schemes.
53func TestOldTokensWithANewThemeStillRenders(t *testing.T) {
54 day, _ := fiesta.ThemeCSS("day")
55 oldTokens := legacyFile(t, "tokens-v028.css")
56 rig := legacyRig(t, oldTokens, day, oldTokens, day, true)
57 ctx, cancel := context.WithTimeout(rig.Context(), 60*time.Second)
58 defer cancel()
59 for _, scheme := range []string{"light", "dark"} {
60 mustRun(t, ctx, chromedp.EmulateViewport(1280, 1400), chromedp.Navigate(rig.Origin+"/new/"), chromedp.WaitVisible("#field", chromedp.ByQuery),
61 chromedp.Evaluate(`document.documentElement.setAttribute("data-theme", "`+scheme+`"), true`, nil))
62 still(t, ctx)
63 wantFill, wantFg := "rgb(31, 86, 214)", "rgb(255, 255, 255)"
64 if scheme == "dark" {
65 wantFill, wantFg = "rgb(122, 162, 255)", "rgb(12, 13, 15)"
66 }
67 if bg, fg := computed(t, ctx, "#b-primary", "background-color"), computed(t, ctx, "#b-primary", "color"); bg != wantFill || fg != wantFg {
68 t.Errorf("%s: old tokens.css paints the primary button %s on %s with the new theme; want %s on %s (the accent and on-accent, which is all the old rules read)", scheme, fg, bg, wantFg, wantFill)
69 }
70 if img := computed(t, ctx, "#b-primary", "background-image"); img != "none" {
71 t.Errorf("%s: old tokens.css painted a background-image %q on the primary button; it has no face rule", scheme, img)
72 }
73 move(t, ctx, 1270, 400)
74 time.Sleep(300 * time.Millisecond)
75 }
76}
77
78// TestAnAppWithLightJSDeletedIsTheStaticDesign: the shells' tag
79// removed, no script, every light property at its default after a move.
80func TestAnAppWithLightJSDeletedIsTheStaticDesign(t *testing.T) {
81 rig := sizingRig(t, false, depthDoc(t), harness.WithHover())
82 ctx, cancel := context.WithTimeout(rig.Context(), 60*time.Second)
83 defer cancel()
84 open(t, ctx, rig, "/", false)
85 move(t, ctx, 1270, 400)
86 time.Sleep(300 * time.Millisecond)
87 if x, lit, px := computed(t, ctx, ":root", "--rst-light-x"), computed(t, ctx, "#box", "--rst-card-lit"), computed(t, ctx, "#b-primary", "--rst-px"); x != "0" || lit != "0" || px != "50%" {
88 t.Errorf("without light.js: light-x %s card-lit %s px %s; want 0, 0, 50%%", x, lit, px)
89 }
90}
91