pluginsdk/plugin/wasmguest/context_test.go

52 lines
1.4 KiB
Go

package wasmguest
import (
"context"
"testing"
abiv1 "git.dev.alexdunmow.com/block/pluginsdk/abi/v1"
"git.dev.alexdunmow.com/block/pluginsdk/blocks"
"github.com/google/uuid"
)
func TestContextFromRenderContextCarriesResolvedPagePaths(t *testing.T) {
pageID := uuid.MustParse("5f0c5f3f-3f1e-4a3a-9b6e-2f4f6a6d7e8f")
ctx := contextFromRenderContext(context.Background(), &abiv1.RenderContext{
Page: &abiv1.PageContext{
Id: pageID.String(),
Slug: "/article",
DerivedSlug: "/knowledge/article",
MountPath: "/knowledge",
Title: "Article",
PostType: "page",
Status: "published",
},
BlockContext: &abiv1.BlockContext{
Slug: "/article",
DerivedSlug: "/knowledge/article",
MountPath: "/knowledge",
},
})
page := blocks.GetCurrentPage(ctx)
if page == nil {
t.Fatal("current page is nil")
}
if page.ID != pageID || page.Slug != "/article" ||
page.DerivedSlug != "/knowledge/article" || page.MountPath != "/knowledge" {
t.Errorf("page context = %+v", page)
}
block := blocks.GetBlockContext(ctx)
if block == nil {
t.Fatal("block context is nil")
}
if block.Slug != "/article" || block.DerivedSlug != "/knowledge/article" || block.MountPath != "/knowledge" {
t.Errorf("block context = %+v", block)
}
data := block.ToMap()
if data["derivedSlug"] != "/knowledge/article" || data["mountPath"] != "/knowledge" {
t.Errorf("block template map = %#v", data)
}
}