Chat Messages: components 201-220
This commit is contained in:
121 files changed
+5737
-1
No files matched your search
@@ -0,0 +1,69 @@
|
||||
package mujica
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
)
|
||||
|
||||
const errorMessageText = `429 Too Many Requests: {"error":"rate_limit","retry_after":30}`
|
||||
|
||||
func TestErrorMessageKeepsTextAndRetries(t *testing.T) {
|
||||
retries := 0
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
Use(c, Settings{})
|
||||
if ErrorMessage(c, errorMessageText, ErrorMessageOptions{}).Retried() {
|
||||
retries++
|
||||
}
|
||||
}, 500, 200)
|
||||
if !tt.HasText(errorMessageText) || !tt.HasText("Something went wrong") {
|
||||
t.Fatalf("texts %q", tt.Texts())
|
||||
}
|
||||
_ = tt.Click("Retry")
|
||||
if retries != 1 {
|
||||
t.Fatalf("retries %d", retries)
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrorMessageRateLimitCountdown(t *testing.T) {
|
||||
retries := 0
|
||||
until := time.Now().Add(2500 * time.Millisecond)
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
Use(c, Settings{})
|
||||
if ErrorMessage(c, errorMessageText, ErrorMessageOptions{Title: "Rate limited by the API", RetryAt: until}).Retried() {
|
||||
retries++
|
||||
}
|
||||
}, 500, 200)
|
||||
if !tt.HasText("Retry in 3 s") {
|
||||
t.Fatalf("countdown missing: %q", tt.Texts())
|
||||
}
|
||||
_ = tt.Click("Retry in 3 s")
|
||||
if retries != 0 {
|
||||
t.Fatal("retried during the rate limit")
|
||||
}
|
||||
until = time.Now().Add(-time.Second)
|
||||
tt.Frame()
|
||||
_ = tt.Click("Retry")
|
||||
if retries != 1 {
|
||||
t.Fatalf("retries %d after the limit lifted", retries)
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrorMessageNeedsText(t *testing.T) {
|
||||
defer func() {
|
||||
if recover() == nil {
|
||||
t.Fatal("no panic without error text")
|
||||
}
|
||||
}()
|
||||
ui.NewTester(func(c *ui.Context) {
|
||||
Use(c, Settings{})
|
||||
ErrorMessage(c, "", ErrorMessageOptions{})
|
||||
}, 100, 100)
|
||||
}
|
||||
|
||||
func TestErrorMessageSnapshot(t *testing.T) {
|
||||
snapshot(t, "error_message", 520, 150, func(c *ui.Context) {
|
||||
ui.Column(c).Padding(16).Children(func() { ErrorMessage(c, errorMessageText, ErrorMessageOptions{}) })
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user