home_test.gno

1.56 Kb ยท 60 lines
 1package home
 2
 3import (
 4	"strings"
 5	"testing"
 6)
 7
 8func TestConfig(t *testing.T) {
 9	cfg := GetConfig()
10
11	if cfg.Title != "JJOptimist's Home Realm ๐Ÿ " {
12		t.Errorf("Expected title to be 'JJOptimist's Home Realm ๐Ÿ ', got %s", cfg.Title)
13	}
14	if cfg.Description != "Exploring Gno and building on-chain" {
15		t.Errorf("Expected description to be 'Exploring Gno and building on-chain', got %s", cfg.Description)
16	}
17	if cfg.Github != "jjoptimist" {
18		t.Errorf("Expected github to be 'jjoptimist', got %s", cfg.Github)
19	}
20}
21
22func TestRender(t *testing.T) {
23	output := Render("")
24
25	// Test that required sections are present
26	if !strings.Contains(output, "# "+config.Title) {
27		t.Error("Rendered output missing title")
28	}
29	if !strings.Contains(output, "## About Me") {
30		t.Error("Rendered output missing About Me section")
31	}
32	if !strings.Contains(output, "## Contact") {
33		t.Error("Rendered output missing Contact section")
34	}
35	if !strings.Contains(output, config.Description) {
36		t.Error("Rendered output missing description")
37	}
38	if !strings.Contains(output, config.Github) {
39		t.Error("Rendered output missing github link")
40	}
41}
42
43func TestGetGnomeArt(t *testing.T) {
44	tests := []struct {
45		height   int64
46		expected string
47	}{
48		{7, gnomeArt4}, // height divisible by 7
49		{5, gnomeArt3}, // height divisible by 5
50		{3, gnomeArt2}, // height divisible by 3
51		{2, gnomeArt1}, // default case
52	}
53
54	for _, tt := range tests {
55		art := getGnomeArt(tt.height)
56		if !strings.Contains(art, tt.expected) {
57			t.Errorf("For height %d, expected art containing %s, got %s", tt.height, tt.expected, art)
58		}
59	}
60}