63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
package platform
|
|
|
|
import "testing"
|
|
|
|
func TestPlatformMenusAreStaticTwoDimensionalData(t *testing.T) {
|
|
if len(PlatformMenus) == 0 {
|
|
t.Fatal("PlatformMenus must contain menu groups")
|
|
}
|
|
seen := make(map[string]bool)
|
|
for _, group := range PlatformMenus {
|
|
if len(group) == 0 {
|
|
t.Fatal("platform menu groups must not be empty")
|
|
}
|
|
parent := group[0]
|
|
if parent.ParentIdentity != "" {
|
|
t.Fatalf("first menu in group must be first-level: %#v", parent)
|
|
}
|
|
for index, menu := range group {
|
|
if menu.Identity == "" || menu.GroupCode == "" {
|
|
t.Fatalf("menu identity and code are required: %#v", menu)
|
|
}
|
|
if index > 0 && menu.ParentIdentity != parent.Identity {
|
|
t.Fatalf("second-level menu %s must reference parent %s", menu.Identity, parent.Identity)
|
|
}
|
|
if seen[menu.Identity] {
|
|
t.Fatalf("duplicate menu identity: %s", menu.Identity)
|
|
}
|
|
seen[menu.Identity] = true
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRootLoadsAllStaticPlatformMenus(t *testing.T) {
|
|
menus, err := LoadPlatformMenus("root")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(menus) != len(AllPlatformMenus()) {
|
|
t.Fatalf("root menu count = %d, want %d", len(menus), len(AllPlatformMenus()))
|
|
}
|
|
}
|
|
|
|
func TestPlatformMenuContainsDashboardRoutes(t *testing.T) {
|
|
want := map[string]string{
|
|
"dashboard_overview": "/dashboard/overview",
|
|
}
|
|
for _, menu := range AllPlatformMenus() {
|
|
if path, ok := want[menu.Identity]; ok {
|
|
if menu.Path != path {
|
|
t.Fatalf("menu %q path = %q, want %q", menu.Identity, menu.Path, path)
|
|
}
|
|
delete(want, menu.Identity)
|
|
}
|
|
}
|
|
if len(want) != 0 {
|
|
t.Fatalf("missing dashboard menus: %#v", want)
|
|
}
|
|
menu, ok := FindPlatformMenu("dashboard_overview")
|
|
if !ok || menu.ParentIdentity != "" || menu.Icon != "icon-dashboard" {
|
|
t.Fatalf("dashboard overview must be a first-level icon menu: %#v", menu)
|
|
}
|
|
}
|