oficina / estilo Public

Clone
git clone https://amadan.net/oficina/estilo

Plain git — no account needed to clone.

Download

Download this file

1package chrome
2
3import (
4 "strings"
5 "testing"
6)
7
8func TestSuiteAppsDerivesEachAppFromTheDirectory(t *testing.T) {
9 apps := SuiteApps("https://oficina.works", "sheets")
10 want := []SwitcherApp{
11 {Name: "Docs", Href: "https://docs.oficina.works/", Icon: "/static/estilo/brand/docs.svg"},
12 {Name: "Sheets", Href: "https://sheets.oficina.works/", Icon: "/static/estilo/brand/sheets.svg", Current: true},
13 {Name: "Slides", Href: "https://slides.oficina.works/", Icon: "/static/estilo/brand/slides.svg"},
14 {Name: "Calendar", Href: "https://calendar.oficina.works/", Icon: "/static/estilo/brand/calendar.svg"},
15 {Name: "Memoria", Href: "https://memoria.oficina.works/", Icon: "/static/estilo/brand/memoria.svg"},
16 {Name: "Calls", Href: "https://calls.oficina.works/", Icon: "/static/estilo/brand/calls.svg"},
17 }
18 if len(apps) != len(want) {
19 t.Fatalf("got %d tiles, want %d: %+v", len(apps), len(want), apps)
20 }
21 for i := range want {
22 if apps[i] != want[i] {
23 t.Errorf("tile %d = %+v, want %+v", i, apps[i], want[i])
24 }
25 }
26 // A trailing slash and a port are the directory's own; both carry over.
27 if got := SuiteApps("http://oficina.localhost:8080/", "calls")[5]; got.Href != "http://calls.oficina.localhost:8080/" || !got.Current {
28 t.Fatalf("calls tile = %+v", got)
29 }
30}
31
32func TestSuiteAppsMarksNothingForAnUnknownApp(t *testing.T) {
33 for _, current := range []string{"", "fichas", "meet", "Docs"} {
34 for _, app := range SuiteApps("https://oficina.works", current) {
35 if app.Current {
36 t.Errorf("current %q marks %s", current, app.Name)
37 }
38 }
39 }
40}
41
42func TestSuiteAppsNeedsAnOrigin(t *testing.T) {
43 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://"} {
44 if apps := SuiteApps(directory, "docs"); apps != nil {
45 t.Errorf("SuiteApps(%q) = %+v, want nil", directory, apps)
46 }
47 }
48}
49
50func TestSwitcherRendersSuiteTilesAboveAllApps(t *testing.T) {
51 b := signedIn("x")
52 b.Switcher.Apps = SuiteApps("https://oficina.example", "slides")
53 b.Switcher.CurrentLabel = "x-thisapp"
54 html := render(t, "estilo-bar", b)
55 panel := html[strings.Index(html, "<div estilo-menu estilo-switcher-panel>"):]
56 panel = panel[:strings.Index(panel, "</details>")]
57
58 grid, rest, ok := strings.Cut(panel, "<hr>")
59 if !ok || !strings.Contains(grid, "<div estilo-switcher-grid>") {
60 t.Fatal("no grid above a divider", panel)
61 }
62 if !strings.Contains(rest, `href="https://oficina.example/"`) || !strings.Contains(rest, "x-allapps") || strings.Contains(rest, "estilo-switcher-app") {
63 t.Fatal("All apps is not alone below the divider", rest)
64 }
65 if n := strings.Count(grid, "<a estilo-switcher-app "); n != 6 {
66 t.Fatalf("%d tiles, want 6", n)
67 }
68 last := -1
69 for _, name := range []string{"Docs", "Sheets", "Slides", "Calendar", "Memoria", "Calls"} {
70 i := strings.Index(grid, "<span>"+name)
71 if i < last {
72 t.Fatalf("%s is missing or out of order", name)
73 }
74 last = i
75 }
76 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>`
77 if !strings.Contains(grid, current) {
78 t.Fatal("the current tile is not marked", grid)
79 }
80 if strings.Count(grid, "aria-current") != 1 || strings.Count(grid, "x-thisapp") != 1 {
81 t.Fatal("more than one tile is current", grid)
82 }
83}
84