thirtyfour_testing_library_ext/options/
label_text.rs1use crate::options::common::TestingLibraryOptions;
2use serde::Serialize;
3
4#[derive(Debug, Clone, Default, Serialize)]
6#[serde(rename_all = "camelCase")]
7pub struct ByLabelTextOptions {
8 #[serde(skip_serializing_if = "Option::is_none")]
10 pub selector: Option<String>,
11 #[serde(skip_serializing_if = "Option::is_none")]
13 pub exact: Option<bool>,
14}
15
16impl ByLabelTextOptions {
17 pub fn new() -> Self {
19 Self::default()
20 }
21
22 pub fn selector(mut self, selector: impl Into<String>) -> Self {
24 self.selector = Some(selector.into());
25 self
26 }
27
28 pub fn exact(mut self, exact: bool) -> Self {
30 self.exact = Some(exact);
31 self
32 }
33}
34
35impl TestingLibraryOptions for ByLabelTextOptions {}
36
37#[cfg(test)]
38mod tests {
39 use super::*;
40
41 #[test]
42 fn test_label_text_options_empty_serialization() {
43 let options = ByLabelTextOptions::new();
44 let json = options.to_json_string().unwrap();
45 assert_eq!(json, "{}");
46 }
47
48 #[test]
49 fn test_label_text_options_basic_serialization() {
50 let options = ByLabelTextOptions::new().selector("input").exact(false);
51
52 let json_value = options.to_json_value().unwrap();
53 assert_eq!(json_value["selector"], "input");
54 assert_eq!(json_value["exact"], false);
55 }
56
57 #[test]
58 fn test_label_text_options_partial_serialization() {
59 let options = ByLabelTextOptions::new().exact(true);
60
61 let json_value = options.to_json_value().unwrap();
62 assert!(json_value["selector"].is_null());
63 assert_eq!(json_value["exact"], true);
64 }
65
66 #[test]
67 fn test_label_text_options_json_string() {
68 let options = ByLabelTextOptions::new().selector("textarea").exact(true);
69
70 let json_string = options.to_json_string().unwrap();
71 assert!(json_string.contains("\"selector\":\"textarea\""));
72 assert!(json_string.contains("\"exact\":true"));
73 }
74}