diff --git a/packages/dom/src/get_queries_for_element.rs b/packages/dom/src/get_queries_for_element.rs index 94b2ef0..fc8a971 100644 --- a/packages/dom/src/get_queries_for_element.rs +++ b/packages/dom/src/get_queries_for_element.rs @@ -2,99 +2,74 @@ use web_sys::HtmlElement; use crate::{ error::QueryError, - get_by_placeholder_text, get_by_test_id, get_by_title, - queries::{get_by_alt_text, get_by_display_value, query_by_alt_text, query_by_display_value}, - query_by_placeholder_text, query_by_test_id, query_by_title, - types::{Matcher, MatcherOptions}, + queries::*, + types::{Matcher, MatcherOptions, WaitForOptions}, }; +pub fn get_queries_for_element(element: HtmlElement) -> BoundFunctions { + BoundFunctions { element } +} + pub struct BoundFunctions { element: HtmlElement, } -impl BoundFunctions { - pub fn get_by_alt_text>( - &self, - matcher: M, - options: MatcherOptions, - ) -> Result, QueryError> { - get_by_alt_text(&self.element, matcher, options) - } - - pub fn get_by_display_value>( - &self, - matcher: M, - options: MatcherOptions, - ) -> Result, QueryError> { - get_by_display_value(&self.element, matcher, options) - } - - pub fn get_by_placeholder_text>( - &self, - matcher: M, - options: MatcherOptions, - ) -> Result, QueryError> { - get_by_placeholder_text(&self.element, matcher, options) - } - - pub fn get_by_test_id>( - &self, - matcher: M, - options: MatcherOptions, - ) -> Result, QueryError> { - get_by_test_id(&self.element, matcher, options) - } +macro_rules! queries_for_element { + ($($name:ident),*) => { + paste::paste! { + impl BoundFunctions { + $(pub fn [< find_by_ $name >]>( + &self, + matcher: M, + options: MatcherOptions, + wait_for_options: WaitForOptions, + ) -> Result, QueryError> { + [< find_by_ $name >](&self.element, matcher, options, wait_for_options) + })* - pub fn get_by_title>( - &self, - matcher: M, - options: MatcherOptions, - ) -> Result, QueryError> { - get_by_title(&self.element, matcher, options) - } + $(pub fn [< find_all_by_ $name >]>( + &self, + matcher: M, + options: MatcherOptions, + wait_for_options: WaitForOptions, + ) -> Result, QueryError> { + [< find_all_by_ $name >](&self.element, matcher, options, wait_for_options) + })* - pub fn query_by_alt_text>( - &self, - matcher: M, - options: MatcherOptions, - ) -> Result, QueryError> { - query_by_alt_text(&self.element, matcher, options) - } - - pub fn query_by_display_value>( - &self, - matcher: M, - options: MatcherOptions, - ) -> Result, QueryError> { - query_by_display_value(&self.element, matcher, options) - } + $(pub fn [< get_by_ $name >]>( + &self, + matcher: M, + options: MatcherOptions, + ) -> Result, QueryError> { + [< get_by_ $name >](&self.element, matcher, options) + })* - pub fn query_by_placeholder_text>( - &self, - matcher: M, - options: MatcherOptions, - ) -> Result, QueryError> { - query_by_placeholder_text(&self.element, matcher, options) - } + $(pub fn [< get_all_by_ $name >]>( + &self, + matcher: M, + options: MatcherOptions, + ) -> Result, QueryError> { + [< get_all_by_ $name >](&self.element, matcher, options) + })* - pub fn query_by_test_id>( - &self, - matcher: M, - options: MatcherOptions, - ) -> Result, QueryError> { - query_by_test_id(&self.element, matcher, options) - } + $(pub fn [< query_by_ $name >]>( + &self, + matcher: M, + options: MatcherOptions, + ) -> Result, QueryError> { + [< query_by_ $name >](&self.element, matcher, options) + })* - pub fn query_by_title>( - &self, - matcher: M, - options: MatcherOptions, - ) -> Result, QueryError> { - query_by_title(&self.element, matcher, options) + $(pub fn [< query_all_by_ $name >]>( + &self, + matcher: M, + options: MatcherOptions, + ) -> Result, QueryError> { + [< query_all_by_ $name >](&self.element, matcher, options) + })* + } + } } } -pub fn get_queries_for_element(element: HtmlElement) -> BoundFunctions { - // TODO - BoundFunctions { element } -} +queries_for_element!(alt_text, display_value, placeholder_text, test_id, title);