Skip to main content

TestApp

Struct TestApp 

Source
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>

Source

pub fn new(root: C) -> Self

Create a new test app with the given root component.

Source

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

Set the virtual terminal size.

Source

pub fn render_to_string(&mut self) -> String

Render to a buffer and return the buffer contents as a string.

Source

pub fn find_all_text(&self) -> Vec<String>

Find all text content in the view tree.

Source

pub fn find_text(&self, needle: &str) -> Option<String>

Find text that contains the given substring.

Source

pub fn has_text(&self, needle: &str) -> bool

Check if text containing the given substring exists.

Source

pub fn find_all_buttons(&self) -> Vec<String>

Find all button labels in the view tree.

Source

pub fn find_button(&self, label: &str) -> Option<String>

Find a button by its label.

Source

pub fn focus_index(&self) -> usize

Get the current focus index.

Source

pub fn focusable_count(&mut self) -> usize

Get the total number of focusable elements.

Source

pub fn focus_next(&mut self)

Move focus to the next element.

Source

pub fn focus_prev(&mut self)

Move focus to the previous element.

Source

pub fn activate(&mut self)

Activate the currently focused element (press button, toggle checkbox).

Source

pub fn press_button(&mut self, label: &str) -> bool

Press a button by its label.

Finds the button, focuses it, and activates it.

Source

pub fn list_up(&mut self)

Move list selection up.

Source

pub fn list_down(&mut self)

Move list selection down.

Source

pub fn type_char(&mut self, c: char)

Type a character into the focused text input or text area.

Source

pub fn type_str(&mut self, s: &str)

Type a string into the focused text input or text area.

Source

pub fn backspace(&mut self)

Press backspace in the focused text input or text area.

Source

pub fn enter(&mut self)

Press Enter in the focused text area (insert new line).

Source

pub fn scroll_up(&mut self, amount: u16)

Scroll up in the focused scrollable.

Source

pub fn scroll_down(&mut self, amount: u16)

Scroll down in the focused scrollable.

Source

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.

Source

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.

Source

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.

Source

pub fn rendered_lines(&mut self) -> Vec<String>

Get the rendered output as a Vec of lines.

Source

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.

Source

pub fn viewport_height(&self) -> u16

Get the viewport height (visible area).

Source

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> 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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.