func TestArchiveContainsAllEntries(t *testing.T) { if len(testPosts) <= NumRecentPosts { t.Fatalf("This test only makes sense if len(testPosts) > NUM_RECENT_POSTS") } nodes := htmltest.Query(t, "archive", "*", ".post-title") require.Len(t, nodes, len(testPosts), "Not all posts rendered in archive!") }
func TestEntriesHaveTagsInList(t *testing.T) { nodes := htmltest.Query(t, "", "+", ".tags") for _, node := range nodes { assertElem(t, node, "div") require.NotEmpty(t, h5.Children(node), "Empty tags div!") checkTagsSection(T{t}, node) } }
func TestEntryListHasAuthor(t *testing.T) { nodes := htmltest.Query(t, "", "+", ".author") for _, node := range nodes { assertElem(t, node, "div") require.NotEmpty(t, h5.Children(node), "Empty author div!") checkAuthorSection(T{t}, node) } }
func TestAllCommentsPageHasAllComments(t *testing.T) { defer testData.reset() ensureLogin() nodes := htmltest.Query(t, "/all_comments", "+", "#comment") if len(nodes) != len(testComm) { t.Fatalf("Not all comments in /all_comments!") } testData.expect(t, (*TestData).allComments, "") }
func TestCommentsFormattingInPostPage(t *testing.T) { for _, p := range testPosts { nodes := htmltest.Query(t, p.URL, "*", "#comments") require.Len(t, nodes, 1, "There should be only one comments section!") for _, node := range nodes { assertElem(t, node, "div") require.False(t, emptyChildren(node), "Empty comments div found!") checkCommentsSection(T{t}, node) } } }
func TestPagination(t *testing.T) { nodes := htmltest.Query(t, "page/2", "*", ".post-title") T{t}.failIf(len(nodes) != PostsPerPage, "Not all posts have been rendered!") if nodes[0].Attr[1].Val != "/hello6" { t.Fatalf("Wrong post!") } if nodes[4].Attr[1].Val != "/hello10" { t.Fatalf("Wrong post!") } html := htmltest.Curl("page/2") mustContain(t, html, "<a href=\"/page/1\">1</a>\n2\n<a href=\"/page/3\">3</a>\n") }
func TestTagFormattingInPostPage(t *testing.T) { for _, e := range testPosts { nodes := htmltest.Query(t, e.URL, "*", ".tags") if len(nodes) > 0 { for _, node := range nodes { assertElem(t, node, "div") require.NotEmpty(t, h5.Children(node), "Empty tags div!") checkTagsSection(T{t}, node) } } } }
func TestMainPageHasEditPostButtonWhenLoggedIn(t *testing.T) { ensureLogin() nodes := htmltest.Query(t, "", "+", ".edit-post-button") require.Len(t, nodes, PostsPerPage, "Not all posts have Edit button!") }
func TestOnlyOnePageOfPostsAppearsOnMainPage(t *testing.T) { nodes := htmltest.Query(t, "", "*", ".post-title") require.Len(t, nodes, PostsPerPage, "Not all posts have been rendered!") }