more features
This commit is contained in:
@@ -24,21 +24,35 @@ func loadTestConfig(t *testing.T) *Config {
|
||||
func TestLoad(t *testing.T) {
|
||||
cfg := loadTestConfig(t)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
got interface{}
|
||||
want interface{}
|
||||
}{
|
||||
{"name", cfg.Name, "Ada Lovelace"},
|
||||
{"links count", len(cfg.Links), 2},
|
||||
{"first link URL", cfg.Links[0].URL, "https://ada.blog"},
|
||||
if cfg.Name != "Ada Lovelace" {
|
||||
t.Errorf("name: got %v, want %v", cfg.Name, "Ada Lovelace")
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
if tt.got != tt.want {
|
||||
t.Errorf("%s: got %v, want %v", tt.name, tt.got, tt.want)
|
||||
if len(cfg.Content) == 0 {
|
||||
t.Fatal("expected content blocks, got none")
|
||||
}
|
||||
|
||||
// Find the links collection
|
||||
var linksFound bool
|
||||
for _, block := range cfg.Content {
|
||||
if block.Type == "vertical-list-text" {
|
||||
for collectionName, items := range block.Collections {
|
||||
if collectionName == "links" {
|
||||
linksFound = true
|
||||
if len(items) != 4 {
|
||||
t.Errorf("links count: got %d, want 4", len(items))
|
||||
}
|
||||
if len(items) > 0 && items[0].URL != "https://ada.blog/research" {
|
||||
t.Errorf("first link URL: got %v, want https://ada.blog/research", items[0].URL)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !linksFound {
|
||||
t.Error("expected to find links collection, but didn't")
|
||||
}
|
||||
}
|
||||
|
||||
func TestThemeValidation(t *testing.T) {
|
||||
@@ -50,49 +64,84 @@ func TestThemeValidation(t *testing.T) {
|
||||
|
||||
func TestLinksCountMethod(t *testing.T) {
|
||||
cfg := loadTestConfig(t)
|
||||
if got, want := cfg.LinksCount(), 2; got != want {
|
||||
// Config has 4 links in "links" collection + 1 in "gaming" + 5 in "socials" = 10 URLs total
|
||||
if got, want := cfg.LinksCount(), 10; got != want {
|
||||
t.Errorf("LinksCount() = %d, want %d", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFooterBlocks(t *testing.T) {
|
||||
func TestContentBlocks(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
cfg Config
|
||||
want int
|
||||
name string
|
||||
cfg Config
|
||||
want int
|
||||
}{
|
||||
{
|
||||
name: "with footer blocks",
|
||||
name: "with content blocks",
|
||||
cfg: Config{
|
||||
Name: "Test",
|
||||
Footer: []FooterBlock{
|
||||
{Text: "© 2025 Test"},
|
||||
{Text: "Made with LinkBeam"},
|
||||
Content: []ContentBlock{
|
||||
{
|
||||
Type: "footer",
|
||||
Collections: map[string][]Item{
|
||||
"footer": {
|
||||
{Text: "© 2025 Test"},
|
||||
{Text: "Made with LinkBeam"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: 2,
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "empty footer",
|
||||
cfg: Config{Name: "Test", Footer: []FooterBlock{}},
|
||||
want: 0,
|
||||
name: "empty content",
|
||||
cfg: Config{Name: "Test", Content: []ContentBlock{}},
|
||||
want: 0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := len(tt.cfg.Footer); got != tt.want {
|
||||
t.Errorf("Footer length = %d, want %d", got, tt.want)
|
||||
if got := len(tt.cfg.Content); got != tt.want {
|
||||
t.Errorf("Content length = %d, want %d", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFooterBlockText(t *testing.T) {
|
||||
block := FooterBlock{Text: "Test Footer"}
|
||||
want := "Test Footer"
|
||||
func TestItemTypes(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
item Item
|
||||
desc string
|
||||
}{
|
||||
{
|
||||
name: "URL item",
|
||||
item: Item{Title: "Test Link", URL: "https://example.com", Icon: "fas fa-link"},
|
||||
desc: "link item",
|
||||
},
|
||||
{
|
||||
name: "CopyText item",
|
||||
item: Item{Title: "Username", CopyText: "testuser", Icon: "fas fa-user"},
|
||||
desc: "copyable text item",
|
||||
},
|
||||
{
|
||||
name: "Text item",
|
||||
item: Item{Text: "© 2025"},
|
||||
desc: "plain text item",
|
||||
},
|
||||
}
|
||||
|
||||
if block.Text != want {
|
||||
t.Errorf("FooterBlock.Text = %q, want %q", block.Text, want)
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.item.Title == "" && tt.item.Text == "" {
|
||||
t.Error("item should have title or text")
|
||||
}
|
||||
hasContent := tt.item.URL != "" || tt.item.CopyText != "" || tt.item.Text != ""
|
||||
if !hasContent {
|
||||
t.Error("item should have at least one content field")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user