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 "regexp"
5 "strings"
6 "testing"
7
8 "github.com/carlosframework/docs/internal/docs"
9)
10
11// The share page is on the design system's vocabulary (the audit's worst
12// Docs finding: browser-default buttons, a bare fieldset, a bulleted list
13// of grants, and a one-time link printed as <code> with no Copy button).
14func TestTheSharePageIsBuiltFromTheDesignSystem(t *testing.T) {
15 app, _ := docs.NewForTest(t)
16 alice := signInCookies(t, app, "alice@example.com")
17 sqid := createDoc(t, app, alice, "Minutes")
18 post(t, app, alice, "/d/"+sqid+"/share", "address=bob@example.com&role=reader")
19 published := post(t, app, alice, "/d/"+sqid+"/share/link", "on=1")
20 body := get(t, app, alice, published.Header().Get("Location")).Body.String()
21 if published.Header().Get("Location") == "" {
22 body = published.Body.String()
23 }
24
25 if m := regexp.MustCompile(`<button(?: [^>]*)?>`).FindAllString(body, -1); len(m) == 0 {
26 t.Fatal("no buttons on the share page")
27 } else {
28 for _, b := range m {
29 if !strings.Contains(b, "rst-btn") && !strings.Contains(b, "estilo-") {
30 t.Errorf("an unstyled button: %s", b)
31 }
32 }
33 }
34 for _, gone := range []string{`<ul[ >]`, `<li[ >]`, `<code>`, `<fieldset>`} {
35 if regexp.MustCompile(gone).MatchString(body) {
36 t.Errorf("the share page still writes %s", gone)
37 }
38 }
39 for _, want := range []string{
40 `<div rst-list docs-share-list>`,
41 `<span docs-share-who>bob@example.com</span>`,
42 `<fieldset rst-choice>`,
43 `type="email" id="share-address" name="address"`,
44 `docs-share-url-input type="text" readonly value="http`,
45 `docs-share-copy data-copied="docs.share.public.copied" hidden>docs.share.public.copy</button>`,
46 `<script type="module" defer src="/static/share.`,
47 } {
48 if !strings.Contains(body, want) {
49 t.Errorf("the share page lacks %s", want)
50 }
51 }
52}
53
54// Without script the Copy button must stay hidden: it does nothing until
55// share-link.mjs mounts. It ships with the hidden attribute, but the
56// user agent's [hidden] { display: none } loses to any author rule that
57// sets display, and [rst-btn] sets inline-flex, so the button showed and
58// did nothing (Astra, docs #65, P3). The page's own [hidden] rule is
59// what keeps it out.
60func TestTheSharePageCopyButtonStaysHiddenWithoutScript(t *testing.T) {
61 app, _ := docs.NewForTest(t)
62 alice := signInCookies(t, app, "alice@example.com")
63 sqid := createDoc(t, app, alice, "Minutes")
64 published := post(t, app, alice, "/d/"+sqid+"/share/link", "on=1")
65 body := published.Body.String()
66 if loc := published.Header().Get("Location"); loc != "" {
67 body = get(t, app, alice, loc).Body.String()
68 }
69 if !strings.Contains(body, "docs-share-copy ") {
70 t.Fatal("no Copy button on the share page; the test is not looking at it")
71 }
72 if !regexp.MustCompile(`\[docs-share-copy\]\[hidden\]\s*\{\s*display:\s*none;?\s*\}`).MatchString(body) {
73 t.Error("the share page has no [docs-share-copy][hidden] { display: none } rule; [rst-btn]'s display beats the UA's [hidden], so the button shows without script")
74 }
75}
76