package movementtest import ( "net/http" "strings" "testing" movement "amadan.net/carlos/movement/internal/movement" ) // Links live beside the copy rather than inside it, matched by phrase. That // keeps markup out of the copy table, and it means a rewrite can silently // orphan a link by rewording around its phrase. Nothing would look broken — // the paragraph would just quietly stop linking — so it is checked here. func TestEveryLinkPhraseStillAppearsInItsCopy(t *testing.T) { for _, id := range []string{"index.lede"} { body := strings.Join(movement.Paragraphs(id), " ") for _, phrase := range movement.LinkPhrases(id) { if !strings.Contains(body, phrase) { t.Errorf("%s links the phrase %q, which the copy no longer "+ "contains — the link has been orphaned by a rewrite", id, phrase) } } } } func TestLedeLinksRenderAndOpenInANewTab(t *testing.T) { h := newApp(t) body := get(t, h, "/").Body.String() for _, want := range []string{ `href="https://11factor.org"`, `href="https://carlosframework.com/"`, } { if !strings.Contains(body, want) { t.Errorf("the lede is missing %s", want) } } // Every outbound link leaves in its own tab, and carries the rel that // stops the new page reaching back into this one. if strings.Count(body, `rel="noopener noreferrer"`) < 3 { t.Error("an outbound link is missing target/rel") } } // The copy is escaped before any anchor is spliced in, so nothing written in // the copy table can become markup. func TestLedeCopyCannotBecomeMarkup(t *testing.T) { h := newApp(t) rec := get(t, h, "/") if rec.Code != http.StatusOK { t.Fatalf("GET /: %d", rec.Code) } body := rec.Body.String() // The apostrophes in the copy must arrive escaped, which is the visible // proof that escaping ran before the links went in. if strings.Contains(body, "We’ve built") && !strings.Contains(body, "'") && !strings.Contains(body, "’") { t.Error("copy reached the page without passing through escaping") } }