pagr

A 'static site generator', built using dati.
Log | Files | Refs | Atom

commit 25c178295fc5f5a9ac91cd6d7d015447fa5b3256
parent 76fd1aee668fb1e4dc0de3a7d0b9191a291ac0a0
Author: gearsix <gearsix@tuta.io>
Date:   Mon, 14 Mar 2022 12:42:12 +0000

testing: added Page.Nav testing

Currently doing checks on making sure all found items exist in pages
and the number of items that exist in the arrays (.All, .Crumbs, etc).
Still need to figure out how to determine the number of .Children and
.Crumbs that should exist for each page.

Diffstat:
Mpagr_test.go | 61++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 60 insertions(+), 1 deletion(-)

diff --git a/pagr_test.go b/pagr_test.go @@ -6,6 +6,7 @@ import ( "time" "path/filepath" "testing" + "strings" ) var templates = map[string]string{ // [ext]template @@ -127,6 +128,64 @@ func createTestContents(dir string) (err error) { return } +func validateTestPagesNav(t *testing.T, pages []Page) { + for _, p := range pages { + var allUnique []string + for _, navp := range p.Nav.All { + for _, a := range allUnique { + if a == navp.Path { + t.Errorf("'%s' has .Nav.All items with duplicate .Path values (%s)", + p.Path, a) + } + } + allUnique = append(allUnique, navp.Path) + } + if (len(p.Nav.All) != len(pages)) { + t.Errorf("'%s' has %d in .Nav.All (should be %d)", + p.Path, len(p.Nav.All), len(pages)) + } + + foundAll := 0 + for _, navp := range p.Nav.All { + for _, pp := range pages { + if navp.Path == pp.Path { + foundAll++ + break + } + } + } + if foundAll != len(p.Nav.All) { + t.Errorf("found %d/%d pages in .Nav.All for '%s'", + foundAll, len(p.Nav.All), p.Path) + } + + foundRoot := false + foundParent := false + for _, pp := range pages { + if !foundRoot && p.Nav.Root.Path == pp.Path { + foundRoot = true + } + if !foundParent && p.Nav.Parent == nil || p.Nav.Parent.Path == pp.Path { + foundParent = true + } + if foundRoot && foundParent { + break + } + } + if !foundRoot { + t.Errorf("could not find .Root '%s' for '%s'", + p.Nav.Root.Path, p.Path) + } + if !foundParent { + t.Errorf("could not find .Parent '%s' for '%s'", + p.Nav.Parent.Path, p.Path) + } + + // TODO test .Nav.Children, figure out how many should exist + // TODO test .Nav.Crumbs, figure out how many should exist + } +} + func validateTestPages(t *testing.T, pages []Page, e error) { if len(pages) != len(contents) { t.Fatalf("invalid number of pages returned (%d should be %d)", @@ -142,7 +201,7 @@ func validateTestPages(t *testing.T, pages []Page, e error) { if len(p.Path) == 0 { t.Error("empty Path for page:", p) } - // TODO test p.Nav here + validateTestPagesNav(t, pages) if _, ok := p.Meta["page"]; !ok || len(p.Meta) == 0 { t.Errorf("missing page Meta key for page: '%s'", p.Path) }