testing_library_dom/types/
suggestions.rs1use std::fmt::Display;
2
3use crate::types::{Matcher, MatcherOptions};
4
5pub struct Suggestion {
6 pub query_name: Method,
7 pub query_method: String,
8 pub query_matcher: Matcher,
9 pub query_options: MatcherOptions,
10 pub variant: Variant,
11 pub warning: Option<String>,
12}
13
14impl Display for Suggestion {
15 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16 if let Some(warning) = self.warning.as_ref() {
17 log::warn!("{warning}");
18 }
19
20 let text = match &self.query_matcher {
21 Matcher::String(matcher) => format!("'{matcher}'"),
22 matcher => format!("{}", matcher),
23 };
24
25 let options = ", TODO";
26
27 write!(f, "{}({}{})", self.query_method, text, options)
28 }
29}
30
31#[derive(Clone, Copy, Debug, PartialEq)]
32pub enum Variant {
33 Find,
34 FindAll,
35 Get,
36 GetAll,
37 Query,
38 QueryAll,
39}
40
41impl Display for Variant {
42 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43 write!(
44 f,
45 "{}",
46 match self {
47 Variant::Find => "find",
48 Variant::FindAll => "find_all",
49 Variant::Get => "get",
50 Variant::GetAll => "get_all",
51 Variant::Query => "query",
52 Variant::QueryAll => "query_all",
53 }
54 )
55 }
56}
57
58#[derive(Clone, Copy, Debug, PartialEq)]
59pub enum Method {
60 AltText,
61 DisplayValue,
62 LabelText,
63 PlaceholderText,
64 Role,
65 TestId,
66 Text,
67 Title,
68}
69
70impl Display for Method {
71 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
72 write!(
73 f,
74 "{}",
75 match self {
76 Method::AltText => "alt_text",
77 Method::DisplayValue => "display_value",
78 Method::LabelText => "label_text",
79 Method::PlaceholderText => "placeholder_text",
80 Method::Role => "role",
81 Method::TestId => "test_id",
82 Method::Text => "text",
83 Method::Title => "title",
84 }
85 )
86 }
87}