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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use crate::composition::text::Text::Plain;
use crate::composition::text::{PlainText, Text};
use serde::Serialize;
#[derive(Debug, Default, Serialize, Clone)]
pub struct ConfirmationDialog {
title: Text,
text: Text,
confirm: Text,
deny: Text,
}
impl ConfirmationDialog {
pub fn new(
title: impl Into<PlainText>,
text: Text,
confirm: impl Into<PlainText>,
deny: impl Into<PlainText>,
) -> Self {
ConfirmationDialog {
title: Plain(title.into()),
text,
confirm: Plain(confirm.into()),
deny: Plain(deny.into()),
}
}
}
#[cfg(test)]
mod test {
use super::*;
use crate::composition::text::MarkdownText;
use crate::composition::text::Text::Markdown;
#[test]
pub fn test_ser_default() {
let confirm = ConfirmationDialog::default();
let json = serde_json::to_string_pretty(&confirm).unwrap_or("".to_string());
let expected = r#"{
"title": {
"type": "plain_text",
"text": ""
},
"text": {
"type": "plain_text",
"text": ""
},
"confirm": {
"type": "plain_text",
"text": ""
},
"deny": {
"type": "plain_text",
"text": ""
}
}"#;
assert_eq!(json, expected.to_string());
}
#[test]
pub fn test_ser_new() {
let confirm = ConfirmationDialog::new(
PlainText::new("title"),
Markdown(MarkdownText::new("text")),
PlainText::new("confirm"),
PlainText::new("deny"),
);
let json = serde_json::to_string_pretty(&confirm).unwrap_or("".to_string());
let expected = r#"{
"title": {
"type": "plain_text",
"text": "title"
},
"text": {
"type": "mrkdwn",
"text": "text"
},
"confirm": {
"type": "plain_text",
"text": "confirm"
},
"deny": {
"type": "plain_text",
"text": "deny"
}
}"#;
assert_eq!(json, expected.to_string());
}
}