oficina / mapa Public

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

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3package mapatest
4
5import (
6 "testing"
7
8 "amadan.net/rastrillo/rastrillo/harness"
9 "github.com/chromedp/chromedp"
10 "github.com/chromedp/chromedp/kb"
11)
12
13// Fable's review of the date picker (3a7ee5f; level-up build note 83,
14// §14 round 7): M1 a date after a ! goes in after a space, never as an
15// embed, and where the Markdown would read it differently it is refused
16// with a note; M3 a selection is kept; L1 the field trims as ⌘K does; L2
17// today is the viewer's zone's; L3 ← → move the field's caret once it
18// holds text.
19
20// insertMenu runs Insert → label's command, by its data-mapa-command.
21func insertMenu(command string) chromedp.Action[chromedp.Void] {
22 return chromedp.Steps(chromedp.Click(`#mapa-menu-insert > summary`),
23 chromedp.Click(`#mapa-menu-insert button[data-mapa-command="`+
24 command+`"]`))
25}
26
27func TestADateAfterABangIsNeverAnEmbed(t *testing.T) {
28 rig, _ := browserRig(t, 0)
29 drive(t, rig, onNewDocument(mondayClock))
30 emptyDay(t, rig, "2026-11-30")
31 drive(t, rig, chromedp.KeyEvent("Look!"), insertMenu("insert-date-pick"),
32 chromedp.WaitVisible(picker), enter(),
33 chromedp.WaitNotPresent(picker))
34 if got := typed(t, rig); got != "Look! [[2026-11-16]]" {
35 t.Fatalf("the picker after a ! wrote %q", got)
36 }
37 drive(t, rig, chromedp.KeyEvent(" Wow!"), insertMenu("insert-date"))
38 if got := typed(t, rig); got != "Look! [[2026-11-16]] Wow! "+
39 "[[2026-11-16]]" {
40 t.Fatalf("Today's date after a ! wrote %q", got)
41 }
42 chips := read(t, rig, chromedp.Evaluate[int](
43 `document.querySelectorAll("article [mapa-chip]").length`))
44 if chips != 2 {
45 t.Fatalf("%d chips on the page, not 2", chips)
46 }
47}
48
49func TestADateTheMarkdownWouldMisreadIsRefused(t *testing.T) {
50 rig, store := browserRig(t, 0)
51 drive(t, rig, onNewDocument(mondayClock))
52 teamPage(t, rig, store, "`` foo ` bar ``")
53 drive(t, rig, chromedp.Evaluate[chromedp.Void](`(function () {
54 var view = mapaEditor.view, Selection = view.state.selection.constructor;
55 view.focus();
56 view.dispatch(view.state.tr.setSelection(
57 Selection.create(view.state.doc, 2)));
58})()`), insertMenu("insert-date-pick"),
59 chromedp.WaitVisible(`[mapa-datepick-note]`))
60 said := text(t, rig, `[mapa-datepick-note]`)
61 if said != "A date can’t go here: the Markdown around it would read "+
62 "differently, such as a stray ` or * pairing up. Move the caret "+
63 "and try again." {
64 t.Fatalf("the refusal says %q", said)
65 }
66 if read(t, rig, chromedp.Evaluate[bool](
67 `!!document.querySelector("[mapa-datepick]")`)) {
68 t.Fatal("the picker opened where no date can go")
69 }
70 if got := typed(t, rig); got != "`` foo ` bar ``" {
71 t.Fatalf("the refusal wrote %q", got)
72 }
73}
74
75func TestADateOverASelectionKeepsTheWords(t *testing.T) {
76 rig, _ := browserRig(t, 0)
77 drive(t, rig, onNewDocument(mondayClock))
78 emptyDay(t, rig, "2026-12-01")
79 drive(t, rig, chromedp.KeyEvent("Call Ana today"), selectWords("Ana"),
80 insertMenu("insert-date-pick"), chromedp.WaitVisible(picker),
81 chromedp.KeyEvent(kb.ArrowRight), enter(),
82 chromedp.WaitNotPresent(picker))
83 if got := typed(t, rig); got != "Call Ana[[2026-11-17]] today" {
84 t.Fatalf("Date… over a selection wrote %q", got)
85 }
86 drive(t, rig, selectWords("Call"), insertMenu("insert-date"))
87 if got := typed(t, rig); got != "Call[[2026-11-16]] Ana[[2026-11-17]] "+
88 "today" {
89 t.Fatalf("Today's date over a selection wrote %q", got)
90 }
91}
92
93func TestThePickersFieldTrimsAsCmdKDoesAndKeepsItsCaret(t *testing.T) {
94 rig, _ := browserRig(t, 0)
95 slashDate(t, rig, "2026-12-02", "Then ")
96 // U+FEFF is not a space to Go's TrimSpace, so ⌘K reads no date here.
97 drive(t, rig, chromedp.Evaluate[chromedp.Void](`(function (field) {
98 field.value = "\ufefffriday";
99 field.dispatchEvent(new Event("input"));
100})(document.querySelector("[mapa-datepick-field]"))`))
101 if got := read(t, rig, chromedp.Evaluate[string](pickerDay)); got !=
102 "2026-11-16" {
103 t.Fatalf("U+FEFF friday chose %s", got)
104 }
105 drive(t, rig, retype("next friday"), chromedp.KeyEvent(kb.ArrowLeft),
106 chromedp.KeyEvent(kb.ArrowLeft))
107 caret := read(t, rig, chromedp.Evaluate[int](
108 `document.querySelector("[mapa-datepick-field]").selectionStart`))
109 if day := read(t, rig, chromedp.Evaluate[string](pickerDay)); caret != 9 ||
110 day != "2026-11-20" {
111 t.Fatalf("← in the field: caret %d, day %s", caret, day)
112 }
113 drive(t, rig, chromedp.KeyEvent(kb.ArrowDown), enter(),
114 chromedp.WaitNotPresent(picker))
115 if got := typed(t, rig); got != "Then [[2026-11-27]]" {
116 t.Fatalf("the field's day wrote %q", got)
117 }
118}
119
120func TestTodayIsTheViewersZones(t *testing.T) {
121 rig, _ := browserRig(t, 0, harness.WithCoarsePointer())
122 drive(t, rig, onNewDocument(mondayClock))
123 emptyDay(t, rig, "2026-12-03")
124 // Noon UTC on the 16th is two in the morning of the 17th at UTC+14.
125 drive(t, rig, chromedp.Evaluate[chromedp.Void](
126 `document.body.setAttribute("data-zone", "Pacific/Kiritimati")`),
127 caretAt(0), insertMenu("insert-date"))
128 if got := typed(t, rig); got != "[[2026-11-17]]" {
129 t.Fatalf("Today's date at UTC+14 wrote %q", got)
130 }
131}
132