testing

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package testing provides test utilities for FluffyUI applications.

This package bridges the simulation backend with the runtime package, providing convenient helpers for widget testing.

Package testing provides test utilities for FluffyUI applications.

Index

Constants

This section is empty.

Variables

View Source
var ErrTimeout = errors.New("timeout waiting for condition")

ErrTimeout is returned when a wait operation times out.

Functions

func Announcements

func Announcements(announcer accessibility.Announcer) []accessibility.Announcement

Announcements returns captured announcements for a SimpleAnnouncer.

func AssertARIACompliant

func AssertARIACompliant(t *testing.T, root runtime.Widget)

AssertARIACompliant runs all ARIA checks and fails on errors.

func AssertAccessible

func AssertAccessible(t *testing.T, root runtime.Widget)

AssertAccessible fails the test if accessibility errors are found.

func AssertAnnounced

func AssertAnnounced(t *testing.T, announcer accessibility.Announcer, contains string)

AssertAnnounced fails the test if the announcer never emitted a matching message.

func AssertCellStyle

func AssertCellStyle(t *testing.T, be *sim.Backend, x, y int, bold, italic, underline bool)

AssertCellStyle fails the test if the cell at (x,y) doesn't have the expected style attributes.

func AssertContains

func AssertContains(t *testing.T, be *sim.Backend, text string)

AssertContains fails the test if the backend screen does not contain the text.

func AssertGolden

func AssertGolden(t *testing.T, path string, actual string)

AssertGolden compares actual output with the golden file at path. When FLUFFYUI_UPDATE_SNAPSHOTS is set, it overwrites the golden file.

func AssertNotContains

func AssertNotContains(t *testing.T, be *sim.Backend, text string)

AssertNotContains fails the test if the backend screen contains the text.

func AssertSnapshot

func AssertSnapshot(t *testing.T, w runtime.Widget, width, height int, expected string)

AssertSnapshot compares the rendered output against expected content. Returns a SnapshotMismatch if they differ, nil otherwise.

func AssertTextAt

func AssertTextAt(t *testing.T, be *sim.Backend, x, y int, text string)

AssertTextAt fails the test if the text is not at the given position.

func AssertWidgetGolden

func AssertWidgetGolden(t *testing.T, w runtime.Widget, width, height int, path string)

AssertWidgetGolden renders a widget and compares against a golden file.

func CaptureWidget

func CaptureWidget(w runtime.Widget, width, height int) string

CaptureWidget captures a widget's rendered output as a string. Shorthand for RenderToString.

func GetCell

func GetCell(w runtime.Widget, width, height, x, y int) runtime.Cell

GetCell returns the cell content at the given position after rendering.

func LayoutAndRender

func LayoutAndRender(w runtime.Widget, width, height int) *runtime.Buffer

LayoutAndRender performs the full measure-layout-render cycle on a widget. Returns the buffer containing the rendered output.

func MeasureWidget

func MeasureWidget(w runtime.Widget, maxWidth, maxHeight int) runtime.Size

MeasureWidget measures a widget and returns its preferred size.

func NewAnnouncer

func NewAnnouncer() *accessibility.SimpleAnnouncer

NewAnnouncer returns an in-memory announcer for accessibility tests.

func NewTestBackend

func NewTestBackend(t *testing.T, width, height int) *sim.Backend

NewTestBackend creates an initialized simulation backend for testing. Returns the backend; callers should defer be.Fini().

func RenderTo

func RenderTo(be *sim.Backend, w runtime.Widget, width, height int)

RenderTo renders a widget to a simulation backend. The widget is measured, laid out, and rendered to the backend's buffer.

func RenderToString

func RenderToString(w runtime.Widget, width, height int) string

RenderToString renders a widget to a string without requiring a backend. This is useful for snapshot testing and simple output verification.

func RenderWidget

func RenderWidget(w runtime.Widget, width, height int) (*sim.Backend, error)

RenderWidget renders a widget to a newly created simulation backend. Returns the backend for further inspection.

func RenderWidgetOrFail

func RenderWidgetOrFail(t *testing.T, w runtime.Widget, width, height int) *sim.Backend

RenderWidgetOrFail renders a widget and fails the test on error.

func RequiredPropertiesForRole

func RequiredPropertiesForRole(role accessibility.Role) []string

RequiredPropertiesForRole returns what a role needs to be valid.

func UpdateSnapshots

func UpdateSnapshots() bool

UpdateSnapshots reports whether golden snapshots should be updated.

func ValidateWidget

func ValidateWidget(t *testing.T, w runtime.Widget)

ValidateWidget validates a single widget's ARIA compliance.

func WaitForRender

func WaitForRender(timeout time.Duration)

WaitForRender waits for the app to process messages and render. This is useful after injecting input events.

Types

type A11yIssue

type A11yIssue struct {
	Path     string
	Message  string
	Severity A11ySeverity
}

A11yIssue describes an accessibility audit issue.

func AuditARIAAll

func AuditARIAAll(root runtime.Widget) []A11yIssue

AuditARIAAll runs all ARIA validation checks and returns combined issues.

func AuditARIARoles

func AuditARIARoles(root runtime.Widget) []A11yIssue

AuditARIARoles validates ARIA role requirements, invalid states, and container children.

func AuditARIAStates

func AuditARIAStates(root runtime.Widget) []A11yIssue

AuditARIAStates validates that ARIA states are used on appropriate roles.

func AuditAccessibility

func AuditAccessibility(root runtime.Widget) []A11yIssue

AuditAccessibility walks the widget tree and reports missing accessibility metadata.

func AuditKeyboardNav

func AuditKeyboardNav(root runtime.Widget) []A11yIssue

AuditKeyboardNav validates keyboard navigation accessibility.

func AuditLiveRegions

func AuditLiveRegions(root runtime.Widget) []A11yIssue

AuditLiveRegions validates live region ARIA attributes.

func AuditRelationships

func AuditRelationships(root runtime.Widget) []A11yIssue

AuditRelationships validates that ARIA relationship references exist in the tree.

type A11ySeverity

type A11ySeverity string

A11ySeverity describes audit severity.

const (
	A11yError   A11ySeverity = "error"
	A11yWarning A11ySeverity = "warning"
)

type SnapshotMismatch

type SnapshotMismatch struct {
	Expected string
	Actual   string
}

SnapshotMismatch represents a difference between expected and actual output.

type TestFrame

type TestFrame struct {
	Stats  runtime.RenderStats
	Screen string
}

TestFrame is an immutable snapshot captured after a completed render pass.

type TestRenderer

type TestRenderer struct {
	// contains filtered or unexported fields
}

TestRenderer runs an app against the simulation backend and exposes deterministic frame, capture, and visual-idle helpers for tests.

func NewTestRenderer

func NewTestRenderer(ctx context.Context, root runtime.Widget, width, height int) (*TestRenderer, error)

NewTestRenderer starts an app and waits for its initial frame.

func NewTestRendererWithConfig

func NewTestRendererWithConfig(ctx context.Context, cfg runtime.AppConfig, width, height int) (*TestRenderer, error)

NewTestRendererWithConfig starts an app with cfg against a simulation backend. Backend is replaced, while an existing render observer is preserved.

func (*TestRenderer) App

func (r *TestRenderer) App() *runtime.App

App returns the running app for posting messages or invoking app-loop work.

func (*TestRenderer) Backend

func (r *TestRenderer) Backend() *sim.Backend

Backend returns the simulation backend for input injection and cell checks.

func (*TestRenderer) Capture

func (r *TestRenderer) Capture() string

Capture returns the current simulated screen.

func (*TestRenderer) CaptureCell

func (r *TestRenderer) CaptureCell(x, y int) (rune, []rune, backend.Style)

CaptureCell returns the content and style at one screen cell.

func (*TestRenderer) CaptureRegion

func (r *TestRenderer) CaptureRegion(x, y, width, height int) string

CaptureRegion returns a rectangular region of the simulated screen.

func (*TestRenderer) Close

func (r *TestRenderer) Close() error

Close stops the app and waits for the renderer to release its backend.

func (*TestRenderer) Flush

func (r *TestRenderer) Flush(timeout time.Duration) (TestFrame, error)

Flush requests a render and waits for its completed frame.

func (*TestRenderer) LatestFrame

func (r *TestRenderer) LatestFrame() TestFrame

LatestFrame returns the most recently completed frame.

func (*TestRenderer) Stats

func (r *TestRenderer) Stats() runtime.RenderSummary

Stats returns the render summary collected by this renderer.

func (*TestRenderer) WaitForFrame

func (r *TestRenderer) WaitForFrame(timeout time.Duration) (TestFrame, error)

WaitForFrame waits for a render newer than the current frame.

func (*TestRenderer) WaitForFrameAfter

func (r *TestRenderer) WaitForFrameAfter(frame int64, timeout time.Duration) (TestFrame, error)

WaitForFrameAfter waits for a render newer than frame. Capture the current frame number before triggering asynchronous work to avoid missing a fast render between posting the work and beginning the wait.

func (*TestRenderer) WaitForVisualIdle

func (r *TestRenderer) WaitForVisualIdle(idleFor, timeout time.Duration) (TestFrame, error)

WaitForVisualIdle waits until no new frames arrive for idleFor.

type TestSync

type TestSync struct {
	// contains filtered or unexported fields
}

TestSync provides channel-based synchronization for deterministic testing. It replaces time.Sleep() hacks with event-driven waiting that's both faster and more reliable.

func NewTestSync

func NewTestSync(app *runtime.App) *TestSync

NewTestSync creates a TestSync connected to an app. The app must have a RenderObserver configured to notify the sync.

func (*TestSync) DrainRenders

func (s *TestSync) DrainRenders()

DrainRenders clears any pending render notifications.

func (*TestSync) InvalidateAndWait

func (s *TestSync) InvalidateAndWait(timeout time.Duration) error

InvalidateAndWait triggers an invalidation and waits for the render.

func (*TestSync) NotifyRender

func (s *TestSync) NotifyRender()

NotifyRender signals that a render completed. Called by the RenderObserver.

func (*TestSync) PostAndWait

func (s *TestSync) PostAndWait(msg runtime.Message, timeout time.Duration) error

PostAndWait posts a custom message and waits for the render.

func (*TestSync) RenderCh

func (s *TestSync) RenderCh() chan struct{}

RenderCh returns the render notification channel. Used to integrate with app's RenderObserver.

func (*TestSync) SendKeyAndWait

func (s *TestSync) SendKeyAndWait(key terminal.Key, timeout time.Duration) error

SendKeyAndWait injects a key event and waits for the resulting render.

func (*TestSync) SendKeyRuneAndWait

func (s *TestSync) SendKeyRuneAndWait(key terminal.Key, r rune, timeout time.Duration) error

SendKeyRuneAndWait injects a key event with a rune and waits for the resulting render.

func (*TestSync) SendMouseAndWait

func (s *TestSync) SendMouseAndWait(x, y int, button runtime.MouseButton, action runtime.MouseAction, timeout time.Duration) error

SendMouseAndWait injects a mouse event and waits for the resulting render.

func (*TestSync) TypeAndWait

func (s *TestSync) TypeAndWait(text string, timeout time.Duration) error

TypeAndWait types a string character by character, waiting for renders after each.

func (*TestSync) WaitForCondition

func (s *TestSync) WaitForCondition(fn func() bool, timeout time.Duration) error

WaitForCondition waits for a condition function to return true.

func (*TestSync) WaitForEvent

func (s *TestSync) WaitForEvent(timeout time.Duration) (runtime.Message, error)

WaitForEvent waits for a message to be processed by the app.

func (*TestSync) WaitForFocus

func (s *TestSync) WaitForFocus(widget runtime.Widget, timeout time.Duration) error

WaitForFocus waits for a widget to receive focus.

func (*TestSync) WaitForRender

func (s *TestSync) WaitForRender(timeout time.Duration) error

WaitForRender waits for a render to complete.

func (*TestSync) WaitForRenders

func (s *TestSync) WaitForRenders(n int, timeout time.Duration) error

WaitForRenders waits for at least n renders to complete.

func (*TestSync) WaitForText

func (s *TestSync) WaitForText(widget runtime.Widget, text string, timeout time.Duration) error

WaitForText waits for a widget to contain specific text. The widget must implement runtime.TextProvider or have a Text() method.

Directories

Path Synopsis
Package a11ytest provides ergonomic accessibility assertion functions for widget testing.
Package a11ytest provides ergonomic accessibility assertion functions for widget testing.
Package widgettest provides test harness utilities for FluffyUI widgets.
Package widgettest provides test harness utilities for FluffyUI widgets.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL