| 1 | package mapatest |
| 2 | |
| 3 | import ( |
| 4 | "net/url" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | // The week strip's tidy-up (Paul, 2026-11-16; level-up build note 82): |
| 10 | // a key under the strip says what the fill, the ring and the dot mean; |
| 11 | // a daily note's panel lists Linked from before Links out, as a team |
| 12 | // page's does; and the empty lists say so in a few words. The panel is |
| 13 | // the server's HTML, so this is what a browser with no script shows. |
| 14 | |
| 15 | // weekKey is the strip's key as drawn. |
| 16 | const weekKey = `<p mapa-week-key><span mapa-k="shown"><span mapa-sr>` + |
| 17 | `Filled: </span>Day shown</span><span mapa-k="today"><span mapa-sr>` + |
| 18 | `, ringed: </span>Today</span><span mapa-k="wrote"><span mapa-sr>` + |
| 19 | `, dot: </span>A note you wrote</span></p>` |
| 20 | |
| 21 | // panelOf is the Links panel's own HTML, the page's foot left out. |
| 22 | func panelOf(page string) string { |
| 23 | return between(page, `<aside mapa-links`, `</aside>`) |
| 24 | } |
| 25 | |
| 26 | // inOrder fails unless each of words is found in text after the last. |
| 27 | func inOrder(t *testing.T, what, text string, words ...string) { |
| 28 | t.Helper() |
| 29 | at := 0 |
| 30 | for _, word := range words { |
| 31 | next := strings.Index(text[at:], word) |
| 32 | if next < 0 { |
| 33 | t.Fatalf("%s: %q is missing, or out of order (%v)", what, |
| 34 | word, words) |
| 35 | } |
| 36 | at += next + len(word) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | func TestTheWeekStripHasAKey(t *testing.T) { |
| 41 | rig := newRig(t) |
| 42 | rig.post(t, Ana, "/d/2026-11-10", url.Values{"body": {"Written."}}) |
| 43 | for _, day := range []string{"/d/2026-11-10", "/d/2026-11-20"} { |
| 44 | panel := panelOf(rig.getWith(Ana, day)) |
| 45 | if !strings.Contains(panel, weekKey) { |
| 46 | t.Fatalf("%s: the strip has no key:\n%s", day, panel) |
| 47 | } |
| 48 | inOrder(t, day, panel, `<ol mapa-week-days>`, weekKey) |
| 49 | } |
| 50 | acme := rig.createPage(t, Ana, "Acme", "One.") |
| 51 | if strings.Contains(rig.getWith(Ana, acme), "mapa-week-key") { |
| 52 | t.Fatal("a team page, which has no strip, has its key") |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | func TestADailyNoteListsLinkedFromFirst(t *testing.T) { |
| 57 | rig := newRig(t) |
| 58 | rig.post(t, Ana, "/d/2026-11-10", url.Values{"body": {"Written."}}) |
| 59 | for _, day := range []string{"/d/2026-11-10", "/d/2026-11-20"} { |
| 60 | inOrder(t, day, panelOf(rig.getWith(Ana, day)), |
| 61 | `>This week</h2>`, `>Linked from `, `>Links out `) |
| 62 | } |
| 63 | acme := rig.createPage(t, Ana, "Acme", "One.") |
| 64 | inOrder(t, "a team page", panelOf(rig.getWith(Ana, acme)), |
| 65 | `>Around this page</h2>`, `>Linked from `, |
| 66 | `>Mentioned without a link `, `>Links out `) |
| 67 | } |
| 68 | |
| 69 | func TestTheEmptyListsSaySoBriefly(t *testing.T) { |
| 70 | rig := newRig(t) |
| 71 | rig.post(t, Ana, "/d/2026-11-10", url.Values{"body": {"Written."}}) |
| 72 | day := rig.getWith(Ana, "/d/2026-11-10") |
| 73 | panel := panelOf(day) |
| 74 | foot := between(day, `<footer mapa-foot-refs rst-stack rst-section>`, |
| 75 | `</footer>`) |
| 76 | for _, where := range []struct{ name, html string }{ |
| 77 | {"the panel", panel}, {"the page's foot", foot}} { |
| 78 | inOrder(t, where.name, where.html, |
| 79 | `<p mapa-meta>Nothing links to this day yet.</p>`, |
| 80 | `<p mapa-meta>No links out yet.</p>`) |
| 81 | if strings.Contains(where.html, "A date link in any") || |
| 82 | strings.Contains(where.html, "links nowhere") { |
| 83 | t.Fatalf("%s keeps an old empty text:\n%s", where.name, |
| 84 | where.html) |
| 85 | } |
| 86 | } |
| 87 | acme := panelOf(rig.getWith(Ana, rig.createPage(t, Ana, "Acme", |
| 88 | "One."))) |
| 89 | inOrder(t, "a team page", acme, `Nothing links here yet.`, |
| 90 | `This page links nowhere yet.`) |
| 91 | } |
| 92 | |