package slidestest import ( "net/http" "net/url" "regexp" "strings" "testing" ) // shelfTile is one cover on the shelf: the tile's link and the picture // inside it. A deck opens in the editor, as a document does in Docs, so // the link is /edit and the captured path is the deck's own. var shelfTile = regexp.MustCompile(`\s*]*>(?:([^<]*)`) // TestListShowsTheNewestFiveAsCoversAndTheRestAsRows: the newest five // decks are their first slides, newest first; everything older is a row // with a small cover and its rung in words. func TestListShowsTheNewestFiveAsCoversAndTheRestAsRows(t *testing.T) { a := newApp(t) cookies := signedIn(t, a, allowedAddress) // The sample deck is first and so oldest; six more after it. var made []string for _, title := range []string{"One", "Two", "Three", "Four", "Five", "Six"} { made = append(made, createDeck(t, a, cookies, title)) } page := mustGet(t, a, "/", http.StatusOK, cookies).Body.String() tiles := shelfTile.FindAllStringSubmatch(page, -1) if len(tiles) != 5 { t.Fatalf("the shelf holds %d covers, want 5:\n%s", len(tiles), page) } for i, tile := range tiles { if want := made[len(made)-1-i]; tile[1] != want { t.Errorf("cover %d links %s, want %s (newest first)", i, tile[1], want) } // The deck's first slide, as the picture thumbs.go serves. if !strings.HasPrefix(tile[2], tile[1]+"/slides/") || !strings.Contains(tile[2], ".svg?w=") { t.Errorf("cover %d is %q, want its first slide's SVG", i, tile[2]) } pic := mustGet(t, a, strings.SplitN(tile[2], "?", 2)[0], http.StatusOK, cookies) if ct := pic.Header().Get("Content-Type"); !strings.HasPrefix(ct, "image/svg+xml") { t.Errorf("cover %d answers %q, want an SVG", i, ct) } } rows := rowLink.FindAllStringSubmatch(page, -1) if len(rows) != 2 || rows[0][1] != made[0] || rows[1][2] != sampleDeckTitle { t.Fatalf("rows = %v, want One then the sample deck", rows) } // The rung is words in every row, never colour alone. if n := strings.Count(page, `rst-status rst-tone="neutral">Only me<`); n != 2 { t.Errorf("%d rows say Only me, want 2", n) } // A time is relative, with the date itself in its title. if !regexp.MustCompile(``).MatchString(page) { t.Errorf("a row's time is not a