Module testing

Module testing 

Source
Expand description

Test utilities for tui-dispatch applications

This module provides helpers for testing TUI applications built with tui-dispatch:

  • key: Create KeyEvent from string (e.g., key("ctrl+p"))
  • key_events: Create multiple Events from space-separated key string
  • TestHarness: Generic test harness with action channel and state management
  • ActionAssertions: Fluent assertion trait for action vectors
  • Assertion macros for verifying emitted actions

§Example

use tui_dispatch::testing::{key, TestHarness, ActionAssertions};

#[derive(Clone, Debug, PartialEq)]
enum Action {
    Increment,
    Decrement,
}

let mut harness = TestHarness::<i32, Action>::new(0);

// Emit and check actions with fluent API
harness.emit(Action::Decrement);
harness.emit(Action::Increment);
let emitted = harness.drain_emitted();
emitted.assert_first(Action::Decrement);
emitted.assert_contains(Action::Increment);
emitted.assert_count(2);

Structs§

RenderHarness
Test harness for capturing rendered output.
TestHarness
Generic test harness for tui-dispatch applications.

Traits§

ActionAssertions
Fluent assertion trait for action vectors.
ActionAssertionsEq
Equality-based assertions for action vectors.

Functions§

alt_key
Create a KeyEvent for a character with Alt modifier.
buffer_rect_to_string_plain
Convert a specific rect of a buffer to a plain string.
buffer_to_string
Convert a ratatui Buffer to a string with ANSI escape codes.
buffer_to_string_plain
Convert a ratatui Buffer to a plain string (no ANSI codes).
char_key
Create a KeyEvent for a character with no modifiers.
ctrl_key
Create a KeyEvent for a character with Ctrl modifier.
into_event
Create an Event<C> from a KeyEvent.
key
Create a KeyEvent from a key string.
key_event
Create an Event<C> containing a key event from a key string.
key_events
Create multiple Event<C> from a space-separated key string.
keys
Parse multiple key strings into KeyEvents.