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, "
"):] panel = panel[:strings.Index(panel, "")] grid, rest, ok := strings.Cut(panel, "
") if !ok || !strings.Contains(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, ""+name) if i < last { t.Fatalf("%s is missing or out of order", name) } last = i } current := `Slides x-thisapp` 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) } }