Selkie--Test--Supply

NAME

Selkie::Test::Supply - Observation and assertion helpers for widget Supply emissions

SYNOPSIS

use Test;
use Selkie::Test::Keys;
use Selkie::Test::Supply;
use Selkie::Widget::Button;

my $btn = Selkie::Widget::Button.new(label => 'OK');
$btn.set-focused(True);

# Collect everything a Supply emits during an action
my @emissions = collect-from $btn.on-press, {
    press-key($btn, 'enter');
    press-key($btn, 'space');
};
is @emissions.elems, 2, 'two presses';

# Or assert directly:
emitted-once-ok $btn.on-press, True, 'Enter presses the button', {
    press-key($btn, 'enter');
};

done-testing;

DESCRIPTION

Widgets expose user-level events as Supplys — on-press, on-change, on-activate, etc. Testing them without these helpers is a tap-collect-assert dance in every test. This module provides the pattern as three named functions.

Supply emissions from widgets are synchronous — the .emit call in a handler fires the tap inline — so collect-from works without needing event-loop integration. The tap is closed automatically at the end of the block.

EXAMPLES

Count emissions

emitted-count-is $list.on-select, 3, 'three cursor moves', {
    press-keys($list, 'down', 'down', 'down');
};

Capture and inspect

my @emitted = collect-from $input.on-change, {
    type-text($input, 'hi');
};
is @emitted[*-1], 'hi', 'last emission is the final text';

Assert nothing emitted

emitted-count-is $btn.on-press, 0, 'unfocused button ignores key', {
    press-key($btn, 'enter');
};

SEE ALSO

sub collect-from

sub collect-from(
    Supply:D $supply,
    &block
) returns List

Tap a Supply, run a block, return every emission in order. The tap is closed when the block finishes. Emissions are collected in the same thread, so this works for widget Supplies that emit synchronously from event handlers.

sub emitted-once-ok

sub emitted-once-ok(
    Supply:D $supply,
    $expected,
    Str:D $desc,
    &block
) returns Mu

Assertion: the supply emitted exactly once, with the given value, during the block. Produces two test lines — one for the count, one for the value (only if the count was 1).

sub emitted-count-is

sub emitted-count-is(
    Supply:D $supply,
    Int:D $n,
    Str:D $desc,
    &block
) returns Mu

Assertion: the supply emitted exactly $n times during the block. $n may be 0 to assert nothing was emitted.

Selkie v0.10.0

High-level TUI framework built on Notcurses

Authors

  • Matt Doughty

License

Artistic-2.0

Dependencies

Notcurses::Native:ver<0.4.0+>:auth<zef:apogee>

Test Dependencies

Provides

  • Selkie
  • Selkie::App
  • Selkie::App::Internal::Dispatch
  • Selkie::App::Internal::ErrorLog
  • Selkie::App::Internal::FocusTree
  • Selkie::App::Internal::HitTest
  • Selkie::App::Internal::IdleBudget
  • Selkie::App::Internal::OverlayTree
  • Selkie::App::Internal::RenderLoop
  • Selkie::App::Internal::ScreenModalLifecycle
  • Selkie::App::Internal::Terminal
  • Selkie::App::Internal::TerminalSequences
  • Selkie::Container
  • Selkie::EffectiveBounds
  • Selkie::Event
  • Selkie::Layout::Allocate
  • Selkie::Layout::HBox
  • Selkie::Layout::Split
  • Selkie::Layout::VBox
  • Selkie::Plot::Palette
  • Selkie::Plot::Scaler
  • Selkie::Plot::Ticks
  • Selkie::ScreenManager
  • Selkie::Sizing
  • Selkie::Store
  • Selkie::Style
  • Selkie::Test::Focus
  • Selkie::Test::Keys
  • Selkie::Test::Snapshot
  • Selkie::Test::Snapshot::Harness
  • Selkie::Test::Store
  • Selkie::Test::Supply
  • Selkie::Test::Tree
  • Selkie::Theme
  • Selkie::Trace
  • Selkie::Tree
  • Selkie::Widget
  • Selkie::Widget::Axis
  • Selkie::Widget::BarChart
  • Selkie::Widget::Border
  • Selkie::Widget::Button
  • Selkie::Widget::CardList
  • Selkie::Widget::Checkbox
  • Selkie::Widget::CommandPalette
  • Selkie::Widget::ConfirmModal
  • Selkie::Widget::FileBrowser
  • Selkie::Widget::FocusableByDefault
  • Selkie::Widget::Heatmap
  • Selkie::Widget::HelpOverlay
  • Selkie::Widget::Histogram
  • Selkie::Widget::Image
  • Selkie::Widget::Legend
  • Selkie::Widget::LineChart
  • Selkie::Widget::ListView
  • Selkie::Widget::Modal
  • Selkie::Widget::MultiLineInput
  • Selkie::Widget::PasswordStrength
  • Selkie::Widget::Plot
  • Selkie::Widget::ProgressBar
  • Selkie::Widget::RadioGroup
  • Selkie::Widget::RichText
  • Selkie::Widget::RichText::Span
  • Selkie::Widget::ScatterPlot
  • Selkie::Widget::ScrollView
  • Selkie::Widget::Select
  • Selkie::Widget::Sparkline
  • Selkie::Widget::Spinner
  • Selkie::Widget::TabBar
  • Selkie::Widget::Table
  • Selkie::Widget::Text
  • Selkie::Widget::TextInput
  • Selkie::Widget::TextInput::HighlightSpan
  • Selkie::Widget::TextStream
  • Selkie::Widget::Toast
  • Selkie::Widget::ViewportedCardList

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.