| 1 | package mapa |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | // menuLabels is a menu's rows by label, a divider as "—". |
| 9 | func menuLabels(items []menuEntry) string { |
| 10 | var out []string |
| 11 | for _, item := range items { |
| 12 | if item.Kind == "divider" { |
| 13 | out = append(out, "—") |
| 14 | continue |
| 15 | } |
| 16 | out = append(out, item.Label) |
| 17 | } |
| 18 | return strings.Join(out, " | ") |
| 19 | } |
| 20 | |
| 21 | // A sidebar row's ⋯ is the File menu's page verbs, from the one source, less |
| 22 | // Link to a block…, which needs the page on screen (build note 88). |
| 23 | func TestARowsMenuIsThePageVerbs(t *testing.T) { |
| 24 | cases := []struct { |
| 25 | name string |
| 26 | page PageView |
| 27 | pinned bool |
| 28 | bar string |
| 29 | row string |
| 30 | }{ |
| 31 | {"a team page", PageView{Public: "t", Kind: KindPage, |
| 32 | Rung: RungTeam}, false, |
| 33 | "Rename… | Icon and banner… | Link to a block… | History | " + |
| 34 | "Pin to sidebar | — | Delete…", |
| 35 | "Rename… | History | Pin to sidebar | — | Delete…"}, |
| 36 | {"a pinned team page", PageView{Public: "t", Kind: KindPage, |
| 37 | Rung: RungTeam}, true, |
| 38 | "Rename… | Icon and banner… | Link to a block… | History | " + |
| 39 | "Unpin from sidebar | — | Delete…", |
| 40 | "Rename… | History | Unpin from sidebar | — | Delete…"}, |
| 41 | {"a pinned note", PageView{Public: "n", Kind: KindScratch, |
| 42 | Rung: RungPrivate}, true, |
| 43 | "Make team page… | History | Unpin from sidebar | — | Delete…", |
| 44 | "Make team page… | History | Unpin from sidebar | — | Delete…"}, |
| 45 | } |
| 46 | for _, each := range cases { |
| 47 | verbs, remove := pageVerbs(each.page, each.pinned) |
| 48 | got := menuLabels(append(verbs, divider, remove)) |
| 49 | if got != each.bar { |
| 50 | t.Errorf("%s: the bar's verbs are %q", each.name, got) |
| 51 | } |
| 52 | row := rowMenu(each.page, each.pinned, "/pages") |
| 53 | if got := menuLabels(row); got != each.row { |
| 54 | t.Errorf("%s: the row's menu is %q", each.name, got) |
| 55 | } |
| 56 | for _, item := range row { |
| 57 | if item.Kind == "form" && item.Fields["return"] != "/pages" { |
| 58 | t.Errorf("%s: %s does not come back", each.name, item.Label) |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | team := PageView{Public: "t", Kind: KindPage} |
| 63 | bar, _ := pageVerbs(team, false) |
| 64 | rowMenu(team, false, "/pages") |
| 65 | if _, back := bar[3].Fields["return"]; back { |
| 66 | t.Error("the row's return leaked into the bar's Pin") |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // A pin from a row comes back without the notice the screen showed. |
| 71 | func TestARowComesBackWithoutTheNotice(t *testing.T) { |
| 72 | cases := map[string]string{"/p/x?done=pinsfull": "/p/x", |
| 73 | "/pages?q=a&done=saved": "/pages?q=a", "/d/2026-11-14": "/d/2026-11-14", |
| 74 | "/": "/"} |
| 75 | for given, want := range cases { |
| 76 | if got := withoutNotice(given); got != want { |
| 77 | t.Errorf("withoutNotice(%q) = %q, want %q", given, got, want) |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |