package mapatest
import (
"net/http"
"net/url"
"strings"
"testing"
)
// LOOK6, LOOK8 and LOOK12's scope half (columns and icons spec §9),
// from the outside: an icon wherever a title is, with every accessible
// name as it was; the look page with script off; and a cached small
// picture answering 404 to anyone who may not read it.
func TestLook6TheIconIsWhereverTheTitleIs(t *testing.T) {
rig := newRig(t)
acme := rig.createPage(t, Ana, "Acme", "Customer since 2024.")
rig.createPage(t, Bo, "Notes", "We met [[Acme]].")
rig.post(t, Bo, acme+"/pin", url.Values{"pin": {"1"}})
before := rig.page(t, Bo, "/pages")
rig.post(t, Ana, acme+"/look", url.Values{"do": {"emoji"},
"emoji": {"🧭"}})
icon := `🧭`
for _, path := range []string{acme, "/pages", "/search?q=Acme"} {
if !strings.Contains(rig.page(t, Bo, path), icon) {
t.Errorf("%s draws no icon", path)
}
}
page := rig.page(t, Bo, acme)
if !strings.Contains(page, "
🧭 Acme · Mapa") {
t.Error("the tab's title has no icon")
}
notes := rig.page(t, Bo, "/search?q=met")
if !strings.Contains(notes, icon) && !strings.Contains(notes, "Notes") {
t.Error("search lost its rows")
}
if strings.Count(before, "aria-label") !=
strings.Count(rig.page(t, Bo, "/pages"), "aria-label") {
t.Error("an icon changed the accessible names")
}
}
func TestLook6AChipShowsItsPagesIcon(t *testing.T) {
rig := newRig(t)
acme := rig.createPage(t, Ana, "Acme", "One.")
notes := rig.createPage(t, Bo, "Notes", "We met [[Acme]].")
rig.post(t, Ana, acme+"/look", url.Values{"do": {"emoji"},
"emoji": {"🧭"}})
page := rig.page(t, Bo, notes)
if !strings.Contains(page, `aria-label="Acme, team page">`+
`🧭Acme`) {
t.Fatal("the chip does not draw the page's icon")
}
}
func TestLook8TheLookPageWorksWithScriptOff(t *testing.T) {
rig := newRig(t)
acme := rig.createPage(t, Ana, "Acme", "One.")
form := rig.page(t, Bo, acme+"/look")
banner := `action="` + acme + `/look?upload=1&for=banner"`
if !strings.Contains(form, banner) {
t.Fatal("the look page has no banner upload")
}
reply := rig.sendFile(t, Bo, acme+"/look?upload=1&for=icon", nil,
"icon.png", pngOf(t, 3))
if reply.Code != http.StatusOK && reply.Code != http.StatusSeeOther {
t.Fatalf("icon upload: %d %s", reply.Code, reply.Body.String())
}
if !strings.Contains(rig.page(t, Ana, acme), `
= 400 {
t.Fatalf("banner upload: %d", reply.Code)
}
rig.post(t, Bo, acme+"/look", url.Values{"do": {"position"},
"y": {"0"}})
page := rig.page(t, Ana, acme)
if !strings.Contains(page, `= 400 {
t.Fatalf("banner: %d", reply.Code)
}
before = rig.count(t, "revisions")
rig.post(t, Bo, acme+"/look", url.Values{"do": {"position"}})
if rig.count(t, "revisions") != before ||
!strings.Contains(rig.page(t, Ana, acme), `data-y="35"`) {
t.Fatal("a position post with none chosen moved the banner")
}
}