//go:build browser package mapatest import ( "context" "strings" "testing" "time" "github.com/chromedp/chromedp" "amadan.net/oficina/mapa/internal/mapa" ) // L9 end to end for Fable's final review of 58fd476: a page deleted // mid-edit keeps what is typed (H1), and the inline choice commits from // the text on screen (M1). Each case, alone, is editor/saver.test.mjs's. // statusText is the lead slot's save status as shown. const statusText = `document.querySelector('[estilo-save-status]').textContent` // toScratch is the deleted page's bar's Save as a scratch page. const toScratch = `[mapa-editor-notice] form[action$="/draft/scratch"]` func TestL9APageDeletedMidEditKeepsWhatIsTyped(t *testing.T) { rig, store := browserRig(t, 0) page := teamPage(t, rig, store, "One.") drive(t, rig, caretAt(0), chromedp.KeyEvent(" Ana.")) eventually(t, "a draft", func() bool { _, found := draftOf(t, store, page.ID) return found }) if err := store.Delete(context.Background(), Bo, page.ID); err != nil { t.Fatal(err) } drive(t, rig, chromedp.KeyEvent(" More."), chromedp.WaitVisible(toScratch), chromedp.KeyEvent(" After.")) eventually(t, "typing after the delete stored as the draft", func() bool { draft, _ := draftOf(t, store, page.ID) return draft.Body == "One. Ana. More. After." }) if got := read(t, rig, chromedp.Evaluate[string](statusText)); got != "Saved as a draft" { t.Fatalf("the status says %q", got) } // Typed and saved at once: the scratch page takes it all. drive(t, rig, chromedp.KeyEvent(" Last."), chromedp.Click(toScratch+" button")) eventually(t, "the scratch page", func() bool { return !strings.HasSuffix(read(t, rig, chromedp.Location()), mapa.PagePath(page)) }) drive(t, rig, chromedp.WaitVisible(mounted)) if got := typed(t, rig); got != "One. Ana. More. After. Last." { t.Fatalf("the scratch page holds %q", got) } } func TestL9TheInlineChoiceCommitsWhatIsOnScreen(t *testing.T) { rig, store := browserRig(t, 0) page := teamPage(t, rig, store, "One.\n\nTwo.") if _, err := store.Commit(context.Background(), Bo, page.ID, page.Revision, "One, as Bo has it.\n\nTwo."); err != nil { t.Fatal(err) } drive(t, rig, caretAt(0), chromedp.KeyEvent(" Ana."), chromedp.WaitVisible(`[mapa-hunk-choice]`)) // Typed elsewhere and chosen before the autosave's 1.2s are up. drive(t, rig, caretAt(1), chromedp.KeyEvent(" Free."), chromedp.Click(`[mapa-hunk-choice] button[data-choice="mine"]`)) eventually(t, "Resolve's commit with the typing", func() bool { _, body := current(t, store, page.ID) return body == "One. Ana.\n\nTwo. Free." }) drive(t, rig, chromedp.Sleep(300*time.Millisecond)) if got := typed(t, rig); got != "One. Ana.\n\nTwo. Free." { t.Fatalf("the editor holds %q", got) } }