oficina / calendar Public

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

Plain git — no account needed to clone.

Download

Download this file

1package calendartest
2
3import (
4 "amadan.net/oficina/estilo.git/base"
5 estilobusy "amadan.net/oficina/estilo.git/busy"
6 "amadan.net/oficina/estilo.git/chrome"
7 "amadan.net/oficina/estilo.git/menu"
8 "amadan.net/oficina/estilo.git/sky"
9 "amadan.net/oficina/estilo.git/theme"
10 "bytes"
11 "os"
12 "path/filepath"
13 "testing"
14
15 "amadan.net/rastrillo/rastrillo/ui"
16)
17
18// vendoredTheme is the theme this app was scaffolded with. Change it
19// here when you swap static/theme.css for another of ui.ThemeNames().
20const vendoredTheme = "day"
21
22// vendoredIsMine names the vendored files this app has edited
23// DELIBERATELY. Add one here when you mean to diverge: this test stops
24// pinning it, and rastrillo doctor leaves it alone too. The file was
25// yours from the moment the scaffold wrote it — this is only where you
26// record that the edit was on purpose, so the next reader (and the next
27// upgrade) can tell it from drift.
28var vendoredIsMine = map[string]bool{
29 // rastrillo's shim as estilo carries it: without the old busy rule,
30 // which would fight busy.js. Pinned to estilo by TestBusyFilesAreEstilos.
31 "rastrillo.js": true,
32 // Calma with Calendar's accent, from estilo (estilo AGENTS.md,
33 // decisions table, row 8; this repo's ruling 2 is superseded). Pinned
34 // to estilo instead, by TestThemeIsEstilosForCalendar below.
35 "theme.css": true,
36 // Calendar's OWN calendar.js (bring the working day into view on
37 // load), not rastrillo's: from v0.26 rastrillo vendors a calendar.js
38 // of its own, the month-grid overlay for date fields, under the same
39 // name. Listed so doctor --fix never overwrites ours with it. Without
40 // rastrillo's overlay, datetime.js's button opens the browser's own
41 // picker, as it did on v0.23. Adopting the overlay means renaming
42 // ours first.
43 "calendar.js": true,
44 // estilo's busy.js, not rastrillo's: from fb806a2 rastrillo's copy
45 // learned to leave pow.js forms alone, and Calendar has no pow (auth
46 // runs ProofOff). Pinned to estilo by TestBusyFilesAreEstilos, like
47 // rastrillo.js; it follows estilo's when estilo takes the change.
48 "busy.js": true,
49 // rastrillo's console shell (from v0.27), which Calendar does not
50 // draw: its bar and page frame are estilo's chrome. Never vendored,
51 // so there is nothing here to pin.
52 "shell.css": true,
53 "shell.js": true,
54 // The library's newer scripts (rastrillo v0.31 to v0.42, most of them
55 // Fiesta's): fiesta.js (the menus, which rastrillo.js and select.js
56 // answer here), live.js, anchor.js, light.js, transition.js and
57 // copy.js. Calendar's layout links none of them, so none is vendored
58 // and there is nothing to pin; adopting one means vendoring it and
59 // taking it off this list. The same choice Slides made (#49).
60 "fiesta.js": true,
61 "live.js": true,
62 "anchor.js": true,
63 "light.js": true,
64 "transition.js": true,
65 "copy.js": true,
66}
67
68// TestThemeIsEstilosForCalendar pins static/theme.css to the estilo this
69// app is built against. After an estilo upgrade, re-write it with
70// `go run ./scripts/writeestilo` — never by hand.
71func TestThemeIsEstilosForCalendar(t *testing.T) {
72 want, ok := theme.ForApp("calendar")
73 if !ok {
74 t.Fatal("estilo's theme ring has no calendar")
75 }
76 got, err := os.ReadFile(filepath.Join("..", "calendar", "static", "theme.css"))
77 if err != nil {
78 t.Fatal(err)
79 }
80 if !bytes.Equal(got, want) {
81 t.Error("static/theme.css differs from estilo's theme for calendar; run go run ./scripts/writeestilo")
82 }
83}
84
85// The scaffold delivered these files once; they are app-owned from
86// then on. This test pins each vendored copy byte-identical to the
87// library it came from: a reviewer runs the suite instead of reading
88// ~56KB of assets as app diff, and a framework upgrade that forgets
89// to re-copy is caught instead of drifting silently.
90//
91// The list is ui.VendoredAssets — the same function rastrillo new
92// wrote these files from and rastrillo doctor compares them against —
93// so a file added to the library's vendored set is pinned here without
94// this file changing.
95func TestVendoredAssetsMatchTheLibrary(t *testing.T) {
96 assets, ok := ui.VendoredAssets(vendoredTheme)
97 if !ok {
98 t.Fatalf("unknown theme %q", vendoredTheme)
99 }
100 for name, lib := range assets {
101 if vendoredIsMine[name] {
102 continue
103 }
104 vendored, err := os.ReadFile(filepath.Join("..", "calendar", "static", name))
105 if err != nil {
106 t.Errorf("read vendored %s: %v", name, err)
107 continue
108 }
109 if !bytes.Equal(vendored, lib) {
110 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)
111 }
112 }
113}
114
115// rastrillo's busy rule (Paul, 2026-09-29): a submit button's label gives
116// way to a spinner for at least 650ms, the button disables, and Back
117// resets it. static/ carries it as estilo does — the shim without the old
118// rule, busy.js and busy.css — pinned here to the estilo this app builds
119// against. After an estilo upgrade: go run ./scripts/writeestilo.
120func TestBusyFilesAreEstilos(t *testing.T) {
121 for name, want := range map[string][]byte{
122 "rastrillo.js": estilobusy.ShimJS(),
123 "busy.js": estilobusy.JS(),
124 "busy.css": estilobusy.CSS(),
125 } {
126 got, err := os.ReadFile(filepath.Join("..", "calendar", "static", name))
127 if err != nil {
128 t.Fatal(err)
129 }
130 if !bytes.Equal(got, want) {
131 t.Errorf("static/%s differs from estilo's; run go run ./scripts/writeestilo", name)
132 }
133 }
134}
135
136// The sign-in door's styles (Paul, 2026-09-29: every app's sign-in is a
137// version of the Oficina sign-in screen): estilo chrome's chrome.css,
138// which holds the [estilo-door] and [estilo-signin] rules, and the sky
139// behind it. Pinned to the estilo this app builds against. After an
140// estilo upgrade: go run ./scripts/writeestilo.
141func TestDoorFilesAreEstilos(t *testing.T) {
142 for name, want := range map[string][]byte{
143 "chrome.css": chrome.CSS(),
144 "sky.css": sky.CSS(),
145 } {
146 got, err := os.ReadFile(filepath.Join("..", "calendar", "static", name))
147 if err != nil {
148 t.Fatal(err)
149 }
150 if !bytes.Equal(got, want) {
151 t.Errorf("static/%s differs from estilo's; run go run ./scripts/writeestilo", name)
152 }
153 }
154}
155
156// The shared chrome's other files (estilo spec 2026-09-23 §1): base.css
157// (the link rule), menu.css (every floating panel) and chrome.js (Esc and
158// outside-click close). The layout links them in the spec's order after
159// theme.css. Pinned like the door's; after an estilo upgrade:
160// go run ./scripts/writeestilo.
161func TestSharedChromeFilesAreEstilos(t *testing.T) {
162 for name, want := range map[string][]byte{
163 "base.css": base.CSS(),
164 "menu.css": menu.CSS(),
165 "chrome.js": chrome.JS(),
166 } {
167 got, err := os.ReadFile(filepath.Join("..", "calendar", "static", name))
168 if err != nil {
169 t.Fatal(err)
170 }
171 if !bytes.Equal(got, want) {
172 t.Errorf("static/%s differs from estilo's; run go run ./scripts/writeestilo", name)
173 }
174 }
175}
176