2022-07-21 17:02:37 +00:00
|
|
|
package kiss_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"h4kor/kiss-social"
|
2022-07-24 18:29:31 +00:00
|
|
|
"os"
|
|
|
|
"path"
|
2022-07-21 17:02:37 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCanRenderPost(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
post, _ := user.CreateNewPost("testpost")
|
2022-07-23 16:37:41 +00:00
|
|
|
result, err := kiss.RenderPost(post)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Error("Error rendering post: " + err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-07-21 17:02:37 +00:00
|
|
|
if !strings.Contains(result, "<h1>testpost</h1>") {
|
|
|
|
t.Error("Post title not rendered as h1. Got: " + result)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-07-21 17:44:07 +00:00
|
|
|
|
|
|
|
func TestRendererUsesBaseTemplate(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
post, _ := user.CreateNewPost("testpost")
|
2022-07-23 16:37:41 +00:00
|
|
|
result, err := kiss.RenderPost(post)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Error("Error rendering post: " + err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-07-23 07:11:25 +00:00
|
|
|
if !strings.Contains(result, "<html") {
|
2022-07-21 17:44:07 +00:00
|
|
|
t.Error("Base template not used. Got: " + result)
|
|
|
|
}
|
|
|
|
}
|
2022-07-23 15:19:47 +00:00
|
|
|
|
|
|
|
func TestCanRenderIndexPage(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
user.CreateNewPost("testpost1")
|
|
|
|
user.CreateNewPost("testpost2")
|
|
|
|
result, _ := kiss.RenderIndexPage(user)
|
|
|
|
if !strings.Contains(result, "testpost1") {
|
2022-07-24 14:30:49 +00:00
|
|
|
t.Error("Post title not rendered. Got: " + result)
|
2022-07-23 15:19:47 +00:00
|
|
|
}
|
|
|
|
if !strings.Contains(result, "testpost2") {
|
2022-07-24 14:30:49 +00:00
|
|
|
t.Error("Post title not rendered. Got: " + result)
|
2022-07-23 15:19:47 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-24 18:29:31 +00:00
|
|
|
|
|
|
|
func TestRenderIndexPageWithBrokenBaseTemplate(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
user.CreateNewPost("testpost1")
|
|
|
|
user.CreateNewPost("testpost2")
|
|
|
|
|
|
|
|
os.WriteFile(path.Join(user.Dir(), "meta/base.html"), []byte("{{content}}"), 0644)
|
|
|
|
|
|
|
|
_, err := kiss.RenderIndexPage(user)
|
|
|
|
if err == nil {
|
|
|
|
t.Error("Expected error rendering index page, got nil")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRenderUserList(t *testing.T) {
|
|
|
|
repo := getTestRepo()
|
|
|
|
repo.CreateUser("user1")
|
|
|
|
repo.CreateUser("user2")
|
|
|
|
|
|
|
|
result, err := kiss.RenderUserList(repo)
|
|
|
|
if err != nil {
|
|
|
|
t.Error("Error rendering user list: " + err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(result, "user1") {
|
|
|
|
t.Error("Post title not rendered. Got: " + result)
|
|
|
|
}
|
|
|
|
if !strings.Contains(result, "user2") {
|
|
|
|
t.Error("Post title not rendered. Got: " + result)
|
|
|
|
}
|
|
|
|
}
|
2022-07-27 19:53:56 +00:00
|
|
|
|
|
|
|
func TestRendersHeaderTitle(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
user.SetConfig(kiss.UserConfig{
|
|
|
|
Title: "Test Title",
|
|
|
|
SubTitle: "Test SubTitle",
|
|
|
|
HeaderColor: "#ff1337",
|
|
|
|
})
|
|
|
|
post, _ := user.CreateNewPost("testpost")
|
|
|
|
|
|
|
|
result, _ := kiss.RenderPost(post)
|
|
|
|
if !strings.Contains(result, "Test Title") {
|
|
|
|
t.Error("Header title not rendered. Got: " + result)
|
|
|
|
}
|
|
|
|
if !strings.Contains(result, "Test SubTitle") {
|
|
|
|
t.Error("Header subtitle not rendered. Got: " + result)
|
|
|
|
}
|
|
|
|
if !strings.Contains(result, "#ff1337") {
|
|
|
|
t.Error("Header color not rendered. Got: " + result)
|
|
|
|
}
|
|
|
|
}
|