Add graph markdown and canvas outputs
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package gsp
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -13,6 +15,7 @@ func TestLoadValidateAndFlatten(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeTestFile(t, design, "page.gsp", `id: page.lottery.main
|
||||
title: Lottery Page
|
||||
type: page
|
||||
resolution: L3
|
||||
context: Lottery page.
|
||||
@@ -52,6 +55,42 @@ context: Base lottery page.
|
||||
if !sameStrings(got, want) {
|
||||
t.Fatalf("flatten ids = %v, want %v", got, want)
|
||||
}
|
||||
index := project.Index()
|
||||
if index[2].Title != "Lottery Page" {
|
||||
t.Fatalf("index title = %q", index[2].Title)
|
||||
}
|
||||
|
||||
graph := project.Graph("page.lottery.main", -1)
|
||||
if !strings.Contains(graph.Mermaid(), `["Lottery Page"]`) {
|
||||
t.Fatalf("expected Mermaid to use title, got:\n%s", graph.Mermaid())
|
||||
}
|
||||
if !strings.Contains(graph.Markdown(), "```mermaid") {
|
||||
t.Fatalf("expected Markdown Mermaid block")
|
||||
}
|
||||
canvasData, err := graph.Canvas()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var canvas struct {
|
||||
Nodes []struct {
|
||||
Text string `json:"text"`
|
||||
} `json:"nodes"`
|
||||
Edges []struct {
|
||||
Label string `json:"label"`
|
||||
} `json:"edges"`
|
||||
}
|
||||
if err := json.Unmarshal(canvasData, &canvas); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foundTitle := false
|
||||
for _, node := range canvas.Nodes {
|
||||
if strings.Contains(node.Text, "Lottery Page") {
|
||||
foundTitle = true
|
||||
}
|
||||
}
|
||||
if !foundTitle {
|
||||
t.Fatalf("expected canvas node text to include title, got %+v", canvas.Nodes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateMissingReference(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user