Documentation
¶
Overview ¶
Package test provides utility drivers for running UI tests without rendering to a screen.
Index ¶
- func ApplyTheme(t *testing.T, theme bellui.Theme)
- func AssertAllColorNamesDefined(t *testing.T, th bellui.Theme, themeName string)
- func AssertCanvasTappableAt(t *testing.T, c core.Canvas, pos geo.Position) bool
- func AssertDisabled(t *testing.T, obj core.Disableable) bool
- func AssertEnabled(t *testing.T, obj core.Disableable) bool
- func AssertFitsWithin(t *testing.T, obj core.CanvasObject, maxW, maxH float32) bool
- func AssertHidden(t *testing.T, obj core.CanvasObject) bool
- func AssertImageMatches(t *testing.T, masterFilename string, img image.Image, msgAndArgs ...any) bool
- func AssertMinSizeAtLeast(t *testing.T, obj core.CanvasObject, minW, minH float32) bool
- func AssertNotificationSent(t *testing.T, n *bellui.Notification, f func())
- func AssertObjectRendersToImage(t *testing.T, masterFilename string, o core.CanvasObject, msgAndArgs ...any) bool
- func AssertObjectRendersToMarkup(t *testing.T, masterFilename string, o core.CanvasObject, msgAndArgs ...any) bool
- func AssertRendersToImage(t *testing.T, masterFilename string, c core.Canvas, msgAndArgs ...any) bool
- func AssertRendersToMarkup(t *testing.T, masterFilename string, c core.Canvas, msgAndArgs ...any) bool
- func AssertVisible(t *testing.T, obj core.CanvasObject) bool
- func AssertWidgetPosition(t *testing.T, obj core.CanvasObject, expectedX, expectedY float32) bool
- func AssertWidgetSize(t *testing.T, obj core.CanvasObject, expectedW, expectedH float32) bool
- func Canvas() core.Canvas
- func Compose(c core.Canvas, text string, cursorPos int)
- func ComposeCancel(c core.Canvas)
- func ComposeCommit(c core.Canvas, text string)
- func DoubleTap(obj event.DoubleTappable)
- func Drag(c core.Canvas, pos geo.Position, deltaX, deltaY float32)
- func DragSteps(c core.Canvas, pos geo.Position, deltaX, deltaY float32, steps int, ...)
- func FocusNext(c core.Canvas)
- func FocusPrevious(c core.Canvas)
- func KnownThemeVariants() map[string]bellui.ThemeVariant
- func LaidOutObjects(o core.CanvasObject) (objects []core.CanvasObject)
- func LongPress(obj event.LongPressable)
- func LongPressAt(obj event.LongPressable, pos geo.Position)
- func MoveMouse(c core.Canvas, pos geo.Position)
- func NewApp() bellui.App
- func NewClipboard() bellui.Clipboard
- func NewDriver() bellui.Driver
- func NewDriverWithPainter(painter SoftwarePainter) bellui.Driver
- func NewTempApp(t testing.TB) bellui.App
- func NewTempWindow(t testing.TB, content core.CanvasObject) bellui.Window
- func NewTheme() bellui.Theme
- func NewWindow(content core.CanvasObject) bellui.Window
- func RenderObjectToMarkup(o core.CanvasObject) string
- func RenderToMarkup(c core.Canvas) string
- func Scroll(c core.Canvas, pos geo.Position, deltaX, deltaY float32)
- func Tap(obj event.Tappable)
- func TapAt(obj event.Tappable, pos geo.Position)
- func TapCanvas(c core.Canvas, pos geo.Position)
- func TapSecondary(obj event.SecondaryTappable)
- func TapSecondaryAt(obj event.SecondaryTappable, pos geo.Position)
- func TempWidgetRenderer(t *testing.T, wid core.Widget) core.WidgetRenderer
- func Theme() bellui.Theme
- func Type(obj event.Focusable, chars string)
- func TypeOnCanvas(c core.Canvas, chars string)
- func WidgetRenderer(wid core.Widget) core.WidgetRenderer
- func WithTestTheme(t *testing.T, f func())
- type SoftwarePainter
- type WindowlessCanvas
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyTheme ¶
ApplyTheme sets the given theme and waits for it to be applied to the current app. The previous theme is automatically restored when the test completes.
func AssertAllColorNamesDefined ¶
AssertAllColorNamesDefined asserts that all known color names are defined for the given theme.
func AssertCanvasTappableAt ¶
AssertCanvasTappableAt asserts that the canvas is tappable at the given position.
func AssertDisabled ¶
func AssertDisabled(t *testing.T, obj core.Disableable) bool
AssertDisabled asserts that a Disableable widget is disabled.
func AssertEnabled ¶
func AssertEnabled(t *testing.T, obj core.Disableable) bool
AssertEnabled asserts that a Disableable widget is enabled.
func AssertFitsWithin ¶
AssertFitsWithin asserts that a widget's size fits within the given bounds. Useful for layout tests without exact size matching.
func AssertHidden ¶
func AssertHidden(t *testing.T, obj core.CanvasObject) bool
AssertHidden asserts that the object is hidden.
func AssertImageMatches ¶
func AssertImageMatches(t *testing.T, masterFilename string, img image.Image, msgAndArgs ...any) bool
AssertImageMatches asserts that the given image is the same as the one stored in the master file. The master filename is relative to the `testdata` directory which is relative to the test. The test `t` fails if the given image is not equal to the loaded master image. In this case the given image is written into a file in `testdata/failed/<masterFilename>` (relative to the test). This path is also reported, thus the file can be used as new master.
func AssertMinSizeAtLeast ¶
AssertMinSizeAtLeast asserts that a widget's MinSize is at least the given dimensions. Useful for checking that a widget has reasonable minimum size without exact values.
func AssertNotificationSent ¶
func AssertNotificationSent(t *testing.T, n *bellui.Notification, f func())
AssertNotificationSent allows an app developer to assert that a notification was sent. After the content of f has executed this utility will check that the specified notification was sent.
func AssertObjectRendersToImage ¶
func AssertObjectRendersToImage(t *testing.T, masterFilename string, o core.CanvasObject, msgAndArgs ...any) bool
AssertObjectRendersToImage asserts that the given `CanvasObject` renders the same image as the one stored in the master file. The theme used is the standard test theme which may look different to how it shows on your device. The master filename is relative to the `testdata` directory which is relative to the test. The test `t` fails if the given image is not equal to the loaded master image. In this case the given image is written into a file in `testdata/failed/<masterFilename>` (relative to the test). This path is also reported, thus the file can be used as new master.
Caveat: the canvas is sized to exactly the object's own bounds (MinSize maxed with Size), so anything the object's renderer draws outside those bounds is cropped by the canvas image and will not appear in the comparison. A widget that overflows its bounds therefore renders to a clean, cropped master — looking as if its content were correctly clipped even when it is not. To verify overflow or clipping behaviour, render the object inside a larger canvas (place it in a sized container and use AssertRendersToImage), and use bellui's clipping API (e.g. container.NewClip) to opt a subtree into clipping.
Since 2.3
func AssertObjectRendersToMarkup ¶
func AssertObjectRendersToMarkup(t *testing.T, masterFilename string, o core.CanvasObject, msgAndArgs ...any) bool
AssertObjectRendersToMarkup asserts that the given `CanvasObject` renders the same markup as the one stored in the master file. The master filename is relative to the `testdata` directory which is relative to the test. The test `t` fails if the rendered markup is not equal to the loaded master markup. In this case the rendered markup is written into a file in `testdata/failed/<masterFilename>` (relative to the test). This path is also reported, thus the file can be used as new master.
Be aware, that the indentation has to use tab characters ('\t') instead of spaces. Every element starts on a new line indented one more than its parent. Closing elements stand on their own line, too, using the same indentation as the opening element. The only exception to this are text elements which do not contain line breaks unless the text includes them.
Caveat: as with AssertObjectRendersToImage, the canvas is sized to exactly the object's own bounds, so markup for content drawn outside those bounds is not captured. Render the object inside a larger canvas (via AssertRendersToMarkup) to observe overflow.
Since 2.3
func AssertRendersToImage ¶
func AssertRendersToImage(t *testing.T, masterFilename string, c core.Canvas, msgAndArgs ...any) bool
AssertRendersToImage asserts that the given canvas renders the same image as the one stored in the master file. The master filename is relative to the `testdata` directory which is relative to the test. The test `t` fails if the given image is not equal to the loaded master image. In this case the given image is written into a file in `testdata/failed/<masterFilename>` (relative to the test). This path is also reported, thus the file can be used as new master.
Since 2.3
func AssertRendersToMarkup ¶
func AssertRendersToMarkup(t *testing.T, masterFilename string, c core.Canvas, msgAndArgs ...any) bool
AssertRendersToMarkup asserts that the given canvas renders the same markup as the one stored in the master file. The master filename is relative to the `testdata` directory which is relative to the test. The test `t` fails if the rendered markup is not equal to the loaded master markup. In this case the rendered markup is written into a file in `testdata/failed/<masterFilename>` (relative to the test). This path is also reported, thus the file can be used as new master.
Be aware, that the indentation has to use tab characters ('\t') instead of spaces. Every element starts on a new line indented one more than its parent. Closing elements stand on their own line, too, using the same indentation as the opening element. The only exception to this are text elements which do not contain line breaks unless the text includes them.
Since: 2.0
func AssertVisible ¶
func AssertVisible(t *testing.T, obj core.CanvasObject) bool
AssertVisible asserts that the object is visible.
func AssertWidgetPosition ¶
AssertWidgetPosition asserts that a widget's current position matches expected values.
func AssertWidgetSize ¶
AssertWidgetSize asserts that a widget's current size matches the expected size. Uses approximate comparison (within 1 pixel) to handle float rounding.
func Compose ¶
Compose sends an in-progress IME composition (preedit) update to the focused object of the canvas when it supports composition (event.Composable). It is a no-op if nothing focusable composable is focused.
Since: 1.0
func ComposeCancel ¶
ComposeCancel cancels any in-progress IME composition on the focused composable object of the canvas. A no-op when the focused object does not support composition.
Since: 1.0
func ComposeCommit ¶
ComposeCommit commits an IME composition on the focused composable object of the canvas, inserting text as if it had been typed. A no-op when the focused object does not support composition.
Since: 1.0
func DoubleTap ¶
func DoubleTap(obj event.DoubleTappable)
DoubleTap simulates a double left mouse click on the specified object.
func Drag ¶
Drag drags at an absolute position on the canvas. deltaX/Y is the dragging distance: <0 for dragging up/left, >0 for dragging down/right.
The dispatched github.com/belluikit/bellui/event.DragEvent carries an AbsolutePosition of pos, matching the real driver, so widgets that resolve the cursor via AbsolutePosition − driver.AbsolutePositionForObject can be driven headlessly. Drag sends a single Dragged event followed immediately by DragEnd; use DragSteps to observe intermediate drag state.
func DragSteps ¶
func DragSteps(c core.Canvas, pos geo.Position, deltaX, deltaY float32, steps int, onStep func(step int))
DragSteps performs a drag starting at absolute position pos and moving by the given delta, split into the requested number of Dragged events (minimum one), finishing with DragEnd. deltaX/Y is the total dragging distance: <0 for up/left, >0 for down/right.
The draggable is resolved once at pos and receives every event of the gesture (mirroring the real driver, which keeps the drag's origin target for the whole gesture), and each event carries an AbsolutePosition that advances toward the target. If onStep is non-nil it is called after each Dragged event — while the drag is still in progress, before DragEnd — so tests can capture or assert mid-drag state such as ghost previews or drop highlights. onStep receives the 1-based step index.
Since: 1.0
func FocusPrevious ¶
FocusPrevious focuses the previous focusable on the canvas.
func KnownThemeVariants ¶
func KnownThemeVariants() map[string]bellui.ThemeVariant
KnownThemeVariants returns the known theme variants mapped by a descriptive key.
func LaidOutObjects ¶
func LaidOutObjects(o core.CanvasObject) (objects []core.CanvasObject)
LaidOutObjects returns all core.CanvasObject starting at the given core.CanvasObject which is laid out previously.
func LongPress ¶
func LongPress(obj event.LongPressable)
LongPress simulates a long-press gesture on the specified object.
func LongPressAt ¶
func LongPressAt(obj event.LongPressable, pos geo.Position)
LongPressAt simulates a long-press gesture on the passed object at a specified place within it.
func NewApp ¶
NewApp returns a new dummy app used for testing. It loads a test driver which creates a virtual window in memory for testing.
func NewClipboard ¶
NewClipboard returns a single use in-memory clipboard used for testing
func NewDriverWithPainter ¶
func NewDriverWithPainter(painter SoftwarePainter) bellui.Driver
NewDriverWithPainter creates a new dummy driver that will pass the given painter to all canvases created
func NewTempApp ¶
NewTempApp returns a new dummy app and tears it down at the end of the test.
Since: 2.5
func NewTempWindow ¶
NewTempWindow creates and registers a new window for test purposes. This window will get removed automatically once the running test ends.
Since: 2.5
func NewWindow ¶
func NewWindow(content core.CanvasObject) bellui.Window
NewWindow creates and registers a new window for test purposes
func RenderObjectToMarkup ¶
func RenderObjectToMarkup(o core.CanvasObject) string
RenderObjectToMarkup renders the given github.com/belluikit/bellui.CanvasObject to a markup string.
Since: 2.6
func RenderToMarkup ¶
RenderToMarkup renders the given github.com/belluikit/bellui.Canvas to a markup string.
Since: 2.6
func Scroll ¶
Scroll scrolls at an absolute position on the canvas. deltaX/Y is the scrolling distance: <0 for scrolling up/left, >0 for scrolling down/right.
func TapAt ¶
TapAt simulates a left mouse click on the passed object at a specified place within it.
func TapSecondary ¶
func TapSecondary(obj event.SecondaryTappable)
TapSecondary simulates a right mouse click on the specified object.
func TapSecondaryAt ¶
func TapSecondaryAt(obj event.SecondaryTappable, pos geo.Position)
TapSecondaryAt simulates a right mouse click on the passed object at a specified place within it.
func TempWidgetRenderer ¶
TempWidgetRenderer allows test scripts to gain access to the current renderer for a widget. This can be used for verifying correctness of rendered components for a widget in unit tests. The widget renderer is automatically destroyed when the test ends.
Since: 2.5
func Type ¶
Type performs a series of key events to simulate typing of a value into the specified object. The focusable object will be focused before typing begins. The chars parameter will be input one rune at a time to the focused object.
func TypeOnCanvas ¶
TypeOnCanvas is like the Type function but it passes the key events to the canvas object rather than a focusable widget.
func WidgetRenderer ¶
func WidgetRenderer(wid core.Widget) core.WidgetRenderer
WidgetRenderer allows test scripts to gain access to the current renderer for a widget. This can be used for verifying correctness of rendered components for a widget in unit tests.
func WithTestTheme ¶
WithTestTheme runs a function with the testTheme temporarily set. The original theme is restored immediately after f returns.
Types ¶
type SoftwarePainter ¶
SoftwarePainter describes a simple type that can render canvases
type WindowlessCanvas ¶
type WindowlessCanvas interface {
core.Canvas
Padded() bool
Resize(geo.Size)
SelectableMode() bellui.SelectableMode
SetPadded(bool)
SetScale(float32)
SetSelectableMode(bellui.SelectableMode)
}
WindowlessCanvas provides functionality for a canvas to operate without a window
func NewCanvas ¶
func NewCanvas() WindowlessCanvas
NewCanvas returns a single use in-memory canvas used for testing. This canvas has no painter so calls to Capture() will return a blank image.
func NewCanvasWithPainter ¶
func NewCanvasWithPainter(painter SoftwarePainter) WindowlessCanvas
NewCanvasWithPainter allows creation of an in-memory canvas with a specific painter. The painter will be used to render in the Capture() call.
func NewTransparentCanvasWithPainter ¶
func NewTransparentCanvasWithPainter(painter SoftwarePainter) WindowlessCanvas
NewTransparentCanvasWithPainter allows creation of an in-memory canvas with a specific painter without a background color. The painter will be used to render in the Capture() call.
Since: 2.2