Add more simple render tests

This commit is contained in:
Andinus 2024-11-16 18:22:01 +05:30
parent 4a49e901ac
commit e09a3298c3
Signed by: andinus
GPG Key ID: B67D55D482A799FD

@ -143,3 +143,69 @@ func TestRenderArrayOfTemplateHash(t *testing.T) {
assert.Equal(t, outputRender, render, "Rendered output does not match expected output") assert.Equal(t, outputRender, render, "Rendered output does not match expected output")
} }
func TestRenderNonExistentFile(t *testing.T) {
nest, err := templatenest.New(templatenest.Option{TemplateDir: "templates"})
if err != nil {
t.Fatalf("Failed to initialize TemplateNest: %+v", err)
}
page := templatenest.Hash{"TEMPLATE": "this-template-file-does-not-exist"}
_, err = nest.Render(page)
if assert.NotNil(t, err) {
expected := "error getting file info:"
assert.Equal(t, expected, err.Error()[:len(expected)])
}
}
func TestRenderNoNameLabel(t *testing.T) {
nest, err := templatenest.New(templatenest.Option{TemplateDir: "templates"})
if err != nil {
t.Fatalf("Failed to initialize TemplateNest: %+v", err)
}
page := templatenest.Hash{"variable": "Simple Variable"}
_, err = nest.Render(page)
if assert.NotNil(t, err) {
expected := "encountered hash with no name label"
assert.Equal(t, expected, err.Error()[:len(expected)])
}
}
func TestRenderSimplePageArrays(t *testing.T) {
nest, err := templatenest.New(templatenest.Option{
TemplateDir: "templates",
NoEscapeInput: true,
})
if err != nil {
t.Fatalf("Failed to initialize TemplateNest: %+v", err)
}
page := templatenest.Hash{
"TEMPLATE": "00-simple-page",
"variable": "Simple Variable",
"simple_component": []interface{}{
templatenest.Hash{
"TEMPLATE": "01-simple-component",
"variable": "Simple Variable in Simple Component",
},
"<strong>Another test</strong>",
[]interface{}{
templatenest.Hash{
"TEMPLATE": "01-simple-component",
"variable": "Simple Variable in Simple Component",
},
"<strong>Another nested test 2</strong>",
},
},
}
outputPage := templatenest.Hash{"TEMPLATE": "output/12-simple-page-arrays"}
render := nest.MustRender(page)
outputRender := nest.MustRender(outputPage)
assert.Equal(t, outputRender, render, "Rendered output does not match expected output")
}