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>
impl<S, A: Action, E> EffectStoreTestHarness<S, A, E>
Sourcepub fn new(state: S, reducer: EffectReducer<S, A, E>) -> Self
pub fn new(state: S, reducer: EffectReducer<S, A, E>) -> Self
Create a new harness with initial state and effect reducer.
Sourcepub fn with_size(self, width: u16, height: u16) -> Self
pub fn with_size(self, width: u16, height: u16) -> Self
Set the default terminal size for rendering.
Sourcepub fn dispatch(&mut self, action: A) -> DispatchResult<E>
pub fn dispatch(&mut self, action: A) -> DispatchResult<E>
Dispatch an action to the store.
Returns the DispatchResult with change status and effects.
Sourcepub fn dispatch_collect(&mut self, action: A) -> bool
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.
Sourcepub fn dispatch_all(
&mut self,
actions: impl IntoIterator<Item = A>,
) -> Vec<bool>
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.
Sourcepub fn drain_effects(&mut self) -> Vec<E>
pub fn drain_effects(&mut self) -> Vec<E>
Drain all collected effects.
Sourcepub fn has_effects(&self) -> bool
pub fn has_effects(&self) -> bool
Check if any effects were collected.
Sourcepub fn effect_count(&self) -> usize
pub fn effect_count(&self) -> usize
Get the number of collected effects.
Sourcepub fn sender(&self) -> UnboundedSender<A>
pub fn sender(&self) -> UnboundedSender<A>
Get a sender clone for simulating async action completions.
Sourcepub fn complete_action(&self, action: A)
pub fn complete_action(&self, action: A)
Simulate async action completion (semantic alias for Self::emit).
Sourcepub fn complete_actions(&self, actions: impl IntoIterator<Item = A>)
pub fn complete_actions(&self, actions: impl IntoIterator<Item = A>)
Simulate multiple async action completions.
Sourcepub fn drain_emitted(&mut self) -> Vec<A>
pub fn drain_emitted(&mut self) -> Vec<A>
Drain all emitted actions from the channel.
Sourcepub fn has_emitted(&mut self) -> bool
pub fn has_emitted(&mut self) -> bool
Check if any actions were emitted.
Sourcepub fn process_emitted(&mut self) -> (usize, usize)
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).
Sourcepub fn send_keys<C, H, I>(&mut self, keys: &str, handler: H) -> Vec<A>
pub fn send_keys<C, H, I>(&mut self, keys: &str, handler: H) -> Vec<A>
Send a sequence of key events and collect actions from a handler.
Sourcepub fn send_keys_dispatch<C, H, I>(&mut self, keys: &str, handler: H) -> Vec<A>
pub fn send_keys_dispatch<C, H, I>(&mut self, keys: &str, handler: H) -> Vec<A>
Send keys and dispatch returned actions to the store.
Returns the actions that were dispatched. Effects are collected.
Sourcepub fn assert_state<F>(&self, predicate: F)
pub fn assert_state<F>(&self, predicate: F)
Assert a condition on the current state.
Sourcepub fn assert_state_msg<F>(&self, predicate: F, msg: &str)
pub fn assert_state_msg<F>(&self, predicate: F, msg: &str)
Assert a condition with a custom message.
Sourcepub fn render<F>(&mut self, width: u16, height: u16, render_fn: F) -> String
pub fn render<F>(&mut self, width: u16, height: u16, render_fn: F) -> String
Render using the provided function, returns string with ANSI codes.
Sourcepub fn render_plain<F>(
&mut self,
width: u16,
height: u16,
render_fn: F,
) -> String
pub fn render_plain<F>( &mut self, width: u16, height: u16, render_fn: F, ) -> String
Render to plain string (no ANSI codes).
Sourcepub fn render_default<F>(&mut self, render_fn: F) -> String
pub fn render_default<F>(&mut self, render_fn: F) -> String
Render with default terminal size.
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>
impl<S, A, E> Sync for EffectStoreTestHarness<S, A, E>
impl<S, A, E> Unpin for EffectStoreTestHarness<S, A, E>
impl<S, A, E> UnwindSafe for EffectStoreTestHarness<S, A, E>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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