oficina / mapa Public

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

Plain git — no account needed to clone.

Download

Download this file

1package mapatest
2
3import (
4 "net/http"
5 "net/url"
6 "regexp"
7 "slices"
8 "strings"
9 "testing"
10
11 "amadan.net/oficina/notion.git/notiontest"
12)
13
14// File is the first menu, as in Docs and Slides, and is ordered the Mac
15// way (level-up build note 87): New first, then the import, then what
16// the page allows, then the lists, and Delete… last, set apart.
17func TestFileIsTheFirstMenuInTheMacOrder(t *testing.T) {
18 rig, _ := newImportRig(t, notiontest.NewWorkspace("empty"))
19 acme := rig.createPage(t, Ana, "Acme", "One.")
20 pinned := rig.createPage(t, Ana, "Pinned", "Two.")
21 if answer := rig.post(t, Ana, pinned+"/pin",
22 url.Values{"pin": {"1"}}); answer.Code != http.StatusSeeOther {
23 t.Fatalf("pinning: %d", answer.Code)
24 }
25 scratch := rig.post(t, Ana, "/scratch", url.Values{"body": {"Mine."}}).
26 Header().Get("Location")
27 for _, check := range []struct {
28 who, at string
29 want []string
30 }{
31 {Ana, acme, []string{"New team page", "New scratch page", "—",
32 "Import from Notion…", "—", "Rename…", "Icon and banner…",
33 "Link to a block…",
34 "History", "Pin to sidebar", "—", "Deleted pages", "—",
35 "Delete…"}},
36 {Bo, acme, []string{"New team page", "New scratch page", "—",
37 "Rename…", "Icon and banner…",
38 "Link to a block…", "History", "Pin to sidebar",
39 "—", "Deleted pages", "—", "Delete…"}},
40 {Ana, pinned, []string{"New team page", "New scratch page", "—",
41 "Import from Notion…", "—", "Rename…", "Icon and banner…",
42 "Link to a block…",
43 "History", "Unpin from sidebar", "—", "Deleted pages", "—",
44 "Delete…"}},
45 {Ana, scratch, []string{"New team page", "New scratch page", "—",
46 "Import from Notion…", "—", "Make team page…", "History",
47 "Pin to sidebar", "—", "Deleted pages", "—", "Delete…"}},
48 {Ana, "/pages", []string{"New team page", "New scratch page",
49 "—", "Import from Notion…", "—", "Deleted pages"}},
50 {Bo, "/pages", []string{"New team page", "New scratch page",
51 "—", "Deleted pages"}},
52 } {
53 page := rig.page(t, check.who, check.at)
54 if first := between(page, "<summary estilo-menubar-title>",
55 "<"); first != "File" {
56 t.Errorf("%s as %s: the first menu is %q", check.at,
57 check.who, first)
58 }
59 if strings.Contains(page, `id="mapa-menu-page"`) {
60 t.Errorf("%s as %s: a Page menu is still drawn", check.at,
61 check.who)
62 }
63 if got := menuRows(fileMenuOf(page)); !slices.Equal(got,
64 check.want) {
65 t.Errorf("%s as %s: File is\n%q\nwant\n%q", check.at,
66 check.who, got, check.want)
67 }
68 }
69}
70
71// menuRow is a menu's row label or its divider.
72var menuRow = regexp.MustCompile(`<hr>|<span estilo-menu-label>([^<]*)<`)
73
74// menuRows is a menu's rows in order, a divider as "—".
75func menuRows(menu string) []string {
76 var rows []string
77 for _, match := range menuRow.FindAllStringSubmatch(menu, -1) {
78 if match[0] == "<hr>" {
79 rows = append(rows, "—")
80 continue
81 }
82 rows = append(rows, match[1])
83 }
84 return rows
85}
86