| 1 | package mapatest |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "net/http" |
| 6 | "net/url" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | "time" |
| 10 | ) |
| 11 | |
| 12 | func TestHistoryListsRestoresAndForgetsAfter90Days(t *testing.T) { |
| 13 | rig := newRig(t) |
| 14 | moving := rig.clocked(t) |
| 15 | acme := rig.createPage(t, Ana, "Acme", "First version.") |
| 16 | first := revisionOf(t, rig, acme) |
| 17 | moving.now = moving.now.Add(time.Hour) |
| 18 | rig.post(t, Bo, acme, url.Values{"revision": {first}, |
| 19 | "body": {"Second version."}}) |
| 20 | history := rig.page(t, Ana, acme+"/history") |
| 21 | if strings.Count(history, `href="`+acme+`/history/`) != 2 || |
| 22 | !strings.Contains(history, "<b>bo</b>") || |
| 23 | !strings.Contains(history, "<b>You</b>") { |
| 24 | t.Fatalf("history does not list both revisions with their actors") |
| 25 | } |
| 26 | old := rig.page(t, Ana, acme+"/history/"+first) |
| 27 | if !strings.Contains(old, "First version.") { |
| 28 | t.Fatal("an old revision does not show its text") |
| 29 | } |
| 30 | restored := rig.post(t, Ana, acme+"/history/"+first, nil) |
| 31 | if restored.Code != http.StatusSeeOther || |
| 32 | !strings.Contains(rig.page(t, Bo, acme), "First version.") || |
| 33 | revisionOf(t, rig, acme) == first { |
| 34 | t.Fatal("restore must mint a new revision with the old text") |
| 35 | } |
| 36 | moving.now = moving.now.Add(91 * 24 * time.Hour) |
| 37 | rig.built.Store.Sweep(context.Background()) |
| 38 | if code := rig.get(t, Ana, acme+"/history/"+first).Code; code != 404 { |
| 39 | t.Fatalf("a revision past the window: %d", code) |
| 40 | } |
| 41 | if rig.count(t, "revisions") != 1 { |
| 42 | t.Fatal("the sweep kept old revisions, or lost the current one") |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | // A block marker is minted only by an edit to the page holding the block |
| 47 | // (§3.2): it is in that page's history as an edit by the person. |
| 48 | func TestLinkToThisBlockMintsAMarkerAsAnEdit(t *testing.T) { |
| 49 | rig := newRig(t) |
| 50 | acme := rig.createPage(t, Ana, "Acme", "First.\n\nSecond.") |
| 51 | minted := rig.post(t, Bo, acme+"/blocks", url.Values{"block": {"1"}}) |
| 52 | location := minted.Header().Get("Location") |
| 53 | marker := between(location, "marker=", "&") |
| 54 | if marker == "" { |
| 55 | t.Fatalf("no marker in %q", location) |
| 56 | } |
| 57 | if !strings.Contains(rig.page(t, Ana, acme+"/edit"), |
| 58 | "Second. ^"+marker) { |
| 59 | t.Fatal("the marker is not in the page's text") |
| 60 | } |
| 61 | if !strings.Contains(rig.page(t, Ana, location), "[[Acme#^"+marker+"]]") { |
| 62 | t.Fatal("the link to copy is not shown") |
| 63 | } |
| 64 | notes := rig.createPage(t, Ana, "Notes", "See [[Acme#^"+marker+"]].") |
| 65 | if !strings.Contains(rig.page(t, Bo, notes), "#b-"+marker) { |
| 66 | t.Fatal("the block link does not lead to the block") |
| 67 | } |
| 68 | scratch := rig.post(t, Ana, "/scratch", url.Values{"body": {"x"}}) |
| 69 | path := scratch.Header().Get("Location") |
| 70 | if rig.get(t, Ana, path+"/blocks").Code != http.StatusNotFound { |
| 71 | t.Fatal("a private page offers block markers") |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // Review M4: a chosen version's diff draws the editor's empty paragraph |
| 76 | // at most once, at its end; never after a kept list mid-text. |
| 77 | func TestAVersionDiffEndsInOneEmptyParagraph(t *testing.T) { |
| 78 | rig := newRig(t) |
| 79 | moving := rig.clocked(t) |
| 80 | acme := rig.createPage(t, Ana, "Acme", "- One\n- Two\n\nOld end.\n\n"+ |
| 81 | "- Three") |
| 82 | first := revisionOf(t, rig, acme) |
| 83 | moving.now = moving.now.Add(time.Hour) |
| 84 | rig.post(t, Bo, acme, url.Values{"revision": {first}, |
| 85 | "body": {"- One\n- Two\n\nA new end entirely.\n\n- Three"}}) |
| 86 | version := rig.page(t, Ana, acme+"/history/"+revisionOf(t, rig, acme)) |
| 87 | empty := `<p><br class="ProseMirror-trailingBreak"></p>` |
| 88 | if strings.Count(version, empty) != 1 || !strings.Contains(version, |
| 89 | "<li><p>Three</p></li></ul>"+empty) { |
| 90 | t.Fatalf("the empty paragraph is not drawn once, at the end:\n%s", |
| 91 | version) |
| 92 | } |
| 93 | } |
| 94 | |