web_sys_ec/
ec.rs

1pub(crate) mod inner {
2    pub enum Ec {
3        InnerTextContains(String),
4        AttributeValueIs(String, String),
5        LocalStorageAttributeValueIs(String, String),
6        LocationSearchIs(String),
7    }
8
9    impl core::fmt::Display for Ec {
10        fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
11            match self {
12                Ec::InnerTextContains(text) => write!(
13                    f,
14                    "HTML element innerText contains the text {:?} (`{:?}`)",
15                    text, &self
16                ),
17                Ec::AttributeValueIs(attr, value) => {
18                    write!(
19                        f,
20                        "HTML element attribute {:?} value is equal to {:?} (`{:?}`)",
21                        attr, value, &self
22                    )
23                }
24                Ec::LocalStorageAttributeValueIs(attr, value) => {
25                    write!(
26                        f,
27                        "localStorage attribute {:?} value is equal to {:?} (`{:?}`)",
28                        attr, value, &self
29                    )
30                }
31                Ec::LocationSearchIs(value) => {
32                    write!(
33                        f,
34                        "window.location.search is equal to {:?} (`{:?}`)",
35                        value, &self
36                    )
37                }
38            }
39        }
40    }
41
42    impl core::fmt::Debug for Ec {
43        fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
44            match self {
45                Ec::InnerTextContains(text) => write!(f, "Ec::InnerTextContains({text:?})"),
46                Ec::AttributeValueIs(attr, value) => {
47                    write!(f, "Ec::AttributeValueIs({attr:?}, {value:?})")
48                }
49                Ec::LocalStorageAttributeValueIs(attr, value) => {
50                    write!(f, "Ec::LocalStorageAttributeValueIs({attr:?}, {value:?})",)
51                }
52                Ec::LocationSearchIs(value) => write!(f, "Ec::LocationSearchIs({value:?})"),
53            }
54        }
55    }
56}
57
58/// Conditions to be expected while waiting.
59#[allow(non_snake_case)]
60pub mod Ec {
61    use super::inner;
62
63    /// The property `innerText` of an element contains the given text.
64    ///
65    /// ```rust,ignore
66    /// use web_sys_ec::{Ec, Wait};
67    ///
68    /// Wait(1).until(("p", Ec::InnerTextContains("text")));
69    /// ```
70    #[inline]
71    pub fn InnerTextContains(text: impl Into<String>) -> inner::Ec {
72        inner::Ec::InnerTextContains(text.into())
73    }
74
75    /// The attribute value of an element is equal to the given value.
76    ///
77    /// ```rust,ignore
78    /// use web_sys_ec::{Ec, Wait};
79    ///
80    /// Wait(1).until(("p", Ec::AttributeValueIs("attr", "value")));
81    /// ```
82    #[inline]
83    pub fn AttributeValueIs(attr: impl Into<String>, value: impl Into<String>) -> inner::Ec {
84        inner::Ec::AttributeValueIs(attr.into(), value.into())
85    }
86
87    /// The localStorage attribute value is equal to the given value.
88    ///
89    /// ```rust,ignore
90    /// use web_sys_ec::{Ec, Wait};
91    ///
92    /// Wait(1).until(Ec::LocalStorageAttributeValueIs("key", "value"));
93    /// ```
94    #[inline]
95    pub fn LocalStorageAttributeValueIs(
96        attr: impl Into<String>,
97        value: impl Into<String>,
98    ) -> inner::Ec {
99        inner::Ec::LocalStorageAttributeValueIs(attr.into(), value.into())
100    }
101
102    /// The `window.location.search` is equal to the given value.
103    ///
104    /// ```rust,ignore
105    /// use web_sys_ec::{Ec, Wait};
106    ///
107    /// Wait(1).until(Ec::LocationSearchIs("?key=value"));
108    /// ```
109    #[inline]
110    pub fn LocationSearchIs(value: impl Into<String>) -> inner::Ec {
111        inner::Ec::LocationSearchIs(value.into())
112    }
113}