package mapatest import ( "context" "net/http" "net/url" "strings" "testing" "time" ) func TestHistoryListsRestoresAndForgetsAfter90Days(t *testing.T) { rig := newRig(t) moving := rig.clocked(t) acme := rig.createPage(t, Ana, "Acme", "First version.") first := revisionOf(t, rig, acme) moving.now = moving.now.Add(time.Hour) rig.post(t, Bo, acme, url.Values{"revision": {first}, "body": {"Second version."}}) history := rig.page(t, Ana, acme+"/history") if strings.Count(history, `href="`+acme+`/history/`) != 2 || !strings.Contains(history, "bo") || !strings.Contains(history, "You") { t.Fatalf("history does not list both revisions with their actors") } old := rig.page(t, Ana, acme+"/history/"+first) if !strings.Contains(old, "First version.") { t.Fatal("an old revision does not show its text") } restored := rig.post(t, Ana, acme+"/history/"+first, nil) if restored.Code != http.StatusSeeOther || !strings.Contains(rig.page(t, Bo, acme), "First version.") || revisionOf(t, rig, acme) == first { t.Fatal("restore must mint a new revision with the old text") } moving.now = moving.now.Add(91 * 24 * time.Hour) rig.built.Store.Sweep(context.Background()) if code := rig.get(t, Ana, acme+"/history/"+first).Code; code != 404 { t.Fatalf("a revision past the window: %d", code) } if rig.count(t, "revisions") != 1 { t.Fatal("the sweep kept old revisions, or lost the current one") } } // A block marker is minted only by an edit to the page holding the block // (ยง3.2): it is in that page's history as an edit by the person. func TestLinkToThisBlockMintsAMarkerAsAnEdit(t *testing.T) { rig := newRig(t) acme := rig.createPage(t, Ana, "Acme", "First.\n\nSecond.") minted := rig.post(t, Bo, acme+"/blocks", url.Values{"block": {"1"}}) location := minted.Header().Get("Location") marker := between(location, "marker=", "&") if marker == "" { t.Fatalf("no marker in %q", location) } if !strings.Contains(rig.page(t, Ana, acme+"/edit"), "Second. ^"+marker) { t.Fatal("the marker is not in the page's text") } if !strings.Contains(rig.page(t, Ana, location), "[[Acme#^"+marker+"]]") { t.Fatal("the link to copy is not shown") } notes := rig.createPage(t, Ana, "Notes", "See [[Acme#^"+marker+"]].") if !strings.Contains(rig.page(t, Bo, notes), "#b-"+marker) { t.Fatal("the block link does not lead to the block") } scratch := rig.post(t, Ana, "/scratch", url.Values{"body": {"x"}}) path := scratch.Header().Get("Location") if rig.get(t, Ana, path+"/blocks").Code != http.StatusNotFound { t.Fatal("a private page offers block markers") } } // Review M4: a chosen version's diff draws the editor's empty paragraph // at most once, at its end; never after a kept list mid-text. func TestAVersionDiffEndsInOneEmptyParagraph(t *testing.T) { rig := newRig(t) moving := rig.clocked(t) acme := rig.createPage(t, Ana, "Acme", "- One\n- Two\n\nOld end.\n\n"+ "- Three") first := revisionOf(t, rig, acme) moving.now = moving.now.Add(time.Hour) rig.post(t, Bo, acme, url.Values{"revision": {first}, "body": {"- One\n- Two\n\nA new end entirely.\n\n- Three"}}) version := rig.page(t, Ana, acme+"/history/"+revisionOf(t, rig, acme)) empty := `


` if strings.Count(version, empty) != 1 || !strings.Contains(version, "
  • Three

  • "+empty) { t.Fatalf("the empty paragraph is not drawn once, at the end:\n%s", version) } }