EffectStoreTestHarness

Struct EffectStoreTestHarness 

Source
pub struct EffectStoreTestHarness<S, A: Action, E> { /* private fields */ }
Expand description

Test harness for effect-based stores.

Similar to StoreTestHarness but for applications using EffectStore with DispatchResult reducers.

§Example

use tui_dispatch::testing::EffectStoreTestHarness;

let mut harness = EffectStoreTestHarness::new(AppState::default(), reducer);

// Dispatch and collect effects
harness.dispatch_collect(Action::WeatherFetch);
harness.assert_state(|s| s.is_loading);

// Check emitted effects
let effects = harness.drain_effects();
effects.assert_count(1);
effects.assert_first_matches(|e| matches!(e, Effect::FetchWeather { .. }));

// Simulate async completion
harness.complete_action(Action::WeatherDidLoad(data));
harness.process_emitted();
harness.assert_state(|s| s.weather.is_some());

Implementations§

Source§

impl<S, A: Action, E> EffectStoreTestHarness<S, A, E>

Source

pub fn new(state: S, reducer: EffectReducer<S, A, E>) -> Self

Create a new harness with initial state and effect reducer.

Source

pub fn with_size(self, width: u16, height: u16) -> Self

Set the default terminal size for rendering.

Source

pub fn dispatch(&mut self, action: A) -> DispatchResult<E>

Dispatch an action to the store.

Returns the DispatchResult with change status and effects.

Source

pub fn dispatch_collect(&mut self, action: A) -> bool

Dispatch an action and automatically collect its effects.

Returns true if state changed. Effects are collected internally and can be retrieved with Self::drain_effects.

Source

pub fn dispatch_all( &mut self, actions: impl IntoIterator<Item = A>, ) -> Vec<bool>

Dispatch multiple actions, collecting all effects.

Returns a vector of booleans indicating which dispatches changed state.

Source

pub fn state(&self) -> &S

Get a reference to the current state.

Source

pub fn state_mut(&mut self) -> &mut S

Get a mutable reference to the state for test setup.

Source

pub fn drain_effects(&mut self) -> Vec<E>

Drain all collected effects.

Source

pub fn has_effects(&self) -> bool

Check if any effects were collected.

Source

pub fn effect_count(&self) -> usize

Get the number of collected effects.

Source

pub fn sender(&self) -> UnboundedSender<A>

Get a sender clone for simulating async action completions.

Source

pub fn emit(&self, action: A)

Emit an action to the channel (simulates async completion).

Source

pub fn complete_action(&self, action: A)

Simulate async action completion (semantic alias for Self::emit).

Source

pub fn complete_actions(&self, actions: impl IntoIterator<Item = A>)

Simulate multiple async action completions.

Source

pub fn drain_emitted(&mut self) -> Vec<A>

Drain all emitted actions from the channel.

Source

pub fn has_emitted(&mut self) -> bool

Check if any actions were emitted.

Source

pub fn process_emitted(&mut self) -> (usize, usize)

Process all emitted actions through the store, collecting effects.

Drains the channel and dispatches each action to the store. Returns (changed_count, total_count).

Source

pub fn send_keys<C, H, I>(&mut self, keys: &str, handler: H) -> Vec<A>
where C: ComponentId, I: IntoIterator<Item = A>, H: FnMut(&mut S, Event<C>) -> I,

Send a sequence of key events and collect actions from a handler.

Source

pub fn send_keys_dispatch<C, H, I>(&mut self, keys: &str, handler: H) -> Vec<A>
where C: ComponentId, I: IntoIterator<Item = A>, H: FnMut(&mut S, Event<C>) -> I,

Send keys and dispatch returned actions to the store.

Returns the actions that were dispatched. Effects are collected.

Source

pub fn assert_state<F>(&self, predicate: F)
where F: FnOnce(&S) -> bool,

Assert a condition on the current state.

Source

pub fn assert_state_msg<F>(&self, predicate: F, msg: &str)
where F: FnOnce(&S) -> bool,

Assert a condition with a custom message.

Source

pub fn render<F>(&mut self, width: u16, height: u16, render_fn: F) -> String
where F: FnOnce(&mut Frame<'_>, Rect, &S),

Render using the provided function, returns string with ANSI codes.

Source

pub fn render_plain<F>( &mut self, width: u16, height: u16, render_fn: F, ) -> String
where F: FnOnce(&mut Frame<'_>, Rect, &S),

Render to plain string (no ANSI codes).

Source

pub fn render_default<F>(&mut self, render_fn: F) -> String
where F: FnOnce(&mut Frame<'_>, Rect, &S),

Render with default terminal size.

Source

pub fn render_default_plain<F>(&mut self, render_fn: F) -> String
where F: FnOnce(&mut Frame<'_>, Rect, &S),

Render with default size to plain string.

Auto Trait Implementations§

§

impl<S, A, E> Freeze for EffectStoreTestHarness<S, A, E>
where S: Freeze,

§

impl<S, A, E> RefUnwindSafe for EffectStoreTestHarness<S, A, E>

§

impl<S, A, E> Send for EffectStoreTestHarness<S, A, E>
where S: Send, E: Send,

§

impl<S, A, E> Sync for EffectStoreTestHarness<S, A, E>
where S: Sync, A: Sync, E: Sync,

§

impl<S, A, E> Unpin for EffectStoreTestHarness<S, A, E>
where S: Unpin, A: Unpin, E: Unpin,

§

impl<S, A, E> UnwindSafe for EffectStoreTestHarness<S, A, E>
where S: UnwindSafe, A: UnwindSafe, E: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more