| index a371f12..7253e06 100644 |
| --- a/internal/calendar/home_consumer_test.go |
| +++ b/internal/calendar/home_consumer_test.go |
| @@ -7,8 +7,8 @@ import ( |
| "io" |
| "log/slog" |
| "net/http" |
| + "net/http/httptest" |
| "path/filepath" |
| - "regexp" |
| "strings" |
| "testing" |
| |
| @@ -70,23 +70,54 @@ func TestHomeSigninWhenSignedInReturnsToPage(t *testing.T) { |
| } |
| } |
| |
| -// "All apps" is the estilo switcher's item (shared-chrome spec §6), linking |
| -// to the hub directory's root: HOME_DIRECTORY_ORIGIN (an origin, which |
| -// connect refuses with a path or a trailing slash) plus "/". No directory, |
| -// no switcher. |
| -func TestAllAppsLinksToDirectory(t *testing.T) { |
| - item := regexp.MustCompile(`<details estilo-switcher[\s\S]*?<a estilo-menu-item href="([^"]*)"><span estilo-menu-label>All apps</span></a>`) |
| - for _, configured := range []string{homeTestDirectory} { |
| - f := newHomeConsumerFixture(t, configured) |
| - f.local(t) |
| - m := item.FindStringSubmatch(f.do("GET", "/day/2026-09-10", "").Body.String()) |
| - if m == nil { |
| - t.Fatalf("HOME_DIRECTORY_ORIGIN=%s: no All apps item in the estilo switcher", configured) |
| +// The switcher (shared-chrome spec §6) appears only with a hub directory |
| +// configured. It shows the suite's six apps as tiles, each at its own host |
| +// under the directory's, Calendar marked current, then below a divider |
| +// "All apps", linking to the directory's root: HOME_DIRECTORY_ORIGIN (an |
| +// origin, which connect refuses with a path or a trailing slash) plus "/". |
| +// The tiles' icons are served sessionless. |
| +func TestTheSwitcherShowsTheSuite(t *testing.T) { |
| + f := newHomeConsumerFixture(t, homeTestDirectory) |
| + f.local(t) |
| + body := f.do("GET", "/day/2026-09-10", "").Body.String() |
| + start := strings.Index(body, `<details estilo-switcher`) |
| + if start < 0 { |
| + t.Fatal("no switcher with a directory configured", 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="`+homeTestDirectory+`/"><span estilo-menu-label>All apps</span></a>`) { |
| + t.Error("the switcher does not offer All apps, at the directory's root, 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>")]) |
| + } |
| + slugs := []string{"docs", "sheets", "slides", "calendar", "memoria", "calls"} |
| + names := []string{"Docs", "Sheets", "Slides", "Calendar", "Memoria", "Calls"} |
| + if len(tiles) != len(slugs) { |
| + t.Fatalf("%d tiles, want %d: %s", len(tiles), len(slugs), grid) |
| + } |
| + for i, slug := range slugs { |
| + head := `href="https://` + slug + `.directory.example.test/"` |
| + if slug == "calendar" { |
| + head += ` aria-current="true"` |
| } |
| - if m[1] != homeTestDirectory+"/" { |
| - t.Errorf("HOME_DIRECTORY_ORIGIN=%s: All apps links to %q, want %q", configured, m[1], homeTestDirectory+"/") |
| + 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[3], "<span estilo-visually-hidden> (this app)</span>") { |
| + t.Error("Calendar is not the one current tile", grid) |
| + } |
| + |
| + icon := httptest.NewRecorder() |
| + f.app.mux.ServeHTTP(icon, httptest.NewRequest("GET", homeTestOrigin+"/static/estilo/brand/calls.svg", nil)) |
| + if icon.Code != http.StatusOK || !strings.Contains(icon.Body.String(), "<svg") { |
| + t.Errorf("a tile's icon, with no session, is %d", icon.Code) |
| + } |
| |
| bare := newHomeConsumerFixture(t, "") |
| bare.local(t) |