pub struct TestApp<C: Component> { /* private fields */ }Expand description
A test harness for Telex components.
Renders components to an in-memory buffer and provides methods for finding elements and simulating interactions.
Implementations§
Source§impl<C: Component> TestApp<C>
impl<C: Component> TestApp<C>
Sourcepub fn render_to_string(&mut self) -> String
pub fn render_to_string(&mut self) -> String
Render to a buffer and return the buffer contents as a string.
Sourcepub fn find_all_text(&self) -> Vec<String>
pub fn find_all_text(&self) -> Vec<String>
Find all text content in the view tree.
Sourcepub fn find_text(&self, needle: &str) -> Option<String>
pub fn find_text(&self, needle: &str) -> Option<String>
Find text that contains the given substring.
Sourcepub fn has_text(&self, needle: &str) -> bool
pub fn has_text(&self, needle: &str) -> bool
Check if text containing the given substring exists.
Find all button labels in the view tree.
Find a button by its label.
Sourcepub fn focus_index(&self) -> usize
pub fn focus_index(&self) -> usize
Get the current focus index.
Sourcepub fn focusable_count(&mut self) -> usize
pub fn focusable_count(&mut self) -> usize
Get the total number of focusable elements.
Sourcepub fn focus_next(&mut self)
pub fn focus_next(&mut self)
Move focus to the next element.
Sourcepub fn focus_prev(&mut self)
pub fn focus_prev(&mut self)
Move focus to the previous element.
Sourcepub fn activate(&mut self)
pub fn activate(&mut self)
Activate the currently focused element (press button, toggle checkbox).
Press a button by its label.
Finds the button, focuses it, and activates it.
Sourcepub fn type_char(&mut self, c: char)
pub fn type_char(&mut self, c: char)
Type a character into the focused text input or text area.
Sourcepub fn scroll_down(&mut self, amount: u16)
pub fn scroll_down(&mut self, amount: u16)
Scroll down in the focused scrollable.
Sourcepub fn assert_visible(&mut self, needle: &str)
pub fn assert_visible(&mut self, needle: &str)
Assert that the given text is visible in the rendered output. Panics with a helpful message showing the rendered output if not found.
Sourcepub fn assert_not_visible(&mut self, needle: &str)
pub fn assert_not_visible(&mut self, needle: &str)
Assert that the given text is NOT visible in the rendered output. Panics with a helpful message if the text is found.
Sourcepub fn visible_items(&mut self, items: &[&str]) -> Vec<String>
pub fn visible_items(&mut self, items: &[&str]) -> Vec<String>
Check which items from the given list are visible in the rendered output. Returns a Vec of the items that are visible.
Sourcepub fn rendered_lines(&mut self) -> Vec<String>
pub fn rendered_lines(&mut self) -> Vec<String>
Get the rendered output as a Vec of lines.
Sourcepub fn find_line_containing(&mut self, needle: &str) -> Option<usize>
pub fn find_line_containing(&mut self, needle: &str) -> Option<usize>
Find the line number (0-indexed) containing the given text. Returns None if not found.
Sourcepub fn viewport_height(&self) -> u16
pub fn viewport_height(&self) -> u16
Get the viewport height (visible area).
Sourcepub fn viewport_width(&self) -> u16
pub fn viewport_width(&self) -> u16
Get the viewport width (visible area).
Auto Trait Implementations§
impl<C> Freeze for TestApp<C>where
C: Freeze,
impl<C> !RefUnwindSafe for TestApp<C>
impl<C> !Send for TestApp<C>
impl<C> !Sync for TestApp<C>
impl<C> Unpin for TestApp<C>where
C: Unpin,
impl<C> !UnwindSafe for TestApp<C>
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.