oficina / base Public

Lay Home out as an apps panel and springboard; chat as a popover

The left rail goes, with its More panel, Keep expanded and Collapse:
the UI, the /rail route and their tests (members.rail_expanded and its
migration stay). Under the greeting, lede and steps, Home now has one
glass "Apps" panel (at most 960px): a wrapping grid of every app, the
Oficina apps in their configured order and then the installed Store
apps, each a 64px icon with its label, and past a hairline a dock of
Store, People and Settings. On a phone the same markup is a
springboard: a compact greeting, four columns of 60px icons whose
labels keep a soft halo over the fog, and a glass dock fixed to the
foot of the screen (safe-area aware) that stays put while Home scrolls.

On a wide screen the chat is a glass popover under the Ask field
(about 440px wide, min(640px, the screen less 120px) tall), its
pointer on the field, kept inside the screen; Escape or a click
outside closes it, and the ⋯ menu still closes first. On a phone the
sheet slides up full-screen while Home steps back (scaled to 0.94,
dimmed and blurred); with reduced motion it just shows. /ask is as
before.

Browser tests cover the panel and grid at 700 to 1280 wide in both
themes, the springboard and its dock, the popover's place and closing,
the sheet's slide and push-back, and AA contrast for the grid and dock
labels and the chat in both themes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev fc1e99887d41f00d70820239f3a0f7d3b0632ce6 parent 089edac
16 files changed, +498 −910
  • README.md +2 −2
  • docs/copy-pending.md +9 −8
  • internal/browsertest/layout_test.go +244 −0
  • internal/browsertest/light_test.go +6 −21
  • internal/browsertest/mobile_test.go +42 −30
  • internal/browsertest/oficina_test.go +0 −396
  • internal/look/rail_test.go +0 −33
  • internal/look/static/app.css +74 −127
  • internal/look/static/ask.js +21 −1
  • internal/look/static/rail.js +0 −23
  • internal/store/rail.go +0 −29
  • internal/store/rail_test.go +0 −44
  • internal/web/app.go +0 −1
  • internal/web/home.go +15 −49
  • internal/web/templates/home.html +12 −28
  • internal/webtest/home_test.go +73 −118
diff --git a/README.md b/README.md
index cb9f94b..16e5bb4 100644
--- a/README.md
+++ b/README.md
@@ -51,8 +51,8 @@ Everything is an environment variable. `BASE_ORIGIN`, `BASE_OWNER` and
stays off. Each person connects Equipo once, from Settings or the Ask
panel; Base keeps their Equipo key sealed with `BASE_INSTANCE_KEY`, so
changing that key disconnects everyone from Equipo.
-- `BASE_OFICINA_APPS` lists your team's Oficina apps, which Home shows down
- the left (as tiles on a phone), each opening in a new tab. Write each as
+- `BASE_OFICINA_APPS` lists your team's Oficina apps, which Home shows first
+ in its grid of apps, each opening in a new tab. Write each as
`id=address`, separated by commas, in the order you want them, such as
`calendar=https://calendar.oficina.works,fichas=https://fichas.oficina.works`.
The ids are `calendar`, `docs`, `sheets`, `slides`, `memoria`, `calls`,
diff --git a/docs/copy-pending.md b/docs/copy-pending.md
index 836c80c..7f70338 100644
--- a/docs/copy-pending.md
+++ b/docs/copy-pending.md
@@ -265,18 +265,19 @@ Review 5 (pending): "Ask Base anything", the chat with Equipo's coordinator.
| internal/web/templates/settings.html | Equipo row, buttons | Disconnect / Finish connecting / Reconnect Equipo / Connect Equipo |
| internal/config/config.go | Start-up refusal (operator-facing log) | BASE_EQUIPO_ORIGIN {value} must be an https origin: a scheme and host only (http only on loopback) |
| README.md | Settings: the BASE_EQUIPO_ORIGIN bullet (new lines only) | `BASE_EQUIPO_ORIGIN` is the Equipo whose coordinator answers "Ask Base anything", such as `https://equipo.example.com`. Without it the Ask field stays off. Each person connects Equipo once, from Settings or the Ask panel; Base keeps their Equipo key sealed with `BASE_INSTANCE_KEY`, so changing that key disconnects everyone from Equipo. |
-| internal/web/templates/home.html | Home on a wide screen: the Oficina apps rail's accessible name (a nav) | Oficina |
-| internal/web/templates/home.html | Home on a phone: the small heading over the Oficina app tiles | Oficina |
-| internal/config/oficina.go | Oficina app names on the rail and the tiles (Base's own, whatever the setting says) | Calendar / Docs / Sheets / Slides / Memoria / Calls / Fichas / Equipo |
+| internal/web/templates/home.html | REMOVED (the rail is gone): Home on a wide screen, the Oficina apps rail's accessible name | ~~Oficina~~ |
+| internal/web/templates/home.html | REMOVED (the phone shows every app in one grid): the small heading over the Oficina app tiles | ~~Oficina~~ |
+| internal/config/oficina.go | Oficina app names, the labels in Home's grid of apps (Base's own, whatever the setting says) | Calendar / Docs / Sheets / Slides / Memoria / Calls / Fichas / Equipo |
| internal/config/oficina.go | Start-up refusal: an item without an id and an address (operator-facing log) | BASE_OFICINA_APPS: {item} must be an app and its address, such as calendar=https://calendar.example.com |
| internal/config/oficina.go | Start-up refusal: an id Base doesn't know (operator-facing log) | BASE_OFICINA_APPS: unknown app {id}; Base knows calendar, docs, sheets, slides, memoria, calls, fichas, equipo |
| internal/config/oficina.go | Start-up refusal: the same id twice (operator-facing log) | BASE_OFICINA_APPS lists {id} twice |
| internal/config/oficina.go | Start-up refusal: an address that is not https and a hostname (operator-facing log) | BASE_OFICINA_APPS: {id}'s address {value} must be https:// and a hostname only |
-| README.md | Settings: the BASE_OFICINA_APPS bullet (new lines only) | `BASE_OFICINA_APPS` lists your team's Oficina apps, which Home shows down the left (as tiles on a phone), each opening in a new tab. Write each as `id=address`, separated by commas, in the order you want them, such as `calendar=https://calendar.oficina.works,fichas=https://fichas.oficina.works`. The ids are `calendar`, `docs`, `sheets`, `slides`, `memoria`, `calls`, `fichas` and `equipo`, and each address is `https://` and a hostname only. Base refuses to start with an id it doesn't know. Without it, Home lists no Oficina apps. |
-| internal/web/templates/home.html | Oficina rail, the last entry when not every app fits (under a ⋯ glyph; opens a panel of the rest). Same word as the Ask panel's ⋯ button | More |
-| internal/web/templates/home.html | The More panel's accessible name (a region) | More Oficina apps |
-| internal/web/templates/home.html | The More panel's switch (on: the rail lists every app, on every device) | Keep expanded |
-| internal/web/templates/home.html | Oficina rail kept expanded, its last entry (puts More back) | Collapse |
+| README.md | Settings: the BASE_OFICINA_APPS bullet (new lines only) | `BASE_OFICINA_APPS` lists your team's Oficina apps, which Home shows first in its grid of apps, each opening in a new tab. Write each as `id=address`, separated by commas, in the order you want them, such as `calendar=https://calendar.oficina.works,fichas=https://fichas.oficina.works`. The ids are `calendar`, `docs`, `sheets`, `slides`, `memoria`, `calls`, `fichas` and `equipo`, and each address is `https://` and a hostname only. Base refuses to start with an id it doesn't know. Without it, Home lists no Oficina apps. |
+| internal/web/templates/home.html | REMOVED (the rail and its More panel are gone): the rail's More entry | ~~More~~ (the Ask panel's ⋯ "More" stays) |
+| internal/web/templates/home.html | REMOVED (with the rail): the More panel's accessible name | ~~More Oficina apps~~ |
+| internal/web/templates/home.html | REMOVED (with the rail): the More panel's switch | ~~Keep expanded~~ |
+| internal/web/templates/home.html | REMOVED (with the rail): the expanded rail's last entry | ~~Collapse~~ |
+| internal/web/templates/home.html | Home: the glass panel holding every app and the dock of Store, People and Settings (its accessible name; a nav) | Apps |
| internal/web/templates/settings.html | Settings label for the theme choice (also the choice's accessible name) | Appearance |
| internal/web/settings.go | Appearance, the three buttons (System follows the device's light or dark setting; the chosen one is pressed) | System / Light / Dark |
diff --git a/internal/browsertest/layout_test.go b/internal/browsertest/layout_test.go
new file mode 100644
index 0000000..1b8d3bb
--- /dev/null
+++ b/internal/browsertest/layout_test.go
@@ -0,0 +1,244 @@
+//go:build browser
+
+package browsertest
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "os"
+ "testing"
+ "time"
+
+ "github.com/chromedp/cdproto/cdp"
+ "github.com/chromedp/cdproto/emulation"
+ "github.com/chromedp/chromedp"
+
+ "amadan.net/rastrillo/rastrillo/harness"
+
+ "amadan.net/carlos/base/internal/config"
+ "amadan.net/carlos/base/internal/store"
+)
+
+// layoutShot saves what is on screen to BASE_LAYOUT_ARTIFACTS, when set.
+func layoutShot(t *testing.T, rig *harness.Rig, name string) {
+ t.Helper()
+ dir := os.Getenv("BASE_LAYOUT_ARTIFACTS")
+ if dir == "" {
+ return
+ }
+ t.Setenv("BASE_BROWSER_ARTIFACTS", dir)
+ viewportShot(t, rig, name)
+}
+
+// reducedMotion emulates the device's reduced-motion setting, with the
+// colour scheme given.
+func reducedMotion(scheme string, on bool) chromedp.Action[chromedp.Void] {
+ v := "no-preference"
+ if on {
+ v = "reduce"
+ }
+ return chromedp.Func(func(ctx context.Context, target *chromedp.Target) error {
+ _, err := cdp.Call(ctx, target, emulation.SetEmulatedMedia, emulation.SetEmulatedMediaParams{
+ Features: []*emulation.MediaFeature{{Name: "prefers-color-scheme", Value: scheme}, {Name: "prefers-reduced-motion", Value: v}}})
+ return err
+ })
+}
+
+// installAll installs Welcome and Scratchpad, so Home's grid has Store apps.
+func installAll(t *testing.T, b *baseApp) {
+ t.Helper()
+ for _, app := range []string{"welcome", "scratchpad"} {
+ if _, err := store.ClaimInstall(context.Background(), b.db, app, "acme-"+app+".test"); err != nil {
+ t.Fatal(err)
+ }
+ if err := store.SetInstallState(context.Background(), b.db, app, "installed", ""); err != nil {
+ t.Fatal(err)
+ }
+ }
+}
+
+// gridNames is every app Home's grid should hold, in order.
+func gridNames(apps []config.OficinaApp) string {
+ b, _ := json.Marshal(append(names(apps), "Scratchpad", "Welcome"))
+ return string(b)
+}
+
+func names(apps []config.OficinaApp) []string {
+ var out []string
+ for _, a := range apps {
+ out = append(out, a.Name)
+ }
+ return out
+}
+
+// appsPanelJS checks Home's apps panel on a wide screen: glass, at most
+// 960px and under the steps; every app in order in a wrapping grid of 64px
+// icons, inside the panel; then a hairline and the dock of Base's own pages.
+const appsPanelJS = `((want) => {
+ const problems = [], vw = document.documentElement.clientWidth;
+ const panel = document.querySelector("nav.apps");
+ if (!panel || !panel.checkVisibility()) return "no apps panel";
+ const p = panel.getBoundingClientRect(), ps = getComputedStyle(panel);
+ if (panel.getAttribute("aria-label") !== "Apps") problems.push("panel labelled " + panel.getAttribute("aria-label"));
+ if (ps.backdropFilter === "none") problems.push("the panel is not glass");
+ if (p.width > 960.5) problems.push("panel is " + p.width + " wide");
+ if (p.top < document.querySelector(".steps").getBoundingClientRect().bottom) problems.push("panel is not under the steps");
+ if (p.left < 0 || p.right > vw) problems.push("panel at " + p.left + "-" + p.right + " of " + vw);
+ const grid = [...panel.querySelectorAll(".app-grid a.app")];
+ const got = grid.map(a => a.textContent.trim());
+ if (JSON.stringify(got) !== JSON.stringify(want)) problems.push("grid " + JSON.stringify(got));
+ const dock = [...panel.querySelectorAll(".dock a.app")];
+ if (dock.map(a => a.getAttribute("href")).join(" ") !== "/store /people /settings") problems.push("dock " + dock.map(a => a.getAttribute("href")));
+ for (const a of grid.concat(dock)) {
+ const r = a.getBoundingClientRect(), i = a.querySelector(".icon").getBoundingClientRect();
+ if (r.width < 44 || r.height < 44) problems.push(a.textContent.trim() + " is " + r.width + "x" + r.height);
+ if (Math.abs(i.width - 64) > 2 || Math.abs(i.height - 64) > 2) problems.push(a.textContent.trim() + "'s icon is " + i.width + "x" + i.height);
+ if (r.left < p.left || r.right > p.right || r.top < p.top || r.bottom > p.bottom) problems.push(a.textContent.trim() + " is outside the panel");
+ const img = a.querySelector("img");
+ if (img && (!img.complete || img.naturalWidth === 0)) problems.push(a.textContent.trim() + "'s icon did not load");
+ }
+ for (const a of grid.slice(0, 8)) if (a.target !== "_blank" || a.rel !== "noopener") problems.push(a.textContent.trim() + " target/rel");
+ const d = panel.querySelector(".dock"), ds = getComputedStyle(d);
+ if (parseFloat(ds.borderTopWidth) !== 1 || ds.borderTopStyle !== "solid") problems.push("no hairline over the dock: " + ds.borderTop);
+ if (grid.length && d.getBoundingClientRect().top < grid[grid.length - 1].getBoundingClientRect().bottom) problems.push("the dock is not under the grid");
+ if (document.documentElement.scrollWidth > vw) problems.push("page is " + document.documentElement.scrollWidth + " wide");
+ return problems.join("; ");
+})`
+
+// springboardJS checks Home on a phone: four columns of 60px icons, and a
+// glass dock fixed to the foot of the screen that stays put while the grid
+// scrolls, never covering an app.
+const springboardJS = `((want) => {
+ const problems = [], vw = document.documentElement.clientWidth, vh = innerHeight;
+ const grid = [...document.querySelectorAll(".app-grid a.app")];
+ const got = grid.map(a => a.textContent.trim());
+ if (JSON.stringify(got) !== JSON.stringify(want)) problems.push("grid " + JSON.stringify(got));
+ const tops = grid.map(a => Math.round(a.getBoundingClientRect().top));
+ if (new Set(tops.slice(0, 4)).size !== 1 || tops[4] <= tops[0]) problems.push("not four columns: " + tops.join(","));
+ for (const a of grid) {
+ const r = a.getBoundingClientRect(), i = a.querySelector(".icon").getBoundingClientRect();
+ if (Math.abs(i.width - 60) > 2 || Math.abs(i.height - 60) > 2) problems.push(a.textContent.trim() + "'s icon is " + i.width + "x" + i.height);
+ if (r.width < 44 || r.height < 44) problems.push(a.textContent.trim() + " is " + r.width + "x" + r.height);
+ if (r.left < 0 || r.right > vw) problems.push(a.textContent.trim() + " runs off the side");
+ }
+ const dock = document.querySelector(".dock"), ds = getComputedStyle(dock);
+ if (ds.position !== "fixed" || ds.backdropFilter === "none") problems.push("dock " + ds.position + ", " + ds.backdropFilter);
+ const before = dock.getBoundingClientRect();
+ if (before.bottom > vh || before.bottom < vh - 40 || before.left < 0 || before.right > vw) problems.push("dock at " + [before.left, before.top, before.right, before.bottom].join(","));
+ const links = [...dock.querySelectorAll("a.app")];
+ if (links.map(a => a.getAttribute("href")).join(" ") !== "/store /people /settings") problems.push("dock holds " + links.map(a => a.getAttribute("href")));
+ for (const a of links) { const r = a.getBoundingClientRect(); if (r.width < 44 || r.height < 44) problems.push(a.textContent.trim() + " is " + r.width + "x" + r.height); }
+ window.scrollTo(0, document.documentElement.scrollHeight);
+ const after = dock.getBoundingClientRect(), last = grid[grid.length - 1].getBoundingClientRect();
+ if (Math.abs(after.top - before.top) > 0.5) problems.push("the dock moved when Home scrolled");
+ if (last.bottom > after.top) problems.push("the last app (bottom " + last.bottom + ") is under the dock (top " + after.top + ")");
+ window.scrollTo(0, 0);
+ if (document.documentElement.scrollWidth > vw) problems.push("page is " + document.documentElement.scrollWidth + " wide");
+ return problems.join("; ");
+})`
+
+// On a wide screen Home is the greeting, the steps and one glass panel
+// of every app, with Base's own pages in a dock at its foot. Nothing runs
+// off the screen at any width, and the keyboard reaches every app in order.
+func TestHomeApps(t *testing.T) {
+ apps := teamApps(t)
+ rig, _, b := askBaseWith(t, func(c *config.Config) { c.OficinaApps = apps })
+ installAll(t, b)
+ for _, scheme := range []string{"dark", "light"} {
+ for _, w := range []int64{1280, 1024, 800, 700} {
+ drive(t, rig, reducedMotion(scheme, false), chromedp.EmulateViewport(w, 800),
+ chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS("nav.apps")))
+ if got := harness.Evaluate[string](rig, appsPanelJS+`(`+gridNames(apps)+`)`); got != "" {
+ t.Errorf("%s at %dx800: %s", scheme, w, got)
+ }
+ if w == 1280 {
+ checkContrast(t, rig, "Home, "+scheme, ".lede", ".app-grid .label", ".dock .label")
+ layoutShot(t, rig, "desktop-home-"+scheme)
+ }
+ }
+ }
+ // The keyboard: the top bar, then every app, then the dock.
+ drive(t, rig, chromedp.EmulateViewport(1280, 800), chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS("nav.apps")))
+ var seen []string
+ for range 3 + len(apps) + 2 + 3 {
+ drive(t, rig, chromedp.KeyEvent("\t"))
+ seen = append(seen, harness.Evaluate[string](rig, `document.activeElement.matches(":focus-visible") ? document.activeElement.textContent.trim() : "(no visible focus)"`))
+ }
+ want := append(append([]string{"Ask Base anything", "PC"}, append(names(apps), "Scratchpad", "Welcome")...), "Store", "People", "Settings")
+ if fmt.Sprint(seen[:len(want)]) != fmt.Sprint(want) && fmt.Sprint(seen[1:len(want)+1]) != fmt.Sprint(want) {
+ t.Errorf("Tab visits %v, want %v", seen, want)
+ }
+}
+
+// popoverJS checks the chat on a wide screen: a popover under the Ask
+// field, about 440px wide and min(640px, the screen less 120px) tall, inside
+// the screen, with its pointer over the field.
+const popoverJS = `(() => {
+ const problems = [], vw = document.documentElement.clientWidth, vh = innerHeight;
+ const d = document.querySelector("#ask-panel"), r = d.getBoundingClientRect();
+ const f = document.querySelector("a.ask").getBoundingClientRect();
+ const w = Math.min(440, vw - 24), h = Math.min(640, vh - 120);
+ if (Math.abs(r.width - w) > 1) problems.push("width " + r.width + ", want " + w);
+ if (Math.abs(r.height - h) > 1) problems.push("height " + r.height + ", want " + h);
+ if (r.top < f.bottom + 4 || r.top > f.bottom + 24) problems.push("top " + r.top + ", the field ends at " + f.bottom);
+ if (r.left < 12 - 0.5 || r.right > vw - 12 + 0.5 || r.bottom > vh) problems.push("at " + [r.left, r.top, r.right, r.bottom].join(","));
+ const p = getComputedStyle(d, "::before");
+ if (p.content === "none") return problems.concat("no pointer").join("; ");
+ const px = r.left + parseFloat(p.left) + parseFloat(p.width) / 2;
+ if (px < f.left || px > f.right) problems.push("pointer at " + px + ", the field is " + f.left + "-" + f.right);
+ if (r.left + parseFloat(p.left) < r.left + 12 || r.left + parseFloat(p.left) + parseFloat(p.width) > r.right - 12) problems.push("the pointer is off the popover's edge");
+ if (document.documentElement.scrollWidth > vw) problems.push("page overflows");
+ return problems.join("; ");
+})()`
+
+// openedJS is true once the panel is open and done moving.
+const openedJS = `(() => { const d = document.querySelector("#ask-panel"), s = getComputedStyle(d);
+ return d.open && s.opacity === "1" && (s.transform === "none" || s.transform === "matrix(1, 0, 0, 1, 0, 0)"); })()`
+
+// On a wide screen the chat is a glass popover under the Ask field, not a
+// side panel; Escape or a click outside closes it, and focus goes back to
+// the field.
+func TestAskPopover(t *testing.T) {
+ apps := teamApps(t)
+ rig, _, b := askBaseWith(t, func(c *config.Config) { c.OficinaApps = apps })
+ installAll(t, b)
+ for _, size := range [][2]int64{{1280, 800}, {1024, 800}, {800, 800}, {700, 800}, {1280, 600}} {
+ when := fmt.Sprintf("%dx%d", size[0], size[1])
+ drive(t, rig, reducedMotion("dark", false), chromedp.EmulateViewport(size[0], size[1]), chromedp.Navigate(rig.Origin+"/"),
+ chromedp.WaitVisible(chromedp.CSS("a.ask")), chromedp.Click(chromedp.CSS("a.ask")),
+ chromedp.Poll[chromedp.Void](openedJS, chromedp.WithPollingTimeout(5*time.Second)))
+ if got := harness.Evaluate[string](rig, popoverJS); got != "" {
+ t.Errorf("%s: %s", when, got)
+ }
+ // A click outside closes it; focus goes back to the field.
+ drive(t, rig, chromedp.MouseClickXY(30, float64(size[1])-30),
+ chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel").open`, chromedp.WithPollingTimeout(3*time.Second)))
+ if got := harness.Evaluate[string](rig, `document.activeElement.className`); got != "ask" {
+ t.Errorf("%s: after a click outside focus is on %q", when, got)
+ }
+ }
+ // Mid-conversation, in both themes.
+ for _, scheme := range []string{"dark", "light"} {
+ drive(t, rig, reducedMotion(scheme, false), chromedp.EmulateViewport(1280, 800), chromedp.Navigate(rig.Origin+"/"),
+ chromedp.WaitVisible(chromedp.CSS("a.ask")), chromedp.Click(chromedp.CSS("a.ask")),
+ chromedp.Poll[chromedp.Void](openedJS, chromedp.WithPollingTimeout(5*time.Second)))
+ if harness.Evaluate[int](rig, `document.querySelectorAll("#ask-panel .msg.coordinator").length`) == 0 {
+ drive(t, rig, chromedp.SendKeys(chromedp.CSS(`#ask-text`), "What can I do"),
+ chromedp.Click(chromedp.CSS(`#ask-panel form.composer button`)),
+ chromedp.Poll[chromedp.Void](`[...document.querySelectorAll("#ask-panel .msg.coordinator")].some(m => !m.classList.contains("draft"))`,
+ chromedp.WithPollingTimeout(10*time.Second)))
+ }
+ if got := harness.Evaluate[string](rig, popoverJS); got != "" {
+ t.Errorf("%s, mid-conversation: %s", scheme, got)
+ }
+ checkContrast(t, rig, "the popover, "+scheme, "#ask-panel .msg.person", "#ask-panel .msg.coordinator", "#ask-panel .ask-head h2")
+ layoutShot(t, rig, "desktop-chat-"+scheme)
+ drive(t, rig, chromedp.KeyEvent("\u001b"),
+ chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel").open`, chromedp.WithPollingTimeout(3*time.Second)))
+ if got := harness.Evaluate[string](rig, `document.activeElement.className`); got != "ask" {
+ t.Errorf("%s: after Escape focus is on %q", scheme, got)
+ }
+ }
+ drive(t, rig, reducedMotion("dark", false))
+}
diff --git a/internal/browsertest/light_test.go b/internal/browsertest/light_test.go
index b333734..4eb837c 100644
--- a/internal/browsertest/light_test.go
+++ b/internal/browsertest/light_test.go
@@ -23,7 +23,6 @@ import (
"amadan.net/rastrillo/rastrillo/harness"
"amadan.net/carlos/base/internal/config"
- "amadan.net/carlos/base/internal/store"
)
// prefersScheme emulates the device's light or dark setting.
@@ -247,15 +246,7 @@ const (
func TestLightMode(t *testing.T) {
apps := teamApps(t)
rig, _, b := askBaseWith(t, func(c *config.Config) { c.OficinaApps = apps })
- // Welcome and Scratchpad installed, so every tile tint is on Home.
- for _, app := range []string{"welcome", "scratchpad"} {
- if _, err := store.ClaimInstall(context.Background(), b.db, app, "acme-"+app+".test"); err != nil {
- t.Fatal(err)
- }
- if err := store.SetInstallState(context.Background(), b.db, app, "installed", ""); err != nil {
- t.Fatal(err)
- }
- }
+ installAll(t, b) // every tile tint on Home
home := func() {
t.Helper()
drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(".hello")))
@@ -276,12 +267,12 @@ func TestLightMode(t *testing.T) {
// Light Home: the greeting, the lede, the steps, the Ask field and the
// rail's labels.
- checkContrast(t, rig, "Home, light", ".hello", ".lede", ".team", ".steps li", "a.ask", "nav.rail a.rail-app span", ".dock a.app")
+ checkContrast(t, rig, "Home, light", ".hello", ".lede", ".team", ".steps li", "a.ask", ".app-grid .label", ".dock .label")
lightShot(t, rig, "home-desktop")
for _, tint := range []string{"teal", "violet", "mist", "amber", "rose"} {
- iconContrast(t, rig, "Home, light", ".dock .tile.t-"+tint+" svg")
+ iconContrast(t, rig, "Home, light", "nav.apps .tile.t-"+tint+" svg")
}
- for _, sel := range []string{"a.ask", "a.me", "nav.rail a.rail-app", ".dock a.app"} {
+ for _, sel := range []string{"a.ask", "a.me", ".app-grid a.app", ".dock a.app"} {
focusRing(t, rig, "Home, light", sel)
}
@@ -296,13 +287,6 @@ func TestLightMode(t *testing.T) {
lightShot(t, rig, "home-panel-open")
drive(t, rig, chromedp.KeyEvent("\u001b"))
- // More's panel.
- drive(t, rig, chromedp.EmulateViewport(1280, 600))
- home()
- drive(t, rig, chromedp.Click(chromedp.CSS(`details.rail-more summary`)), chromedp.WaitVisible(chromedp.CSS(`.rail-panel`)))
- checkContrast(t, rig, "More's panel, light", ".rail-panel a span", ".rail-panel .switch span")
- lightShot(t, rig, "home-more-open")
-
// Settings.
drive(t, rig, chromedp.EmulateViewport(1280, 800), chromedp.Navigate(rig.Origin+"/settings"), chromedp.WaitVisible(chromedp.CSS(`form.segmented`)))
checkContrast(t, rig, "Settings, light", ".sheet h2", ".people .who", ".people .who small", ".soon", "form.segmented button")
@@ -314,8 +298,9 @@ func TestLightMode(t *testing.T) {
// A phone.
drive(t, rig, chromedp.EmulateViewport(390, 844, chromedp.EmulateMobile, chromedp.EmulateScale(3)))
home()
- checkContrast(t, rig, "Home on a phone, light", ".lede", ".oficina h3", ".oficina a.app", ".dock a.app")
+ checkContrast(t, rig, "Home on a phone, light", ".lede", ".app-grid .label", ".dock .label")
lightShot(t, rig, "home-phone")
+ layoutShot(t, rig, "phone-home-light")
noOverflow(t, rig, "Home on a phone, light")
drive(t, rig, chromedp.EmulateViewport(1280, 800))
diff --git a/internal/browsertest/mobile_test.go b/internal/browsertest/mobile_test.go
index b9e3fa5..82677d2 100644
--- a/internal/browsertest/mobile_test.go
+++ b/internal/browsertest/mobile_test.go
@@ -7,6 +7,7 @@ import (
"net/http"
"os"
"path/filepath"
+ "regexp"
"testing"
"time"
@@ -73,9 +74,10 @@ func TestMobile(t *testing.T) {
b = newBase(t, cfg)
return b.handler
})
- drive(t, rig, chromedp.EmulateViewport(390, 844, chromedp.EmulateMobile, chromedp.EmulateScale(3)))
+ drive(t, rig, chromedp.EmulateViewport(390, 844, chromedp.EmulateMobile, chromedp.EmulateScale(3)), reducedMotion("dark", false))
drive(t, rig, chromedp.Navigate(rig.Origin+"/signin"), chromedp.WaitVisible(chromedp.CSS(`input[name="address"]`)))
noOverflow(t, rig, "sign-in")
+ installAll(t, b)
signInByEmail(t, rig, rig.Origin, b.mail)
// Home: on a phone the Ask field is a round icon button, on one line
@@ -101,37 +103,20 @@ func TestMobile(t *testing.T) {
}
mobileShot(t, rig, "1-home")
- // Home: no rail on a phone; the team's Oficina apps are tiles, the size
- // of Store's, under a small heading above Store, People and Settings.
- if got := harness.Evaluate[string](rig, `((want) => {
- const problems = [];
- const rail = document.querySelector("nav.rail");
- if (rail && rail.checkVisibility()) problems.push("the rail shows");
- const sec = document.querySelector("section.oficina");
- if (!sec || !sec.checkVisibility()) return "no Oficina tiles";
- const h = sec.querySelector("h3");
- if (!h || h.textContent !== "Oficina" || !h.checkVisibility()) problems.push("no Oficina heading");
- const links = [...sec.querySelectorAll("a.app")];
- const got = links.map(a => ({Name: a.textContent.trim(), Href: a.getAttribute("href")}));
- if (JSON.stringify(got) !== JSON.stringify(want)) problems.push("apps " + JSON.stringify(got));
- const store = document.querySelector('.dock a[href="/store"] .tile').getBoundingClientRect();
- for (const a of links) {
- const t = a.querySelector(".tile").getBoundingClientRect();
- if (Math.round(t.width) !== Math.round(store.width) || Math.round(t.height) !== Math.round(store.height)) problems.push(a.textContent + " is " + t.width + "x" + t.height);
- if (a.target !== "_blank" || a.rel !== "noopener") problems.push(a.textContent + " target " + a.target + " rel " + a.rel);
- const img = a.querySelector("img");
- if (!img || !img.complete || img.naturalWidth === 0) problems.push(a.textContent + "'s icon did not load");
- }
- if (links.length && links[links.length - 1].getBoundingClientRect().bottom > store.top) problems.push("the tiles are not above Store");
- return problems.join("; ");
- })(`+wantApps(t, apps)+`)`); got != "" {
- t.Errorf("Oficina on a phone: %s", got)
+ // Home on a phone is a springboard: four columns of apps and a glass
+ // dock of Store, People and Settings fixed to the foot of the screen.
+ if got := harness.Evaluate[string](rig, springboardJS+`(`+gridNames(apps)+`)`); got != "" {
+ t.Errorf("the springboard: %s", got)
}
+ checkContrast(t, rig, "Home on a phone, dark", ".lede", ".app-grid .label", ".dock .label")
viewportShot(t, rig, "home-phone")
+ layoutShot(t, rig, "phone-home-dark")
// The panel before connecting.
drive(t, rig, chromedp.Click(chromedp.CSS(`a.ask-icon`)),
- chromedp.WaitVisible(chromedp.CSS(`#ask-panel [data-when="connect"] button`)))
+ chromedp.WaitVisible(chromedp.CSS(`#ask-panel [data-when="connect"] button`)),
+ // The sheet slides up; click once it has arrived.
+ chromedp.Poll[chromedp.Void](`document.querySelector("#ask-panel").getBoundingClientRect().top === 0`, chromedp.WithPollingTimeout(3*time.Second)))
mobileShot(t, rig, "2-panel-connect")
// Connect from the panel: the code page, then back to the open panel.
@@ -145,7 +130,8 @@ func TestMobile(t *testing.T) {
t.Fatal(err)
}
drive(t, rig, chromedp.Click(chromedp.CSS(`form[action="/ask/connect/check"] button`)),
- chromedp.WaitVisible(chromedp.CSS(`#ask-panel textarea`)))
+ chromedp.WaitVisible(chromedp.CSS(`#ask-panel textarea`)),
+ chromedp.Poll[chromedp.Void](`document.querySelector("#ask-panel").getBoundingClientRect().top === 0`, chromedp.WithPollingTimeout(3*time.Second)))
// Mid-conversation: the sheet fills the screen, the header is at the
// top, the composer on screen at the bottom, targets 44px.
@@ -186,6 +172,12 @@ func TestMobile(t *testing.T) {
t.Errorf("the panel on a phone: %s", got)
}
mobileShot(t, rig, "4-panel-conversation")
+ layoutShot(t, rig, "phone-chat-dark")
+ // Home behind the sheet is pushed back: smaller, dimmed and blurred.
+ if got := harness.Evaluate[string](rig, `(() => { const s = getComputedStyle(document.querySelector("main.home"));
+ return s.transform + " | " + s.filter; })()`); !regexp.MustCompile(`^matrix\(0\.94, 0, 0, 0\.94, [^)]*\) \| .*blur\(`).MatchString(got) {
+ t.Errorf("Home behind the open sheet: %s, want scaled to 0.94 and blurred", got)
+ }
mobileShot(t, rig, "4c-panel-tight")
mobileShot(t, rig, "4d-panel-menu-closed")
drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel summary`)), chromedp.WaitVisible(chromedp.CSS(`#ask-panel .ask-menu a`)))
@@ -195,11 +187,31 @@ func TestMobile(t *testing.T) {
chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel").open`, chromedp.WithPollingTimeout(3*time.Second)))
// Focus goes back once the close event has run.
drive(t, rig, chromedp.Poll[chromedp.Void](`document.activeElement.className === "ask-icon"`, chromedp.WithPollingTimeout(3*time.Second)))
- // Reopened from the icon, mid-conversation.
- drive(t, rig, chromedp.Click(chromedp.CSS(`a.ask-icon`)), chromedp.WaitVisible(chromedp.CSS(`#ask-panel .msg.coordinator`)))
+ // Reopened from the icon, mid-conversation: the sheet slides up.
+ drive(t, rig, chromedp.Click(chromedp.CSS(`a.ask-icon`)), chromedp.Sleep(90*time.Millisecond))
+ if top := harness.Evaluate[float64](rig, `document.querySelector("#ask-panel").getBoundingClientRect().top`); top <= 1 {
+ t.Errorf("the sheet did not slide up: at %v moments after opening", top)
+ }
+ opening := harness.Read(rig, chromedp.CaptureScreenshot())
+ if dir := os.Getenv("BASE_LAYOUT_ARTIFACTS"); dir != "" {
+ if err := os.WriteFile(filepath.Join(dir, "phone-chat-opening.png"), opening, 0o644); err != nil {
+ t.Fatal(err)
+ }
+ }
+ drive(t, rig, chromedp.WaitVisible(chromedp.CSS(`#ask-panel .msg.coordinator`)),
+ chromedp.Poll[chromedp.Void](`document.querySelector("#ask-panel").getBoundingClientRect().top === 0`, chromedp.WithPollingTimeout(3*time.Second)))
mobileShot(t, rig, "4b-home-panel-open")
drive(t, rig, chromedp.KeyEvent("\u001b"))
+ // With reduced motion there is no slide and no push-back: it just shows.
+ drive(t, rig, reducedMotion("dark", true), chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel").open`, chromedp.WithPollingTimeout(3*time.Second)),
+ chromedp.Click(chromedp.CSS(`a.ask-icon`)), chromedp.Sleep(30*time.Millisecond))
+ if got := harness.Evaluate[string](rig, `(() => { const d = document.querySelector("#ask-panel").getBoundingClientRect();
+ return d.top + " " + getComputedStyle(document.querySelector("main.home")).transform; })()`); got != "0 none" {
+ t.Errorf("with reduced motion the sheet is at %s (want 0 none)", got)
+ }
+ drive(t, rig, chromedp.KeyEvent("\u001b"), reducedMotion("dark", false))
+
for _, p := range []struct{ path, wait, name string }{
{"/store", ".sheet", "5-store"},
{"/people", ".sheet", "6-people"},
diff --git a/internal/browsertest/oficina_test.go b/internal/browsertest/oficina_test.go
index e34bb1a..9a4ef62 100644
--- a/internal/browsertest/oficina_test.go
+++ b/internal/browsertest/oficina_test.go
@@ -5,21 +5,15 @@ package browsertest
import (
"context"
"encoding/json"
- "fmt"
- "net/http"
"os"
"path/filepath"
"testing"
- "time"
- "github.com/chromedp/cdproto/cdp"
- "github.com/chromedp/cdproto/network"
"github.com/chromedp/chromedp"
"amadan.net/rastrillo/rastrillo/harness"
"amadan.net/carlos/base/internal/config"
- "amadan.net/carlos/base/internal/equipo/equipotest"
)
// teamApps is every Oficina app, as the team's BASE_OFICINA_APPS lists them.
@@ -74,393 +68,3 @@ func viewportShot(t *testing.T, rig *harness.Rig, name string) {
t.Fatal(err)
}
}
-
-// On a wide screen Home has a slim glass rail of the team's Oficina apps
-// down the left, under the top bar, beside Home's content and not over it.
-// Each is a plain link that opens the app in a new tab, a 44px target that
-// the keyboard reaches with a visible focus ring.
-func TestOficinaRail(t *testing.T) {
- f := equipotest.New(t)
- apps := teamApps(t)
- var b *baseApp
- rig := newRig(t, func(origin string) http.Handler {
- cfg := baseConfig(origin)
- cfg.EquipoOrigin = f.URL
- cfg.OficinaApps = apps
- b = newBase(t, cfg)
- return b.handler
- })
- drive(t, rig, chromedp.EmulateViewport(1280, 800))
- signInByEmail(t, rig, rig.Origin, b.mail)
- noOverflow(t, rig, "Home")
-
- if got := harness.Evaluate[string](rig, `((want) => {
- const problems = [];
- const rail = document.querySelector("nav.rail");
- if (!rail || !rail.checkVisibility()) return "no rail";
- if (rail.getAttribute("aria-label") !== "Oficina") problems.push("rail labelled " + rail.getAttribute("aria-label"));
- const phone = document.querySelector("section.oficina");
- if (phone && phone.checkVisibility()) problems.push("the phone's tiles show too");
- const links = [...rail.querySelectorAll(":scope > a.rail-app")];
- const got = links.map(a => ({Name: a.textContent.trim(), Href: a.getAttribute("href")}));
- if (JSON.stringify(got) !== JSON.stringify(want)) problems.push("apps " + JSON.stringify(got));
- for (const a of links) {
- const r = a.getBoundingClientRect();
- if (a.target !== "_blank" || a.rel !== "noopener") problems.push(a.textContent + " target " + a.target + " rel " + a.rel);
- if (r.width < 44 || r.height < 44) problems.push(a.textContent + " is " + r.width + "x" + r.height);
- const img = a.querySelector("img");
- if (!img || !img.complete || img.naturalWidth === 0) problems.push(a.textContent + "'s icon did not load");
- if (r.bottom > window.innerHeight) problems.push(a.textContent + " is below the fold at " + r.bottom);
- }
- const rr = rail.getBoundingClientRect(), bar = document.querySelector(".topbar").getBoundingClientRect();
- if (rr.top < bar.bottom + 8) problems.push("rail top " + rr.top + " under the top bar's bottom " + bar.bottom);
- if (Math.abs(rr.left - bar.left) > 1) problems.push("rail left " + rr.left + ", top bar left " + bar.left);
- if (rr.width > 96) problems.push("rail is " + rr.width + "px wide");
- for (const sel of [".home-body", ".hello", ".lede", ".steps", ".dock"]) {
- const r = document.querySelector(sel).getBoundingClientRect();
- if (r.left < rr.right + 12) problems.push(sel + " starts at " + r.left + ", rail ends at " + rr.right);
- }
- return problems.join("; ");
- })(`+wantApps(t, apps)+`)`); got != "" {
- t.Errorf("the rail: %s", got)
- }
-
- // The keyboard reaches the rail after the top bar, and shows where it is.
- drive(t, rig, chromedp.KeyEvent("\t"), chromedp.KeyEvent("\t"), chromedp.KeyEvent("\t"))
- if got := harness.Evaluate[string](rig, `(() => {
- const a = document.activeElement;
- if (!a.matches("nav.rail a:first-child")) return "focus is on " + a.outerHTML.slice(0, 80);
- const s = getComputedStyle(a);
- if (!a.matches(":focus-visible") || s.outlineStyle !== "solid" || parseFloat(s.outlineWidth) < 2) return "no visible focus: " + s.outline;
- const r = a.getBoundingClientRect(), rail = document.querySelector("nav.rail").getBoundingClientRect();
- const off = parseFloat(s.outlineOffset), w = parseFloat(s.outlineWidth);
- if (r.left - off - w < rail.left - 0.5 && getComputedStyle(document.querySelector("nav.rail")).overflowX !== "visible") return "focus ring clipped";
- return "";
- })()`); got != "" {
- t.Errorf("keyboard: %s", got)
- }
- viewportShot(t, rig, "home-desktop-focus")
-
- // The rail stays on screen when Home scrolls (a long Home stands in for
- // one with many apps installed).
- if got := harness.Evaluate[string](rig, `(() => {
- const tall = document.createElement("div");
- tall.style.height = "2000px";
- document.querySelector(".home-body").append(tall);
- window.scrollTo(0, 1200);
- const r = document.querySelector("nav.rail").getBoundingClientRect(), y = window.scrollY;
- tall.remove();
- if (y < 1000) return "Home did not scroll: " + y;
- if (r.top < 0 || r.bottom > window.innerHeight || r.height < 100) return "rail at " + r.top + "-" + r.bottom + " of " + window.innerHeight;
- return "";
- })()`); got != "" {
- t.Errorf("after scrolling Home: %s", got)
- }
-
- drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(".hello")))
- viewportShot(t, rig, "home-desktop")
-}
-
-// The open Ask panel keeps a gap to the Oficina rail at every width the
-// rail shows at, and nothing runs off the screen.
-func TestAskPanelBesideRail(t *testing.T) {
- f := equipotest.New(t)
- apps := teamApps(t)
- var b *baseApp
- rig := newRig(t, func(origin string) http.Handler {
- cfg := baseConfig(origin)
- cfg.EquipoOrigin = f.URL
- cfg.OficinaApps = apps
- b = newBase(t, cfg)
- return b.handler
- })
- drive(t, rig, chromedp.EmulateViewport(1280, 800))
- signInByEmail(t, rig, rig.Origin, b.mail)
- for _, width := range []int64{601, 640, 700, 800, 900, 1024, 1280} {
- drive(t, rig, chromedp.EmulateViewport(width, 800), chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(`a.ask`)),
- chromedp.Click(chromedp.CSS(`a.ask`)),
- chromedp.Poll[chromedp.Void](`(() => { const p = document.querySelector("#ask-panel"); return p.open && getComputedStyle(p).transform === "none" && getComputedStyle(p).opacity === "1"; })()`,
- chromedp.WithPollingTimeout(5*time.Second)))
- if got := harness.Evaluate[string](rig, `(() => {
- const problems = [], vw = document.documentElement.clientWidth;
- const rail = document.querySelector("nav.rail").getBoundingClientRect();
- const p = document.querySelector("#ask-panel").getBoundingClientRect();
- if (rail.width === 0) problems.push("no rail");
- if (p.left < rail.right + 12 || p.width < 200) problems.push("panel starts at " + p.left + ", rail ends at " + rail.right);
- if (p.right > vw) problems.push("panel ends at " + p.right + " of " + vw);
- if (p.width > 460.5) problems.push("panel is " + p.width + " wide");
- if (document.documentElement.scrollWidth > vw) problems.push("page is " + document.documentElement.scrollWidth + " wide");
- return problems.join("; ");
- })()`); got != "" {
- t.Errorf("at %dx800: %s", width, got)
- }
- if width == 800 || width == 1280 {
- viewportShot(t, rig, fmt.Sprintf("panel-%d", width))
- }
- drive(t, rig, chromedp.KeyEvent("\u001b"),
- chromedp.Poll[chromedp.Void](`!document.querySelector("#ask-panel").open`, chromedp.WithPollingTimeout(5*time.Second)))
- }
-}
-
-// railState is what the rail shows: the apps in it, whether More shows and
-// the apps its panel lists while open, as names; and any problem with how
-// it sits on screen.
-const railStateJS = `(() => {
- const rail = document.querySelector("nav.rail"), vw = document.documentElement.clientWidth, vh = window.innerHeight;
- const rr = rail.getBoundingClientRect(), problems = [];
- const shown = [...rail.querySelectorAll(":scope > a.rail-app")].filter(a => a.checkVisibility());
- const more = rail.querySelector(":scope > details.rail-more");
- const moreShown = !!more && more.checkVisibility();
- const panel = more ? more.querySelector(".rail-panel") : null;
- const listed = panel && more.open ? [...panel.querySelectorAll("a")].filter(a => a.checkVisibility()) : [];
- const entries = shown.concat(moreShown ? [more.querySelector("summary")] : []);
- for (const e of entries) {
- const r = e.getBoundingClientRect();
- if (r.width < 44 || r.height < 44) problems.push(e.textContent.trim() + " is " + r.width + "x" + r.height);
- if (r.top < rr.top - 0.5 || r.bottom > rr.bottom + 0.5) problems.push(e.textContent.trim() + " sticks out of the rail");
- if (r.bottom > vh) problems.push(e.textContent.trim() + " is below the screen");
- }
- if (panel && more.open) {
- const p = panel.getBoundingClientRect();
- if (panel.getAttribute("role") !== "region" || panel.getAttribute("aria-label") !== "More Oficina apps") problems.push("panel not a labelled region");
- if (p.left < rr.right || p.right > vw || p.top < 0 || p.bottom > vh) problems.push("panel at " + [p.left, p.top, p.right, p.bottom].join(","));
- for (const e of listed.concat([...panel.querySelectorAll("button")])) {
- const r = e.getBoundingClientRect();
- if (r.height < 44) problems.push(e.textContent.trim() + " in the panel is " + r.height + " tall");
- if (e.matches("a") && (e.target !== "_blank" || e.rel !== "noopener")) problems.push(e.textContent + " target/rel");
- }
- const hit = document.elementFromPoint(p.left + p.width / 2, p.top + 12);
- if (!panel.contains(hit)) problems.push("the panel is under " + (hit && hit.className));
- }
- if (document.documentElement.scrollWidth > vw) problems.push("page is " + document.documentElement.scrollWidth + " wide");
- return JSON.stringify({rail: shown.map(a => a.textContent.trim()), more: moreShown, panel: listed.map(a => a.textContent.trim()),
- expanded: rail.classList.contains("expanded"), problems: problems.join("; ")});
-})()`
-
-type railState struct {
- Rail, Panel []string
- More bool
- Expanded bool
- Problems string
-}
-
-func readRail(t *testing.T, rig *harness.Rig) railState {
- t.Helper()
- var s railState
- if err := json.Unmarshal([]byte(harness.Evaluate[string](rig, railStateJS)), &s); err != nil {
- t.Fatal(err)
- }
- return s
-}
-
-func names(apps []config.OficinaApp) []string {
- var out []string
- for _, a := range apps {
- out = append(out, a.Name)
- }
- return out
-}
-
-func same(a, b []string) bool { return fmt.Sprint(a) == fmt.Sprint(b) }
-
-// tabThrough presses Tab until focus leaves the rail, opening More with
-// Enter on the way, and returns the hrefs (or labels) focus visited in it.
-func tabThrough(t *testing.T, rig *harness.Rig) []string {
- t.Helper()
- drive(t, rig, chromedp.Evaluate[chromedp.Void](`document.activeElement.blur(), window.scrollTo(0, 0)`))
- var seen []string
- for range 30 {
- drive(t, rig, chromedp.KeyEvent("\t"))
- at := harness.Evaluate[string](rig, `(() => { const a = document.activeElement;
- if (!a.closest("nav.rail")) return "";
- if (!a.matches(":focus-visible")) return "no visible focus on " + a.textContent.trim();
- return a.getAttribute("href") || a.textContent.trim(); })()`)
- if at == "" && len(seen) > 0 {
- break
- }
- if at == "" {
- continue
- }
- seen = append(seen, at)
- if at == "More" && !harness.Evaluate[bool](rig, `document.querySelector("details.rail-more").open`) {
- drive(t, rig, chromedp.KeyEvent("\r"))
- }
- }
- return seen
-}
-
-func reachesAll(t *testing.T, seen []string, apps []config.OficinaApp, mode string) {
- t.Helper()
- got := map[string]bool{}
- for _, s := range seen {
- got[s] = true
- }
- for _, a := range apps {
- if !got[a.Origin+"/"] {
- t.Errorf("%s: the keyboard never reaches %s (visited %v)", mode, a.Name, seen)
- }
- }
-}
-
-// The rail shows as many apps as fit; the last spot is More, whose panel
-// lists the rest with the Keep expanded switch. Kept expanded, the rail
-// lists every app and scrolls, ending in Collapse; that holds across
-// sign-ins. All of it works with scripts off too.
-func TestRailMoreInBrowser(t *testing.T) {
- f := equipotest.New(t)
- apps := teamApps(t)
- all := names(apps)
- var b *baseApp
- rig := newRig(t, func(origin string) http.Handler {
- cfg := baseConfig(origin)
- cfg.EquipoOrigin = f.URL
- cfg.OficinaApps = apps
- b = newBase(t, cfg)
- return b.handler
- })
- drive(t, rig, chromedp.EmulateViewport(1280, 600))
- signInByEmail(t, rig, rig.Origin, b.mail)
- home := func() {
- t.Helper()
- drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(".hello")))
- }
-
- // 1280x600: some apps, then More; the panel lists the rest, in order.
- home()
- s := readRail(t, rig)
- if !s.More || s.Expanded || len(s.Rail) == 0 || len(s.Rail) >= len(all) || !same(s.Rail, all[:len(s.Rail)]) || s.Problems != "" {
- t.Fatalf("collapsed at 1280x600: %+v", s)
- }
- viewportShot(t, rig, "more-closed")
- drive(t, rig, chromedp.Click(chromedp.CSS(`details.rail-more summary`)), chromedp.WaitVisible(chromedp.CSS(`.rail-panel`)))
- s = readRail(t, rig)
- if !same(s.Panel, all[len(s.Rail):]) || s.Problems != "" {
- t.Errorf("More's panel at 1280x600: %+v", s)
- }
- viewportShot(t, rig, "more-open")
-
- // Escape from inside the panel closes it and gives focus back to More;
- // so does a click elsewhere.
- drive(t, rig, chromedp.KeyEvent("\t"),
- chromedp.Poll[chromedp.Void](`document.activeElement.matches(".rail-panel a")`, chromedp.WithPollingTimeout(3*time.Second)),
- chromedp.KeyEvent("\u001b"),
- chromedp.Poll[chromedp.Void](`!document.querySelector("details.rail-more").open`, chromedp.WithPollingTimeout(3*time.Second)),
- chromedp.Poll[chromedp.Void](`document.activeElement.matches("details.rail-more summary")`, chromedp.WithPollingTimeout(3*time.Second)))
- drive(t, rig, chromedp.Click(chromedp.CSS(`details.rail-more summary`)), chromedp.WaitVisible(chromedp.CSS(`.rail-panel`)),
- chromedp.Click(chromedp.CSS(`.hello`)),
- chromedp.Poll[chromedp.Void](`!document.querySelector("details.rail-more").open`, chromedp.WithPollingTimeout(3*time.Second)))
- reachesAll(t, tabThrough(t, rig), apps, "collapsed")
-
- // Tall enough for every app: no More.
- drive(t, rig, chromedp.EmulateViewport(1280, 1000))
- home()
- if s := readRail(t, rig); s.More || !same(s.Rail, all) || s.Problems != "" {
- t.Errorf("at 1280x1000: %+v", s)
- }
-
- // Keep expanded: every app, the rail scrolls, Collapse is last.
- drive(t, rig, chromedp.EmulateViewport(1280, 600))
- home()
- drive(t, rig, chromedp.Click(chromedp.CSS(`details.rail-more summary`)), chromedp.WaitVisible(chromedp.CSS(`.rail-panel button[role="switch"]`)),
- chromedp.Click(chromedp.CSS(`.rail-panel button[role="switch"]`)), chromedp.WaitVisible(chromedp.CSS(`nav.rail.expanded`)))
- expanded := func(when string) {
- t.Helper()
- s := readRail(t, rig)
- if !s.Expanded || s.More || !same(s.Rail, all) {
- t.Errorf("%s: %+v", when, s)
- }
- if got := harness.Evaluate[string](rig, `(() => {
- const rail = document.querySelector("nav.rail"), last = rail.lastElementChild;
- if (!last.matches("form.rail-collapse") || last.textContent.trim() !== "Collapse") return "last entry is " + last.outerHTML.slice(0, 80);
- if (rail.scrollHeight <= rail.clientHeight) return "the rail does not scroll";
- if (document.documentElement.scrollWidth > document.documentElement.clientWidth) return "page overflows";
- return "";
- })()`); got != "" {
- t.Errorf("%s: %s", when, got)
- }
- }
- expanded("after Keep expanded")
- viewportShot(t, rig, "expanded")
- reachesAll(t, tabThrough(t, rig), apps, "expanded")
-
- // It holds in a new sign-in on a browser that has never seen Base (no
- // cookies at all), so it is the member's, not the browser's.
- drive(t, rig, chromedp.Func(func(ctx context.Context, target *chromedp.Target) error {
- _, err := cdp.Call(ctx, target, network.ClearBrowserCookies, cdp.Empty{})
- return err
- }))
- signInByEmail(t, rig, rig.Origin, b.mail)
- expanded("after signing in again")
-
- // Collapse puts More back.
- drive(t, rig, chromedp.Click(chromedp.CSS(`form.rail-collapse button`)), chromedp.WaitVisible(chromedp.CSS(`details.rail-more summary`)))
- if s := readRail(t, rig); s.Expanded || !s.More {
- t.Errorf("after Collapse: %+v", s)
- }
-
- // Scripts off: More is a <details>, the switch and Collapse plain POSTs.
- drive(t, rig, scriptsDisabled(true))
- home()
- drive(t, rig, chromedp.Click(chromedp.CSS(`details.rail-more summary`)), chromedp.WaitVisible(chromedp.CSS(`.rail-panel button[role="switch"]`)))
- if s := readRail(t, rig); !same(s.Panel, all[len(s.Rail):]) || s.Problems != "" {
- t.Errorf("More with scripts off: %+v", s)
- }
- drive(t, rig, chromedp.Click(chromedp.CSS(`.rail-panel button[role="switch"]`)), chromedp.WaitVisible(chromedp.CSS(`nav.rail.expanded`)))
- expanded("Keep expanded with scripts off")
- drive(t, rig, chromedp.Click(chromedp.CSS(`form.rail-collapse button`)), chromedp.WaitVisible(chromedp.CSS(`details.rail-more summary`)))
- drive(t, rig, scriptsDisabled(false))
-}
-
-// On a short screen, with Home scrolled so the rail is stuck at the top,
-// More's panel stays on screen: every link in it is visible or a scroll of
-// the panel away, and the keyboard's focus is always in view. With scripts
-// on and off.
-func TestRailMoreShortScreens(t *testing.T) {
- apps := teamApps(t)
- var b *baseApp
- rig := newRig(t, func(origin string) http.Handler {
- cfg := baseConfig(origin)
- cfg.OficinaApps = apps
- b = newBase(t, cfg)
- return b.handler
- })
- drive(t, rig, chromedp.EmulateViewport(1280, 800))
- signInByEmail(t, rig, rig.Origin, b.mail)
- for _, off := range []bool{false, true} {
- for _, h := range []int64{400, 500} {
- when := fmt.Sprintf("1280x%d, scripts off %v", h, off)
- drive(t, rig, scriptsDisabled(off), chromedp.EmulateViewport(1280, h),
- chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS(".hello")),
- chromedp.Evaluate[chromedp.Void](`(() => { const d = document.createElement("div"); d.style.height = "2000px";
- document.querySelector(".home-body").append(d); window.scrollTo(0, 1200); })()`),
- chromedp.Click(chromedp.CSS(`details.rail-more summary`)), chromedp.WaitVisible(chromedp.CSS(`.rail-panel`)))
- if got := harness.Evaluate[string](rig, `(() => {
- const p = document.querySelector(".rail-panel").getBoundingClientRect(), vh = window.innerHeight;
- if (window.scrollY < 1000) return "Home did not scroll";
- if (p.top < 0 || p.bottom > vh) return "panel at " + p.top + "-" + p.bottom + " of " + vh;
- return "";
- })()`); got != "" {
- t.Errorf("%s: %s", when, got)
- }
- // Tab from More through the panel: each link, then the switch.
- drive(t, rig, chromedp.Focus(chromedp.CSS(`details.rail-more summary`)))
- want := harness.Evaluate[int](rig, `[...document.querySelectorAll(".rail-panel a, .rail-panel button")].filter(e => e.checkVisibility()).length`)
- for i := 0; i < want; i++ {
- drive(t, rig, chromedp.KeyEvent("\t"))
- if got := harness.Evaluate[string](rig, `(() => {
- const a = document.activeElement, panel = document.querySelector(".rail-panel");
- if (!panel.contains(a)) return "focus left the panel for " + a.outerHTML.slice(0, 60);
- const r = a.getBoundingClientRect(), p = panel.getBoundingClientRect();
- if (r.top < 0 || r.bottom > window.innerHeight || r.top < p.top - 0.5 || r.bottom > p.bottom + 0.5)
- return a.textContent.trim() + " at " + r.top + "-" + r.bottom + ", panel " + p.top + "-" + p.bottom;
- return "";
- })()`); got != "" {
- t.Errorf("%s, entry %d: %s", when, i+1, got)
- break
- }
- }
- viewportShot(t, rig, fmt.Sprintf("more-short-%d-scripts-off-%v", h, off))
- }
- }
- drive(t, rig, scriptsDisabled(false))
-}
diff --git a/internal/look/rail_test.go b/internal/look/rail_test.go
deleted file mode 100644
index 80e2508..0000000
--- a/internal/look/rail_test.go
+++ /dev/null
@@ -1,33 +0,0 @@
-package look
-
-import (
- "regexp"
- "strconv"
- "testing"
-
- "amadan.net/carlos/base/internal/config"
-)
-
-// moreShownRE is how app.css turns More on in one of its rail cut-off
-// ranges: when an Nth app exists, the rail can't show them all.
-var moreShownRE = regexp.MustCompile(`a\.rail-app:nth-of-type\((\d+)\) ~ \.rail-more \{ display: block; \}`)
-
-// app.css decides how many Oficina apps the rail shows with one
-// @container oficina-rail block per count that fits. Past the last block
-// the rail shows every app, so it must cover every app Base knows.
-func TestRailCutOffsCoverEveryOficinaApp(t *testing.T) {
- css, err := embedded.ReadFile("static/app.css")
- if err != nil {
- t.Fatal(err)
- }
- covered := 0
- for _, m := range moreShownRE.FindAllStringSubmatch(string(css), -1) {
- n, _ := strconv.Atoi(m[1])
- covered = max(covered, n)
- }
- if known := len(config.OficinaIDs()); known > covered {
- t.Errorf("Base knows %d Oficina apps but internal/look/static/app.css's @container oficina-rail cut-offs cover %d: "+
- "add a block for each extra app, the next one (%dpx <= height < %dpx) folding app %d and on under More",
- known, covered, 76*covered-4, 76*(covered+1)-4, covered)
- }
-}
diff --git a/internal/look/static/app.css b/internal/look/static/app.css
index e37139c..a9392dc 100644
--- a/internal/look/static/app.css
+++ b/internal/look/static/app.css
@@ -112,6 +112,7 @@
--theirs-edge: rgba(238,242,248,.16);
--card: rgba(139,92,246,.16);
--card-edge: rgba(139,92,246,.45);
+ --halo: rgba(10,12,30,.75);
}
:root[data-theme="light"] {
color-scheme: light; --sky-stop: 55%; --glass-lift: -22px;
@@ -140,7 +141,7 @@
--sheet-1: rgba(255,255,255,.82); --sheet-2: rgba(255,255,255,.72); --sheet-base: rgba(244,245,252,.6);
--scrim: rgba(30,36,64,.18); --mine: rgba(15,168,156,.14); --mine-edge: rgba(15,168,156,.38);
--theirs: rgba(255,255,255,.88); --theirs-edge: rgba(30,36,64,.1); --card: rgba(139,92,246,.1);
- --card-edge: rgba(124,77,232,.35);
+ --card-edge: rgba(124,77,232,.35); --halo: rgba(255,255,255,.7);
}
:root[data-theme="dark"] { color-scheme: dark; }
@supports (color: light-dark(white, black)) {
@@ -219,6 +220,7 @@
--theirs-edge: light-dark(rgba(30,36,64,.1), rgba(238,242,248,.16));
--card: light-dark(rgba(139,92,246,.1), rgba(139,92,246,.16));
--card-edge: light-dark(rgba(124,77,232,.35), rgba(139,92,246,.45));
+ --halo: light-dark(rgba(255,255,255,.7), rgba(10,12,30,.75));
}
/* The few values that are not colours follow the device too. */
@media (prefers-color-scheme: light) {
@@ -313,8 +315,20 @@ button.alt[aria-busy="true"] { cursor: progress; }
.steps .done .mark { background: var(--signal); box-shadow: none; color: var(--on-signal); }
.steps .done { color: var(--haze); }
-.dock { display: flex; gap: 18px; flex-wrap: wrap; margin-top: auto; padding-top: 44px; }
-.app { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 80px; font-size: 13px; font-weight: 500; }
+/* Home's apps: one glass panel under the greeting and steps, every app
+ in a grid that wraps (the Oficina apps first, then the installed Store
+ apps), and Base's own pages in a dock at its foot, past a hairline. On a
+ phone the same markup is a springboard (see the phone rules). */
+.apps { width: 100%; max-width: 960px; margin-top: 28px; padding: 20px 20px 14px; border-radius: 22px; }
+.app-grid, .dock { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 14px 8px; justify-items: center; }
+.dock { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--rule-strong); }
+.app { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 96px; padding: 6px 4px 4px; border-radius: 16px;
+ font-size: 13px; font-weight: 500; text-align: center; transition: background .2s; }
+a.app:hover { background: var(--hover); }
+.app .icon { flex: none; width: 64px; height: 64px; display: grid; place-items: center; }
+.app .icon img { width: 100%; height: 100%; display: block; }
+.app .tile { border-radius: 16px; border: 1px solid var(--glass-edge); box-shadow: inset 0 1px 0 var(--glass-shine); }
+.app .label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile { width: 76px; height: 76px; border-radius: 20px; display: grid; place-items: center; }
.tile svg { width: 28px; height: 28px; stroke: var(--tile-ink); fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.tile.t-amber { background: linear-gradient(155deg, var(--amber-1), var(--amber-2)); }
@@ -322,109 +336,6 @@ button.alt[aria-busy="true"] { cursor: progress; }
.tile.t-violet { background: linear-gradient(155deg, var(--violet-1), var(--violet-2)); }
.tile.t-mist { background: linear-gradient(155deg, var(--mist-1), var(--mist-2)); }
.tile.t-rose { background: linear-gradient(155deg, var(--rose-1), var(--rose-2)); }
-/* Home's columns: the Oficina rail, when there is one, and everything else. */
-.home-cols { flex: 1; display: flex; gap: 22px; }
-.home-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
-/* The Oficina rail: a slim column of glass down the left, under the top bar.
- Each app is its icon with its name under it, a link that opens it in a new tab.
- It sticks when Home scrolls. Its height fits the screen below the top bar
- (117px: Home's padding, the top bar and the gap under it). Collapsed (the
- default) it shows as many apps as fit and the last spot is More; kept
- expanded it lists every app, scrolls if it must, and ends in Collapse. */
-.rail { flex: none; width: 80px; margin-top: 16px; padding: 8px 6px; border-radius: 18px;
- display: flex; flex-direction: column; gap: 4px;
- position: sticky; top: 16px; z-index: 3; align-self: flex-start;
- height: max(160px, calc(100dvh - 117px)); container: oficina-rail / size;
- overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
-.rail.collapsed { overflow: visible; }
-/* Every entry is 72px tall, so the rail's height says how many fit. */
-.rail-app { flex: none; height: 72px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
- width: 100%; padding: 0 2px; border: 0; border-radius: 12px; background: none; cursor: pointer;
- color: var(--frost); text-decoration: none; font: inherit; font-size: 12px; font-weight: 500; line-height: 1.2; transition: background .2s; }
-.rail-app img { width: 36px; height: 36px; display: block; }
-.rail-app:hover, .rail-more[open] > summary { background: var(--hover); }
-.rail-app:focus-visible { outline-offset: -2px; background: var(--hover); }
-/* More and Collapse: a round glass glyph in place of an app's icon. */
-.rail-app .glyph { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
- background: var(--chip); box-shadow: inset 0 0 0 1px var(--chip-edge); }
-.rail-app .glyph svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; fill: none; }
-.rail-more .glyph svg { stroke-width: 3.2; }
-.rail-more, .rail-collapse { flex: none; }
-.rail-more { display: none; position: relative; }
-.rail-more > summary { list-style: none; }
-.rail-more > summary::-webkit-details-marker { display: none; }
-/* More's panel opens beside the rail, its foot level with More's. */
-.rail-panel { position: absolute; left: calc(100% + 18px); bottom: 0; width: 224px; max-height: calc(100dvh - 120px); overflow-y: auto;
- padding: 6px; border-radius: 14px;
- background: linear-gradient(var(--menu-1), var(--menu-2)), var(--menu-base);
- box-shadow: inset 0 1px 0 var(--menu-shine), 0 18px 40px -12px var(--menu-shadow); }
-.rail-panel-apps { display: flex; flex-direction: column; }
-.rail-panel-app { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 10px; border-radius: 8px;
- color: var(--frost); text-decoration: none; font-size: 15px; font-weight: 500; }
-.rail-panel-app img { width: 28px; height: 28px; display: block; }
-.rail-panel form { margin: 6px 0 0; padding-top: 6px; border-top: 1px solid var(--rule); }
-.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 44px; padding: 0 10px;
- border: 0; border-radius: 8px; background: none; color: var(--frost); font: inherit; font-size: 15px; font-weight: 500; cursor: pointer; }
-.switch i { flex: none; position: relative; width: 36px; height: 22px; border-radius: 11px;
- background: var(--track); box-shadow: inset 0 0 0 1px var(--track-edge); }
-.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--haze); }
-.rail-panel-app:hover, .rail-panel-app:focus-visible, .switch:hover, .switch:focus-visible { background: var(--hover); }
-.rail-panel-app:focus-visible, .switch:focus-visible { outline-offset: -2px; }
-/* How many apps fit: S entries need 76S - 4px of the rail's inner height.
- When the apps outnumber S, the rail shows the first S - 1 and More, and
- More's panel hides those S - 1. Eight apps (every one Base knows) fit
- from 604px up; internal/look's TestRailCutOffsCoverEveryOficinaApp fails
- if Base learns more apps than these blocks cover.
- The panel's foot is level with More's, so it may only be as tall as More's
- foot is below the rail's top (76S + 5px: the rail's border and padding,
- then S entries less a gap). The rail is always on screen, so the panel is
- too, scrolling inside itself when its apps need more room. */
-@container oficina-rail (height < 148px) {
- .rail-panel { max-height: 81px; }
- .rail.collapsed > a.rail-app:nth-of-type(n+2), .rail.collapsed > a.rail-app:nth-of-type(1):not(:last-of-type) { display: none; }
- .rail.collapsed > a.rail-app:nth-of-type(2) ~ .rail-more { display: block; }
-}
-@container oficina-rail (148px <= height < 224px) {
- .rail-panel { max-height: 157px; }
- .rail.collapsed > a.rail-app:nth-of-type(n+3), .rail.collapsed > a.rail-app:nth-of-type(2):not(:last-of-type) { display: none; }
- .rail.collapsed > a.rail-app:nth-of-type(3) ~ .rail-more { display: block; }
- .rail-panel-app:nth-of-type(-n+1) { display: none; }
-}
-@container oficina-rail (224px <= height < 300px) {
- .rail-panel { max-height: 233px; }
- .rail.collapsed > a.rail-app:nth-of-type(n+4), .rail.collapsed > a.rail-app:nth-of-type(3):not(:last-of-type) { display: none; }
- .rail.collapsed > a.rail-app:nth-of-type(4) ~ .rail-more { display: block; }
- .rail-panel-app:nth-of-type(-n+2) { display: none; }
-}
-@container oficina-rail (300px <= height < 376px) {
- .rail-panel { max-height: 309px; }
- .rail.collapsed > a.rail-app:nth-of-type(n+5), .rail.collapsed > a.rail-app:nth-of-type(4):not(:last-of-type) { display: none; }
- .rail.collapsed > a.rail-app:nth-of-type(5) ~ .rail-more { display: block; }
- .rail-panel-app:nth-of-type(-n+3) { display: none; }
-}
-@container oficina-rail (376px <= height < 452px) {
- .rail-panel { max-height: 385px; }
- .rail.collapsed > a.rail-app:nth-of-type(n+6), .rail.collapsed > a.rail-app:nth-of-type(5):not(:last-of-type) { display: none; }
- .rail.collapsed > a.rail-app:nth-of-type(6) ~ .rail-more { display: block; }
- .rail-panel-app:nth-of-type(-n+4) { display: none; }
-}
-@container oficina-rail (452px <= height < 528px) {
- .rail-panel { max-height: 461px; }
- .rail.collapsed > a.rail-app:nth-of-type(n+7), .rail.collapsed > a.rail-app:nth-of-type(6):not(:last-of-type) { display: none; }
- .rail.collapsed > a.rail-app:nth-of-type(7) ~ .rail-more { display: block; }
- .rail-panel-app:nth-of-type(-n+5) { display: none; }
-}
-@container oficina-rail (528px <= height < 604px) {
- .rail-panel { max-height: 537px; }
- .rail.collapsed > a.rail-app:nth-of-type(n+8), .rail.collapsed > a.rail-app:nth-of-type(7):not(:last-of-type) { display: none; }
- .rail.collapsed > a.rail-app:nth-of-type(8) ~ .rail-more { display: block; }
- .rail-panel-app:nth-of-type(-n+6) { display: none; }
-}
-/* On a phone the same apps are tiles above the dock (see the phone rules). */
-.oficina { display: none; }
-.oficina h3 { margin: 0 0 12px; font-size: 13px; font-weight: 600; letter-spacing: .02em; color: var(--haze); }
-.oficina-row { display: flex; gap: 18px; flex-wrap: wrap; }
-.oficina .tile img { width: 100%; height: 100%; display: block; }
.app.new { animation: condense 1.2s cubic-bezier(.2,.7,0,1) both; }
@keyframes condense { from { opacity: 0; filter: blur(14px); transform: scale(.94); } to { opacity: 1; filter: none; transform: none; } }
.app.leaving { animation: dissolve .5s ease forwards; }
@@ -501,23 +412,24 @@ a.ask::after { content: "/"; color: var(--haze); opacity: .7; }
.ask-icon svg path + path { stroke-width: 2.4; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
-/* Ask Base: a sheet of dark glass that slides in from the right over Home
- (full screen on a phone), and the same conversation on /ask. */
-dialog.ask-panel { position: fixed; inset: 12px 12px 12px auto; width: min(460px, calc(100vw - 24px)); height: auto;
+/* Ask Base. On a wide screen, a glass popover under the Ask field, its
+ pointer toward it (ask.js places it: --pop-top, --pop-left, --pointer-x);
+ on a phone, a sheet that slides up over Home, which steps back behind it
+ (see the phone rules). The same conversation is the /ask page. */
+dialog.ask-panel { position: fixed; inset: auto; top: var(--pop-top, 76px); left: var(--pop-left, auto); right: var(--pop-right, 26px);
+ width: min(440px, calc(100vw - 24px)); height: min(640px, calc(100dvh - 120px));
max-width: none; max-height: none; margin: 0; padding: 0; border-radius: 18px; color: var(--frost);
background: linear-gradient(var(--sheet-1), var(--sheet-2)), var(--sheet-base);
- flex-direction: column; overflow: hidden;
- transition: transform .35s cubic-bezier(.2,.7,0,1), opacity .35s, overlay .35s allow-discrete, display .35s allow-discrete;
- transform: translateX(32px); opacity: 0; }
-/* Beside the Oficina rail (wider than a phone) the panel keeps a 16px gap to
- it: the rail ends 106px in (Home's 26px padding and its 80px), plus the
- gap and the panel's own 12px inset on the right. */
-@media (min-width: 601px) {
- body:has(nav.rail) dialog.ask-panel { width: min(460px, calc(100% - 134px)); }
-}
+ flex-direction: column; overflow: visible; transform-origin: var(--pointer-x, 50%) 0;
+ transition: transform .25s cubic-bezier(.2,.7,0,1), opacity .25s, overlay .25s allow-discrete, display .25s allow-discrete;
+ transform: translateY(-8px) scale(.98); opacity: 0; }
+dialog.ask-panel::before { content: ""; position: absolute; top: -8px; left: var(--pointer-x, calc(50% - 7px)); width: 14px; height: 14px;
+ transform: rotate(45deg); border-radius: 3px 0 0 0;
+ background: linear-gradient(var(--sheet-1), var(--sheet-1)), var(--sheet-base);
+ border-left: 1px solid var(--glass-edge); border-top: 1px solid var(--glass-edge); }
dialog.ask-panel[open] { display: flex; transform: none; opacity: 1; }
-@starting-style { dialog.ask-panel[open] { transform: translateX(32px); opacity: 0; } }
-dialog.ask-panel::backdrop { background: var(--scrim); }
+@starting-style { dialog.ask-panel[open] { transform: translateY(-8px) scale(.98); opacity: 0; } }
+dialog.ask-panel::backdrop { background: transparent; }
.ask-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 12px 20px; border-bottom: 1px solid var(--rule); }
.ask-head h2 { flex: 1; margin: 0; font-size: 20px; font-weight: 500; letter-spacing: -0.02em; font-variation-settings: "STYL" 0; }
/* The header's round glass buttons: ⋯ (a menu holding Open Equipo) and close. */
@@ -569,7 +481,7 @@ main { min-height: 100dvh; }
the top, the conversation scrolling between, and room for the notch and
the home indicator. */
@media (max-width: 600px) {
- .home { padding: 12px 12px 20px; }
+ .home { padding: 12px 12px calc(132px + env(safe-area-inset-bottom)); }
.topbar { gap: 10px; padding: 6px 6px 6px 12px; }
.team { display: none; }
.ask { min-width: 0; min-height: 44px; max-width: none; padding: 0 14px; }
@@ -577,16 +489,41 @@ main { min-height: 100dvh; }
.ask-icon { display: grid; }
.ask, a.ask { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me { flex: none; width: 44px; height: 44px; font-size: 14px; }
- .rail { display: none; }
- .oficina { display: block; margin-top: auto; padding-top: 36px; }
- .oficina + .dock { margin-top: 0; padding-top: 24px; }
- .oficina-row, .dock { gap: 14px; }
- .hello { margin-top: 32px; }
+ /* A springboard: a compact greeting, four columns of apps on the
+ atmosphere, and a glass dock fixed to the foot of the screen. */
+ .hello { margin-top: 26px; font-size: 30px; }
+ .lede { margin: 8px 0 14px; font-size: 15px; }
+ .steps { gap: 6px; }
+ .steps li { padding: 6px 10px; font-size: 13px; gap: 8px; }
+ .apps { margin-top: 26px; padding: 0; max-width: none; border: 0; border-radius: 0; background: none; box-shadow: none;
+ backdrop-filter: none; -webkit-backdrop-filter: none; }
+ .app-grid { grid-template-columns: repeat(4, 1fr); gap: 18px 0; }
+ .app { width: 100%; max-width: 86px; padding: 4px 2px 2px; gap: 6px; font-size: 12px; }
+ .app .icon { width: 60px; height: 60px; }
+ .app .tile { border-radius: 15px; }
+ .app .tile svg { width: 26px; height: 26px; }
+ /* Labels on the atmosphere, as on a springboard, keep a soft halo so they
+ read over any colour of fog. */
+ .app-grid .label { text-shadow: 0 0 3px var(--halo), 0 1px 6px var(--halo); }
+ .dock { position: fixed; z-index: 2; left: 12px; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom));
+ margin: 0; padding: 10px 8px 8px; border-radius: 30px; grid-template-columns: repeat(3, 1fr);
+ background: linear-gradient(var(--glass-1), var(--glass-2)), var(--glass-base); border: 1px solid var(--glass-edge);
+ backdrop-filter: blur(22px) saturate(130%); -webkit-backdrop-filter: blur(22px) saturate(130%);
+ box-shadow: inset 0 1px 0 var(--glass-shine), 0 18px 40px var(--glass-lift) var(--glass-shadow); }
+ /* Opening the chat, Home steps back behind the sheet. */
+ main.home { transform-origin: 50% 30%; transition: transform .4s cubic-bezier(.2,.8,.2,1), filter .4s; }
+ body:has(dialog.ask-panel[open]) main.home { transform: scale(.94); filter: blur(3px) brightness(.8); }
.inner { padding: 10px; }
.sheet { padding: 18px 16px 20px; }
.people li { flex-wrap: wrap; }
dialog.ask-panel { inset: auto 0 auto 0; top: var(--vv-top, 0); width: 100%; height: var(--vv-h, 100dvh); max-height: var(--vv-h, 100dvh);
- border: 0; border-radius: 0; padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left); }
+ border: 0; border-radius: 0; padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
+ overflow: hidden; opacity: 1; transform: none; transition: none; }
+ dialog.ask-panel::before { display: none; }
+ /* The sheet slides up each time it opens. */
+ dialog.ask-panel[open] { animation: sheet-up .4s cubic-bezier(.2,.8,.2,1); }
+ @starting-style { dialog.ask-panel[open] { transform: none; opacity: 1; } }
+ dialog.ask-panel::backdrop { background: var(--scrim); }
dialog.ask-panel .ask-head { position: sticky; top: 0; z-index: 1; padding: max(8px, env(safe-area-inset-top)) 12px 8px; }
dialog.ask-panel .ask-head h2 { font-size: 18px; }
dialog.ask-panel .composer { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
@@ -597,6 +534,16 @@ main { min-height: 100dvh; }
.ask-page { min-height: calc(100dvh - 20px); }
}
+/* With reduced motion the chat just shows: no slide, no scale, and Home
+ does not step back (it still dims behind a phone's sheet). */
+@media (prefers-reduced-motion: reduce) {
+ dialog.ask-panel, dialog.ask-panel[open], main.home { transition: none; transform: none; animation: none; }
+ @starting-style { dialog.ask-panel[open] { transform: none; opacity: 1; } }
+ body:has(dialog.ask-panel[open]) main.home { transform: none; }
+}
+
+@keyframes sheet-up { from { transform: translateY(100%); } }
+
/* Scratchpad's shared note: a field that grows past one control height. */
.notepad { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.notepad textarea.input { font: inherit; width: 100%; height: auto; min-height: 280px; padding: 12px 14px;
diff --git a/internal/look/static/ask.js b/internal/look/static/ask.js
index 4398518..e386b82 100644
--- a/internal/look/static/ask.js
+++ b/internal/look/static/ask.js
@@ -302,9 +302,29 @@ function start(root) {
vv.addEventListener("scroll", () => { if (dialog.open) fit(); });
}
+ // On a wide screen the panel is a popover under the Ask field, centred on
+ // it as far as the screen allows, its pointer over the field's middle.
+ // On a phone the CSS makes it a full-screen sheet and ignores these.
+ const wide = matchMedia("(min-width: 601px)");
+ const askField = document.querySelector("a.ask");
+ function place() {
+ if (!wide.matches || !askField) return;
+ const f = askField.getBoundingClientRect();
+ const vw = document.documentElement.clientWidth;
+ const w = Math.min(440, vw - 24);
+ const left = Math.max(12, Math.min(f.left + f.width / 2 - w / 2, vw - 12 - w));
+ const pointer = Math.max(20, Math.min(f.left + f.width / 2 - left, w - 20));
+ dialog.style.setProperty("--pop-top", f.bottom + 12 + "px");
+ dialog.style.setProperty("--pop-left", left + "px");
+ dialog.style.setProperty("--pop-right", "auto");
+ dialog.style.setProperty("--pointer-x", pointer - 7 + "px");
+ }
+ window.addEventListener("resize", () => { if (dialog.open) place(); });
+
function open() {
if (dialog.open) return;
fit();
+ place();
dialog.showModal();
load().then(() => {
const first = root.dataset.state === "ready" ? field : dialog.querySelector("[data-when]:not([hidden]) .btn");
@@ -320,7 +340,7 @@ function start(root) {
});
}
dialog.querySelector("[data-ask-close]").addEventListener("click", () => dialog.close());
- // A click on the backdrop (outside the panel) closes it too.
+ // A click outside the panel (on its backdrop) closes it too.
dialog.addEventListener("click", (e) => {
if (e.target === dialog) dialog.close();
});
diff --git a/internal/look/static/rail.js b/internal/look/static/rail.js
deleted file mode 100644
index 867639f..0000000
--- a/internal/look/static/rail.js
+++ /dev/null
@@ -1,23 +0,0 @@
-// The Oficina rail's More panel. Without scripts it is a plain <details>;
-// with them, Escape and a click elsewhere close it, and Escape (or opening
-// an app from it) gives focus back to More. How many apps the rail shows is
-// CSS's doing (container queries), so nothing here moves the layout.
-const more = document.querySelector("nav.rail details.rail-more");
-if (more) {
- const summary = more.querySelector("summary");
- const shut = (refocus) => {
- if (!more.open) return;
- more.open = false;
- if (refocus) summary.focus();
- };
- document.addEventListener("keydown", (e) => {
- // The Ask panel, when open, has Escape to itself.
- if (e.key !== "Escape" || !more.open || document.querySelector("dialog[open]")) return;
- e.preventDefault();
- shut(true);
- });
- document.addEventListener("click", (e) => {
- if (!more.contains(e.target)) shut(more.contains(document.activeElement));
- });
- for (const a of more.querySelectorAll(".rail-panel a")) a.addEventListener("click", () => shut(true));
-}
diff --git a/internal/store/rail.go b/internal/store/rail.go
deleted file mode 100644
index 3c008d5..0000000
--- a/internal/store/rail.go
+++ /dev/null
@@ -1,29 +0,0 @@
-package store
-
-import (
- "context"
- "database/sql"
- "fmt"
-)
-
-// RailExpanded reports whether the member keeps Home's Oficina rail
-// expanded.
-func RailExpanded(ctx context.Context, db *sql.DB, memberID string) (bool, error) {
- var on bool
- err := db.QueryRowContext(ctx, `SELECT rail_expanded FROM members WHERE id = ?`, memberID).Scan(&on)
- return on, err
-}
-
-// SetRailExpanded keeps the member's Oficina rail expanded, or not.
-func SetRailExpanded(ctx context.Context, db *sql.DB, memberID string, on bool) error {
- res, err := db.ExecContext(ctx, `UPDATE members SET rail_expanded = ? WHERE id = ?`, on, memberID)
- if err != nil {
- return err
- }
- if n, err := res.RowsAffected(); err != nil {
- return err
- } else if n != 1 {
- return fmt.Errorf("store: no member %s", memberID)
- }
- return nil
-}
diff --git a/internal/store/rail_test.go b/internal/store/rail_test.go
deleted file mode 100644
index 31d1e0d..0000000
--- a/internal/store/rail_test.go
+++ /dev/null
@@ -1,44 +0,0 @@
-package store
-
-import (
- "context"
- "testing"
-)
-
-// A member's Oficina rail starts collapsed; Keep expanded is theirs alone
-// and holds until they collapse it again.
-func TestRailExpanded(t *testing.T) {
- ctx, db := context.Background(), open(t)
- if err := Bootstrap(ctx, db, "owner@example.com"); err != nil {
- t.Fatal(err)
- }
- owner, _, err := MemberByEmail(ctx, db, "owner@example.com")
- if err != nil {
- t.Fatal(err)
- }
- other, _, err := Invite(ctx, db, "maria@example.com")
- if err != nil {
- t.Fatal(err)
- }
- if on, err := RailExpanded(ctx, db, owner.ID); err != nil || on {
- t.Fatalf("fresh member: %v, %v; want collapsed", on, err)
- }
- if err := SetRailExpanded(ctx, db, owner.ID, true); err != nil {
- t.Fatal(err)
- }
- if on, err := RailExpanded(ctx, db, owner.ID); err != nil || !on {
- t.Fatalf("after Keep expanded: %v, %v", on, err)
- }
- if on, _ := RailExpanded(ctx, db, other.ID); on {
- t.Fatal("another member's rail expanded too")
- }
- if err := SetRailExpanded(ctx, db, owner.ID, false); err != nil {
- t.Fatal(err)
- }
- if on, _ := RailExpanded(ctx, db, owner.ID); on {
- t.Fatal("Collapse did not hold")
- }
- if err := SetRailExpanded(ctx, db, "no-such-member", true); err == nil {
- t.Fatal("set for a member who isn't there")
- }
-}
diff --git a/internal/web/app.go b/internal/web/app.go
index e361a10..cff2fd8 100644
--- a/internal/web/app.go
+++ b/internal/web/app.go
@@ -188,7 +188,6 @@ func App(d *db.DB, cfg config.Config, mailer mail.Sender, inst Installer, logger
r.Group(func(r chi.Router) {
r.Use(a.requireMember)
r.Get("/", a.home)
- r.Post("/rail", a.railSet)
r.Get("/people", a.people)
r.Post("/people", a.invite)
r.Get("/store", a.storePage)
diff --git a/internal/web/home.go b/internal/web/home.go
index 55b8f0c..9f79f3e 100644
--- a/internal/web/home.go
+++ b/internal/web/home.go
@@ -15,18 +15,16 @@ type step struct {
Done bool
}
+// tile is one app on Home: in the grid of apps or in the dock of Base's own
+// pages. Its icon is an image (Image, a path in the static tree for
+// {{asset}}: an Oficina app's) or line art on a tint (Icon and Tint).
type tile struct {
- Name string
- Href string
- Tint string
- Icon template.HTML
-}
-
-// oficinaLink is one Oficina app on Home: a link that opens it in a new tab.
-type oficinaLink struct {
- Name string
- Href string
- Icon string // the icon's path in the static tree, for {{asset}}
+ Name string
+ Href string
+ Tint string
+ Icon template.HTML
+ Image string
+ NewTab bool // an Oficina app, which opens in a new tab
}
type homePage struct {
@@ -35,13 +33,9 @@ type homePage struct {
Initials string
Lede string
Steps []step
- Tiles []tile
- // Oficina is the team's Oficina apps (BASE_OFICINA_APPS), drawn as a
- // rail on a wide screen and as tiles on a phone.
- Oficina []oficinaLink
- // RailExpanded is the member's Keep expanded: the rail lists every app
- // and ends in Collapse, instead of folding what doesn't fit under More.
- RailExpanded bool
+ // Apps is the grid: the team's Oficina apps (BASE_OFICINA_APPS) in
+ // their order, then the installed Store apps. Dock is Base's own pages.
+ Apps, Dock []tile
// Ask is the chat panel, nil with the chat off.
Ask *askView
}
@@ -112,20 +106,13 @@ func (a *app) home(w http.ResponseWriter, r *http.Request) {
}
name := displayName(me)
page := homePage{Name: a.cfg.Name, Greeting: greeting(time.Now(), a.cfg.Timezone, name), Initials: initials(name)}
- page.Tiles = []tile{
+ page.Dock = []tile{
{Name: "Store", Href: "/store", Tint: "teal", Icon: iconStore},
{Name: "People", Href: "/people", Tint: "violet", Icon: iconPeople},
{Name: "Settings", Href: "/settings", Tint: "mist", Icon: iconSettings},
}
for _, o := range a.cfg.OficinaApps {
- page.Oficina = append(page.Oficina, oficinaLink{Name: o.Name, Href: o.Origin + "/", Icon: "static/oficina/" + o.ID + ".svg"})
- }
- if len(page.Oficina) > 0 {
- if page.RailExpanded, err = store.RailExpanded(r.Context(), a.db, me.ID); err != nil {
- a.logger.Error("home: rail", "err", err)
- http.Error(w, "unavailable", http.StatusServiceUnavailable)
- return
- }
+ page.Apps = append(page.Apps, tile{Name: o.Name, Href: o.Origin + "/", Image: "static/oficina/" + o.ID + ".svg", NewTab: true})
}
installedOwn := false
for _, in := range installs {
@@ -134,7 +121,7 @@ func (a *app) home(w http.ResponseWriter, r *http.Request) {
continue
}
// The host the app was installed at: config may name another now.
- page.Tiles = append(page.Tiles, tile{Name: e.Name, Href: "https://" + in.Host + "/", Tint: e.Tint, Icon: template.HTML(e.Icon)})
+ page.Apps = append(page.Apps, tile{Name: e.Name, Href: "https://" + in.Host + "/", Tint: e.Tint, Icon: template.HTML(e.Icon)})
if !e.Default {
installedOwn = true
}
@@ -170,24 +157,3 @@ func (a *app) home(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store")
a.render(w, r, "home", page)
}
-
-// railSet is Keep expanded (expanded=1) and Collapse (expanded=0) for Home's
-// Oficina rail: a plain form, so it works without scripts.
-func (a *app) railSet(w http.ResponseWriter, r *http.Request) {
- me, _ := CurrentMember(r)
- var on bool
- switch r.PostFormValue("expanded") {
- case "1":
- on = true
- case "0":
- default:
- http.Error(w, "bad request", http.StatusBadRequest)
- return
- }
- if err := store.SetRailExpanded(r.Context(), a.db, me.ID, on); err != nil {
- a.logger.Error("rail: set", "err", err)
- http.Error(w, "unavailable", http.StatusServiceUnavailable)
- return
- }
- http.Redirect(w, r, "/", http.StatusSeeOther)
-}
diff --git a/internal/web/templates/home.html b/internal/web/templates/home.html
index 5beccec..44b11ac 100644
--- a/internal/web/templates/home.html
+++ b/internal/web/templates/home.html
@@ -7,39 +7,23 @@
<a class="ask-icon" href="/ask" data-ask-open aria-haspopup="dialog" aria-controls="ask-panel" aria-label="Ask Base"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 5.5h14a1.5 1.5 0 0 1 1.5 1.5v8.5A1.5 1.5 0 0 1 19 17h-8l-4.5 3.5V17H5a1.5 1.5 0 0 1-1.5-1.5V7A1.5 1.5 0 0 1 5 5.5z"/><path d="M8.5 11.25h.01M12 11.25h.01M15.5 11.25h.01"/></svg></a>{{else}}<input class="ask" type="text" disabled placeholder="Ask Base anything" title="Asking Base arrives in a later slice" aria-label="Ask Base anything">{{end}}
<a class="me" href="/settings" aria-label="Settings">{{.Initials}}</a>
</div>
-<div class="home-cols">
-{{if .Oficina}}<nav class="rail glass {{if .RailExpanded}}expanded{{else}}collapsed{{end}}" aria-label="Oficina">
-{{range .Oficina}}<a class="rail-app" href="{{.Href}}" target="_blank" rel="noopener"><img src="{{asset .Icon}}" alt=""><span>{{.Name}}</span></a>
-{{end}}{{if .RailExpanded}}<form class="rail-collapse" method="post" action="/rail"><input type="hidden" name="expanded" value="0"><button class="rail-app" type="submit"><i class="glyph" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M7 14l5-5 5 5"/></svg></i><span>Collapse</span></button></form>
-{{else}}{{/* CSS shows as many apps as fit and turns the last spot into More,
- whose panel shows the rest: it lists every app and hides the ones the
- rail already shows. */}}<details class="rail-more"><summary class="rail-app"><i class="glyph" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M6 12h.01M12 12h.01M18 12h.01"/></svg></i><span>More</span></summary>
-<div class="rail-panel" role="region" aria-label="More Oficina apps">
-<div class="rail-panel-apps">
-{{range .Oficina}}<a class="rail-panel-app" href="{{.Href}}" target="_blank" rel="noopener"><img src="{{asset .Icon}}" alt=""><span>{{.Name}}</span></a>
-{{end}}</div>
-<form method="post" action="/rail"><input type="hidden" name="expanded" value="1"><button class="switch" type="submit" role="switch" aria-checked="false"><span>Keep expanded</span><i aria-hidden="true"></i></button></form>
-</div>
-</details>
-<script type="module" src="{{asset "static/rail.js"}}"></script>
-{{end}}</nav>
-{{end}}<div class="home-body">
<h2 class="hello">{{.Greeting}}</h2>
<p class="lede">{{.Lede}}</p>
<ul class="steps">
{{range .Steps}}<li class="glass{{if .Done}} done{{end}}"><span class="mark">{{if .Done}}✓{{end}}</span>{{.Label}}</li>
{{end}}</ul>
-{{with .Oficina}}<section class="oficina" aria-labelledby="oficina-heading">
-<h3 id="oficina-heading">Oficina</h3>
-<div class="oficina-row">
-{{range .}}<a class="app" href="{{.Href}}" target="_blank" rel="noopener"><div class="tile"><img src="{{asset .Icon}}" alt=""></div>{{.Name}}</a>
-{{end}}</div>
-</section>
-{{end}}<div class="dock">
-{{range .Tiles}}<a class="app" href="{{.Href}}"><div class="tile glass t-{{.Tint}}">{{.Icon}}</div>{{.Name}}</a>
-{{end}}</div>
-</div>
-</div>
+{{/* Every app in one glass panel: on a wide screen a wrapping grid with
+ Base's own pages in a dock at its foot; on a phone a springboard, the
+ dock fixed to the bottom of the screen. */}}<nav class="apps glass" aria-label="Apps">
+{{with .Apps}}<ul class="app-grid">
+{{range .}}{{template "app" .}}
+{{end}}</ul>
+{{end}}<ul class="dock">
+{{range .Dock}}{{template "app" .}}
+{{end}}</ul>
+</nav>
{{with .Ask}}{{template "ask-panel" .}}
<script type="module" src="{{asset "static/ask.js"}}"></script>{{end}}
</main>{{end}}
+
+{{define "app"}}<li><a class="app" href="{{.Href}}"{{if .NewTab}} target="_blank" rel="noopener"{{end}}>{{if .Image}}<span class="icon"><img src="{{asset .Image}}" alt=""></span>{{else}}<span class="icon tile t-{{.Tint}}">{{.Icon}}</span>{{end}}<span class="label">{{.Name}}</span></a></li>{{end}}
diff --git a/internal/webtest/home_test.go b/internal/webtest/home_test.go
index a75a820..92e89ae 100644
--- a/internal/webtest/home_test.go
+++ b/internal/webtest/home_test.go
@@ -100,7 +100,7 @@ func TestHomeTilesLinkToOrigins(t *testing.T) {
a.setInstall("scratchpad", "installing", "")
a.setInstall("scratchpad", "installed", "")
body = a.get("/").Body
- re := regexp.MustCompile(`<a class="app" href="https://acme-scratchpad\.bab\.oncarlos\.com/"><div class="tile glass t-rose">`)
+ re := regexp.MustCompile(`<a class="app" href="https://acme-scratchpad\.bab\.oncarlos\.com/"><span class="icon tile t-rose">`)
if !re.MatchString(body) {
t.Fatalf("no tile for scratchpad:\n%s", body)
}
@@ -128,11 +128,9 @@ func TestHomeTileUsesRecordedHost(t *testing.T) {
}
var (
- railRE = regexp.MustCompile(`(?s)<nav class="rail glass (collapsed|expanded)" aria-label="Oficina">(.*?)</nav>`)
- oficinaRE = regexp.MustCompile(`(?s)<section class="oficina" aria-labelledby="oficina-heading">\s*<h3 id="oficina-heading">Oficina</h3>(.*?)</section>`)
- appLinkRE = regexp.MustCompile(`<a class="([^"]*)" href="([^"]*)" target="_blank" rel="noopener">`)
- appIconRE = regexp.MustCompile(`<img src="(/static/oficina/[a-z]+\.[0-9a-f]+\.svg)" alt="">`)
- appLabelRE = regexp.MustCompile(`</div>([A-Za-z]+)</a>|<span>([A-Za-z]+)</span></a>`)
+ appsRE = regexp.MustCompile(`(?s)<nav class="apps glass" aria-label="Apps">\s*(?:<ul class="app-grid">(.*?)</ul>\s*)?<ul class="dock">(.*?)</ul>\s*</nav>`)
+ itemRE = regexp.MustCompile(`<li><a class="app" href="([^"]*)"( target="_blank" rel="noopener")?><span class="icon[^"]*">(.*?)</span><span class="label">([^<]*)</span></a></li>`)
+ appIconRE = regexp.MustCompile(`^<img src="(/static/oficina/[a-z]+\.[0-9a-f]+\.svg)" alt="">$`)
oficinaApps = []config.OficinaApp{
{ID: "fichas", Name: "Fichas", Origin: "https://fichas.oficina.works"},
{ID: "calendar", Name: "Calendar", Origin: "https://calendar.oficina.works"},
@@ -140,59 +138,88 @@ var (
}
)
-// Home lists the Oficina apps the setting names, in its order, twice: a
-// rail down the left on a wide screen and a row of tiles on a phone (CSS
-// shows one or the other). Each is a plain link to the app's origin in a
-// new tab, with Estilo's icon served from Base itself.
-func TestHomeListsOficinaApps(t *testing.T) {
+type homeItem struct {
+ Href, Icon, Name string
+ NewTab bool
+}
+
+// homeApps is Home's apps panel: the grid of apps, then the dock of Base's
+// own pages.
+func homeApps(t *testing.T, body string) (grid, dock []homeItem) {
+ t.Helper()
+ m := appsRE.FindStringSubmatch(body)
+ if m == nil {
+ t.Fatalf("no apps panel:\n%s", body)
+ }
+ items := func(html string) []homeItem {
+ var out []homeItem
+ for _, i := range itemRE.FindAllStringSubmatch(html, -1) {
+ out = append(out, homeItem{Href: i[1], NewTab: i[2] != "", Icon: i[3], Name: i[4]})
+ }
+ return out
+ }
+ return items(m[1]), items(m[2])
+}
+
+// Home's apps panel holds every app in one grid: the team's Oficina apps in
+// the setting's order (each opening in a new tab, with Estilo's icon served
+// from Base), then the installed Store apps (by app id, as the Store keeps them). Under it, the dock: Store,
+// People and Settings. The same markup is the phone's springboard.
+func TestHomeAppsPanel(t *testing.T) {
a := newAppConfigured(t, func(*sql.DB, config.Config) web.Installer { return noInstaller{} }, time.UTC,
func(c *config.Config) { c.OficinaApps = oficinaApps })
a.signedInOwner()
+ a.setInstall("welcome", "installed", "")
+ a.setInstall("scratchpad", "installed", "")
body := a.get("/").Body
-
- rail := railRE.FindStringSubmatch(body)
- tiles := oficinaRE.FindStringSubmatch(body)
- if rail == nil || tiles == nil {
- t.Fatalf("rail found %v, phone tiles found %v:\n%s", rail != nil, tiles != nil, body)
+ grid, dock := homeApps(t, body)
+ var names []string
+ for _, i := range grid {
+ names = append(names, i.Name)
+ }
+ if want := "Fichas Calendar Equipo Scratchpad Welcome"; strings.Join(names, " ") != want {
+ t.Fatalf("grid %v, want %s", names, want)
+ }
+ for i, want := range oficinaApps {
+ g := grid[i]
+ if g.Href != want.Origin+"/" || !g.NewTab {
+ t.Errorf("%s: href %q, new tab %v", want.Name, g.Href, g.NewTab)
+ }
+ icon := appIconRE.FindStringSubmatch(g.Icon)
+ if icon == nil || !strings.HasPrefix(icon[1], "/static/oficina/"+want.ID+".") {
+ t.Errorf("%s: icon %q", want.Name, g.Icon)
+ continue
+ }
+ if r := a.get(icon[1]); r.Code != 200 || r.Header.Get("Content-Type") != "image/svg+xml" {
+ t.Errorf("%s: %d %q", icon[1], r.Code, r.Header.Get("Content-Type"))
+ }
}
- if strings.Index(body, `class="oficina"`) > strings.Index(body, `class="dock"`) {
- t.Error("the phone's Oficina tiles come after Store, People and Settings")
+ for _, g := range grid[len(oficinaApps):] {
+ if g.NewTab || !strings.HasPrefix(g.Href, "https://acme-") || !strings.HasPrefix(g.Icon, "<svg") {
+ t.Errorf("installed app %s: href %q, new tab %v, icon %.20q", g.Name, g.Href, g.NewTab, g.Icon)
+ }
}
- railApps, panel, ok := strings.Cut(rail[2], `<details class="rail-more">`)
- if rail[1] != "collapsed" || !ok {
- t.Fatalf("rail is %s, More entry found %v:\n%s", rail[1], ok, rail[2])
+ if len(dock) != 3 || dock[0].Href != "/store" || dock[1].Href != "/people" || dock[2].Href != "/settings" ||
+ dock[0].Name != "Store" || dock[1].Name != "People" || dock[2].Name != "Settings" {
+ t.Errorf("dock %+v", dock)
}
- for _, c := range []struct{ name, html, class string }{{"rail", railApps, "rail-app"}, {"More panel", panel, "rail-panel-app"}, {"tiles", tiles[1], "app"}} {
- links := appLinkRE.FindAllStringSubmatch(c.html, -1)
- icons := appIconRE.FindAllStringSubmatch(c.html, -1)
- labels := appLabelRE.FindAllStringSubmatch(c.html, -1)
- if len(links) != len(oficinaApps) || len(icons) != len(oficinaApps) || len(labels) != len(oficinaApps) {
- t.Fatalf("%s: %d links, %d icons, %d names; want %d of each:\n%s", c.name, len(links), len(icons), len(labels), len(oficinaApps), c.html)
- }
- for i, want := range oficinaApps {
- if links[i][1] != c.class || links[i][2] != want.Origin+"/" {
- t.Errorf("%s %d: class %q href %q, want %q %q", c.name, i, links[i][1], links[i][2], c.class, want.Origin+"/")
- }
- if !strings.HasPrefix(icons[i][1], "/static/oficina/"+want.ID+".") {
- t.Errorf("%s %d: icon %s, want %s's", c.name, i, icons[i][1], want.ID)
- }
- if got := labels[i][1] + labels[i][2]; got != want.Name {
- t.Errorf("%s %d: named %q, want %q", c.name, i, got, want.Name)
- }
- if r := a.get(icons[i][1]); r.Code != 200 || r.Header.Get("Content-Type") != "image/svg+xml" {
- t.Errorf("%s: %d %q", icons[i][1], r.Code, r.Header.Get("Content-Type"))
- }
+ for _, gone := range []string{`class="rail`, `rail-more`, `action="/rail"`, "Keep expanded", "Collapse", `class="oficina"`} {
+ if strings.Contains(body, gone) {
+ t.Errorf("Home still has %s", gone)
}
}
+ if r := a.post("/rail", url.Values{"expanded": {"1"}}); r.Code != 404 && r.Code != 405 {
+ t.Errorf("POST /rail: %d, want it gone", r.Code)
+ }
}
-// Without the setting there is no rail and no Oficina row.
-func TestHomeWithoutOficinaApps(t *testing.T) {
+// With no Oficina apps and nothing installed, the panel is just the dock.
+func TestHomeAppsPanelEmpty(t *testing.T) {
a := newApp(t)
a.signedInOwner()
- body := a.get("/").Body
- if strings.Contains(body, `class="rail`) || strings.Contains(body, `class="oficina"`) || strings.Contains(body, `has-rail`) {
- t.Fatalf("Oficina apps drawn with none configured:\n%s", body)
+ grid, dock := homeApps(t, a.get("/").Body)
+ if len(grid) != 0 || len(dock) != 3 {
+ t.Fatalf("grid %v, dock %v", grid, dock)
}
}
@@ -205,75 +232,3 @@ func TestEveryOficinaAppHasAnIcon(t *testing.T) {
}
}
}
-
-var (
- moreRE = regexp.MustCompile(`(?s)<details class="rail-more"><summary class="rail-app">.*?<span>More</span></summary>\s*<div class="rail-panel" role="region" aria-label="More Oficina apps">(.*?)</div>\s*</details>`)
- keepRE = regexp.MustCompile(`(?s)<form method="post" action="/rail"><input type="hidden" name="expanded" value="1"><button class="switch" type="submit" role="switch" aria-checked="false"><span>Keep expanded</span>`)
- collapseRE = regexp.MustCompile(`(?s)<form class="rail-collapse" method="post" action="/rail"><input type="hidden" name="expanded" value="0"><button class="rail-app" type="submit">.*?<span>Collapse</span></button></form>\s*</nav>`)
-)
-
-func newRailApp(t *testing.T) *testApp {
- t.Helper()
- a := newAppConfigured(t, func(*sql.DB, config.Config) web.Installer { return noInstaller{} }, time.UTC,
- func(c *config.Config) { c.OficinaApps = oficinaApps })
- a.signedInOwner()
- return a
-}
-
-// The rail starts collapsed: every app is in it, and in a More panel too
-// (CSS shows in each whichever the rail's height leaves over), with the
-// Keep expanded switch, a plain POST form.
-func TestRailMore(t *testing.T) {
- a := newRailApp(t)
- body := a.get("/").Body
- m := moreRE.FindStringSubmatch(body)
- if m == nil {
- t.Fatalf("no More entry with its labelled panel:\n%s", body)
- }
- if !keepRE.MatchString(m[1]) {
- t.Errorf("no Keep expanded switch in the panel:\n%s", m[1])
- }
- if collapseRE.MatchString(body) {
- t.Error("a collapsed rail offers Collapse")
- }
-}
-
-// Keep expanded is the member's, kept on the server: it holds in a new
-// sign-in on another browser, until they collapse the rail again.
-func TestRailKeepExpanded(t *testing.T) {
- a := newRailApp(t)
- if r := a.post("/rail", url.Values{"expanded": {"1"}}); r.Code != 303 || r.Location() != "/" {
- t.Fatalf("Keep expanded: %d %q", r.Code, r.Location())
- }
- expanded := func(b *testApp) {
- t.Helper()
- body := b.get("/").Body
- rail := railRE.FindStringSubmatch(body)
- if rail == nil || rail[1] != "expanded" {
- t.Fatalf("rail not expanded:\n%s", body)
- }
- if strings.Contains(rail[2], "rail-more") || !collapseRE.MatchString(body) {
- t.Errorf("expanded rail: More shown or no Collapse at the end:\n%s", rail[2])
- }
- if n := len(appLinkRE.FindAllString(rail[2], -1)); n != len(oficinaApps) {
- t.Errorf("expanded rail lists %d apps, want %d", n, len(oficinaApps))
- }
- }
- expanded(a)
-
- other := a.newBrowser()
- other.signedInOwner()
- expanded(other)
-
- if r := other.post("/rail", url.Values{"expanded": {"0"}}); r.Code != 303 || r.Location() != "/" {
- t.Fatalf("Collapse: %d %q", r.Code, r.Location())
- }
- if rail := railRE.FindStringSubmatch(a.get("/").Body); rail == nil || rail[1] != "collapsed" {
- t.Fatal("Collapse did not hold for the member's other browser")
- }
- for _, bad := range []url.Values{{"expanded": {"yes"}}, {}} {
- if r := a.post("/rail", bad); r.Code != 400 {
- t.Errorf("%v: %d, want 400", bad, r.Code)
- }
- }
-}