block_kit/composition/
confirmation_dialog.rs1use crate::composition::text::Text::Plain;
2use crate::composition::text::{PlainText, Text};
3use serde::Serialize;
4
5#[derive(Debug, Default, Serialize, Clone)]
8pub struct ConfirmationDialog {
9 title: Text,
10 text: Text,
11 confirm: Text,
12 deny: Text,
13}
14
15impl ConfirmationDialog {
16 pub fn new(
17 title: impl Into<PlainText>,
18 text: Text,
19 confirm: impl Into<PlainText>,
20 deny: impl Into<PlainText>,
21 ) -> Self {
22 ConfirmationDialog {
23 title: Plain(title.into()),
24 text,
25 confirm: Plain(confirm.into()),
26 deny: Plain(deny.into()),
27 }
28 }
29}
30
31#[cfg(test)]
32mod test {
33 use super::*;
34 use crate::composition::text::MarkdownText;
35 use crate::composition::text::Text::Markdown;
36
37 #[test]
38 pub fn test_ser_default() {
39 let confirm = ConfirmationDialog::default();
40 let json = serde_json::to_string_pretty(&confirm).unwrap_or("".to_string());
41 let expected = r#"{
42 "title": {
43 "type": "plain_text",
44 "text": ""
45 },
46 "text": {
47 "type": "plain_text",
48 "text": ""
49 },
50 "confirm": {
51 "type": "plain_text",
52 "text": ""
53 },
54 "deny": {
55 "type": "plain_text",
56 "text": ""
57 }
58}"#;
59 assert_eq!(json, expected.to_string());
60 }
61
62 #[test]
63 pub fn test_ser_new() {
64 let confirm = ConfirmationDialog::new(
65 PlainText::new("title"),
66 Markdown(MarkdownText::new("text")),
67 PlainText::new("confirm"),
68 PlainText::new("deny"),
69 );
70 let json = serde_json::to_string_pretty(&confirm).unwrap_or("".to_string());
71 let expected = r#"{
72 "title": {
73 "type": "plain_text",
74 "text": "title"
75 },
76 "text": {
77 "type": "mrkdwn",
78 "text": "text"
79 },
80 "confirm": {
81 "type": "plain_text",
82 "text": "confirm"
83 },
84 "deny": {
85 "type": "plain_text",
86 "text": "deny"
87 }
88}"#;
89 assert_eq!(json, expected.to_string());
90 }
91}