1use iced::Element;
2use iced::widget::{Id, container};
3
4use crate::app::Message;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub enum Role {
8 Button,
9 Checkbox,
10 TextInput,
11 PickList,
12 Scrollable,
13 Text,
14 Dialog,
15 Tab,
16 List,
17 ListItem,
18 Custom,
19}
20
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub struct Metadata {
23 pub role: Role,
24 pub label: Option<String>,
25 pub test_id: Option<String>,
26}
27
28impl Metadata {
29 pub fn new(role: Role) -> Self {
30 Self {
31 role,
32 label: None,
33 test_id: None,
34 }
35 }
36
37 #[must_use]
38 pub fn label(mut self, label: impl Into<String>) -> Self {
39 self.label = Some(label.into());
40 self
41 }
42
43 #[must_use]
44 pub fn test_id(mut self, test_id: impl Into<String>) -> Self {
45 self.test_id = Some(test_id.into());
46 self
47 }
48}
49
50pub fn widget_id(test_id: impl Into<String>) -> Id {
51 format!("test-id:{}", test_id.into()).into()
52}
53
54pub fn test_id<'a>(
55 test_id: impl Into<String>,
56 content: impl Into<Element<'a, Message>>,
57) -> Element<'a, Message> {
58 container(content).id(widget_id(test_id)).into()
59}