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 std.TestSetOrigCaller(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 std.TestSetOrigSend(coinsSent, coinsSpent)
45 VoteModern()
46
47 uassert.Equal(t, int64(75000000), modernVotes, "Modern votes should be calculated correctly")
48 uassert.Equal(t, "modern", currentTheme, "Theme should be updated to modern")
49}
50
51func TestVoteClassic(t *testing.T) {
52 setupTest()
53 modernVotes, classicVotes, minimalVotes = 0, 0, 0
54
55 coinsSent := std.NewCoins(std.NewCoin("ugnot", 75000000))
56 coinsSpent := std.NewCoins(std.NewCoin("ugnot", 1))
57
58 std.TestSetOrigSend(coinsSent, coinsSpent)
59 VoteClassic()
60
61 uassert.Equal(t, int64(75000000), classicVotes, "Classic votes should be calculated correctly")
62 uassert.Equal(t, "classic", currentTheme, "Theme should be updated to classic")
63}
64
65func TestVoteMinimal(t *testing.T) {
66 setupTest()
67 modernVotes, classicVotes, minimalVotes = 0, 0, 0
68
69 coinsSent := std.NewCoins(std.NewCoin("ugnot", 75000000))
70 coinsSpent := std.NewCoins(std.NewCoin("ugnot", 1))
71
72 std.TestSetOrigSend(coinsSent, coinsSpent)
73 VoteMinimal()
74
75 uassert.Equal(t, int64(75000000), minimalVotes, "Minimal votes should be calculated correctly")
76 uassert.Equal(t, "minimal", currentTheme, "Theme should be updated to minimal")
77}
78
79func TestRender(t *testing.T) {
80 setupTest()
81 // Reset the state to known values
82 modernVotes, classicVotes, minimalVotes = 0, 0, 0
83 currentTheme = "classic"
84 pfp = "https://example.com/pic.png"
85 pfpCaption = "Test Caption"
86 abtMe = "Test About Me"
87
88 out := Render("")
89 urequire.NotEqual(t, out, "", "Render output should not be empty")
90
91 // Test classic theme specific content
92 uassert.True(t, strings.Contains(out, "✨ Welcome to Matija's Homepage ✨"), "Classic theme should have correct header")
93 uassert.True(t, strings.Contains(out, pfp), "Should contain profile picture URL")
94 uassert.True(t, strings.Contains(out, pfpCaption), "Should contain profile picture caption")
95 uassert.True(t, strings.Contains(out, "About me"), "Should contain About me section")
96 uassert.True(t, strings.Contains(out, abtMe), "Should contain about me content")
97 uassert.True(t, strings.Contains(out, "Theme Customization"), "Should contain theme customization section")
98 uassert.True(t, strings.Contains(out, "Connect With Me"), "Should contain connect section")
99}
100
101func TestRenderModernTheme(t *testing.T) {
102 setupTest()
103 modernVotes, classicVotes, minimalVotes = 100, 0, 0
104 currentTheme = "modern"
105 updateCurrentTheme()
106
107 out := Render("")
108 uassert.True(t, strings.Contains(out, "🚀 Matija's Space"), "Modern theme should have correct header")
109}
110
111func TestRenderMinimalTheme(t *testing.T) {
112 setupTest()
113 modernVotes, classicVotes, minimalVotes = 0, 0, 100
114 currentTheme = "minimal"
115 updateCurrentTheme()
116
117 out := Render("")
118 uassert.True(t, strings.Contains(out, "Matija Marjanovic"), "Minimal theme should have correct header")
119}
120
121func TestUpdateLinks(t *testing.T) {
122 setupTest()
123
124 newLink := "https://example.com/vote"
125
126 UpdateModernLink(newLink)
127 urequire.Equal(t, modernLink, newLink, "Modern link should be updated")
128
129 UpdateClassicLink(newLink)
130 urequire.Equal(t, classicLink, newLink, "Classic link should be updated")
131
132 UpdateMinimalLink(newLink)
133 urequire.Equal(t, minimalLink, newLink, "Minimal link should be updated")
134}
home_test.gno
4.06 Kb · 134 lines