ee2c52bbc6
Add an optional renderContent field to canvas nodes across the go-zero API type, domain node, SQLC models/queries, PostgreSQL schema, and mappers so a lightweight transparent-WebP display texture persists alongside the original content. Prefer renderContent for project thumbnails and main-canvas previews, and treat both content and renderContent as protected/deletable asset URLs during canvas asset cleanup. Extend round-trip coverage. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package application
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"img_infinite_canvas/internal/domain/design"
|
|
)
|
|
|
|
func TestProjectThumbnailUsesCanvasPreview(t *testing.T) {
|
|
project := design.Project{
|
|
Brief: "still day 官网首页",
|
|
Nodes: []design.Node{
|
|
{
|
|
ID: "small",
|
|
Type: design.NodeTypeImage,
|
|
Title: "Small",
|
|
Content: "http://localhost:19000/canvas-assets/small.png",
|
|
Width: 240,
|
|
Height: 240,
|
|
Status: "success",
|
|
},
|
|
{
|
|
ID: "main",
|
|
Type: design.NodeTypeImage,
|
|
Title: "Main",
|
|
Content: "http://localhost:19000/canvas-assets/main.svg",
|
|
RenderContent: "http://localhost:19000/canvas-assets/main.render.webp",
|
|
Width: 1024,
|
|
Height: 768,
|
|
Status: "success",
|
|
},
|
|
},
|
|
}
|
|
|
|
got := projectThumbnail(project)
|
|
if !strings.HasPrefix(got, projectCanvasPreviewPrefix) {
|
|
t.Fatalf("expected canvas preview thumbnail, got %s", got)
|
|
}
|
|
var preview projectCanvasPreview
|
|
raw, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(got, projectCanvasPreviewPrefix))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := json.Unmarshal(raw, &preview); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(preview.Nodes) != 2 {
|
|
t.Fatalf("expected two preview nodes, got %#v", preview.Nodes)
|
|
}
|
|
if preview.Nodes[1].Content != "http://localhost:19000/canvas-assets/main.svg" || preview.Nodes[1].RenderContent != "http://localhost:19000/canvas-assets/main.render.webp" {
|
|
t.Fatalf("expected generated image in canvas preview, got %#v", preview.Nodes[1])
|
|
}
|
|
}
|
|
|
|
func TestProjectThumbnailFallsBackToPromptVariant(t *testing.T) {
|
|
project := design.Project{Brief: "电商产品图"}
|
|
if got := projectThumbnail(project); got != "commerce" {
|
|
t.Fatalf("expected commerce fallback, got %s", got)
|
|
}
|
|
}
|