oficina / slides Public

Merge main (app switcher lists the suite) into fix/connect-item-when-linked

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	go.mod
#	go.sum
Paul Campbell pushed by paul@keymail.dev deeb4aad6f1ddaf7988964f1f1c0524639601378 parent 4984c13parent 0a098cb
2 files changed, +79 −4
  • internal/slides/chrome.go +4 −3
  • internal/slides/home_test.go +75 −1
diff --git a/internal/slides/chrome.go b/internal/slides/chrome.go
index 2568c02..beb072e 100644
--- a/internal/slides/chrome.go
+++ b/internal/slides/chrome.go
@@ -250,9 +250,9 @@ func (a *app) offersHomeLink(r *http.Request, v viewerState) bool {
}
// switcher is the app switcher, or nil when no hub directory is
-// configured. It shows "All apps" alone and no tiles (Paul's §13 answer
-// 2): a tile today still costs an assertion exchange through the
-// directory session.
+// configured: the suite's six apps as tiles, each at its own host under
+// the directory's (estilo's chrome.SuiteApps), with Slides marked
+// current, then "All apps".
func (a *app) switcher(r *http.Request) *chrome.Switcher {
if a.directory == "" {
return nil
@@ -260,6 +260,7 @@ func (a *app) switcher(r *http.Request) *chrome.Switcher {
return &chrome.Switcher{
Label: rastrillo.T(r, "slides.chrome.switcher"),
CurrentLabel: rastrillo.T(r, "slides.chrome.switcher.current"),
+ Apps: chrome.SuiteApps(a.directory, "slides"),
AllApps: estilomenu.Item{Href: a.directory + "/", Label: rastrillo.T(r, "slides.chrome.switcher.all")},
}
}
diff --git a/internal/slides/home_test.go b/internal/slides/home_test.go
index 026a375..5f9a885 100644
--- a/internal/slides/home_test.go
+++ b/internal/slides/home_test.go
@@ -36,6 +36,13 @@ func homeFixture(t *testing.T) (*http.ServeMux, *app, User) {
return mux, a, u
}
func homeFixtureKey(t *testing.T) (*http.ServeMux, *app, User, *assertioncrypto.Keypair) {
+ t.Helper()
+ return homeFixtureDirectory(t, "")
+}
+
+// homeFixtureDirectory is homeFixtureKey with a hub directory origin
+// (HOME_DIRECTORY_ORIGIN) configured, which is what turns the switcher on.
+func homeFixtureDirectory(t *testing.T, directory string) (*http.ServeMux, *app, User, *assertioncrypto.Keypair) {
t.Helper()
d := testDB(t)
key, err := assertioncrypto.Generate()
@@ -43,7 +50,7 @@ func homeFixtureKey(t *testing.T) (*http.ServeMux, *app, User, *assertioncrypto.
t.Fatal(err)
}
raw, _ := json.Marshal(map[string]string{"test": base64.StdEncoding.EncodeToString(key.SignPub())})
- cfg := Config{Mailer: &homeTestMail{}, Env: EnvDevelopment, Origin: homeTestOrigin, Logger: quietLogger(), AllowedAddresses: []string{"owner@example.com"}, Home: &connect.Credentials{Issuer: "https://home.example.com", ConsumerID: "slides-test", KeysBase64: base64.StdEncoding.EncodeToString(raw), DEKBase64: base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{8}, 32))}}
+ cfg := Config{Mailer: &homeTestMail{}, Env: EnvDevelopment, Origin: homeTestOrigin, Logger: quietLogger(), AllowedAddresses: []string{"owner@example.com"}, Home: &connect.Credentials{Issuer: "https://home.example.com", ConsumerID: "slides-test", KeysBase64: base64.StdEncoding.EncodeToString(raw), DEKBase64: base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{8}, 32)), Directory: directory}}
mux, a, err := New(d, cfg)
if err != nil {
t.Fatal(err)
@@ -687,3 +694,70 @@ func TestHomeStartPageActionSaysConnect(t *testing.T) {
t.Error("the start action still says Continue")
}
}
+
+// The switcher appears only with a hub directory configured. It shows the
+// suite's six apps as tiles at their hosts under the directory's, with
+// Slides marked current, and "All apps" below a divider.
+func TestTheSwitcherShowsTheSuite(t *testing.T) {
+ loc, err := rastrillo.NewLocales(Locales, DefaultLocale, rastrillo.BaseCatalog(), LocaleFS)
+ if err != nil {
+ t.Fatal(err)
+ }
+ page := func(mux *http.ServeMux, a *app, u User) string {
+ t.Helper()
+ r := httptest.NewRequest("GET", homeTestOrigin+"/", nil)
+ r.AddCookie(homeSession(t, a, u.Email, "magiclink"))
+ w := httptest.NewRecorder()
+ loc.Middleware(mux).ServeHTTP(w, r)
+ if w.Code != 200 {
+ t.Fatal(w.Code)
+ }
+ return w.Body.String()
+ }
+
+ if body := page(homeFixture(t)); strings.Contains(body, "estilo-switcher") {
+ t.Error("a switcher with no hub directory")
+ }
+
+ mux, a, u, _ := homeFixtureDirectory(t, "https://oficina.works")
+ body := page(mux, a, u)
+ start := strings.Index(body, `<details estilo-switcher name="estilo-menus">`)
+ if start < 0 {
+ t.Fatal("no switcher", body)
+ }
+ panel := body[start:]
+ panel = panel[:strings.Index(panel, "</details>")]
+ grid, allApps, ok := strings.Cut(panel, "<hr>")
+ if !ok || !strings.Contains(allApps, `<a estilo-menu-item href="https://oficina.works/"><span estilo-menu-label>All apps</span></a>`) {
+ t.Error("the switcher does not offer All apps below the tiles", panel)
+ }
+ var tiles []string
+ for _, tile := range strings.Split(grid, "<a estilo-switcher-app ")[1:] {
+ tiles = append(tiles, tile[:strings.Index(tile, "</a>")])
+ }
+ want := []string{"docs", "sheets", "slides", "calendar", "memoria", "calls"}
+ names := []string{"Docs", "Sheets", "Slides", "Calendar", "Memoria", "Calls"}
+ if len(tiles) != len(want) {
+ t.Fatalf("%d tiles, want %d: %s", len(tiles), len(want), grid)
+ }
+ for i, slug := range want {
+ head := `href="https://` + slug + `.oficina.works/"`
+ if slug == "slides" {
+ head += ` aria-current="true"`
+ }
+ head += `><img src="/static/estilo/brand/` + slug + `.svg" alt="" width="32" height="32"><span>` + names[i]
+ if !strings.HasPrefix(tiles[i], head) {
+ t.Errorf("tile %d = %s, want it to start %s", i, tiles[i], head)
+ }
+ }
+ if strings.Count(grid, "aria-current") != 1 || !strings.Contains(tiles[2], "<span estilo-visually-hidden> (this app)</span>") {
+ t.Error("Slides is not the one current tile", grid)
+ }
+
+ // The tiles' icons are public: no cookie, no session.
+ w := httptest.NewRecorder()
+ mux.ServeHTTP(w, httptest.NewRequest("GET", homeTestOrigin+"/static/estilo/brand/calls.svg", nil))
+ if w.Code != http.StatusOK {
+ t.Errorf("a tile's icon is %d", w.Code)
+ }
+}