| new file mode 100644 |
| index 0000000..579ef7c |
| --- /dev/null |
| +++ b/chrome/suite_test.go |
| @@ -0,0 +1,83 @@ |
| +package chrome |
| + |
| +import ( |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func TestSuiteAppsDerivesEachAppFromTheDirectory(t *testing.T) { |
| + apps := SuiteApps("https://oficina.works", "sheets") |
| + want := []SwitcherApp{ |
| + {Name: "Docs", Href: "https://docs.oficina.works/", Icon: "/static/estilo/brand/docs.svg"}, |
| + {Name: "Sheets", Href: "https://sheets.oficina.works/", Icon: "/static/estilo/brand/sheets.svg", Current: true}, |
| + {Name: "Slides", Href: "https://slides.oficina.works/", Icon: "/static/estilo/brand/slides.svg"}, |
| + {Name: "Calendar", Href: "https://calendar.oficina.works/", Icon: "/static/estilo/brand/calendar.svg"}, |
| + {Name: "Memoria", Href: "https://memoria.oficina.works/", Icon: "/static/estilo/brand/memoria.svg"}, |
| + {Name: "Calls", Href: "https://calls.oficina.works/", Icon: "/static/estilo/brand/calls.svg"}, |
| + } |
| + if len(apps) != len(want) { |
| + t.Fatalf("got %d tiles, want %d: %+v", len(apps), len(want), apps) |
| + } |
| + for i := range want { |
| + if apps[i] != want[i] { |
| + t.Errorf("tile %d = %+v, want %+v", i, apps[i], want[i]) |
| + } |
| + } |
| + // A trailing slash and a port are the directory's own; both carry over. |
| + if got := SuiteApps("http://oficina.localhost:8080/", "calls")[5]; got.Href != "http://calls.oficina.localhost:8080/" || !got.Current { |
| + t.Fatalf("calls tile = %+v", got) |
| + } |
| +} |
| + |
| +func TestSuiteAppsMarksNothingForAnUnknownApp(t *testing.T) { |
| + for _, current := range []string{"", "fichas", "meet", "Docs"} { |
| + for _, app := range SuiteApps("https://oficina.works", current) { |
| + if app.Current { |
| + t.Errorf("current %q marks %s", current, app.Name) |
| + } |
| + } |
| + } |
| +} |
| + |
| +func TestSuiteAppsNeedsAnOrigin(t *testing.T) { |
| + for _, directory := range []string{"", "oficina.works", "/apps", "ftp://oficina.works", "https://oficina.works/apps", "https://u@oficina.works", "https://oficina.works?x=1", "https://oficina.works#x", "https://"} { |
| + if apps := SuiteApps(directory, "docs"); apps != nil { |
| + t.Errorf("SuiteApps(%q) = %+v, want nil", directory, apps) |
| + } |
| + } |
| +} |
| + |
| +func TestSwitcherRendersSuiteTilesAboveAllApps(t *testing.T) { |
| + b := signedIn("x") |
| + b.Switcher.Apps = SuiteApps("https://oficina.example", "slides") |
| + b.Switcher.CurrentLabel = "x-thisapp" |
| + html := render(t, "estilo-bar", b) |
| + panel := html[strings.Index(html, "<div estilo-menu estilo-switcher-panel>"):] |
| + panel = panel[:strings.Index(panel, "</details>")] |
| + |
| + grid, rest, ok := strings.Cut(panel, "<hr>") |
| + if !ok || !strings.Contains(grid, "<div estilo-switcher-grid>") { |
| + t.Fatal("no grid above a divider", panel) |
| + } |
| + if !strings.Contains(rest, `href="https://oficina.example/"`) || !strings.Contains(rest, "x-allapps") || strings.Contains(rest, "estilo-switcher-app") { |
| + t.Fatal("All apps is not alone below the divider", rest) |
| + } |
| + if n := strings.Count(grid, "<a estilo-switcher-app "); n != 6 { |
| + t.Fatalf("%d tiles, want 6", n) |
| + } |
| + last := -1 |
| + for _, name := range []string{"Docs", "Sheets", "Slides", "Calendar", "Memoria", "Calls"} { |
| + i := strings.Index(grid, "<span>"+name) |
| + if i < last { |
| + t.Fatalf("%s is missing or out of order", name) |
| + } |
| + last = i |
| + } |
| + current := `<a estilo-switcher-app href="https://slides.oficina.example/" aria-current="true"><img src="/static/estilo/brand/slides.svg" alt="" width="32" height="32"><span>Slides<span estilo-visually-hidden> x-thisapp</span></span></a>` |
| + if !strings.Contains(grid, current) { |
| + t.Fatal("the current tile is not marked", grid) |
| + } |
| + if strings.Count(grid, "aria-current") != 1 || strings.Count(grid, "x-thisapp") != 1 { |
| + t.Fatal("more than one tile is current", grid) |
| + } |
| +} |