Documentation
¶
Overview ¶
Package widgettest provides test harness utilities for FluffyUI widgets.
Index ¶
- Constants
- Variables
- func AssertBindable(t testing.TB, w runtime.Widget)
- func AssertFocusable(t testing.TB, w runtime.Widget)
- func AssertLabel(t testing.TB, w runtime.Widget, expected string)
- func AssertMeasure(t testing.TB, w runtime.Widget, minWidth, minHeight int)
- func AssertRenders(t testing.TB, w runtime.Widget, width, height int)
- func AssertRole(t testing.TB, w runtime.Widget, expected string)
- func AssertState(t testing.TB, w runtime.Widget, check func(accessibility.StateSet) bool, ...)
- func AssertValue(t testing.TB, w runtime.Widget, expected string)
- func Snapshot(t testing.TB, name string, widget runtime.Widget, width, height int)
- func SnapshotString(widget runtime.Widget, width, height int) string
- type Harness
- func (h *Harness) AssertContains(text string)
- func (h *Harness) AssertNotContains(text string)
- func (h *Harness) Capture() string
- func (h *Harness) CaptureRegion(x, y, width, height int) string
- func (h *Harness) Close()
- func (h *Harness) ContainsText(text string) bool
- func (h *Harness) DrainRenders()
- func (h *Harness) InjectKey(key terminal.Key, r rune)
- func (h *Harness) InjectKeyAndWait(key terminal.Key, r rune, timeout time.Duration) bool
- func (h *Harness) InjectKeyString(str string)
- func (h *Harness) InjectMouse(x, y int, button terminal.MouseButton)
- func (h *Harness) InjectMouseAndWait(x, y int, button terminal.MouseButton, timeout time.Duration) bool
- func (h *Harness) InvalidateAndWait(timeout time.Duration) bool
- func (h *Harness) Resize(width, height int)
- func (h *Harness) ResizeAndWait(width, height int, timeout time.Duration) bool
- func (h *Harness) SendKey(key terminal.Key, r rune) bool
- func (h *Harness) SendKeyWithTimeout(key terminal.Key, r rune, timeout time.Duration) bool
- func (h *Harness) TypeAndWait(text string, timeout time.Duration) bool
- func (h *Harness) Wait(d time.Duration)
- func (h *Harness) WaitForCondition(fn func() bool, timeout time.Duration) error
- func (h *Harness) WaitForFocus(widget runtime.Widget, timeout time.Duration) error
- func (h *Harness) WaitForRender(timeout time.Duration) bool
- func (h *Harness) WaitForRenders(n int, timeout time.Duration) bool
- func (h *Harness) WaitForText(widget runtime.Widget, text string, timeout time.Duration) error
Constants ¶
const DefaultTimeout = 100 * time.Millisecond
DefaultTimeout is the default timeout for wait operations.
Variables ¶
var ErrTimeout = errors.New("timeout waiting for condition")
ErrTimeout is returned when a wait operation times out.
var UpdateSnapshots = false
UpdateSnapshots controls whether Snapshot overwrites golden files instead of comparing against them. Set to true (e.g. via TestMain or an init function that reads a flag/env var) to regenerate snapshots.
Functions ¶
func AssertBindable ¶
AssertBindable checks that a widget implements runtime.Bindable.
func AssertFocusable ¶
AssertFocusable checks that a widget implements runtime.Focusable and reports CanFocus() == true.
func AssertLabel ¶
AssertLabel checks that a widget's accessibility label matches expected. The widget must implement accessibility.Accessible.
func AssertMeasure ¶
AssertMeasure checks that a widget measures to at least the given minimum width and height. The widget is measured with unconstrained limits.
func AssertRenders ¶
AssertRenders checks that a widget renders without panicking. It performs a full measure-layout-render cycle at the given dimensions.
func AssertRole ¶
AssertRole checks that a widget has the expected ARIA role. The widget must implement accessibility.Accessible.
func AssertState ¶
func AssertState(t testing.TB, w runtime.Widget, check func(accessibility.StateSet) bool, desc string)
AssertState checks that a specific accessibility state condition holds. The check function receives the widget's StateSet and should return true if the condition is met. The desc parameter describes the expected state for the error message (e.g. "Disabled == true").
func AssertValue ¶
AssertValue checks that a widget's accessibility value text matches expected. The widget must implement accessibility.Accessible and have a non-nil value.
func Snapshot ¶
Snapshot captures the rendered output of a widget and compares it against a golden file. On first run (or when UpdateSnapshots is true), creates the golden file. On subsequent runs, compares against the golden file and fails the test if the output differs.
Golden files are stored in testdata/snapshots/<name>.snap relative to the caller's test directory. The name should be a simple identifier without path separators (e.g. "label_hello", "button_disabled").
func SnapshotString ¶
SnapshotString captures the rendered output of a widget and returns it as a string without comparing against a golden file. Useful for debugging.
The widget goes through a full measure-layout-render cycle at the given dimensions. The buffer is then serialized cell-by-cell, row-by-row.
Types ¶
type Harness ¶
type Harness struct {
App *runtime.App
Backend *sim.Backend
// contains filtered or unexported fields
}
Harness runs a widget inside a live app with a simulation backend. It provides deterministic synchronization for testing widget behavior.
func (*Harness) AssertContains ¶
AssertContains fails the test if screen doesn't contain the text.
func (*Harness) AssertNotContains ¶
AssertNotContains fails the test if screen contains the text.
func (*Harness) CaptureRegion ¶
CaptureRegion returns a region of the screen buffer.
func (*Harness) Close ¶
func (h *Harness) Close()
Close stops the app and releases backend resources.
func (*Harness) ContainsText ¶
ContainsText checks if the screen contains the given text.
func (*Harness) DrainRenders ¶
func (h *Harness) DrainRenders()
DrainRenders clears any pending render notifications.
func (*Harness) InjectKeyAndWait ¶
InjectKeyAndWait injects a key and waits for the resulting render.
func (*Harness) InjectKeyString ¶
InjectKeyString injects a string as key events.
func (*Harness) InjectMouse ¶
func (h *Harness) InjectMouse(x, y int, button terminal.MouseButton)
InjectMouse injects a mouse event into the backend.
func (*Harness) InjectMouseAndWait ¶
func (h *Harness) InjectMouseAndWait(x, y int, button terminal.MouseButton, timeout time.Duration) bool
InjectMouseAndWait injects a mouse event and waits for render.
func (*Harness) InvalidateAndWait ¶
InvalidateAndWait triggers an invalidation and waits for render.
func (*Harness) ResizeAndWait ¶
ResizeAndWait resizes and waits for the resulting render.
func (*Harness) SendKeyWithTimeout ¶
SendKeyWithTimeout posts a key message and waits with custom timeout.
func (*Harness) TypeAndWait ¶
TypeAndWait types a string and waits for renders after each character.
func (*Harness) Wait ¶
Wait is deprecated. Use WaitForRender or WaitForCondition instead. Kept for backwards compatibility.
func (*Harness) WaitForCondition ¶
WaitForCondition waits for a condition function to return true.
func (*Harness) WaitForFocus ¶
WaitForFocus waits for a widget to receive focus.
func (*Harness) WaitForRender ¶
WaitForRender waits for a render to complete or times out.
func (*Harness) WaitForRenders ¶
WaitForRenders waits for at least n renders to complete.