package mapatest import ( "html" "net/http" "net/url" "strings" "testing" ) // L8 for images (images spec §4.4, §6): with script off, Upload and // insert on every Markdown screen, the Images on this page list, and // Remove's confirm page. // textarea is the Markdown screen's text, unescaped. func textarea(page string) string { _, after, _ := strings.Cut(page, `name="body"`) _, after, _ = strings.Cut(after, ">") text, _, _ := strings.Cut(after, "") return html.UnescapeString(text) } func TestL8UploadAndInsertOnAPagesMarkdownScreen(t *testing.T) { rig := newRig(t) acme := rig.createPage(t, Ana, "Acme", "Customer since 2024.") edit := rig.page(t, Ana, acme+"/edit") if !strings.Contains(edit, `type="file"`) || !strings.Contains(edit, `formaction="`+acme+`?upload=1"`) { t.Fatal("the Markdown screen has no Upload and insert") } revision := revisionAs(t, rig, Ana, acme) before := rig.count(t, "revisions") reply := rig.sendFile(t, Ana, acme+"?upload=1", url.Values{ "body": {"Customer since 2024."}, "revision": {revision}, "alt": {" The signed contract \n"}}, "contract.png", pngOf(t, 1)) shown := reply.Body.String() text := textarea(shown) if reply.Code != http.StatusOK || !strings.HasPrefix(text, "Customer since 2024.\n\n![The signed contract](/i/") { t.Fatalf("%d, text %q", reply.Code, text) } if !strings.Contains(shown, `name="revision" value="`+revision+`"`) || rig.count(t, "revisions") != before || rig.count(t, "drafts") != 0 { t.Fatal("the upload committed, wrote a draft or moved the base") } if !strings.Contains(shown, "Images on this page") || !strings.Contains(shown, "The signed contract") { t.Error("the list does not name the pending image") } rig.post(t, Ana, acme, url.Values{"body": {text}, "revision": {revision}}) page := rig.page(t, Bo, acme) if !strings.Contains(page, `