2022-08-03 14:55:48 +00:00
|
|
|
package owl_test
|
2022-07-21 17:02:37 +00:00
|
|
|
|
|
|
|
import (
|
2022-08-03 14:55:48 +00:00
|
|
|
"h4kor/owl-blogs"
|
2022-11-06 13:17:14 +00:00
|
|
|
"h4kor/owl-blogs/test/assertions"
|
2022-07-24 18:29:31 +00:00
|
|
|
"os"
|
|
|
|
"path"
|
2022-07-21 17:02:37 +00:00
|
|
|
"testing"
|
2022-09-01 20:01:36 +00:00
|
|
|
"time"
|
2022-07-21 17:02:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCanRenderPost(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost"}, "")
|
2022-10-13 19:03:16 +00:00
|
|
|
result, err := owl.RenderPost(post)
|
2022-07-23 16:37:41 +00:00
|
|
|
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertNoError(t, err, "Error rendering post")
|
|
|
|
assertions.AssertContains(t, result, "testpost")
|
2022-07-21 17:02:37 +00:00
|
|
|
|
|
|
|
}
|
2022-07-21 17:44:07 +00:00
|
|
|
|
2022-11-01 20:35:47 +00:00
|
|
|
func TestRenderOneMe(t *testing.T) {
|
2022-09-06 19:32:31 +00:00
|
|
|
user := getTestUser()
|
2022-11-03 19:25:53 +00:00
|
|
|
config := user.Config()
|
2022-11-01 20:35:47 +00:00
|
|
|
config.Me = append(config.Me, owl.UserMe{
|
|
|
|
Name: "Twitter",
|
|
|
|
Url: "https://twitter.com/testhandle",
|
|
|
|
})
|
|
|
|
|
2022-09-06 19:32:31 +00:00
|
|
|
user.SetConfig(config)
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost"}, "")
|
2022-10-13 19:03:16 +00:00
|
|
|
result, err := owl.RenderPost(post)
|
2022-09-06 19:32:31 +00:00
|
|
|
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertNoError(t, err, "Error rendering post")
|
|
|
|
assertions.AssertContains(t, result, "href=\"https://twitter.com/testhandle\" rel=\"me\"")
|
2022-09-06 19:32:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-01 20:35:47 +00:00
|
|
|
func TestRenderTwoMe(t *testing.T) {
|
2022-09-08 19:28:05 +00:00
|
|
|
user := getTestUser()
|
2022-11-03 19:25:53 +00:00
|
|
|
config := user.Config()
|
2022-11-01 20:35:47 +00:00
|
|
|
config.Me = append(config.Me, owl.UserMe{
|
|
|
|
Name: "Twitter",
|
|
|
|
Url: "https://twitter.com/testhandle",
|
|
|
|
})
|
|
|
|
config.Me = append(config.Me, owl.UserMe{
|
|
|
|
Name: "Github",
|
|
|
|
Url: "https://github.com/testhandle",
|
|
|
|
})
|
|
|
|
|
2022-09-08 19:28:05 +00:00
|
|
|
user.SetConfig(config)
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost"}, "")
|
2022-10-13 19:03:16 +00:00
|
|
|
result, err := owl.RenderPost(post)
|
2022-09-08 19:28:05 +00:00
|
|
|
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertNoError(t, err, "Error rendering post")
|
|
|
|
assertions.AssertContains(t, result, "href=\"https://twitter.com/testhandle\" rel=\"me\"")
|
|
|
|
assertions.AssertContains(t, result, "href=\"https://github.com/testhandle\" rel=\"me\"")
|
2022-09-08 19:28:05 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-08-18 19:32:50 +00:00
|
|
|
func TestRenderPostHEntry(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost"}, "")
|
2022-10-13 19:03:16 +00:00
|
|
|
result, _ := owl.RenderPost(post)
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertContains(t, result, "class=\"h-entry\"")
|
|
|
|
assertions.AssertContains(t, result, "class=\"p-name\"")
|
|
|
|
assertions.AssertContains(t, result, "class=\"e-content\"")
|
2022-08-18 19:32:50 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-07-21 17:44:07 +00:00
|
|
|
func TestRendererUsesBaseTemplate(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost"}, "")
|
2022-10-13 19:03:16 +00:00
|
|
|
result, err := owl.RenderPost(post)
|
2022-07-23 16:37:41 +00:00
|
|
|
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertNoError(t, err, "Error rendering post")
|
|
|
|
assertions.AssertContains(t, result, "<html")
|
2022-07-21 17:44:07 +00:00
|
|
|
}
|
2022-07-23 15:19:47 +00:00
|
|
|
|
2022-12-01 18:10:08 +00:00
|
|
|
func TestCanRenderPostList(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost1"}, "")
|
|
|
|
user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost2"}, "")
|
2022-12-01 18:32:49 +00:00
|
|
|
result, err := owl.RenderPostList(user, &owl.PostList{
|
2022-12-01 18:10:08 +00:00
|
|
|
Id: "testlist",
|
|
|
|
Title: "Test List",
|
|
|
|
Include: []string{
|
|
|
|
"article",
|
|
|
|
},
|
|
|
|
})
|
2022-12-01 18:32:49 +00:00
|
|
|
assertions.AssertNoError(t, err, "Error rendering post list")
|
2022-12-01 18:10:08 +00:00
|
|
|
assertions.AssertContains(t, result, "testpost1")
|
|
|
|
assertions.AssertContains(t, result, "testpost2")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCanRenderPostListNotIncludeOther(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
user.CreateNewPost(owl.PostMeta{Title: "testpost1", Type: "article"}, "testpost1")
|
|
|
|
user.CreateNewPost(owl.PostMeta{Title: "testpost2", Type: "note"}, "testpost2")
|
2022-12-01 18:10:08 +00:00
|
|
|
result, _ := owl.RenderPostList(user, &owl.PostList{
|
|
|
|
Id: "testlist",
|
|
|
|
Title: "Test List",
|
|
|
|
Include: []string{
|
|
|
|
"article",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assertions.AssertContains(t, result, "testpost1")
|
|
|
|
assertions.AssertNotContains(t, result, "testpost2")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCanRenderPostListNotIncludeMultiple(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
user.CreateNewPost(owl.PostMeta{Title: "testpost1", Type: "article"}, "testpost1")
|
|
|
|
user.CreateNewPost(owl.PostMeta{Title: "testpost2", Type: "note"}, "testpost2")
|
|
|
|
user.CreateNewPost(owl.PostMeta{Title: "testpost3", Type: "recipe"}, "testpost3")
|
2022-12-01 18:10:08 +00:00
|
|
|
result, _ := owl.RenderPostList(user, &owl.PostList{
|
|
|
|
Id: "testlist",
|
|
|
|
Title: "Test List",
|
|
|
|
Include: []string{
|
|
|
|
"article", "recipe",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assertions.AssertContains(t, result, "testpost1")
|
|
|
|
assertions.AssertNotContains(t, result, "testpost2")
|
|
|
|
assertions.AssertContains(t, result, "testpost3")
|
|
|
|
}
|
|
|
|
|
2022-07-23 15:19:47 +00:00
|
|
|
func TestCanRenderIndexPage(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost1"}, "")
|
|
|
|
user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost2"}, "")
|
2022-08-03 14:55:48 +00:00
|
|
|
result, _ := owl.RenderIndexPage(user)
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertContains(t, result, "testpost1")
|
|
|
|
assertions.AssertContains(t, result, "testpost2")
|
2022-07-23 15:19:47 +00:00
|
|
|
}
|
2022-07-24 18:29:31 +00:00
|
|
|
|
2022-11-19 15:02:41 +00:00
|
|
|
func TestCanRenderIndexPageNoTitle(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{}, "hi")
|
2022-11-19 15:02:41 +00:00
|
|
|
result, _ := owl.RenderIndexPage(user)
|
|
|
|
assertions.AssertContains(t, result, post.Id())
|
2022-12-01 18:32:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRenderNoteAsFullContent(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
user.CreateNewPost(owl.PostMeta{Type: "note"}, "This is a note")
|
2022-12-01 18:37:13 +00:00
|
|
|
result, _ := owl.RenderPostList(user, &owl.PostList{
|
|
|
|
Include: []string{"note"},
|
|
|
|
})
|
|
|
|
assertions.AssertContains(t, result, "This is a note")
|
2022-12-01 18:43:59 +00:00
|
|
|
assertions.AssertNotContains(t, result, "<p>This is a note")
|
2022-11-19 15:02:41 +00:00
|
|
|
}
|
|
|
|
|
2022-08-18 19:32:50 +00:00
|
|
|
func TestIndexPageContainsHFeedContainer(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost1"}, "")
|
2022-08-18 19:32:50 +00:00
|
|
|
|
|
|
|
result, _ := owl.RenderIndexPage(user)
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertContains(t, result, "<div class=\"h-feed\">")
|
2022-08-18 19:32:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestIndexPageContainsHEntryAndUUrl(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost1"}, "")
|
2022-08-18 19:32:50 +00:00
|
|
|
|
|
|
|
result, _ := owl.RenderIndexPage(user)
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertContains(t, result, "class=\"h-entry\"")
|
|
|
|
assertions.AssertContains(t, result, "class=\"u-url\"")
|
2022-08-18 19:32:50 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-29 20:22:39 +00:00
|
|
|
func TestIndexPageDoesNotContainsArticle(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
user.CreateNewPost(owl.PostMeta{Type: "article"}, "hi")
|
2022-11-29 20:22:39 +00:00
|
|
|
|
|
|
|
result, _ := owl.RenderIndexPage(user)
|
|
|
|
assertions.AssertContains(t, result, "class=\"h-entry\"")
|
|
|
|
assertions.AssertContains(t, result, "class=\"u-url\"")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIndexPageDoesNotContainsReply(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
user.CreateNewPost(owl.PostMeta{Type: "reply", Reply: owl.ReplyData{Url: "https://example.com/post"}}, "hi")
|
2022-11-29 20:22:39 +00:00
|
|
|
|
|
|
|
result, _ := owl.RenderIndexPage(user)
|
|
|
|
assertions.AssertContains(t, result, "class=\"h-entry\"")
|
|
|
|
assertions.AssertContains(t, result, "class=\"u-url\"")
|
|
|
|
}
|
|
|
|
|
2022-07-24 18:29:31 +00:00
|
|
|
func TestRenderIndexPageWithBrokenBaseTemplate(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost1"}, "")
|
|
|
|
user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost2"}, "")
|
2022-07-24 18:29:31 +00:00
|
|
|
|
|
|
|
os.WriteFile(path.Join(user.Dir(), "meta/base.html"), []byte("{{content}}"), 0644)
|
|
|
|
|
2022-08-03 14:55:48 +00:00
|
|
|
_, err := owl.RenderIndexPage(user)
|
2022-11-03 18:23:13 +00:00
|
|
|
assertions.AssertError(t, err, "Expected error rendering index page")
|
2022-07-24 18:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRenderUserList(t *testing.T) {
|
2022-09-05 18:50:46 +00:00
|
|
|
repo := getTestRepo(owl.RepoConfig{})
|
2022-07-24 18:29:31 +00:00
|
|
|
repo.CreateUser("user1")
|
|
|
|
repo.CreateUser("user2")
|
|
|
|
|
2022-08-03 14:55:48 +00:00
|
|
|
result, err := owl.RenderUserList(repo)
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertNoError(t, err, "Error rendering user list")
|
|
|
|
assertions.AssertContains(t, result, "user1")
|
|
|
|
assertions.AssertContains(t, result, "user2")
|
2022-07-24 18:29:31 +00:00
|
|
|
}
|
2022-07-27 19:53:56 +00:00
|
|
|
|
|
|
|
func TestRendersHeaderTitle(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-08-03 14:55:48 +00:00
|
|
|
user.SetConfig(owl.UserConfig{
|
2022-07-27 19:53:56 +00:00
|
|
|
Title: "Test Title",
|
|
|
|
SubTitle: "Test SubTitle",
|
|
|
|
HeaderColor: "#ff1337",
|
|
|
|
})
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost"}, "")
|
2022-07-27 19:53:56 +00:00
|
|
|
|
2022-10-13 19:03:16 +00:00
|
|
|
result, _ := owl.RenderPost(post)
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertContains(t, result, "Test Title")
|
|
|
|
assertions.AssertContains(t, result, "Test SubTitle")
|
|
|
|
assertions.AssertContains(t, result, "#ff1337")
|
2022-07-27 19:53:56 +00:00
|
|
|
}
|
2022-08-31 18:20:16 +00:00
|
|
|
|
|
|
|
func TestRenderPostIncludesRelToWebMention(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost"}, "")
|
2022-08-31 18:20:16 +00:00
|
|
|
|
2022-10-13 19:03:16 +00:00
|
|
|
result, _ := owl.RenderPost(post)
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertContains(t, result, "rel=\"webmention\"")
|
2022-08-31 18:20:16 +00:00
|
|
|
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertContains(t, result, "href=\""+user.WebmentionUrl()+"\"")
|
2022-08-31 18:20:16 +00:00
|
|
|
}
|
2022-09-01 20:01:36 +00:00
|
|
|
|
|
|
|
func TestRenderPostAddsLinksToApprovedWebmention(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost"}, "")
|
2022-09-04 13:03:16 +00:00
|
|
|
webmention := owl.WebmentionIn{
|
2022-09-01 20:01:36 +00:00
|
|
|
Source: "http://example.com/source3",
|
|
|
|
Title: "Test Title",
|
|
|
|
ApprovalStatus: "approved",
|
|
|
|
RetrievedAt: time.Now().Add(time.Hour * -2),
|
|
|
|
}
|
2022-09-07 20:06:59 +00:00
|
|
|
post.PersistIncomingWebmention(webmention)
|
2022-09-04 13:03:16 +00:00
|
|
|
webmention = owl.WebmentionIn{
|
2022-09-01 20:01:36 +00:00
|
|
|
Source: "http://example.com/source4",
|
|
|
|
ApprovalStatus: "rejected",
|
|
|
|
RetrievedAt: time.Now().Add(time.Hour * -3),
|
|
|
|
}
|
2022-09-07 20:06:59 +00:00
|
|
|
post.PersistIncomingWebmention(webmention)
|
2022-09-01 20:01:36 +00:00
|
|
|
|
2022-10-13 19:03:16 +00:00
|
|
|
result, _ := owl.RenderPost(post)
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertContains(t, result, "http://example.com/source3")
|
|
|
|
assertions.AssertContains(t, result, "Test Title")
|
2022-11-03 18:23:13 +00:00
|
|
|
assertions.AssertNotContains(t, result, "http://example.com/source4")
|
2022-09-01 20:01:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRenderPostNotMentioningWebmentionsIfNoAvail(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost"}, "")
|
2022-10-13 19:03:16 +00:00
|
|
|
result, _ := owl.RenderPost(post)
|
2022-09-01 20:01:36 +00:00
|
|
|
|
2022-11-03 18:23:13 +00:00
|
|
|
assertions.AssertNotContains(t, result, "Webmention")
|
2022-09-01 20:01:36 +00:00
|
|
|
|
|
|
|
}
|
2022-09-06 18:00:12 +00:00
|
|
|
|
|
|
|
func TestRenderIncludesFullUrl(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost"}, "")
|
2022-10-13 19:03:16 +00:00
|
|
|
result, _ := owl.RenderPost(post)
|
2022-09-06 18:00:12 +00:00
|
|
|
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertContains(t, result, "class=\"u-url\"")
|
|
|
|
assertions.AssertContains(t, result, post.FullUrl())
|
2022-09-06 18:00:12 +00:00
|
|
|
}
|
2022-09-10 13:22:18 +00:00
|
|
|
|
|
|
|
func TestAddAvatarIfExist(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
os.WriteFile(path.Join(user.MediaDir(), "avatar.png"), []byte("test"), 0644)
|
|
|
|
|
|
|
|
result, _ := owl.RenderIndexPage(user)
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertContains(t, result, "avatar.png")
|
2022-09-10 13:22:18 +00:00
|
|
|
}
|
2022-10-07 17:51:13 +00:00
|
|
|
|
|
|
|
func TestAuthorNameInPost(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
user.SetConfig(owl.UserConfig{
|
|
|
|
Title: "Test Title",
|
|
|
|
SubTitle: "Test SubTitle",
|
|
|
|
HeaderColor: "#ff1337",
|
|
|
|
AuthorName: "Test Author",
|
|
|
|
})
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost"}, "")
|
2022-10-07 17:51:13 +00:00
|
|
|
|
2022-10-13 19:03:16 +00:00
|
|
|
result, _ := owl.RenderPost(post)
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertContains(t, result, "Test Author")
|
2022-10-07 17:51:13 +00:00
|
|
|
}
|
2022-10-10 18:59:06 +00:00
|
|
|
|
|
|
|
func TestRenderReplyWithoutText(t *testing.T) {
|
|
|
|
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{
|
2022-12-05 19:31:48 +00:00
|
|
|
Type: "reply",
|
|
|
|
Reply: owl.ReplyData{
|
|
|
|
Url: "https://example.com/post",
|
|
|
|
},
|
|
|
|
}, "Hi ")
|
2022-10-10 18:59:06 +00:00
|
|
|
|
2022-10-13 19:03:16 +00:00
|
|
|
result, _ := owl.RenderPost(post)
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertContains(t, result, "https://example.com/post")
|
2022-10-10 18:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRenderReplyWithText(t *testing.T) {
|
|
|
|
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{
|
2022-12-05 19:31:48 +00:00
|
|
|
Type: "reply",
|
|
|
|
Reply: owl.ReplyData{
|
|
|
|
Url: "https://example.com/post",
|
|
|
|
Text: "This is a reply",
|
|
|
|
},
|
|
|
|
}, "Hi ")
|
2022-10-10 18:59:06 +00:00
|
|
|
|
2022-10-13 19:03:16 +00:00
|
|
|
result, _ := owl.RenderPost(post)
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertContains(t, result, "https://example.com/post")
|
2022-10-10 18:59:06 +00:00
|
|
|
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertContains(t, result, "This is a reply")
|
2022-10-10 18:59:06 +00:00
|
|
|
}
|
2022-10-19 19:14:31 +00:00
|
|
|
|
2022-12-04 14:45:51 +00:00
|
|
|
func TestRengerPostContainsBookmark(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{Type: "bookmark", Bookmark: owl.BookmarkData{Url: "https://example.com/post"}}, "hi")
|
2022-12-04 14:45:51 +00:00
|
|
|
|
|
|
|
result, _ := owl.RenderPost(post)
|
|
|
|
assertions.AssertContains(t, result, "https://example.com/post")
|
|
|
|
}
|
|
|
|
|
2022-10-19 19:14:31 +00:00
|
|
|
func TestOpenGraphTags(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost"}, "")
|
2022-10-19 19:14:31 +00:00
|
|
|
|
|
|
|
content := "---\n"
|
|
|
|
content += "title: The Rock\n"
|
|
|
|
content += "description: Dwayne Johnson\n"
|
|
|
|
content += "date: Wed, 17 Aug 2022 10:50:02 +0000\n"
|
|
|
|
content += "---\n"
|
|
|
|
content += "\n"
|
|
|
|
content += "Hi \n"
|
|
|
|
|
2022-11-02 21:02:49 +00:00
|
|
|
os.WriteFile(post.ContentFile(), []byte(content), 0644)
|
2022-10-19 19:14:31 +00:00
|
|
|
post, _ = user.GetPost(post.Id())
|
|
|
|
result, _ := owl.RenderPost(post)
|
|
|
|
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertContains(t, result, "<meta property=\"og:title\" content=\"The Rock\" />")
|
|
|
|
assertions.AssertContains(t, result, "<meta property=\"og:description\" content=\"Dwayne Johnson\" />")
|
|
|
|
assertions.AssertContains(t, result, "<meta property=\"og:type\" content=\"article\" />")
|
|
|
|
assertions.AssertContains(t, result, "<meta property=\"og:url\" content=\""+post.FullUrl()+"\" />")
|
2022-10-19 19:14:31 +00:00
|
|
|
|
|
|
|
}
|
2022-11-01 20:14:03 +00:00
|
|
|
|
|
|
|
func TestAddFaviconIfExist(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
os.WriteFile(path.Join(user.MediaDir(), "favicon.png"), []byte("test"), 0644)
|
|
|
|
|
|
|
|
result, _ := owl.RenderIndexPage(user)
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertContains(t, result, "favicon.png")
|
2022-11-01 20:14:03 +00:00
|
|
|
}
|
2022-11-03 20:22:55 +00:00
|
|
|
|
|
|
|
func TestRenderUserAuth(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
user.ResetPassword("test")
|
2022-11-04 20:53:14 +00:00
|
|
|
result, err := owl.RenderUserAuthPage(owl.AuthRequestData{
|
|
|
|
User: user,
|
|
|
|
})
|
2022-11-03 20:22:55 +00:00
|
|
|
assertions.AssertNoError(t, err, "Error rendering user auth page")
|
|
|
|
assertions.AssertContains(t, result, "<form")
|
|
|
|
}
|
2022-11-04 20:53:14 +00:00
|
|
|
|
|
|
|
func TestRenderUserAuthIncludesClientId(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
user.ResetPassword("test")
|
|
|
|
result, err := owl.RenderUserAuthPage(owl.AuthRequestData{
|
|
|
|
User: user,
|
|
|
|
ClientId: "https://example.com/",
|
|
|
|
})
|
|
|
|
assertions.AssertNoError(t, err, "Error rendering user auth page")
|
|
|
|
assertions.AssertContains(t, result, "https://example.com/")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRenderUserAuthHiddenFields(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
user.ResetPassword("test")
|
|
|
|
result, err := owl.RenderUserAuthPage(owl.AuthRequestData{
|
|
|
|
User: user,
|
|
|
|
ClientId: "https://example.com/",
|
|
|
|
RedirectUri: "https://example.com/redirect",
|
|
|
|
ResponseType: "code",
|
|
|
|
State: "teststate",
|
|
|
|
})
|
|
|
|
assertions.AssertNoError(t, err, "Error rendering user auth page")
|
|
|
|
assertions.AssertContains(t, result, "name=\"client_id\" value=\"https://example.com/\"")
|
|
|
|
assertions.AssertContains(t, result, "name=\"redirect_uri\" value=\"https://example.com/redirect\"")
|
|
|
|
assertions.AssertContains(t, result, "name=\"response_type\" value=\"code\"")
|
|
|
|
assertions.AssertContains(t, result, "name=\"state\" value=\"teststate\"")
|
|
|
|
}
|
2022-12-03 15:21:51 +00:00
|
|
|
|
|
|
|
func TestRenderHeaderMenuListItem(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
user.AddHeaderMenuItem(owl.MenuItem{
|
|
|
|
Title: "Test Entry",
|
|
|
|
List: "test",
|
|
|
|
})
|
|
|
|
result, _ := owl.RenderIndexPage(user)
|
|
|
|
assertions.AssertContains(t, result, "Test Entry")
|
|
|
|
assertions.AssertContains(t, result, "/lists/test")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRenderHeaderMenuUrlItem(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
user.AddHeaderMenuItem(owl.MenuItem{
|
|
|
|
Title: "Test Entry",
|
|
|
|
Url: "https://example.com",
|
|
|
|
})
|
|
|
|
result, _ := owl.RenderIndexPage(user)
|
|
|
|
assertions.AssertContains(t, result, "Test Entry")
|
|
|
|
assertions.AssertContains(t, result, "https://example.com")
|
|
|
|
}
|
2022-12-04 18:15:50 +00:00
|
|
|
|
|
|
|
func TestRenderHeaderMenuPost(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{Type: "article", Title: "testpost"}, "")
|
2022-12-04 18:15:50 +00:00
|
|
|
user.AddHeaderMenuItem(owl.MenuItem{
|
|
|
|
Title: "Test Entry",
|
|
|
|
Post: post.Id(),
|
|
|
|
})
|
|
|
|
result, _ := owl.RenderIndexPage(user)
|
|
|
|
assertions.AssertContains(t, result, "Test Entry")
|
|
|
|
assertions.AssertContains(t, result, post.UrlPath())
|
|
|
|
}
|
2022-12-04 18:51:53 +00:00
|
|
|
|
|
|
|
func TestRenderFooterMenuListItem(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
user.AddFooterMenuItem(owl.MenuItem{
|
|
|
|
Title: "Test Entry",
|
|
|
|
List: "test",
|
|
|
|
})
|
|
|
|
result, _ := owl.RenderIndexPage(user)
|
|
|
|
assertions.AssertContains(t, result, "Test Entry")
|
|
|
|
assertions.AssertContains(t, result, "/lists/test")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRenderFooterMenuUrlItem(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
user.AddFooterMenuItem(owl.MenuItem{
|
|
|
|
Title: "Test Entry",
|
|
|
|
Url: "https://example.com",
|
|
|
|
})
|
|
|
|
result, _ := owl.RenderIndexPage(user)
|
|
|
|
assertions.AssertContains(t, result, "Test Entry")
|
|
|
|
assertions.AssertContains(t, result, "https://example.com")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRenderFooterMenuPost(t *testing.T) {
|
|
|
|
user := getTestUser()
|
2022-12-05 19:47:52 +00:00
|
|
|
post, _ := user.CreateNewPost(owl.PostMeta{
|
2022-12-05 17:48:15 +00:00
|
|
|
Type: "private",
|
|
|
|
}, "")
|
|
|
|
result, _ := owl.RenderIndexPage(user)
|
|
|
|
assertions.AssertNotContains(t, result, "Test Entry")
|
|
|
|
assertions.AssertNotContains(t, result, post.UrlPath())
|
2022-12-04 18:51:53 +00:00
|
|
|
user.AddFooterMenuItem(owl.MenuItem{
|
|
|
|
Title: "Test Entry",
|
|
|
|
Post: post.Id(),
|
|
|
|
})
|
2022-12-05 17:48:15 +00:00
|
|
|
result, _ = owl.RenderIndexPage(user)
|
2022-12-04 18:51:53 +00:00
|
|
|
assertions.AssertContains(t, result, "Test Entry")
|
|
|
|
assertions.AssertContains(t, result, post.UrlPath())
|
|
|
|
}
|