diff --git a/baseline_states_test.go b/baseline_states_test.go new file mode 100644 index 0000000..3026371 --- /dev/null +++ b/baseline_states_test.go @@ -0,0 +1,57 @@ +package mujica + +import ( + "testing" + + "github.com/egoist/mygo/ui" +) + +// baselineAt returns the center of the element whose text is s. +func baselineAt(t *testing.T, tt *ui.Tester, s string) (float32, float32) { + t.Helper() + r, ok := tt.Find(s) + if !ok { + t.Fatalf("%q not found in %q", s, tt.Texts()) + } + return r.X + r.W/2, r.Y + r.H/2 +} + +func TestBaselineButtonStates(t *testing.T) { + view := func(c *ui.Context) { + ui.Row(c).Padding(24).Gap(12).Children(func() { + Button(c, "Save", ButtonOptions{}) + Button(c, "Cancel", ButtonOptions{Variant: Secondary}) + }) + } + overlaySnapshot(t, "button-hover", 300, 90, view, func(tt *ui.Tester) { tt.Move(baselineAt(t, tt, "Save")) }) + overlaySnapshot(t, "button-pressed", 300, 90, view, func(tt *ui.Tester) { tt.Press(baselineAt(t, tt, "Save")) }) + overlaySnapshot(t, "button-focus", 300, 90, view, func(tt *ui.Tester) { tt.Key(0, ui.KeyTab) }) +} + +func TestBaselineTextInputStates(t *testing.T) { + name, date := "Uika", "1789-13-01" + view := func(c *ui.Context) { + ui.Column(c).Padding(24).Gap(12).Width(360).Children(func() { + TextInput(c, &name, TextInputOptions{Label: "Name"}) + TextInput(c, &date, TextInputOptions{Label: "Date", Error: "No such date"}) + }) + } + overlaySnapshot(t, "text_input-focus", 400, 170, view, func(tt *ui.Tester) { tt.Key(0, ui.KeyTab) }) + overlaySnapshot(t, "text_input-error-focus", 400, 170, view, func(tt *ui.Tester) { + tt.Key(0, ui.KeyTab) + tt.Key(0, ui.KeyTab) + }) +} + +func TestBaselineCheckboxStates(t *testing.T) { + on, off := true, false + view := func(c *ui.Context) { + ui.Column(c).Padding(24).Gap(12).Children(func() { + Checkbox(c, &on, "Sealed", CheckboxOptions{}) + Checkbox(c, &off, "Open", CheckboxOptions{}) + }) + } + overlaySnapshot(t, "checkbox-hover", 240, 110, view, func(tt *ui.Tester) { tt.Move(baselineAt(t, tt, "Open")) }) + overlaySnapshot(t, "checkbox-focus", 240, 110, view, func(tt *ui.Tester) { tt.Key(0, ui.KeyTab) }) + overlaySnapshot(t, "checkbox-pressed", 240, 110, view, func(tt *ui.Tester) { tt.Press(baselineAt(t, tt, "Sealed")) }) +} diff --git a/testdata/snapshots/darwin/button-focus-dark.png b/testdata/snapshots/darwin/button-focus-dark.png new file mode 100644 index 0000000..25f1b42 Binary files /dev/null and b/testdata/snapshots/darwin/button-focus-dark.png differ diff --git a/testdata/snapshots/darwin/button-focus-light.png b/testdata/snapshots/darwin/button-focus-light.png new file mode 100644 index 0000000..876f93b Binary files /dev/null and b/testdata/snapshots/darwin/button-focus-light.png differ diff --git a/testdata/snapshots/darwin/button-hover-dark.png b/testdata/snapshots/darwin/button-hover-dark.png new file mode 100644 index 0000000..69a6751 Binary files /dev/null and b/testdata/snapshots/darwin/button-hover-dark.png differ diff --git a/testdata/snapshots/darwin/button-hover-light.png b/testdata/snapshots/darwin/button-hover-light.png new file mode 100644 index 0000000..2e135cc Binary files /dev/null and b/testdata/snapshots/darwin/button-hover-light.png differ diff --git a/testdata/snapshots/darwin/button-pressed-dark.png b/testdata/snapshots/darwin/button-pressed-dark.png new file mode 100644 index 0000000..037bc0d Binary files /dev/null and b/testdata/snapshots/darwin/button-pressed-dark.png differ diff --git a/testdata/snapshots/darwin/button-pressed-light.png b/testdata/snapshots/darwin/button-pressed-light.png new file mode 100644 index 0000000..ca6e121 Binary files /dev/null and b/testdata/snapshots/darwin/button-pressed-light.png differ diff --git a/testdata/snapshots/darwin/checkbox-focus-dark.png b/testdata/snapshots/darwin/checkbox-focus-dark.png new file mode 100644 index 0000000..e2098a6 Binary files /dev/null and b/testdata/snapshots/darwin/checkbox-focus-dark.png differ diff --git a/testdata/snapshots/darwin/checkbox-focus-light.png b/testdata/snapshots/darwin/checkbox-focus-light.png new file mode 100644 index 0000000..fe3931a Binary files /dev/null and b/testdata/snapshots/darwin/checkbox-focus-light.png differ diff --git a/testdata/snapshots/darwin/checkbox-hover-dark.png b/testdata/snapshots/darwin/checkbox-hover-dark.png new file mode 100644 index 0000000..3a0a90d Binary files /dev/null and b/testdata/snapshots/darwin/checkbox-hover-dark.png differ diff --git a/testdata/snapshots/darwin/checkbox-hover-light.png b/testdata/snapshots/darwin/checkbox-hover-light.png new file mode 100644 index 0000000..ae6552d Binary files /dev/null and b/testdata/snapshots/darwin/checkbox-hover-light.png differ diff --git a/testdata/snapshots/darwin/checkbox-pressed-dark.png b/testdata/snapshots/darwin/checkbox-pressed-dark.png new file mode 100644 index 0000000..b1fae26 Binary files /dev/null and b/testdata/snapshots/darwin/checkbox-pressed-dark.png differ diff --git a/testdata/snapshots/darwin/checkbox-pressed-light.png b/testdata/snapshots/darwin/checkbox-pressed-light.png new file mode 100644 index 0000000..ff4283a Binary files /dev/null and b/testdata/snapshots/darwin/checkbox-pressed-light.png differ diff --git a/testdata/snapshots/darwin/text_input-error-focus-dark.png b/testdata/snapshots/darwin/text_input-error-focus-dark.png new file mode 100644 index 0000000..aa5392f Binary files /dev/null and b/testdata/snapshots/darwin/text_input-error-focus-dark.png differ diff --git a/testdata/snapshots/darwin/text_input-error-focus-light.png b/testdata/snapshots/darwin/text_input-error-focus-light.png new file mode 100644 index 0000000..d31374b Binary files /dev/null and b/testdata/snapshots/darwin/text_input-error-focus-light.png differ diff --git a/testdata/snapshots/darwin/text_input-focus-dark.png b/testdata/snapshots/darwin/text_input-focus-dark.png new file mode 100644 index 0000000..fd17bd0 Binary files /dev/null and b/testdata/snapshots/darwin/text_input-focus-dark.png differ diff --git a/testdata/snapshots/darwin/text_input-focus-light.png b/testdata/snapshots/darwin/text_input-focus-light.png new file mode 100644 index 0000000..c12bcb3 Binary files /dev/null and b/testdata/snapshots/darwin/text_input-focus-light.png differ