home_test.gno

4.18 Kb · 115 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
 12func TestUpdatePFP(t *testing.T) {
 13	testing.SetRealm(std.NewUserRealm(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y")))
 14	pfp = ""
 15	pfpCaption = ""
 16
 17	UpdatePFP(cross, "https://example.com/pic.png", "New Caption")
 18
 19	urequire.Equal(t, pfp, "https://example.com/pic.png", "Profile picture URL should be updated")
 20	urequire.Equal(t, pfpCaption, "New Caption", "Profile picture caption should be updated")
 21}
 22
 23func TestUpdateAboutMe(t *testing.T) {
 24	testing.SetRealm(std.NewUserRealm(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y")))
 25	abtMe = ""
 26
 27	UpdateAboutMe(cross, "This is my new bio.")
 28
 29	urequire.Equal(t, abtMe, "This is my new bio.", "About Me should be updated")
 30}
 31
 32func TestVoteModern(t *testing.T) {
 33	testing.SetRealm(std.NewUserRealm(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y")))
 34	modernVotes, classicVotes, minimalVotes = 0, 0, 0
 35
 36	coinsSent := std.NewCoins(std.NewCoin("ugnot", 75000000))
 37	coinsSpent := std.NewCoins(std.NewCoin("ugnot", 1))
 38
 39	testing.SetOriginSend(coinsSent)
 40	testing.SetOriginSpend(coinsSpent)
 41	VoteModern(cross)
 42
 43	uassert.Equal(t, int64(75000000), modernVotes, "Modern votes should be calculated correctly")
 44	uassert.Equal(t, "modern", currentTheme, "Theme should be updated to modern")
 45}
 46
 47func TestVoteClassic(t *testing.T) {
 48	testing.SetRealm(std.NewUserRealm(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y")))
 49	modernVotes, classicVotes, minimalVotes = 0, 0, 0
 50
 51	coinsSent := std.NewCoins(std.NewCoin("ugnot", 75000000))
 52	coinsSpent := std.NewCoins(std.NewCoin("ugnot", 1))
 53
 54	testing.SetOriginSend(coinsSent)
 55	testing.SetOriginSpend(coinsSpent)
 56	VoteClassic(cross)
 57
 58	uassert.Equal(t, int64(75000000), classicVotes, "Classic votes should be calculated correctly")
 59	uassert.Equal(t, "classic", currentTheme, "Theme should be updated to classic")
 60}
 61
 62func TestVoteMinimal(t *testing.T) {
 63	testing.SetRealm(std.NewUserRealm(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y")))
 64	modernVotes, classicVotes, minimalVotes = 0, 0, 0
 65
 66	coinsSent := std.NewCoins(std.NewCoin("ugnot", 75000000))
 67	coinsSpent := std.NewCoins(std.NewCoin("ugnot", 1))
 68
 69	testing.SetOriginSend(coinsSent)
 70	testing.SetOriginSpend(coinsSpent)
 71	VoteMinimal(cross)
 72
 73	uassert.Equal(t, int64(75000000), minimalVotes, "Minimal votes should be calculated correctly")
 74	uassert.Equal(t, "minimal", currentTheme, "Theme should be updated to minimal")
 75}
 76
 77func TestRender(t *testing.T) {
 78	testing.SetRealm(std.NewUserRealm(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y")))
 79	modernVotes, classicVotes, minimalVotes = 0, 0, 0
 80	currentTheme = "classic"
 81	pfp = "https://example.com/pic.png"
 82	pfpCaption = "Test Caption"
 83	abtMe = "Test About Me"
 84
 85	out := Render("")
 86	urequire.NotEqual(t, out, "", "Render output should not be empty")
 87
 88	uassert.True(t, strings.Contains(out, "✨ Welcome to Matija's Homepage ✨"), "Classic theme should have correct header")
 89	uassert.True(t, strings.Contains(out, pfp), "Should contain profile picture URL")
 90	uassert.True(t, strings.Contains(out, pfpCaption), "Should contain profile picture caption")
 91	uassert.True(t, strings.Contains(out, "About me"), "Should contain About me section")
 92	uassert.True(t, strings.Contains(out, abtMe), "Should contain about me content")
 93	uassert.True(t, strings.Contains(out, "Theme Customization"), "Should contain theme customization section")
 94	uassert.True(t, strings.Contains(out, "Connect With Me"), "Should contain connect section")
 95}
 96
 97func TestRenderModernTheme(t *testing.T) {
 98	testing.SetRealm(std.NewUserRealm(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y")))
 99	modernVotes, classicVotes, minimalVotes = 100, 0, 0
100	currentTheme = "modern"
101	updateCurrentTheme()
102
103	out := Render("")
104	uassert.True(t, strings.Contains(out, "🚀 Matija's Space"), "Modern theme should have correct header")
105}
106
107func TestRenderMinimalTheme(t *testing.T) {
108	testing.SetRealm(std.NewUserRealm(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y")))
109	modernVotes, classicVotes, minimalVotes = 0, 0, 100
110	currentTheme = "minimal"
111	updateCurrentTheme()
112
113	out := Render("")
114	uassert.True(t, strings.Contains(out, "Matija Marjanovic"), "Minimal theme should have correct header")
115}