home_test.gno
4.14 Kb · 137 lines
1package home
2
3import (
4 "std"
5 "strings"
6 "testing"
7
8 "gno.land/p/demo/uassert"
9 "gno.land/p/demo/urequire"
10)
11
12// Helper function to set up test environment
13func setupTest() {
14 testing.SetOriginCaller(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y"))
15}
16
17func TestUpdatePFP(t *testing.T) {
18 setupTest()
19 pfp = ""
20 pfpCaption = ""
21
22 UpdatePFP("https://example.com/pic.png", "New Caption")
23
24 urequire.Equal(t, pfp, "https://example.com/pic.png", "Profile picture URL should be updated")
25 urequire.Equal(t, pfpCaption, "New Caption", "Profile picture caption should be updated")
26}
27
28func TestUpdateAboutMe(t *testing.T) {
29 setupTest()
30 abtMe = ""
31
32 UpdateAboutMe("This is my new bio.")
33
34 urequire.Equal(t, abtMe, "This is my new bio.", "About Me should be updated")
35}
36
37func TestVoteModern(t *testing.T) {
38 setupTest()
39 modernVotes, classicVotes, minimalVotes = 0, 0, 0
40
41 coinsSent := std.NewCoins(std.NewCoin("ugnot", 75000000))
42 coinsSpent := std.NewCoins(std.NewCoin("ugnot", 1))
43
44 testing.SetOriginSend(coinsSent)
45 testing.SetOriginSpend(coinsSpent)
46 VoteModern()
47
48 uassert.Equal(t, int64(75000000), modernVotes, "Modern votes should be calculated correctly")
49 uassert.Equal(t, "modern", currentTheme, "Theme should be updated to modern")
50}
51
52func TestVoteClassic(t *testing.T) {
53 setupTest()
54 modernVotes, classicVotes, minimalVotes = 0, 0, 0
55
56 coinsSent := std.NewCoins(std.NewCoin("ugnot", 75000000))
57 coinsSpent := std.NewCoins(std.NewCoin("ugnot", 1))
58
59 testing.SetOriginSend(coinsSent)
60 testing.SetOriginSpend(coinsSpent)
61 VoteClassic()
62
63 uassert.Equal(t, int64(75000000), classicVotes, "Classic votes should be calculated correctly")
64 uassert.Equal(t, "classic", currentTheme, "Theme should be updated to classic")
65}
66
67func TestVoteMinimal(t *testing.T) {
68 setupTest()
69 modernVotes, classicVotes, minimalVotes = 0, 0, 0
70
71 coinsSent := std.NewCoins(std.NewCoin("ugnot", 75000000))
72 coinsSpent := std.NewCoins(std.NewCoin("ugnot", 1))
73
74 testing.SetOriginSend(coinsSent)
75 testing.SetOriginSpend(coinsSpent)
76 VoteMinimal()
77
78 uassert.Equal(t, int64(75000000), minimalVotes, "Minimal votes should be calculated correctly")
79 uassert.Equal(t, "minimal", currentTheme, "Theme should be updated to minimal")
80}
81
82func TestRender(t *testing.T) {
83 setupTest()
84 // Reset the state to known values
85 modernVotes, classicVotes, minimalVotes = 0, 0, 0
86 currentTheme = "classic"
87 pfp = "https://example.com/pic.png"
88 pfpCaption = "Test Caption"
89 abtMe = "Test About Me"
90
91 out := Render("")
92 urequire.NotEqual(t, out, "", "Render output should not be empty")
93
94 // Test classic theme specific content
95 uassert.True(t, strings.Contains(out, "✨ Welcome to Matija's Homepage ✨"), "Classic theme should have correct header")
96 uassert.True(t, strings.Contains(out, pfp), "Should contain profile picture URL")
97 uassert.True(t, strings.Contains(out, pfpCaption), "Should contain profile picture caption")
98 uassert.True(t, strings.Contains(out, "About me"), "Should contain About me section")
99 uassert.True(t, strings.Contains(out, abtMe), "Should contain about me content")
100 uassert.True(t, strings.Contains(out, "Theme Customization"), "Should contain theme customization section")
101 uassert.True(t, strings.Contains(out, "Connect With Me"), "Should contain connect section")
102}
103
104func TestRenderModernTheme(t *testing.T) {
105 setupTest()
106 modernVotes, classicVotes, minimalVotes = 100, 0, 0
107 currentTheme = "modern"
108 updateCurrentTheme()
109
110 out := Render("")
111 uassert.True(t, strings.Contains(out, "🚀 Matija's Space"), "Modern theme should have correct header")
112}
113
114func TestRenderMinimalTheme(t *testing.T) {
115 setupTest()
116 modernVotes, classicVotes, minimalVotes = 0, 0, 100
117 currentTheme = "minimal"
118 updateCurrentTheme()
119
120 out := Render("")
121 uassert.True(t, strings.Contains(out, "Matija Marjanovic"), "Minimal theme should have correct header")
122}
123
124func TestUpdateLinks(t *testing.T) {
125 setupTest()
126
127 newLink := "https://example.com/vote"
128
129 UpdateModernLink(newLink)
130 urequire.Equal(t, modernLink, newLink, "Modern link should be updated")
131
132 UpdateClassicLink(newLink)
133 urequire.Equal(t, classicLink, newLink, "Classic link should be updated")
134
135 UpdateMinimalLink(newLink)
136 urequire.Equal(t, minimalLink, newLink, "Minimal link should be updated")
137}