MCPcopy Create free account
hub / github.com/GuyARoss/orbit / TestBuildHTMLPages

Function TestBuildHTMLPages

examples/basic-react/orbitgen/orb_test.go:434–468  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

432 }
433}
434func TestBuildHTMLPages(t *testing.T) {
435 t.Run("use static content", func(t *testing.T) {
436 p := PageRender("thing")
437 staticResourceMap[p] = true
438 tmpDir := t.TempDir()
439 tempBdir := bundleDir
440 bundleDir = tmpDir
441 t.Cleanup(func() {
442 bundleDir = tempBdir
443 })
444 dir := fmt.Sprintf("%s%c%s", http.Dir(tmpDir), os.PathSeparator, p)
445 ioutil.WriteFile(dir, []byte("<body> thing </body> <head> thint2 </head>"), 0666)
446 o := buildHTMLPages([]byte(""), p)
447 if len(o.Head) != 1 && len(o.Body) != 1 {
448 t.Errorf("body and head len do not match")
449 }
450 })
451 t.Run("wrap content", func(t *testing.T) {
452 p := PageRender("wrapme")
453 wrapDocRender[p] = &DocumentRenderer{
454 fn: func(ctx context.Context, s string, b []byte, hd *htmlDoc) (*htmlDoc, context.Context) {
455 hd.Body = append(hd.Body, "thing thing")
456 return hd, ctx
457 },
458 version: "some_version",
459 }
460 t.Cleanup(func() {
461 wrapDocRender[p] = nil
462 })
463 o := buildHTMLPages([]byte(""), p)
464 if len(o.Body) != 1 {
465 t.Errorf("did not apply wrap doc correctly")
466 }
467 })
468}
469func TestParseStaticDocument(t *testing.T) {
470 t.Run("valid content", func(t *testing.T) {
471 tempDir := t.TempDir()

Callers

nothing calls this directly

Calls 4

CleanupMethod · 0.80
PageRenderTypeAlias · 0.70
buildHTMLPagesFunction · 0.70
WriteFileMethod · 0.65

Tested by

no test coverage detected