diff --git a/examples/gno.land/r/gnoland/events/errors.gno b/examples/gno.land/r/gnoland/events/errors.gno index 788115015a4..fb44d3c9f82 100644 --- a/examples/gno.land/r/gnoland/events/errors.gno +++ b/examples/gno.land/r/gnoland/events/errors.gno @@ -8,8 +8,8 @@ import ( var ( ErrEmptyName = errors.New("event name cannot be empty") ErrNoSuchID = errors.New("event with specified ID does not exist") - ErrWidgetMinAmt = errors.New("you need to request at least 1 event to render") - ErrWidgetMaxAmt = errors.New("maximum number of events in widget is" + strconv.Itoa(MaxWidgetSize)) + ErrMinWidgetSize = errors.New("you need to request at least 1 event to render") + ErrMaxWidgetSize = errors.New("maximum number of events in widget is" + strconv.Itoa(MaxWidgetSize)) ErrDescriptionTooLong = errors.New("event description is too long") ErrInvalidStartTime = errors.New("invalid start time format") ErrInvalidEndTime = errors.New("invalid end time format") diff --git a/examples/gno.land/r/gnoland/events/events_test.gno b/examples/gno.land/r/gnoland/events/events_test.gno index 1e5625e0b2c..357857352d8 100644 --- a/examples/gno.land/r/gnoland/events/events_test.gno +++ b/examples/gno.land/r/gnoland/events/events_test.gno @@ -7,6 +7,7 @@ import ( "time" "gno.land/p/demo/uassert" + "gno.land/p/demo/urequire" ) var ( @@ -159,3 +160,41 @@ func TestParseTimes(t *testing.T) { _, _, err = parseTimes("2009-02-10T23:30:30+02:00", "2009-02-13T21:30:33+05:00") uassert.ErrorContains(t, err, ErrStartEndTimezonemMismatch.Error()) } + +func TestRenderEventWidget(t *testing.T) { + events = nil // remove elements from previous tests - see issue #1982 + + // No events yet + out, err := RenderEventWidget(1) + uassert.NoError(t, err) + uassert.Equal(t, out, "No events.") + + // Too many events + out, err = RenderEventWidget(MaxWidgetSize + 1) + uassert.ErrorIs(t, err, ErrMaxWidgetSize) + + // Too little events + out, err = RenderEventWidget(0) + uassert.ErrorIs(t, err, ErrMinWidgetSize) + + // Ordering & if requested amt is larger than the num of events that exist + e1Start := parsedTimeNow.Add(time.Hour * 24 * 5) + e1End := e1Start.Add(time.Hour * 4) + + e2Start := parsedTimeNow.Add(time.Hour * 24 * 10) // event 2 is after event 1 + e2End := e2Start.Add(time.Hour * 4) + + _, err = AddEvent("Event 1", "description", "gno.land", "loc", e1Start.Format(time.RFC3339), e1End.Format(time.RFC3339)) + urequire.NoError(t, err) + + _, err = AddEvent("Event 2", "description", "gno.land", "loc", e2Start.Format(time.RFC3339), e2End.Format(time.RFC3339)) + urequire.NoError(t, err) + + out, err = RenderEventWidget(MaxWidgetSize) + urequire.NoError(t, err) + + uniqueSequence := "- [" // sequence that is displayed once per each event as per the RenderEventWidget function + uassert.Equal(t, 2, strings.Count(out, uniqueSequence)) + + uassert.True(t, strings.Index(out, "Event 1") > strings.Index(out, "Event 2")) +} diff --git a/examples/gno.land/r/gnoland/events/gno.mod b/examples/gno.land/r/gnoland/events/gno.mod index 5a4c6ac56f3..bd3e4652b04 100644 --- a/examples/gno.land/r/gnoland/events/gno.mod +++ b/examples/gno.land/r/gnoland/events/gno.mod @@ -5,4 +5,5 @@ require ( gno.land/p/demo/seqid v0.0.0-latest gno.land/p/demo/uassert v0.0.0-latest gno.land/p/demo/ufmt v0.0.0-latest + gno.land/p/demo/urequire v0.0.0-latest ) diff --git a/examples/gno.land/r/gnoland/events/rendering.gno b/examples/gno.land/r/gnoland/events/rendering.gno index bde32065d27..d98879c68f6 100644 --- a/examples/gno.land/r/gnoland/events/rendering.gno +++ b/examples/gno.land/r/gnoland/events/rendering.gno @@ -19,11 +19,11 @@ func RenderEventWidget(eventsToRender int) (string, error) { } if eventsToRender > MaxWidgetSize { - return "", ErrWidgetMaxAmt + return "", ErrMaxWidgetSize } if eventsToRender < 1 { - return "", ErrWidgetMinAmt + return "", ErrMinWidgetSize } if eventsToRender > numOfEvents { @@ -32,7 +32,7 @@ func RenderEventWidget(eventsToRender int) (string, error) { output := "" - for _, event := range events[eventsToRender:] { + for _, event := range events[:eventsToRender] { output += ufmt.Sprintf("- [%s](%s)\n", event.name, event.link) } diff --git a/examples/gno.land/r/gnoland/home/home.gno b/examples/gno.land/r/gnoland/home/home.gno index e5f24f87135..921492d81b4 100644 --- a/examples/gno.land/r/gnoland/home/home.gno +++ b/examples/gno.land/r/gnoland/home/home.gno @@ -269,7 +269,7 @@ func discoverLinks() ui.Element { - [Discover demo packages](https://github.com/gnolang/gno/tree/master/examples) - [Gnoscan](https://gnoscan.io) - [Portal Loop](https://docs.gno.land/concepts/portal-loop) -- Testnet 4 (upcoming) +- [Testnet 4](https://test4.gno.land/) (Launched July 2024!) - [Testnet 3](https://test3.gno.land/) (archive) - [Testnet 2](https://test2.gno.land/) (archive) - Testnet Faucet Hub (soon) diff --git a/examples/gno.land/r/gnoland/home/home_filetest.gno b/examples/gno.land/r/gnoland/home/home_filetest.gno index 15f329683f4..b70b22c80af 100644 --- a/examples/gno.land/r/gnoland/home/home_filetest.gno +++ b/examples/gno.land/r/gnoland/home/home_filetest.gno @@ -56,7 +56,7 @@ func main() { // - [Discover demo packages](https://github.com/gnolang/gno/tree/master/examples) // - [Gnoscan](https://gnoscan.io) // - [Portal Loop](https://docs.gno.land/concepts/portal-loop) -// - Testnet 4 (upcoming) +// - [Testnet 4](https://test4.gno.land/) (Launched July 2024!) // - [Testnet 3](https://test3.gno.land/) (archive) // - [Testnet 2](https://test2.gno.land/) (archive) // - Testnet Faucet Hub (soon)