oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1package docs_test
2
3import (
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.
20func 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 //
39 // And order (spec I2): the header's controls are one set, undo/redo in
40 // the lead, then Format, then Share, the one primary, last before the
41 // account.
42 end := strings.Index(body, "<div estilo-bar-end>")
43 if end < 0 {
44 t.Fatal("the bar has no end group")
45 }
46 tail := body[end:]
47 lead := strings.Index(tail, "<div estilo-bar-lead>")
48 format := strings.Index(tail, `<div estilo-bar-control="wide"><button rst-btn type="button" aria-expanded="true" aria-controls="docs-inspector" disabled data-estilo-toggle estilo-bar-wide>`)
49 link := strings.Index(tail, `<div estilo-bar-control="primary"><a rst-btn="primary" href="/d/`+sqid+`/share">`)
50 acct := strings.Index(tail, "<details estilo-account")
51 if lead < 0 || format < 0 || link < 0 || acct < 0 {
52 t.Fatalf("the bar's end group lacks a piece: lead %d, Format %d, Share %d, account %d", lead, format, link, acct)
53 }
54 if !(lead < format && format < link && link < acct) {
55 t.Errorf("the bar's end group is out of order: lead %d, Format %d, Share %d, account %d; want lead, Format, Share, account", lead, format, link, acct)
56 }
57 if strings.Count(tail[:acct], "estilo-bar-control=\"primary\"") != 1 {
58 t.Error("Share is not the bar's one primary action")
59 }
60}
61
62// A grantee must not be offered it. sharePage is owner-only and answers a
63// grantee with 404, so a share link on their page would be a control that
64// visibly fails — worse than no control, because it reads as a broken app
65// rather than as a boundary.
66func TestAGranteeIsNotOfferedTheShareControl(t *testing.T) {
67 app, _ := docs.NewForTest(t)
68 alice := signInCookies(t, app, "alice@example.com")
69 sqid := createDoc(t, app, alice, "Minutes")
70 bob := signInCookies(t, app, "bob@example.com")
71
72 // A writer, deliberately: the strongest grant there is still does not
73 // carry re-sharing (Store.Grant's own rule).
74 post(t, app, alice, "/d/"+sqid+"/share", "address=bob@example.com&role=writer")
75
76 rec := get(t, app, bob, "/d/"+sqid)
77 if rec.Code != http.StatusOK {
78 t.Fatalf("GET /d/%s as Bob: status %d, want 200", sqid, rec.Code)
79 }
80 if strings.Contains(rec.Body.String(), "/d/"+sqid+"/share") {
81 t.Error("a writer grantee was offered a share control they cannot use")
82 }
83
84 // And the boundary it stands for is real, not just hidden in markup.
85 if rec := get(t, app, bob, "/d/"+sqid+"/share"); rec.Code != http.StatusNotFound {
86 t.Errorf("GET share as a grantee: status %d, want 404", rec.Code)
87 }
88}
89