plushie/testing/element

Element: a query-friendly wrapper around a tree Node.

Elements provide convenient accessors for testing – find by ID, extract text content, read props, and traverse children.

Types

A test element wrapping a Node for convenient querying.

pub type Element {
  Element(node: node.Node)
}

Constructors

Values

pub fn child_at(
  element: Element,
  index: Int,
) -> option.Option(Element)

Get a child element by index.

pub fn children(element: Element) -> List(Element)

Get the element’s children as Elements.

pub fn find(
  in root: node.Node,
  id target: String,
) -> option.Option(Element)

Find an element by ID in a normalized tree.

pub fn find_all(
  element: Element,
  predicate: fn(Element) -> Bool,
) -> List(Element)

Collect all descendant elements matching a predicate.

pub fn find_within(
  element: Element,
  target: String,
) -> option.Option(Element)

Find a descendant element by ID within this element’s subtree.

pub fn from_node(node: node.Node) -> Element

Wrap a Node as an Element.

pub fn has_children(element: Element) -> Bool

Check if the element has any children.

pub fn id(element: Element) -> String

Get the element’s ID.

pub fn kind(element: Element) -> String

Get the element’s kind (widget type).

pub fn local_id(element: Element) -> String

Get the local ID (last segment after “/”).

pub fn prop(
  element: Element,
  key: String,
) -> option.Option(node.PropValue)

Get a prop value by key.

pub fn text(element: Element) -> option.Option(String)

Extract text content from an element. Checks props in order: “content”, “label”, “value”, “placeholder”.

Search Document