Files
moteva/server/internal/logic/get_agent_starter_config_logic_test.go
T
root c94b163540 feat(server): add localized agent starter config endpoint
Add a public GET /api/ui/agent-starters endpoint returning localized
empty-state content (title, description, preview images, and starter
prompts) for the canvas Agent panel. Content is server-configurable via
AgentStarter config with built-in zh-CN/en-US fallbacks, and the route is
exempt from authentication so shared canvases render the same content.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-10 22:19:14 +08:00

71 lines
3.4 KiB
Go

package logic
import (
"context"
"testing"
"img_infinite_canvas/internal/config"
"img_infinite_canvas/internal/svc"
"img_infinite_canvas/internal/types"
)
func TestGetAgentStarterConfigReturnsLocalizedDefaults(t *testing.T) {
logic := NewGetAgentStarterConfigLogic(context.Background(), &svc.ServiceContext{})
response, err := logic.GetAgentStarterConfig(&types.GetAgentStarterConfigRequest{Locale: "en-US"})
if err != nil {
t.Fatalf("get agent starter config: %v", err)
}
if response.Title != "What would you like to create today?" {
t.Fatalf("unexpected title: %q", response.Title)
}
if len(response.PreviewImages) != 3 {
t.Fatalf("expected three preview images, got %d", len(response.PreviewImages))
}
if len(response.Starters) != 5 {
t.Fatalf("expected five starters, got %d", len(response.Starters))
}
expected := []types.AgentStarterItem{
{Id: "ecommerce", Label: "E-commerce product", Prompt: "Create a premium ecommerce product image for a portable espresso machine, with realistic lighting, clean composition, benefit callouts, and marketplace-ready visual hierarchy"},
{Id: "poster", Label: "Poster", Prompt: "Design a bold launch poster for a new skincare product line, with strong typography, product focus, campaign headline, date, and a polished premium layout"},
{Id: "brand-visual", Label: "Brand visual", Prompt: "Create a brand identity direction for a modern wellness drink brand, including color palette, typography mood, logo usage, packaging accents, and social-ready visual elements"},
{Id: "social-media", Label: "Social media", Prompt: "Create a square Instagram promotion for a weekend fashion sale, with product cutouts, discount headline, brand colors, and a layout that works as a paid social ad"},
{Id: "logo", Label: "Logo design", Prompt: "Design a clean vector logo for a direct-to-consumer home goods brand named Loom & Line, with a simple mark, balanced wordmark, and clear black-and-white usage"},
}
for index, item := range expected {
if response.Starters[index] != item {
t.Fatalf("unexpected starter %d: got %#v, want %#v", index, response.Starters[index], item)
}
}
}
func TestGetAgentStarterConfigUsesConfiguredContent(t *testing.T) {
serviceContext := &svc.ServiceContext{Config: config.Config{AgentStarter: config.AgentStarterConfig{
PreviewImages: []string{" https://cdn.example.com/one.webp ", ""},
ZhCN: config.AgentStarterLocaleConfig{
Title: "新的入口标题",
Description: "新的入口说明",
Starters: []config.AgentStarterItemConfig{
{ID: "campaign", Label: "运营活动", Prompt: "Create a campaign visual"},
{ID: "campaign", Label: "重复项", Prompt: "Ignore duplicate"},
{ID: "incomplete", Label: "不完整"},
},
},
}}}
logic := NewGetAgentStarterConfigLogic(context.Background(), serviceContext)
response, err := logic.GetAgentStarterConfig(&types.GetAgentStarterConfigRequest{Locale: "zh-CN"})
if err != nil {
t.Fatalf("get configured agent starter content: %v", err)
}
if response.Title != "新的入口标题" || response.Description != "新的入口说明" {
t.Fatalf("unexpected configured copy: %+v", response)
}
if len(response.PreviewImages) != 1 || response.PreviewImages[0] != "https://cdn.example.com/one.webp" {
t.Fatalf("unexpected configured images: %#v", response.PreviewImages)
}
if len(response.Starters) != 1 || response.Starters[0].Id != "campaign" {
t.Fatalf("unexpected configured starters: %#v", response.Starters)
}
}