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,127 @@
|
||||
package overlay
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
"github.com/ZacharyZhang-NY/MujicaUI/core"
|
||||
"github.com/ZacharyZhang-NY/MujicaUI/input"
|
||||
)
|
||||
|
||||
type alertApp struct {
|
||||
open bool
|
||||
opts AlertDialogOptions
|
||||
confirmed, canceled int
|
||||
}
|
||||
|
||||
func (a *alertApp) view(c *ui.Context) {
|
||||
core.Use(c, core.Settings{})
|
||||
if input.Button(c, "Remove", input.ButtonOptions{}).Clicked() {
|
||||
a.open = true
|
||||
}
|
||||
r := AlertDialog(c, &a.open, a.opts)
|
||||
if r.Confirmed {
|
||||
a.confirmed++
|
||||
}
|
||||
if r.Canceled {
|
||||
a.canceled++
|
||||
}
|
||||
}
|
||||
|
||||
func newAlertApp(opts AlertDialogOptions) (*alertApp, *ui.Tester) {
|
||||
opts.Title = "Delete the archive?"
|
||||
a := &alertApp{opts: opts}
|
||||
tt := ui.NewTester(a.view, 600, 400)
|
||||
_ = tt.Click("Remove")
|
||||
return a, tt
|
||||
}
|
||||
|
||||
func TestAlertDialogFocusesCancelAndEnterCancels(t *testing.T) {
|
||||
a, tt := newAlertApp(AlertDialogOptions{Description: "This cannot be undone."})
|
||||
if !a.open || !tt.Focused("Cancel") {
|
||||
t.Fatalf("open %v, Cancel focused %v", a.open, tt.Focused("Cancel"))
|
||||
}
|
||||
tt.Key(0, ui.KeyEnter)
|
||||
if a.confirmed != 0 || a.canceled != 1 || a.open {
|
||||
t.Fatalf("Enter: confirmed %d canceled %d open %v", a.confirmed, a.canceled, a.open)
|
||||
}
|
||||
if !tt.Focused("Remove") {
|
||||
t.Fatal("focus not restored")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlertDialogIgnoresBackdropEscapeCancels(t *testing.T) {
|
||||
a, tt := newAlertApp(AlertDialogOptions{})
|
||||
tt.ClickAt(8, 392)
|
||||
if !a.open || a.canceled != 0 {
|
||||
t.Fatalf("backdrop click: open %v canceled %d", a.open, a.canceled)
|
||||
}
|
||||
tt.Key(0, ui.KeyEscape)
|
||||
if a.open || a.canceled != 1 || a.confirmed != 0 {
|
||||
t.Fatalf("Escape: open %v canceled %d confirmed %d", a.open, a.canceled, a.confirmed)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlertDialogConfirmOnce(t *testing.T) {
|
||||
a, tt := newAlertApp(AlertDialogOptions{ConfirmLabel: "Erase"})
|
||||
if err := tt.Click("Erase"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if a.confirmed != 1 || a.canceled != 0 || a.open {
|
||||
t.Fatalf("confirmed %d canceled %d open %v", a.confirmed, a.canceled, a.open)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlertDialogConfirmTextGatesEnter(t *testing.T) {
|
||||
a, tt := newAlertApp(AlertDialogOptions{ConfirmText: "archive"})
|
||||
_ = tt.Click("Delete") // locked
|
||||
if a.confirmed != 0 || !a.open {
|
||||
t.Fatal("locked Delete confirmed")
|
||||
}
|
||||
if err := tt.Click("Type “archive” to confirm"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tt.Type("archiv")
|
||||
tt.Key(0, ui.KeyEnter)
|
||||
if a.confirmed != 0 || !a.open {
|
||||
t.Fatalf("before the target matched: confirmed %d open %v", a.confirmed, a.open)
|
||||
}
|
||||
tt.Type("e")
|
||||
tt.Key(0, ui.KeyEnter)
|
||||
if a.confirmed != 0 || !a.open {
|
||||
t.Fatalf("Enter in the field confirmed: %d", a.confirmed)
|
||||
}
|
||||
tt.Key(0, ui.KeyTab)
|
||||
tt.Key(0, ui.KeyTab)
|
||||
if !tt.Focused("Delete") {
|
||||
t.Fatal("Delete not reachable once unlocked")
|
||||
}
|
||||
tt.Key(0, ui.KeyEnter)
|
||||
if a.confirmed != 1 || a.open {
|
||||
t.Fatalf("typed target: confirmed %d open %v", a.confirmed, a.open)
|
||||
}
|
||||
}
|
||||
|
||||
// MyGo commits a composition on Enter and then handles the key (ui/editor.go:688).
|
||||
func TestAlertDialogEnterDuringCompositionDoesNotConfirm(t *testing.T) {
|
||||
a, tt := newAlertApp(AlertDialogOptions{ConfirmText: "archive"})
|
||||
if err := tt.Click("Type “archive” to confirm"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tt.Compose("archive", 7)
|
||||
tt.Key(0, ui.KeyEnter)
|
||||
if a.confirmed != 0 || !a.open {
|
||||
t.Fatalf("Enter while composing confirmed: %d", a.confirmed)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlertDialogSnapshot(t *testing.T) {
|
||||
snapshot(t, "alert_dialog", 560, 320, func(c *ui.Context) {
|
||||
open := true
|
||||
AlertDialog(c, &open, AlertDialogOptions{
|
||||
Title: "Burn the old letters?", Description: "Twelve letters will be destroyed. This cannot be undone.",
|
||||
ConfirmText: "letters",
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user