coding_agent_search/ui/components/
pills.rs1#[derive(Clone, Debug)]
7pub struct Pill {
8 pub label: String,
9 pub value: String,
10 pub active: bool,
11 pub editable: bool,
12}
13
14#[cfg(test)]
15mod tests {
16 use super::*;
17
18 #[test]
19 fn test_pill_creation() {
20 let pill = Pill {
21 label: "Agent".to_string(),
22 value: "claude".to_string(),
23 active: true,
24 editable: false,
25 };
26
27 assert_eq!(pill.label, "Agent");
28 assert_eq!(pill.value, "claude");
29 assert!(pill.active);
30 assert!(!pill.editable);
31 }
32
33 #[test]
34 fn test_pill_clone() {
35 let pill = Pill {
36 label: "Workspace".to_string(),
37 value: "/home/user".to_string(),
38 active: false,
39 editable: true,
40 };
41
42 let cloned = pill.clone();
43 assert_eq!(cloned.label, pill.label);
44 assert_eq!(cloned.value, pill.value);
45 assert_eq!(cloned.active, pill.active);
46 assert_eq!(cloned.editable, pill.editable);
47 }
48
49 #[test]
50 fn test_pill_debug() {
51 let pill = Pill {
52 label: "Test".to_string(),
53 value: "Value".to_string(),
54 active: true,
55 editable: true,
56 };
57
58 let debug_str = format!("{:?}", pill);
59 assert!(debug_str.contains("Pill"));
60 assert!(debug_str.contains("Test"));
61 assert!(debug_str.contains("Value"));
62 }
63
64 #[test]
65 fn test_pill_with_empty_strings() {
66 let pill = Pill {
67 label: "".to_string(),
68 value: "".to_string(),
69 active: false,
70 editable: false,
71 };
72
73 assert!(pill.label.is_empty());
74 assert!(pill.value.is_empty());
75 }
76
77 #[test]
78 fn test_pill_with_special_characters() {
79 let pill = Pill {
80 label: "Path".to_string(),
81 value: "/home/user/my project/src".to_string(),
82 active: true,
83 editable: false,
84 };
85
86 assert!(pill.value.contains(' '));
87 assert!(pill.value.contains('/'));
88 }
89
90 #[test]
91 fn test_pill_states() {
92 let inactive_readonly = Pill {
94 label: "A".to_string(),
95 value: "1".to_string(),
96 active: false,
97 editable: false,
98 };
99 assert!(!inactive_readonly.active && !inactive_readonly.editable);
100
101 let inactive_editable = Pill {
102 label: "B".to_string(),
103 value: "2".to_string(),
104 active: false,
105 editable: true,
106 };
107 assert!(!inactive_editable.active && inactive_editable.editable);
108
109 let active_readonly = Pill {
110 label: "C".to_string(),
111 value: "3".to_string(),
112 active: true,
113 editable: false,
114 };
115 assert!(active_readonly.active && !active_readonly.editable);
116
117 let active_editable = Pill {
118 label: "D".to_string(),
119 value: "4".to_string(),
120 active: true,
121 editable: true,
122 };
123 assert!(active_editable.active && active_editable.editable);
124 }
125}