package fichastest import ( "amadan.net/oficina/estilo.git/busy" "amadan.net/oficina/estilo.git/chrome" "amadan.net/oficina/estilo.git/menu" "amadan.net/oficina/estilo.git/savestatus" "amadan.net/oficina/estilo.git/sky" "amadan.net/oficina/estilo.git/theme" "bytes" "os" "path/filepath" "regexp" "strings" "testing" "amadan.net/rastrillo/rastrillo/ui" ) // vendoredTheme is the theme this app was scaffolded with. Change it // here when you swap static/theme.css for another of ui.ThemeNames(). const vendoredTheme = "day" // vendoredIsMine names the vendored files this app has edited // DELIBERATELY. Add one here when you mean to diverge: this test stops // pinning it, and rastrillo doctor leaves it alone too. The file was // yours from the moment the scaffold wrote it — this is only where you // record that the edit was on purpose, so the next reader (and the next // upgrade) can tell it from drift. var vendoredIsMine = map[string]bool{ // rastrillo's shim as estilo carries it: without the old busy rule, // which would fight busy.js. Pinned to estilo by TestBusyFilesAreEstilos. "rastrillo.js": true, // Calma with Fichas' accent, from estilo (estilo AGENTS.md, decisions // table, row 8). Pinned to estilo instead, by TestThemeIsEstilosForFichas. "theme.css": true, // Deliberately absent. datetime.js opens rastrillo's calendar overlay // when calendar.js is on the page and the browser's own picker when it // is not — which is what Fichas has always had. Adopting the overlay // is a visible change of its own, not part of moving rastrillo's path. "calendar.js": true, // Deliberately absent. The library splits its script into fiesta.js // plus a thin rastrillo.js; estilo's shim (rastrillo.js above) is // whole on its own, so fiesta.js beside it would be a second copy of // the same behaviour. "fiesta.js": true, } // TestThemeIsEstilosForFichas pins static/theme.css to the estilo this app // is built against. After an estilo upgrade, re-write it with // `go run ./scripts/writeestilo` — never by hand. func TestThemeIsEstilosForFichas(t *testing.T) { want, ok := theme.ForApp("fichas") if !ok { t.Fatal("estilo's theme ring has no fichas") } got, err := os.ReadFile(filepath.Join("..", "fichas", "static", "theme.css")) if err != nil { t.Fatal(err) } if !bytes.Equal(got, want) { t.Error("static/theme.css differs from estilo's theme for fichas; run go run ./scripts/writeestilo") } } // The scaffold delivered these files once; they are app-owned from // then on. This test pins each vendored copy byte-identical to the // library it came from: a reviewer runs the suite instead of reading // ~56KB of assets as app diff, and a framework upgrade that forgets // to re-copy is caught instead of drifting silently. // // The list is ui.VendoredAssets — the same function rastrillo new // wrote these files from and rastrillo doctor compares them against — // so a file added to the library's vendored set is pinned here without // this file changing. func TestVendoredAssetsMatchTheLibrary(t *testing.T) { assets, ok := ui.VendoredAssets(vendoredTheme) if !ok { t.Fatalf("unknown theme %q", vendoredTheme) } for name, lib := range assets { if vendoredIsMine[name] { continue } vendored, err := os.ReadFile(filepath.Join("..", "fichas", "static", name)) if err != nil { t.Errorf("read vendored %s: %v", name, err) continue } if !bytes.Equal(vendored, lib) { t.Errorf("static/%s differs from the library copy; re-copy it with rastrillo doctor --fix (or add it to vendoredIsMine if the edit was deliberate)", name) } } } // rastrillo's busy rule (Paul, 2026-09-29; GETs revised 2026-11-10): a // POST's button gives way to a spinner for at least 650ms; a GET goes at // once and shows a spinner only after 500ms; the button disables, and // Back resets it. static/ carries it as estilo does — the shim without the old // rule, busy.js and busy.css — pinned here to the estilo this app builds // against. After an estilo upgrade: go run ./scripts/writeestilo. func TestBusyFilesAreEstilos(t *testing.T) { for name, want := range map[string][]byte{ "rastrillo.js": busy.ShimJS(), "busy.js": busy.JS(), "busy.css": busy.CSS(), } { got, err := os.ReadFile(filepath.Join("..", "fichas", "static", name)) if err != nil { t.Fatal(err) } if !bytes.Equal(got, want) { t.Errorf("static/%s differs from estilo's; run go run ./scripts/writeestilo", name) } } } // The sign-in door (estilo chrome's estilo-signin and friends) is styled // by chrome.css and sky.css, which static/ carries as estilo does and the // sign-in page links. Pinned here to the estilo this app builds against. // After an estilo upgrade: go run ./scripts/writeestilo. func TestDoorFilesAreEstilos(t *testing.T) { for name, want := range map[string][]byte{ "chrome.css": chrome.CSS(), "sky.css": sky.CSS(), // The account menu in the rail: its panel and rows, and the script // that closes it on Escape or an outside click. "menu.css": menu.CSS(), "chrome.js": chrome.JS(), // The bar's save state (level-up §3.1). "savestatus.css": savestatus.CSS(), } { got, err := os.ReadFile(filepath.Join("..", "fichas", "static", name)) if err != nil { t.Fatal(err) } if !bytes.Equal(got, want) { t.Errorf("static/%s differs from estilo's; run go run ./scripts/writeestilo", name) } } } // scriptSrc is every