| 1 | package docs_test |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/carlosframework/docs/internal/docs" |
| 9 | ) |
| 10 | |
| 11 | // Paul's note: "there should be a 'share' icon probably beside the account |
| 12 | // dropdown top right". Before this, the share page existed and nothing led |
| 13 | // to it — sharing worked only for somebody who knew to type /share onto a |
| 14 | // URL, which is not a feature, it is a rumour. |
| 15 | // |
| 16 | // The control is the estilo bar's one action, "Share…", which the bar puts |
| 17 | // at the inline end immediately before the switcher and the account menu. |
| 18 | // That is the requested position, and it is a slot the suite's shared bar |
| 19 | // owns rather than one this app draws for itself. |
| 20 | func TestTheOwnerGetsAShareControlInTheBar(t *testing.T) { |
| 21 | app, _ := docs.NewForTest(t) |
| 22 | alice := signInCookies(t, app, "alice@example.com") |
| 23 | sqid := createDoc(t, app, alice, "Minutes") |
| 24 | |
| 25 | rec := get(t, app, alice, "/d/"+sqid) |
| 26 | if rec.Code != http.StatusOK { |
| 27 | t.Fatalf("GET /d/%s: status %d, want 200", sqid, rec.Code) |
| 28 | } |
| 29 | body := rec.Body.String() |
| 30 | if !strings.Contains(body, "/d/"+sqid+"/share") { |
| 31 | t.Error("the document page offers no route to its own share page") |
| 32 | } |
| 33 | |
| 34 | // Position, not just presence: the link has to be in the bar's end |
| 35 | // group, beside the account menu, rather than anywhere on the page. A |
| 36 | // test that only asserted presence would pass on a link buried in the |
| 37 | // footer. |
| 38 | end := strings.Index(body, "<div estilo-bar-end>") |
| 39 | if end < 0 { |
| 40 | t.Fatal("the bar has no end group") |
| 41 | } |
| 42 | tail := body[end:] |
| 43 | acct := strings.Index(tail, "<details estilo-account") |
| 44 | link := strings.Index(tail, `<div estilo-bar-actions><a rst-btn href="/d/`+sqid+`/share">`) |
| 45 | if link < 0 || acct < 0 || link > acct { |
| 46 | t.Error("the share control is not in the bar's actions before the account menu") |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // A grantee must not be offered it. sharePage is owner-only and answers a |
| 51 | // grantee with 404, so a share link on their page would be a control that |
| 52 | // visibly fails — worse than no control, because it reads as a broken app |
| 53 | // rather than as a boundary. |
| 54 | func TestAGranteeIsNotOfferedTheShareControl(t *testing.T) { |
| 55 | app, _ := docs.NewForTest(t) |
| 56 | alice := signInCookies(t, app, "alice@example.com") |
| 57 | sqid := createDoc(t, app, alice, "Minutes") |
| 58 | bob := signInCookies(t, app, "bob@example.com") |
| 59 | |
| 60 | // A writer, deliberately: the strongest grant there is still does not |
| 61 | // carry re-sharing (Store.Grant's own rule). |
| 62 | post(t, app, alice, "/d/"+sqid+"/share", "address=bob@example.com&role=writer") |
| 63 | |
| 64 | rec := get(t, app, bob, "/d/"+sqid) |
| 65 | if rec.Code != http.StatusOK { |
| 66 | t.Fatalf("GET /d/%s as Bob: status %d, want 200", sqid, rec.Code) |
| 67 | } |
| 68 | if strings.Contains(rec.Body.String(), "/d/"+sqid+"/share") { |
| 69 | t.Error("a writer grantee was offered a share control they cannot use") |
| 70 | } |
| 71 | |
| 72 | // And the boundary it stands for is real, not just hidden in markup. |
| 73 | if rec := get(t, app, bob, "/d/"+sqid+"/share"); rec.Code != http.StatusNotFound { |
| 74 | t.Errorf("GET share as a grantee: status %d, want 404", rec.Code) |
| 75 | } |
| 76 | } |
| 77 | |