| 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) |
| + } |
| +} |