From e176729358694064c11914657abb0912aea6710b Mon Sep 17 00:00:00 2001 From: Niko Abeler Date: Thu, 18 Aug 2022 21:32:50 +0200 Subject: [PATCH] h-feed and h-entry for microformats. #6 --- embed/post-list.html | 8 ++++++-- embed/post.html | 8 ++++++-- renderer_test.go | 42 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/embed/post-list.html b/embed/post-list.html index 232dd64..25f633b 100644 --- a/embed/post-list.html +++ b/embed/post-list.html @@ -1,3 +1,7 @@ +
{{range .}} -

{{.Title}}

-{{end}} \ No newline at end of file +
+

{{.Title}}

+
+{{end}} +
\ No newline at end of file diff --git a/embed/post.html b/embed/post.html index 19a2483..d6c1ffb 100644 --- a/embed/post.html +++ b/embed/post.html @@ -1,2 +1,6 @@ -

{{.Title}}

-{{.Post}} \ No newline at end of file +
+

{{.Title}}

+
+ {{.Post}} +
+
\ No newline at end of file diff --git a/renderer_test.go b/renderer_test.go index 407989f..d97f8e2 100644 --- a/renderer_test.go +++ b/renderer_test.go @@ -18,12 +18,28 @@ func TestCanRenderPost(t *testing.T) { return } - if !strings.Contains(result, "

testpost

") { + if !strings.Contains(result, "

testpost

") { t.Error("Post title not rendered as h1. Got: " + result) } } +func TestRenderPostHEntry(t *testing.T) { + user := getTestUser() + post, _ := user.CreateNewPost("testpost") + result, _ := owl.RenderPost(post) + if !strings.Contains(result, "class=\"h-entry\"") { + t.Error("h-entry container not rendered. Got: " + result) + } + if !strings.Contains(result, "class=\"p-name\"") { + t.Error("p-name not rendered. Got: " + result) + } + if !strings.Contains(result, "class=\"e-content\"") { + t.Error("e-content not rendered. Got: " + result) + } + +} + func TestRendererUsesBaseTemplate(t *testing.T) { user := getTestUser() post, _ := user.CreateNewPost("testpost") @@ -52,6 +68,30 @@ func TestCanRenderIndexPage(t *testing.T) { } } +func TestIndexPageContainsHFeedContainer(t *testing.T) { + user := getTestUser() + user.CreateNewPost("testpost1") + + result, _ := owl.RenderIndexPage(user) + if !strings.Contains(result, "
") { + t.Error("h-feed container not rendered. Got: " + result) + } +} + +func TestIndexPageContainsHEntryAndUUrl(t *testing.T) { + user := getTestUser() + user.CreateNewPost("testpost1") + + result, _ := owl.RenderIndexPage(user) + if !strings.Contains(result, "class=\"h-entry\"") { + t.Error("h-entry container not rendered. Got: " + result) + } + if !strings.Contains(result, "class=\"u-url\"") { + t.Error("u-url not rendered. Got: " + result) + } + +} + func TestRenderIndexPageWithBrokenBaseTemplate(t *testing.T) { user := getTestUser() user.CreateNewPost("testpost1")