146 lines
3.9 KiB
Go
146 lines
3.9 KiB
Go
package tests
|
|
|
|
import (
|
|
"git.virtual.blue/tomgracey/template-nest-go"
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
func TestRenderSimplePage(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": "00-simple-page",
|
|
"variable": "Simple Variable",
|
|
"simple_component": []templatenest.Hash{
|
|
templatenest.Hash{
|
|
"TEMPLATE": "01-simple-component",
|
|
"variable": "Simple Variable in Simple Component",
|
|
},
|
|
},
|
|
}
|
|
|
|
outputPage := templatenest.Hash{"TEMPLATE": "output/01-simple-page"}
|
|
|
|
render, err := nest.Render(page)
|
|
if err != nil {
|
|
t.Fatalf("Render failed for page: %+v", err)
|
|
}
|
|
|
|
outputRender := nest.MustRender(outputPage)
|
|
|
|
assert.Equal(t, outputRender, render, "Rendered output does not match expected output")
|
|
}
|
|
|
|
func TestRenderIncompletePage(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": "00-simple-page",
|
|
"variable": "Simple Variable",
|
|
"simple_component": []templatenest.Hash{
|
|
templatenest.Hash{
|
|
"TEMPLATE": "01-simple-component",
|
|
},
|
|
},
|
|
}
|
|
|
|
outputPage := templatenest.Hash{"TEMPLATE": "output/03-incomplete-page"}
|
|
|
|
render := nest.MustRender(page)
|
|
outputRender := nest.MustRender(outputPage)
|
|
|
|
assert.Equal(t, outputRender, render, "Rendered output does not match expected output")
|
|
}
|
|
|
|
func TestRenderComplexPage(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": "10-complex-page",
|
|
"title": "Complex Page",
|
|
"pre_body": templatenest.Hash{
|
|
"TEMPLATE": "18-styles",
|
|
},
|
|
"navigation": templatenest.Hash{
|
|
"TEMPLATE": "11-navigation",
|
|
"banner": templatenest.Hash{
|
|
"TEMPLATE": "12-navigation-banner",
|
|
},
|
|
"items": []templatenest.Hash{
|
|
templatenest.Hash{"TEMPLATE": "13-navigation-item-00-services"},
|
|
templatenest.Hash{"TEMPLATE": "13-navigation-item-01-resources"},
|
|
},
|
|
},
|
|
"hero_section": templatenest.Hash{
|
|
"TEMPLATE": "14-hero-section",
|
|
},
|
|
"main_content": []templatenest.Hash{
|
|
templatenest.Hash{"TEMPLATE": "15-isdc-card"},
|
|
templatenest.Hash{
|
|
"TEMPLATE": "16-vb-brand-cards",
|
|
"cards": []templatenest.Hash{
|
|
templatenest.Hash{
|
|
"TEMPLATE": "17-vb-brand-card-00",
|
|
"parent_classes": "p-card brand-card col-4",
|
|
},
|
|
templatenest.Hash{
|
|
"TEMPLATE": "17-vb-brand-card-01",
|
|
"parent_classes": "p-card brand-card col-4",
|
|
},
|
|
templatenest.Hash{
|
|
"TEMPLATE": "17-vb-brand-card-02",
|
|
"parent_classes": "p-card brand-card col-4",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"post_footer": templatenest.Hash{
|
|
"TEMPLATE": "19-scripts",
|
|
},
|
|
}
|
|
|
|
outputPage := templatenest.Hash{"TEMPLATE": "output/02-complex-page"}
|
|
|
|
render := nest.MustRender(page)
|
|
outputRender := nest.MustRender(outputPage)
|
|
|
|
assert.Equal(t, outputRender, render, "Rendered output does not match expected output")
|
|
}
|
|
|
|
func TestRenderArrayOfTemplateHash(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{
|
|
templatenest.Hash{
|
|
"TEMPLATE": "01-simple-component",
|
|
"variable": "This is a variable",
|
|
},
|
|
templatenest.Hash{
|
|
"TEMPLATE": "01-simple-component",
|
|
"variable": "This is another variable",
|
|
},
|
|
}
|
|
|
|
outputPage := templatenest.Hash{"TEMPLATE": "output/13-render-with-array-of-template-hash"}
|
|
|
|
render := nest.MustRender(page)
|
|
outputRender := nest.MustRender(outputPage)
|
|
|
|
assert.Equal(t, outputRender, render, "Rendered output does not match expected output")
|
|
}
|