Split into category packages; module github.com/ZacharyZhang-NY/MujicaUI
This commit is contained in:
1822 files changed
+24568
-21314
No files matched your search
@@ -0,0 +1,77 @@
|
||||
package input
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
"github.com/ZacharyZhang-NY/MujicaUI/core"
|
||||
)
|
||||
|
||||
func TestBannerActionCloseAndAnnounce(t *testing.T) {
|
||||
open := true
|
||||
var last core.AlertResult
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
core.Use(c, core.Settings{})
|
||||
if r := Banner(c, &open, "Maintenance tonight at 22:00", BannerOptions{Severity: core.SeverityWarning, Action: "Details"}); r.Action || r.Closed {
|
||||
last = r
|
||||
}
|
||||
}, 700, 200)
|
||||
if a := tt.Announcements(); !slices.Equal(a, []string{"Warning: Maintenance tonight at 22:00"}) {
|
||||
t.Fatalf("announcements %q", a)
|
||||
}
|
||||
if err := tt.Click("Details"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !last.Action || !open {
|
||||
t.Fatalf("action: %+v open %v", last, open)
|
||||
}
|
||||
tt.Key(0, ui.KeyTab) // from Details to Dismiss
|
||||
tt.Key(0, ui.KeyEnter)
|
||||
if open || !last.Closed || tt.HasText("Maintenance") {
|
||||
t.Fatalf("keyboard close: open %v %+v", open, last)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBannerDisabledAndFixed(t *testing.T) {
|
||||
open := true
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
core.Use(c, core.Settings{})
|
||||
ui.Column(c).Disabled(true).Children(func() {
|
||||
Banner(c, &open, "Read only", BannerOptions{Severity: core.SeverityError})
|
||||
})
|
||||
Banner(c, nil, "Always here", BannerOptions{})
|
||||
}, 700, 200)
|
||||
_ = tt.Click("Dismiss")
|
||||
if !open {
|
||||
t.Fatal("disabled banner closed")
|
||||
}
|
||||
if !tt.HasText("Always here") {
|
||||
t.Fatal("banner without open missing")
|
||||
}
|
||||
for _, f := range []func(c *ui.Context){
|
||||
func(c *ui.Context) { Banner(c, nil, "", BannerOptions{}) },
|
||||
func(c *ui.Context) { Banner(c, nil, "x", BannerOptions{Severity: 7}) },
|
||||
} {
|
||||
func() {
|
||||
defer func() {
|
||||
if recover() == nil {
|
||||
t.Error("no panic")
|
||||
}
|
||||
}()
|
||||
ui.NewTester(func(c *ui.Context) { core.Use(c, core.Settings{}); f(c) }, 300, 100)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func TestBannerSnapshot(t *testing.T) {
|
||||
open := true
|
||||
snapshot(t, "banner", 640, 200, func(c *ui.Context) {
|
||||
ui.Column(c).Gap(8).Children(func() {
|
||||
Banner(c, &open, "A new version is available.", BannerOptions{Action: "Update"})
|
||||
Banner(c, &open, "Your trial ends in 3 days.", BannerOptions{Severity: core.SeverityWarning})
|
||||
Banner(c, nil, "Sync is failing; changes stay on this device.", BannerOptions{Severity: core.SeverityError, Action: "Retry"})
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user