-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprogress.rs
More file actions
75 lines (61 loc) · 1.81 KB
/
Copy pathprogress.rs
File metadata and controls
75 lines (61 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! Progress message type for ongoing operations
use super::super::{Channel, OutputMessage, Theme, VerbosityLevel};
/// Progress message for ongoing operations
///
/// Progress messages indicate that work is in progress. They are displayed
/// during operations to provide feedback to users.
///
/// # Examples
///
/// ```rust,ignore
/// use torrust_tracker_deployer_lib::presentation::views::ProgressMessage;
///
/// let message = ProgressMessage {
/// text: "Destroying environment...".to_string(),
/// };
/// ```
pub struct ProgressMessage {
/// The progress message text
pub text: String,
}
impl OutputMessage for ProgressMessage {
fn format(&self, theme: &Theme) -> String {
format!("{} {}\n", theme.progress_symbol(), self.text)
}
fn required_verbosity(&self) -> VerbosityLevel {
VerbosityLevel::Normal
}
fn channel(&self) -> Channel {
Channel::Stderr
}
fn type_name(&self) -> &'static str {
"ProgressMessage"
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_should_format_with_theme_when_displaying_progress() {
let theme = Theme::emoji();
let message = ProgressMessage {
text: "Test message".to_string(),
};
let formatted = message.format(&theme);
assert_eq!(formatted, "⏳ Test message\n");
}
#[test]
fn it_should_require_normal_verbosity_when_displaying_progress() {
let message = ProgressMessage {
text: "Test".to_string(),
};
assert_eq!(message.required_verbosity(), VerbosityLevel::Normal);
}
#[test]
fn it_should_use_stderr_channel_when_displaying_progress() {
let message = ProgressMessage {
text: "Test".to_string(),
};
assert_eq!(message.channel(), Channel::Stderr);
}
}