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 "context"
7 "strings"
8 "testing"
9 "time"
10
11 "github.com/chromedp/chromedp"
12
13 "amadan.net/oficina/mapa/internal/mapa"
14)
15
16// L9 end to end for Fable's final review of 58fd476: a page deleted
17// mid-edit keeps what is typed (H1), and the inline choice commits from
18// the text on screen (M1). Each case, alone, is editor/saver.test.mjs's.
19
20// statusText is the lead slot's save status as shown.
21const statusText = `document.querySelector('[estilo-save-status]').textContent`
22
23// toScratch is the deleted page's bar's Save as a scratch page.
24const toScratch = `[mapa-editor-notice] form[action$="/draft/scratch"]`
25
26func TestL9APageDeletedMidEditKeepsWhatIsTyped(t *testing.T) {
27 rig, store := browserRig(t, 0)
28 page := teamPage(t, rig, store, "One.")
29 drive(t, rig, caretAt(0), chromedp.KeyEvent(" Ana."))
30 eventually(t, "a draft", func() bool {
31 _, found := draftOf(t, store, page.ID)
32 return found
33 })
34 if err := store.Delete(context.Background(), Bo, page.ID); err != nil {
35 t.Fatal(err)
36 }
37 drive(t, rig, chromedp.KeyEvent(" More."),
38 chromedp.WaitVisible(toScratch),
39 chromedp.KeyEvent(" After."))
40 eventually(t, "typing after the delete stored as the draft", func() bool {
41 draft, _ := draftOf(t, store, page.ID)
42 return draft.Body == "One. Ana. More. After."
43 })
44 if got := read(t, rig, chromedp.Evaluate[string](statusText)); got !=
45 "Saved as a draft" {
46 t.Fatalf("the status says %q", got)
47 }
48 // Typed and saved at once: the scratch page takes it all.
49 drive(t, rig, chromedp.KeyEvent(" Last."),
50 chromedp.Click(toScratch+" button"))
51 eventually(t, "the scratch page", func() bool {
52 return !strings.HasSuffix(read(t, rig, chromedp.Location()),
53 mapa.PagePath(page))
54 })
55 drive(t, rig, chromedp.WaitVisible(mounted))
56 if got := typed(t, rig); got != "One. Ana. More. After. Last." {
57 t.Fatalf("the scratch page holds %q", got)
58 }
59}
60
61func TestL9TheInlineChoiceCommitsWhatIsOnScreen(t *testing.T) {
62 rig, store := browserRig(t, 0)
63 page := teamPage(t, rig, store, "One.\n\nTwo.")
64 if _, err := store.Commit(context.Background(), Bo, page.ID,
65 page.Revision, "One, as Bo has it.\n\nTwo."); err != nil {
66 t.Fatal(err)
67 }
68 drive(t, rig, caretAt(0), chromedp.KeyEvent(" Ana."),
69 chromedp.WaitVisible(`[mapa-hunk-choice]`))
70 // Typed elsewhere and chosen before the autosave's 1.2s are up.
71 drive(t, rig, caretAt(1), chromedp.KeyEvent(" Free."),
72 chromedp.Click(`[mapa-hunk-choice] button[data-choice="mine"]`))
73 eventually(t, "Resolve's commit with the typing", func() bool {
74 _, body := current(t, store, page.ID)
75 return body == "One. Ana.\n\nTwo. Free."
76 })
77 drive(t, rig, chromedp.Sleep(300*time.Millisecond))
78 if got := typed(t, rig); got != "One. Ana.\n\nTwo. Free." {
79 t.Fatalf("the editor holds %q", got)
80 }
81}
82