BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-state / src / importance.rs

importance.rs

importance.rs 1.2 KiB Download Raw
1use store::MessageImportance;
2
3/// Teams strings "Important!" / "Urgent!", shown in capitals (`text-transform: uppercase`).
4pub const IMPORTANT_LABEL: &str = "IMPORTANT!";
5pub const URGENT_LABEL: &str = "URGENT!";
6pub const URGENT_TOAST_SUFFIX: &str = "sent an urgent message";
7
8pub fn importance_label(importance: MessageImportance) -> Option<&'static str> {
9 match importance {
10 MessageImportance::Normal => None,
11 MessageImportance::High => Some(IMPORTANT_LABEL),
12 MessageImportance::Urgent => Some(URGENT_LABEL),
13 }
14}
15
16pub fn urgent_toast_title(sender: &str) -> String {
17 format!("{sender} {URGENT_TOAST_SUFFIX}")
18}
19
20#[cfg(test)]
21mod tests {
22 use super::*;
23
24 #[test]
25 fn labels_match_the_teams_strings_in_capitals() {
26 assert_eq!(importance_label(MessageImportance::Normal), None);
27 assert_eq!(
28 importance_label(MessageImportance::High),
29 Some("IMPORTANT!")
30 );
31 assert_eq!(importance_label(MessageImportance::Urgent), Some("URGENT!"));
32 }
33
34 #[test]
35 fn the_urgent_toast_title_names_the_sender() {
36 assert_eq!(
37 urgent_toast_title("Lea Schneider"),
38 "Lea Schneider sent an urgent message"
39 );
40 }
41}