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 "strings"
7 "testing"
8)
9
10// LOOK6, LOOK8 and LOOK12's scope half (columns and icons spec §9),
11// from the outside: an icon wherever a title is, with every accessible
12// name as it was; the look page with script off; and a cached small
13// picture answering 404 to anyone who may not read it.
14
15func TestLook6TheIconIsWhereverTheTitleIs(t *testing.T) {
16 rig := newRig(t)
17 acme := rig.createPage(t, Ana, "Acme", "Customer since 2024.")
18 rig.createPage(t, Bo, "Notes", "We met [[Acme]].")
19 rig.post(t, Bo, acme+"/pin", url.Values{"pin": {"1"}})
20 before := rig.page(t, Bo, "/pages")
21 rig.post(t, Ana, acme+"/look", url.Values{"do": {"emoji"},
22 "emoji": {"🧭"}})
23 icon := `<span mapa-icon aria-hidden="true">🧭</span>`
24 for _, path := range []string{acme, "/pages", "/search?q=Acme"} {
25 if !strings.Contains(rig.page(t, Bo, path), icon) {
26 t.Errorf("%s draws no icon", path)
27 }
28 }
29 page := rig.page(t, Bo, acme)
30 if !strings.Contains(page, "<title>🧭 Acme · Mapa</title>") {
31 t.Error("the tab's title has no icon")
32 }
33 notes := rig.page(t, Bo, "/search?q=met")
34 if !strings.Contains(notes, icon) && !strings.Contains(notes, "Notes") {
35 t.Error("search lost its rows")
36 }
37 if strings.Count(before, "aria-label") !=
38 strings.Count(rig.page(t, Bo, "/pages"), "aria-label") {
39 t.Error("an icon changed the accessible names")
40 }
41}
42
43func TestLook6AChipShowsItsPagesIcon(t *testing.T) {
44 rig := newRig(t)
45 acme := rig.createPage(t, Ana, "Acme", "One.")
46 notes := rig.createPage(t, Bo, "Notes", "We met [[Acme]].")
47 rig.post(t, Ana, acme+"/look", url.Values{"do": {"emoji"},
48 "emoji": {"🧭"}})
49 page := rig.page(t, Bo, notes)
50 if !strings.Contains(page, `aria-label="Acme, team page">`+
51 `<span mapa-i mapa-icon aria-hidden="true">🧭</span>Acme</a>`) {
52 t.Fatal("the chip does not draw the page's icon")
53 }
54}
55
56func TestLook8TheLookPageWorksWithScriptOff(t *testing.T) {
57 rig := newRig(t)
58 acme := rig.createPage(t, Ana, "Acme", "One.")
59 form := rig.page(t, Bo, acme+"/look")
60 banner := `action="` + acme + `/look?upload=1&amp;for=banner"`
61 if !strings.Contains(form, banner) {
62 t.Fatal("the look page has no banner upload")
63 }
64 reply := rig.sendFile(t, Bo, acme+"/look?upload=1&for=icon", nil,
65 "icon.png", pngOf(t, 3))
66 if reply.Code != http.StatusOK && reply.Code != http.StatusSeeOther {
67 t.Fatalf("icon upload: %d %s", reply.Code, reply.Body.String())
68 }
69 if !strings.Contains(rig.page(t, Ana, acme), `<img mapa-icon src="/i/`) {
70 t.Fatal("the uploaded icon is not drawn")
71 }
72 reply = rig.sendFile(t, Bo, acme+"/look?upload=1&for=banner",
73 url.Values{"y": {"50"}}, "wide.png", pngOf(t, 4))
74 if reply.Code >= 400 {
75 t.Fatalf("banner upload: %d", reply.Code)
76 }
77 rig.post(t, Bo, acme+"/look", url.Values{"do": {"position"},
78 "y": {"0"}})
79 page := rig.page(t, Ana, acme)
80 if !strings.Contains(page, `<div mapa-banner data-y="0"`) {
81 t.Fatal("the banner is not drawn at the top")
82 }
83 rig.post(t, Bo, acme+"/look", url.Values{"do": {"remove-banner"}})
84 rig.post(t, Bo, acme+"/look", url.Values{"do": {"remove-icon"}})
85 page = rig.page(t, Ana, acme)
86 if strings.Contains(page, "<div mapa-banner") ||
87 strings.Contains(page, "<img mapa-icon") {
88 t.Fatal("removing left the look drawn")
89 }
90}
91
92func TestLookRefusesAnEmojiThatIsNotOne(t *testing.T) {
93 rig := newRig(t)
94 acme := rig.createPage(t, Ana, "Acme", "One.")
95 reply := rig.post(t, Bo, acme+"/look", url.Values{"do": {"emoji"},
96 "emoji": {"two words"}})
97 if reply.Code != http.StatusUnprocessableEntity ||
98 !strings.Contains(reply.Body.String(), "Choose one emoji") {
99 t.Fatalf("%d", reply.Code)
100 }
101}
102
103func TestLook12ACachedPictureStillAnswersToTheReadRule(t *testing.T) {
104 rig := newRig(t)
105 created := rig.post(t, Ana, "/scratch", url.Values{"body": {"Mine."}})
106 note := created.Header().Get("Location")
107 picture := rig.upload(t, Ana, pngOf(t, 5))
108 revision := revisionAs(t, rig, Ana, note)
109 rig.post(t, Ana, note, url.Values{"revision": {revision},
110 "body": {"Mine.\n\n" + picture.markdown("x")}})
111 if code := rig.get(t, Ana, picture.Src).Code; code != http.StatusOK {
112 t.Fatalf("Ana's own picture: %d", code)
113 }
114 if code := rig.get(t, Bo, picture.Src).Code; code != http.StatusNotFound {
115 t.Fatalf("Bo read Ana's cached private picture: %d", code)
116 }
117 acme := rig.createPage(t, Ana, "Acme", "One.")
118 icon := rig.upload(t, Ana, pngOf(t, 6))
119 rig.post(t, Ana, acme+"/look", url.Values{"do": {"icon"},
120 "image": {icon.ID}})
121 if code := rig.get(t, Bo, icon.Src).Code; code != http.StatusOK {
122 t.Fatalf("a team page's icon: %d", code)
123 }
124 rig.post(t, Ana, acme+"/delete", nil)
125 if code := rig.get(t, Bo, icon.Src).Code; code != http.StatusNotFound {
126 t.Fatalf("a deleted page's cached icon: %d", code)
127 }
128}
129
130// Review round 1 on the build, M2 and M3: an icon post naming no
131// picture writes nothing, and a position post choosing none keeps the
132// one stored.
133func TestLookRefusesAnEmptyPictureAndKeepsAnUnchosenPosition(t *testing.T) {
134 rig := newRig(t)
135 acme := rig.createPage(t, Ana, "Acme", "One.")
136 before := rig.count(t, "revisions")
137 reply := rig.post(t, Bo, acme+"/look", url.Values{"do": {"icon"},
138 "image": {""}})
139 if reply.Code != http.StatusNotFound ||
140 rig.count(t, "revisions") != before {
141 t.Fatalf("an empty icon: %d", reply.Code)
142 }
143 reply = rig.sendFile(t, Bo, acme+"/look?upload=1&for=banner",
144 url.Values{"y": {"35"}}, "wide.png", pngOf(t, 8))
145 if reply.Code >= 400 {
146 t.Fatalf("banner: %d", reply.Code)
147 }
148 before = rig.count(t, "revisions")
149 rig.post(t, Bo, acme+"/look", url.Values{"do": {"position"}})
150 if rig.count(t, "revisions") != before ||
151 !strings.Contains(rig.page(t, Ana, acme), `data-y="35"`) {
152 t.Fatal("a position post with none chosen moved the banner")
153 }
154}
155