slack-web-api 0.2.0

Typed async Slack Web API client for Rust: all 330 methods incl. admin, Block Kit, pagination, file upload, rate-limit retry (reqwest + rustls, no OpenSSL)
Documentation
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
use super::*;

#[test]
fn plain_text() {
    assert_json(
        &PlainText::new("s"),
        r#"{"type": "plain_text", "text": "s"}"#,
    );
    assert_json(
        &PlainText::new("s").emoji(true),
        r#"{"type": "plain_text", "text": "s", "emoji": true}"#,
    );
}

#[test]
fn mrkdwn() {
    assert_json(&Mrkdwn::new("s"), r#"{"type": "mrkdwn", "text": "s"}"#);
    assert_json(
        &Mrkdwn::new("s").verbatim(true),
        r#"{"type": "mrkdwn", "text": "s", "verbatim": true}"#,
    );
}

#[test]
fn confirmation_dialog() {
    assert_json(
        &ConfirmationDialog::new(
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
        ),
        r#"{"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}"#,
    );
    assert_json(
        &ConfirmationDialog::new(
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
        )
        .style(ButtonStyle::Primary),
        r#"{"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}, "style": "primary"}"#,
    );
}

#[test]
fn option_object() {
    assert_json(
        &OptionObject::new(TextObject::from(PlainText::new("s")), "s"),
        r#"{"text": {"type": "plain_text", "text": "s"}, "value": "s"}"#,
    );
    assert_json(
        &OptionObject::new(TextObject::from(PlainText::new("s")), "s")
            .description(TextObject::from(PlainText::new("s")))
            .url("s"),
        r#"{"text": {"type": "plain_text", "text": "s"}, "value": "s", "description": {"type": "plain_text", "text": "s"}, "url": "s"}"#,
    );
}

#[test]
fn option_group() {
    assert_json(
        &OptionGroup::new(
            TextObject::from(PlainText::new("s")),
            vec![OptionObject::new(
                TextObject::from(PlainText::new("s")),
                "s",
            )],
        ),
        r#"{"label": {"type": "plain_text", "text": "s"}, "options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}]}"#,
    );
}

#[test]
fn conversation_filter() {
    assert_json(&ConversationFilter::new(), r#"{}"#);
    assert_json(
        &ConversationFilter::new()
            .include(vec![ConversationType::Im])
            .exclude_external_shared_channels(true)
            .exclude_bot_users(true),
        r#"{"include": ["im"], "exclude_external_shared_channels": true, "exclude_bot_users": true}"#,
    );
}

#[test]
fn dispatch_action_config() {
    assert_json(&DispatchActionConfig::new(), r#"{}"#);
    assert_json(
        &DispatchActionConfig::new().trigger_actions_on(vec![TriggerAction::OnEnterPressed]),
        r#"{"trigger_actions_on": ["on_enter_pressed"]}"#,
    );
}

#[test]
fn slack_file() {
    assert_json(&SlackFile::from_id("s"), r#"{"id": "s"}"#);
    assert_json(
        &SlackFile::from_id("s").url("s").id("s"),
        r#"{"id": "s", "url": "s"}"#,
    );
}

#[test]
fn slack_icon() {
    assert_json(&SlackIcon::new("s"), r#"{"type": "icon", "name": "s"}"#);
}

#[test]
fn workflow() {
    assert_json(
        &Workflow::new(Trigger::new("s")),
        r#"{"trigger": {"url": "s"}}"#,
    );
}

#[test]
fn trigger() {
    assert_json(&Trigger::new("s"), r#"{"url": "s"}"#);
    assert_json(
        &Trigger::new("s").customizable_input_parameters(vec![InputParameter::new("s", "s")]),
        r#"{"url": "s", "customizable_input_parameters": [{"name": "s", "value": "s"}]}"#,
    );
}

#[test]
fn input_parameter() {
    assert_json(
        &InputParameter::new("s", "s"),
        r#"{"name": "s", "value": "s"}"#,
    );
}

#[test]
fn button_element() {
    assert_json(
        &ButtonElement::new(TextObject::from(PlainText::new("s"))),
        r#"{"type": "button", "text": {"type": "plain_text", "text": "s"}}"#,
    );
    assert_json(
        &ButtonElement::new(TextObject::from(PlainText::new("s")))
            .action_id("s")
            .url("s")
            .value("s")
            .style(ButtonStyle::Primary)
            .confirm(ConfirmationDialog::new(
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
            ))
            .accessibility_label("s")
            .agent_prompt("s")
            .agent_prompt_display("s")
            .visible_to_user_ids(vec!["s".to_string()]),
        r#"{"type": "button", "text": {"type": "plain_text", "text": "s"}, "action_id": "s", "url": "s", "value": "s", "style": "primary", "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "accessibility_label": "s", "agent_prompt": "s", "agent_prompt_display": "s", "visible_to_user_ids": ["s"]}"#,
    );
}

#[test]
fn checkboxes_element() {
    assert_json(
        &CheckboxesElement::new(vec![OptionObject::new(
            TextObject::from(PlainText::new("s")),
            "s",
        )]),
        r#"{"type": "checkboxes", "options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}]}"#,
    );
    assert_json(
        &CheckboxesElement::new(vec![OptionObject::new(
            TextObject::from(PlainText::new("s")),
            "s",
        )])
        .action_id("s")
        .initial_options(vec![OptionObject::new(
            TextObject::from(PlainText::new("s")),
            "s",
        )])
        .confirm(ConfirmationDialog::new(
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
        ))
        .focus_on_load(true)
        .visible_to_user_ids(vec!["s".to_string()]),
        r#"{"type": "checkboxes", "options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}], "action_id": "s", "initial_options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}], "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "focus_on_load": true, "visible_to_user_ids": ["s"]}"#,
    );
}

#[test]
fn date_picker_element() {
    assert_json(&DatePickerElement::new(), r#"{"type": "datepicker"}"#);
    assert_json(
        &DatePickerElement::new()
            .action_id("s")
            .initial_date("s")
            .confirm(ConfirmationDialog::new(
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
            ))
            .focus_on_load(true)
            .placeholder(TextObject::from(PlainText::new("s"))),
        r#"{"type": "datepicker", "action_id": "s", "initial_date": "s", "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "focus_on_load": true, "placeholder": {"type": "plain_text", "text": "s"}}"#,
    );
}

#[test]
fn datetime_picker_element() {
    assert_json(
        &DatetimePickerElement::new(),
        r#"{"type": "datetimepicker"}"#,
    );
    assert_json(
        &DatetimePickerElement::new()
            .action_id("s")
            .initial_date_time(1)
            .confirm(ConfirmationDialog::new(
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
            ))
            .focus_on_load(true),
        r#"{"type": "datetimepicker", "action_id": "s", "initial_date_time": 1, "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "focus_on_load": true}"#,
    );
}

#[test]
fn email_input_element() {
    assert_json(&EmailInputElement::new(), r#"{"type": "email_text_input"}"#);
    assert_json(
        &EmailInputElement::new()
            .action_id("s")
            .initial_value("s")
            .dispatch_action_config(DispatchActionConfig::new())
            .focus_on_load(true)
            .placeholder(TextObject::from(PlainText::new("s"))),
        r#"{"type": "email_text_input", "action_id": "s", "initial_value": "s", "dispatch_action_config": {}, "focus_on_load": true, "placeholder": {"type": "plain_text", "text": "s"}}"#,
    );
}

#[test]
fn feedback_buttons_element() {
    assert_json(
        &FeedbackButtonsElement::new(
            FeedbackButton::new(TextObject::from(PlainText::new("s")), "s"),
            FeedbackButton::new(TextObject::from(PlainText::new("s")), "s"),
        ),
        r#"{"type": "feedback_buttons", "positive_button": {"text": {"type": "plain_text", "text": "s"}, "value": "s"}, "negative_button": {"text": {"type": "plain_text", "text": "s"}, "value": "s"}}"#,
    );
    assert_json(
        &FeedbackButtonsElement::new(
            FeedbackButton::new(TextObject::from(PlainText::new("s")), "s"),
            FeedbackButton::new(TextObject::from(PlainText::new("s")), "s"),
        )
        .action_id("s"),
        r#"{"type": "feedback_buttons", "positive_button": {"text": {"type": "plain_text", "text": "s"}, "value": "s"}, "negative_button": {"text": {"type": "plain_text", "text": "s"}, "value": "s"}, "action_id": "s"}"#,
    );
}

#[test]
fn feedback_button() {
    assert_json(
        &FeedbackButton::new(TextObject::from(PlainText::new("s")), "s"),
        r#"{"text": {"type": "plain_text", "text": "s"}, "value": "s"}"#,
    );
    assert_json(
        &FeedbackButton::new(TextObject::from(PlainText::new("s")), "s").accessibility_label("s"),
        r#"{"text": {"type": "plain_text", "text": "s"}, "value": "s", "accessibility_label": "s"}"#,
    );
}

#[test]
fn file_input_element() {
    assert_json(&FileInputElement::new(), r#"{"type": "file_input"}"#);
    assert_json(
        &FileInputElement::new()
            .action_id("s")
            .filetypes(vec!["s".to_string()])
            .max_files(1),
        r#"{"type": "file_input", "action_id": "s", "filetypes": ["s"], "max_files": 1}"#,
    );
}

#[test]
fn icon_button_element() {
    assert_json(
        &IconButtonElement::new("s", TextObject::from(PlainText::new("s"))),
        r#"{"type": "icon_button", "icon": "s", "text": {"type": "plain_text", "text": "s"}}"#,
    );
    assert_json(
        &IconButtonElement::new("s", TextObject::from(PlainText::new("s")))
            .action_id("s")
            .value("s")
            .confirm(ConfirmationDialog::new(
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
            ))
            .accessibility_label("s")
            .visible_to_user_ids(vec!["s".to_string()]),
        r#"{"type": "icon_button", "icon": "s", "text": {"type": "plain_text", "text": "s"}, "action_id": "s", "value": "s", "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "accessibility_label": "s", "visible_to_user_ids": ["s"]}"#,
    );
}

#[test]
fn image_element() {
    assert_json(
        &ImageElement::new("s", "s"),
        r#"{"type": "image", "alt_text": "s", "image_url": "s"}"#,
    );
    assert_json(
        &ImageElement::new("s", "s")
            .image_url("s")
            .slack_file(SlackFile::from_id("s")),
        r#"{"type": "image", "alt_text": "s", "image_url": "s", "slack_file": {"id": "s"}}"#,
    );
}

#[test]
fn number_input_element() {
    assert_json(
        &NumberInputElement::new(true),
        r#"{"type": "number_input", "is_decimal_allowed": true}"#,
    );
    assert_json(
        &NumberInputElement::new(true)
            .action_id("s")
            .initial_value("s")
            .min_value("s")
            .max_value("s")
            .dispatch_action_config(DispatchActionConfig::new())
            .focus_on_load(true)
            .placeholder(TextObject::from(PlainText::new("s"))),
        r#"{"type": "number_input", "is_decimal_allowed": true, "action_id": "s", "initial_value": "s", "min_value": "s", "max_value": "s", "dispatch_action_config": {}, "focus_on_load": true, "placeholder": {"type": "plain_text", "text": "s"}}"#,
    );
}

#[test]
fn overflow_element() {
    assert_json(
        &OverflowElement::new(vec![OptionObject::new(
            TextObject::from(PlainText::new("s")),
            "s",
        )]),
        r#"{"type": "overflow", "options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}]}"#,
    );
    assert_json(
        &OverflowElement::new(vec![OptionObject::new(
            TextObject::from(PlainText::new("s")),
            "s",
        )])
        .action_id("s")
        .confirm(ConfirmationDialog::new(
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
        )),
        r#"{"type": "overflow", "options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}], "action_id": "s", "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}}"#,
    );
}

#[test]
fn plain_text_input_element() {
    assert_json(
        &PlainTextInputElement::new(),
        r#"{"type": "plain_text_input"}"#,
    );
    assert_json(
        &PlainTextInputElement::new()
            .action_id("s")
            .initial_value("s")
            .multiline(true)
            .min_length(1)
            .max_length(1)
            .dispatch_action_config(DispatchActionConfig::new())
            .focus_on_load(true)
            .placeholder(TextObject::from(PlainText::new("s"))),
        r#"{"type": "plain_text_input", "action_id": "s", "initial_value": "s", "multiline": true, "min_length": 1, "max_length": 1, "dispatch_action_config": {}, "focus_on_load": true, "placeholder": {"type": "plain_text", "text": "s"}}"#,
    );
}

#[test]
fn radio_buttons_element() {
    assert_json(
        &RadioButtonsElement::new(vec![OptionObject::new(
            TextObject::from(PlainText::new("s")),
            "s",
        )]),
        r#"{"type": "radio_buttons", "options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}]}"#,
    );
    assert_json(
        &RadioButtonsElement::new(vec![OptionObject::new(
            TextObject::from(PlainText::new("s")),
            "s",
        )])
        .action_id("s")
        .initial_option(OptionObject::new(
            TextObject::from(PlainText::new("s")),
            "s",
        ))
        .confirm(ConfirmationDialog::new(
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
        ))
        .focus_on_load(true),
        r#"{"type": "radio_buttons", "options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}], "action_id": "s", "initial_option": {"text": {"type": "plain_text", "text": "s"}, "value": "s"}, "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "focus_on_load": true}"#,
    );
}

#[test]
fn rich_text_input_element() {
    assert_json(
        &RichTextInputElement::new("s"),
        r#"{"type": "rich_text_input", "action_id": "s"}"#,
    );
    assert_json(
        &RichTextInputElement::new("s")
            .initial_value(RichTextBlock::new(vec![RichTextObject::from(
                RichTextSection::new(vec![RichTextElement::from(AttachmentMentionElement::new(
                    "s",
                ))]),
            )]))
            .dispatch_action_config(DispatchActionConfig::new())
            .focus_on_load(true)
            .placeholder(TextObject::from(PlainText::new("s")))
            .min_lines(1)
            .max_lines(1),
        r#"{"type": "rich_text_input", "action_id": "s", "initial_value": {"type": "rich_text", "elements": [{"type": "rich_text_section", "elements": [{"type": "attachment_mention", "url": "s"}]}]}, "dispatch_action_config": {}, "focus_on_load": true, "placeholder": {"type": "plain_text", "text": "s"}, "min_lines": 1, "max_lines": 1}"#,
    );
}

#[test]
fn time_picker_element() {
    assert_json(&TimePickerElement::new(), r#"{"type": "timepicker"}"#);
    assert_json(
        &TimePickerElement::new()
            .action_id("s")
            .initial_time("s")
            .confirm(ConfirmationDialog::new(
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
            ))
            .focus_on_load(true)
            .placeholder(TextObject::from(PlainText::new("s")))
            .timezone("s"),
        r#"{"type": "timepicker", "action_id": "s", "initial_time": "s", "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "focus_on_load": true, "placeholder": {"type": "plain_text", "text": "s"}, "timezone": "s"}"#,
    );
}

#[test]
fn url_input_element() {
    assert_json(&UrlInputElement::new(), r#"{"type": "url_text_input"}"#);
    assert_json(
        &UrlInputElement::new()
            .action_id("s")
            .initial_value("s")
            .dispatch_action_config(DispatchActionConfig::new())
            .focus_on_load(true)
            .placeholder(TextObject::from(PlainText::new("s"))),
        r#"{"type": "url_text_input", "action_id": "s", "initial_value": "s", "dispatch_action_config": {}, "focus_on_load": true, "placeholder": {"type": "plain_text", "text": "s"}}"#,
    );
}

#[test]
fn workflow_button_element() {
    assert_json(
        &WorkflowButtonElement::new(
            TextObject::from(PlainText::new("s")),
            Workflow::new(Trigger::new("s")),
            "s",
        ),
        r#"{"type": "workflow_button", "text": {"type": "plain_text", "text": "s"}, "workflow": {"trigger": {"url": "s"}}, "action_id": "s"}"#,
    );
    assert_json(
        &WorkflowButtonElement::new(
            TextObject::from(PlainText::new("s")),
            Workflow::new(Trigger::new("s")),
            "s",
        )
        .style(ButtonStyle::Primary)
        .accessibility_label("s"),
        r#"{"type": "workflow_button", "text": {"type": "plain_text", "text": "s"}, "workflow": {"trigger": {"url": "s"}}, "action_id": "s", "style": "primary", "accessibility_label": "s"}"#,
    );
}

#[test]
fn url_source_element() {
    assert_json(
        &UrlSourceElement::new("s", "s"),
        r#"{"type": "url", "url": "s", "text": "s"}"#,
    );
}

#[test]
fn static_select_element() {
    assert_json(
        &StaticSelectElement::new(vec![OptionObject::new(
            TextObject::from(PlainText::new("s")),
            "s",
        )]),
        r#"{"type": "static_select", "options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}]}"#,
    );
    assert_json(
        &StaticSelectElement::new(vec![OptionObject::new(
            TextObject::from(PlainText::new("s")),
            "s",
        )])
        .action_id("s")
        .option_groups(vec![OptionGroup::new(
            TextObject::from(PlainText::new("s")),
            vec![OptionObject::new(
                TextObject::from(PlainText::new("s")),
                "s",
            )],
        )])
        .initial_option(OptionObject::new(
            TextObject::from(PlainText::new("s")),
            "s",
        ))
        .confirm(ConfirmationDialog::new(
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
        ))
        .focus_on_load(true)
        .placeholder(TextObject::from(PlainText::new("s"))),
        r#"{"type": "static_select", "options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}], "action_id": "s", "option_groups": [{"label": {"type": "plain_text", "text": "s"}, "options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}]}], "initial_option": {"text": {"type": "plain_text", "text": "s"}, "value": "s"}, "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "focus_on_load": true, "placeholder": {"type": "plain_text", "text": "s"}}"#,
    );
}

#[test]
fn external_select_element() {
    assert_json(
        &ExternalSelectElement::new(),
        r#"{"type": "external_select"}"#,
    );
    assert_json(
        &ExternalSelectElement::new()
            .action_id("s")
            .initial_option(OptionObject::new(
                TextObject::from(PlainText::new("s")),
                "s",
            ))
            .min_query_length(1)
            .confirm(ConfirmationDialog::new(
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
            ))
            .focus_on_load(true)
            .placeholder(TextObject::from(PlainText::new("s"))),
        r#"{"type": "external_select", "action_id": "s", "initial_option": {"text": {"type": "plain_text", "text": "s"}, "value": "s"}, "min_query_length": 1, "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "focus_on_load": true, "placeholder": {"type": "plain_text", "text": "s"}}"#,
    );
}

#[test]
fn users_select_element() {
    assert_json(&UsersSelectElement::new(), r#"{"type": "users_select"}"#);
    assert_json(
        &UsersSelectElement::new()
            .action_id("s")
            .initial_user("s")
            .confirm(ConfirmationDialog::new(
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
            ))
            .focus_on_load(true)
            .placeholder(TextObject::from(PlainText::new("s"))),
        r#"{"type": "users_select", "action_id": "s", "initial_user": "s", "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "focus_on_load": true, "placeholder": {"type": "plain_text", "text": "s"}}"#,
    );
}

#[test]
fn conversations_select_element() {
    assert_json(
        &ConversationsSelectElement::new(),
        r#"{"type": "conversations_select"}"#,
    );
    assert_json(
        &ConversationsSelectElement::new()
            .action_id("s")
            .initial_conversation("s")
            .default_to_current_conversation(true)
            .confirm(ConfirmationDialog::new(
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
            ))
            .response_url_enabled(true)
            .filter(ConversationFilter::new())
            .focus_on_load(true)
            .placeholder(TextObject::from(PlainText::new("s"))),
        r#"{"type": "conversations_select", "action_id": "s", "initial_conversation": "s", "default_to_current_conversation": true, "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "response_url_enabled": true, "filter": {}, "focus_on_load": true, "placeholder": {"type": "plain_text", "text": "s"}}"#,
    );
}

#[test]
fn channels_select_element() {
    assert_json(
        &ChannelsSelectElement::new(),
        r#"{"type": "channels_select"}"#,
    );
    assert_json(
        &ChannelsSelectElement::new()
            .action_id("s")
            .initial_channel("s")
            .confirm(ConfirmationDialog::new(
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
            ))
            .response_url_enabled(true)
            .focus_on_load(true)
            .placeholder(TextObject::from(PlainText::new("s"))),
        r#"{"type": "channels_select", "action_id": "s", "initial_channel": "s", "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "response_url_enabled": true, "focus_on_load": true, "placeholder": {"type": "plain_text", "text": "s"}}"#,
    );
}

#[test]
fn multi_static_select_element() {
    assert_json(
        &MultiStaticSelectElement::new(vec![OptionObject::new(
            TextObject::from(PlainText::new("s")),
            "s",
        )]),
        r#"{"type": "multi_static_select", "options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}]}"#,
    );
    assert_json(
        &MultiStaticSelectElement::new(vec![OptionObject::new(
            TextObject::from(PlainText::new("s")),
            "s",
        )])
        .action_id("s")
        .option_groups(vec![OptionGroup::new(
            TextObject::from(PlainText::new("s")),
            vec![OptionObject::new(
                TextObject::from(PlainText::new("s")),
                "s",
            )],
        )])
        .initial_options(vec![OptionObject::new(
            TextObject::from(PlainText::new("s")),
            "s",
        )])
        .confirm(ConfirmationDialog::new(
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
            TextObject::from(PlainText::new("s")),
        ))
        .max_selected_items(1)
        .focus_on_load(true)
        .placeholder(TextObject::from(PlainText::new("s"))),
        r#"{"type": "multi_static_select", "options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}], "action_id": "s", "option_groups": [{"label": {"type": "plain_text", "text": "s"}, "options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}]}], "initial_options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}], "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "max_selected_items": 1, "focus_on_load": true, "placeholder": {"type": "plain_text", "text": "s"}}"#,
    );
}

#[test]
fn multi_external_select_element() {
    assert_json(
        &MultiExternalSelectElement::new(),
        r#"{"type": "multi_external_select"}"#,
    );
    assert_json(
        &MultiExternalSelectElement::new()
            .action_id("s")
            .min_query_length(1)
            .initial_options(vec![OptionObject::new(
                TextObject::from(PlainText::new("s")),
                "s",
            )])
            .confirm(ConfirmationDialog::new(
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
            ))
            .max_selected_items(1)
            .placeholder(TextObject::from(PlainText::new("s"))),
        r#"{"type": "multi_external_select", "action_id": "s", "min_query_length": 1, "initial_options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}], "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "max_selected_items": 1, "placeholder": {"type": "plain_text", "text": "s"}}"#,
    );
}

#[test]
fn multi_users_select_element() {
    assert_json(
        &MultiUsersSelectElement::new(),
        r#"{"type": "multi_users_select"}"#,
    );
    assert_json(
        &MultiUsersSelectElement::new()
            .action_id("s")
            .initial_users(vec!["s".to_string()])
            .confirm(ConfirmationDialog::new(
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
            ))
            .max_selected_items(1)
            .focus_on_load(true)
            .placeholder(TextObject::from(PlainText::new("s"))),
        r#"{"type": "multi_users_select", "action_id": "s", "initial_users": ["s"], "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "max_selected_items": 1, "focus_on_load": true, "placeholder": {"type": "plain_text", "text": "s"}}"#,
    );
}

#[test]
fn multi_conversations_select_element() {
    assert_json(
        &MultiConversationsSelectElement::new(),
        r#"{"type": "multi_conversations_select"}"#,
    );
    assert_json(
        &MultiConversationsSelectElement::new()
            .action_id("s")
            .initial_conversations(vec!["s".to_string()])
            .default_to_current_conversation(true)
            .confirm(ConfirmationDialog::new(
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
            ))
            .max_selected_items(1)
            .filter(ConversationFilter::new())
            .focus_on_load(true)
            .placeholder(TextObject::from(PlainText::new("s"))),
        r#"{"type": "multi_conversations_select", "action_id": "s", "initial_conversations": ["s"], "default_to_current_conversation": true, "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "max_selected_items": 1, "filter": {}, "focus_on_load": true, "placeholder": {"type": "plain_text", "text": "s"}}"#,
    );
}

#[test]
fn multi_channels_select_element() {
    assert_json(
        &MultiChannelsSelectElement::new(),
        r#"{"type": "multi_channels_select"}"#,
    );
    assert_json(
        &MultiChannelsSelectElement::new()
            .action_id("s")
            .initial_channels(vec!["s".to_string()])
            .confirm(ConfirmationDialog::new(
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
                TextObject::from(PlainText::new("s")),
            ))
            .max_selected_items(1)
            .focus_on_load(true)
            .placeholder(TextObject::from(PlainText::new("s"))),
        r#"{"type": "multi_channels_select", "action_id": "s", "initial_channels": ["s"], "confirm": {"title": {"type": "plain_text", "text": "s"}, "text": {"type": "plain_text", "text": "s"}, "confirm": {"type": "plain_text", "text": "s"}, "deny": {"type": "plain_text", "text": "s"}}, "max_selected_items": 1, "focus_on_load": true, "placeholder": {"type": "plain_text", "text": "s"}}"#,
    );
}

#[test]
fn rich_text_block() {
    assert_json(
        &RichTextBlock::new(vec![RichTextObject::from(RichTextSection::new(vec![
            RichTextElement::from(AttachmentMentionElement::new("s")),
        ]))]),
        r#"{"type": "rich_text", "elements": [{"type": "rich_text_section", "elements": [{"type": "attachment_mention", "url": "s"}]}]}"#,
    );
    assert_json(
        &RichTextBlock::new(vec![RichTextObject::from(RichTextSection::new(vec![
            RichTextElement::from(AttachmentMentionElement::new("s")),
        ]))])
        .block_id("s"),
        r#"{"type": "rich_text", "elements": [{"type": "rich_text_section", "elements": [{"type": "attachment_mention", "url": "s"}]}], "block_id": "s"}"#,
    );
}

#[test]
fn rich_text_section() {
    assert_json(
        &RichTextSection::new(vec![RichTextElement::from(AttachmentMentionElement::new(
            "s",
        ))]),
        r#"{"type": "rich_text_section", "elements": [{"type": "attachment_mention", "url": "s"}]}"#,
    );
}

#[test]
fn rich_text_list() {
    assert_json(
        &RichTextList::new(
            RichTextListStyle::Bullet,
            vec![RichTextSection::new(vec![RichTextElement::from(
                AttachmentMentionElement::new("s"),
            )])],
        ),
        r#"{"type": "rich_text_list", "style": "bullet", "elements": [{"type": "rich_text_section", "elements": [{"type": "attachment_mention", "url": "s"}]}]}"#,
    );
    assert_json(
        &RichTextList::new(
            RichTextListStyle::Bullet,
            vec![RichTextSection::new(vec![RichTextElement::from(
                AttachmentMentionElement::new("s"),
            )])],
        )
        .indent(1)
        .offset(1)
        .border(1),
        r#"{"type": "rich_text_list", "style": "bullet", "elements": [{"type": "rich_text_section", "elements": [{"type": "attachment_mention", "url": "s"}]}], "indent": 1, "offset": 1, "border": 1}"#,
    );
}

#[test]
fn rich_text_preformatted() {
    assert_json(
        &RichTextPreformatted::new(vec![PreformattedElement::from(TextElement::new("s"))]),
        r#"{"type": "rich_text_preformatted", "elements": [{"type": "text", "text": "s"}]}"#,
    );
    assert_json(
        &RichTextPreformatted::new(vec![PreformattedElement::from(TextElement::new("s"))])
            .border(1)
            .language("s"),
        r#"{"type": "rich_text_preformatted", "elements": [{"type": "text", "text": "s"}], "border": 1, "language": "s"}"#,
    );
}

#[test]
fn rich_text_quote() {
    assert_json(
        &RichTextQuote::new(vec![RichTextElement::from(AttachmentMentionElement::new(
            "s",
        ))]),
        r#"{"type": "rich_text_quote", "elements": [{"type": "attachment_mention", "url": "s"}]}"#,
    );
    assert_json(
        &RichTextQuote::new(vec![RichTextElement::from(AttachmentMentionElement::new(
            "s",
        ))])
        .border(1),
        r#"{"type": "rich_text_quote", "elements": [{"type": "attachment_mention", "url": "s"}], "border": 1}"#,
    );
}

#[test]
fn rich_text_style() {
    assert_json(&RichTextStyle::new(), r#"{}"#);
    assert_json(
        &RichTextStyle::new()
            .bold(true)
            .italic(true)
            .strike(true)
            .highlight(true)
            .client_highlight(true)
            .underline(true)
            .unlink(true)
            .code(true),
        r#"{"bold": true, "italic": true, "strike": true, "highlight": true, "client_highlight": true, "underline": true, "unlink": true, "code": true}"#,
    );
}

#[test]
fn attachment_mention_element() {
    assert_json(
        &AttachmentMentionElement::new("s"),
        r#"{"type": "attachment_mention", "url": "s"}"#,
    );
    assert_json(
        &AttachmentMentionElement::new("s")
            .text("s")
            .app_id("s")
            .entity_id("s")
            .icon_url("s")
            .channel_id("s")
            .ts("s")
            .full_size_preview_enabled(true)
            .icon_name("s")
            .reference_object_type("s")
            .product_name("s")
            .style(RichTextStyle::new()),
        r#"{"type": "attachment_mention", "url": "s", "text": "s", "app_id": "s", "entity_id": "s", "icon_url": "s", "channel_id": "s", "ts": "s", "full_size_preview_enabled": true, "icon_name": "s", "reference_object_type": "s", "product_name": "s", "style": {}}"#,
    );
}

#[test]
fn broadcast_element() {
    assert_json(
        &BroadcastElement::new(BroadcastRange::Here),
        r#"{"type": "broadcast", "range": "here"}"#,
    );
    assert_json(
        &BroadcastElement::new(BroadcastRange::Here).style(RichTextStyle::new()),
        r#"{"type": "broadcast", "range": "here", "style": {}}"#,
    );
}

#[test]
fn canvas_element() {
    assert_json(
        &CanvasElement::new("s"),
        r#"{"type": "canvas", "file_id": "s"}"#,
    );
    assert_json(
        &CanvasElement::new("s")
            .label("s")
            .hide_title(true)
            .section_id("s")
            .style(RichTextStyle::new())
            .text("s")
            .url("s")
            .is_skill_invocation(true),
        r#"{"type": "canvas", "file_id": "s", "label": "s", "hide_title": true, "section_id": "s", "style": {}, "text": "s", "url": "s", "is_skill_invocation": true}"#,
    );
}

#[test]
fn canvas_user_mention_element() {
    assert_json(
        &CanvasUserMentionElement::new("s"),
        r#"{"type": "canvas_user_mention", "user_id": "s"}"#,
    );
    assert_json(
        &CanvasUserMentionElement::new("s")
            .thread_id("s")
            .style(RichTextStyle::new()),
        r#"{"type": "canvas_user_mention", "user_id": "s", "thread_id": "s", "style": {}}"#,
    );
}

#[test]
fn canvas_message_unfurl_element() {
    assert_json(
        &CanvasMessageUnfurlElement::new("s", "s"),
        r#"{"type": "canvas_message_unfurl", "root_message_ts": "s", "root_message_channel": "s"}"#,
    );
    assert_json(
        &CanvasMessageUnfurlElement::new("s", "s").style(RichTextStyle::new()),
        r#"{"type": "canvas_message_unfurl", "root_message_ts": "s", "root_message_channel": "s", "style": {}}"#,
    );
}

#[test]
fn channel_element() {
    assert_json(
        &ChannelElement::new("s"),
        r#"{"type": "channel", "channel_id": "s"}"#,
    );
    assert_json(
        &ChannelElement::new("s")
            .tab_id("s")
            .style(RichTextStyle::new())
            .from_llm(true),
        r#"{"type": "channel", "channel_id": "s", "tab_id": "s", "style": {}, "from_llm": true}"#,
    );
}

#[test]
fn citation_element() {
    assert_json(
        &CitationElement::new("s", "s", 1, CitationDetails::from(FileCitation::new())),
        r#"{"type": "citation", "url": "s", "text": "s", "index": 1, "details": {"citation_type": "file"}}"#,
    );
    assert_json(
        &CitationElement::new("s", "s", 1, CitationDetails::from(FileCitation::new()))
            .from_llm(true)
            .is_slack_url(true),
        r#"{"type": "citation", "url": "s", "text": "s", "index": 1, "details": {"citation_type": "file"}, "from_llm": true, "is_slack_url": true}"#,
    );
}

#[test]
fn file_citation() {
    assert_json(&FileCitation::new(), r#"{"citation_type": "file"}"#);
    assert_json(
        &FileCitation::new().descriptor("s").file_id("s"),
        r#"{"citation_type": "file", "descriptor": "s", "file_id": "s"}"#,
    );
}

#[test]
fn external_citation() {
    assert_json(&ExternalCitation::new(), r#"{"citation_type": "external"}"#);
    assert_json(
        &ExternalCitation::new().app_name("s").app_icon_url("s"),
        r#"{"citation_type": "external", "app_name": "s", "app_icon_url": "s"}"#,
    );
}

#[test]
fn web_citation() {
    assert_json(&WebCitation::new(), r#"{"citation_type": "web"}"#);
    assert_json(
        &WebCitation::new().display_name("s").title("s").snippet("s"),
        r#"{"citation_type": "web", "display_name": "s", "title": "s", "snippet": "s"}"#,
    );
}

#[test]
fn message_citation() {
    assert_json(&MessageCitation::new(), r#"{"citation_type": "message"}"#);
    assert_json(
        &MessageCitation::new().channel("s").message_ts("s"),
        r#"{"citation_type": "message", "channel": "s", "message_ts": "s"}"#,
    );
}

#[test]
fn memory_citation() {
    assert_json(&MemoryCitation::new(), r#"{"citation_type": "memory"}"#);
    assert_json(
        &MemoryCitation::new().memory_id("s"),
        r#"{"citation_type": "memory", "memory_id": "s"}"#,
    );
}

#[test]
fn color_element() {
    assert_json(
        &ColorElement::new("s"),
        r#"{"type": "color", "value": "s"}"#,
    );
    assert_json(
        &ColorElement::new("s").style(RichTextStyle::new()),
        r#"{"type": "color", "value": "s", "style": {}}"#,
    );
}

#[test]
fn date_element() {
    assert_json(
        &DateElement::new(1, "s"),
        r#"{"type": "date", "timestamp": 1, "format": "s"}"#,
    );
    assert_json(
        &DateElement::new(1, "s")
            .timezone("s")
            .url("s")
            .fallback("s")
            .style(RichTextStyle::new()),
        r#"{"type": "date", "timestamp": 1, "format": "s", "timezone": "s", "url": "s", "fallback": "s", "style": {}}"#,
    );
}

#[test]
fn emoji_element() {
    assert_json(&EmojiElement::new("s"), r#"{"type": "emoji", "name": "s"}"#);
    assert_json(
        &EmojiElement::new("s").unicode("s"),
        r#"{"type": "emoji", "name": "s", "unicode": "s"}"#,
    );
}

#[test]
fn file_element() {
    assert_json(
        &FileElement::new("s"),
        r#"{"type": "file", "file_id": "s"}"#,
    );
    assert_json(
        &FileElement::new("s")
            .style(RichTextStyle::new())
            .text("s")
            .url("s")
            .is_skill_invocation(true),
        r#"{"type": "file", "file_id": "s", "style": {}, "text": "s", "url": "s", "is_skill_invocation": true}"#,
    );
}

#[test]
fn link_element() {
    assert_json(&LinkElement::new("s"), r#"{"type": "link", "url": "s"}"#);
    assert_json(
        &LinkElement::new("s")
            .text("s")
            .r#unsafe(true)
            .from_llm(true)
            .is_slack_url(true)
            .truncated(true)
            .style(RichTextStyle::new()),
        r#"{"type": "link", "url": "s", "text": "s", "unsafe": true, "from_llm": true, "is_slack_url": true, "truncated": true, "style": {}}"#,
    );
}

#[test]
fn list_record_element() {
    assert_json(
        &ListRecordElement::new("s"),
        r#"{"type": "list_record", "file_id": "s"}"#,
    );
    assert_json(
        &ListRecordElement::new("s")
            .record_id("s")
            .view_id("s")
            .style(RichTextStyle::new())
            .text("s")
            .url("s"),
        r#"{"type": "list_record", "file_id": "s", "record_id": "s", "view_id": "s", "style": {}, "text": "s", "url": "s"}"#,
    );
}

#[test]
fn message_mention_element() {
    assert_json(
        &MessageMentionElement::new("s", "s"),
        r#"{"type": "message_mention", "channel_id": "s", "message_ts": "s"}"#,
    );
    assert_json(
        &MessageMentionElement::new("s", "s")
            .author_id("s")
            .thread_ts("s")
            .style(RichTextStyle::new())
            .text("s")
            .url("s"),
        r#"{"type": "message_mention", "channel_id": "s", "message_ts": "s", "author_id": "s", "thread_ts": "s", "style": {}, "text": "s", "url": "s"}"#,
    );
}

#[test]
fn salesforce_data_field_element() {
    assert_json(
        &SalesforceDataFieldElement::new("s"),
        r#"{"type": "salesforce_data_field", "salesforce_record_id": "s"}"#,
    );
    assert_json(
        &SalesforceDataFieldElement::new("s")
            .salesforce_field_label("s")
            .salesforce_field_api_name("s")
            .salesforce_include_field_label(true)
            .style(RichTextStyle::new()),
        r#"{"type": "salesforce_data_field", "salesforce_record_id": "s", "salesforce_field_label": "s", "salesforce_field_api_name": "s", "salesforce_include_field_label": true, "style": {}}"#,
    );
}

#[test]
fn tag_element() {
    assert_json(&TagElement::new("s"), r#"{"type": "tag", "text": "s"}"#);
    assert_json(
        &TagElement::new("s")
            .color(TagColor::Gray)
            .style(RichTextStyle::new()),
        r#"{"type": "tag", "text": "s", "color": "gray", "style": {}}"#,
    );
}

#[test]
fn team_element() {
    assert_json(
        &TeamElement::new("s"),
        r#"{"type": "team", "team_id": "s"}"#,
    );
    assert_json(
        &TeamElement::new("s").style(RichTextStyle::new()),
        r#"{"type": "team", "team_id": "s", "style": {}}"#,
    );
}

#[test]
fn text_element() {
    assert_json(&TextElement::new("s"), r#"{"type": "text", "text": "s"}"#);
    assert_json(
        &TextElement::new("s").style(RichTextStyle::new()),
        r#"{"type": "text", "text": "s", "style": {}}"#,
    );
}

#[test]
fn user_element() {
    assert_json(
        &UserElement::new("s"),
        r#"{"type": "user", "user_id": "s"}"#,
    );
    assert_json(
        &UserElement::new("s")
            .style(RichTextStyle::new())
            .from_llm(true),
        r#"{"type": "user", "user_id": "s", "style": {}, "from_llm": true}"#,
    );
}

#[test]
fn usergroup_element() {
    assert_json(
        &UsergroupElement::new("s"),
        r#"{"type": "usergroup", "usergroup_id": "s"}"#,
    );
    assert_json(
        &UsergroupElement::new("s").style(RichTextStyle::new()),
        r#"{"type": "usergroup", "usergroup_id": "s", "style": {}}"#,
    );
}

#[test]
fn work_object_mention_element() {
    assert_json(
        &WorkObjectMentionElement::new("s", "s", "s", "s"),
        r#"{"type": "work_object_mention", "entity_id": "s", "app_id": "s", "text": "s", "url": "s"}"#,
    );
    assert_json(
        &WorkObjectMentionElement::new("s", "s", "s", "s")
            .icon_url("s")
            .full_size_preview_enabled(true)
            .product_name("s")
            .style(RichTextStyle::new()),
        r#"{"type": "work_object_mention", "entity_id": "s", "app_id": "s", "text": "s", "url": "s", "icon_url": "s", "full_size_preview_enabled": true, "product_name": "s", "style": {}}"#,
    );
}

#[test]
fn workflow_mention_element() {
    assert_json(
        &WorkflowMentionElement::new("s", "s", "s"),
        r#"{"type": "workflow_mention", "workflow_id": "s", "function_trigger_id": "s", "text": "s"}"#,
    );
    assert_json(
        &WorkflowMentionElement::new("s", "s", "s")
            .url("s")
            .channel_id("s")
            .ts("s")
            .style(RichTextStyle::new()),
        r#"{"type": "workflow_mention", "workflow_id": "s", "function_trigger_id": "s", "text": "s", "url": "s", "channel_id": "s", "ts": "s", "style": {}}"#,
    );
}

#[test]
fn actions_block() {
    assert_json(
        &ActionsBlock::new(vec![ActionsElement::from(ButtonElement::new(
            TextObject::from(PlainText::new("s")),
        ))]),
        r#"{"type": "actions", "elements": [{"type": "button", "text": {"type": "plain_text", "text": "s"}}]}"#,
    );
    assert_json(
        &ActionsBlock::new(vec![ActionsElement::from(ButtonElement::new(
            TextObject::from(PlainText::new("s")),
        ))])
        .block_id("s"),
        r#"{"type": "actions", "elements": [{"type": "button", "text": {"type": "plain_text", "text": "s"}}], "block_id": "s"}"#,
    );
}

#[test]
fn alert_block() {
    assert_json(
        &AlertBlock::new(TextObject::from(PlainText::new("s"))),
        r#"{"type": "alert", "text": {"type": "plain_text", "text": "s"}}"#,
    );
    assert_json(
        &AlertBlock::new(TextObject::from(PlainText::new("s")))
            .level(AlertLevel::Default)
            .block_id("s"),
        r#"{"type": "alert", "text": {"type": "plain_text", "text": "s"}, "level": "default", "block_id": "s"}"#,
    );
}

#[test]
fn card_block() {
    assert_json(&CardBlock::new(), r#"{"type": "card"}"#);
    assert_json(
        &CardBlock::new()
            .block_id("s")
            .hero_image(ImageElement::new("s", "s"))
            .icon(ImageElement::new("s", "s"))
            .title(TextObject::from(PlainText::new("s")))
            .subtitle(TextObject::from(PlainText::new("s")))
            .body(TextObject::from(PlainText::new("s")))
            .actions(vec![ButtonElement::new(TextObject::from(PlainText::new(
                "s",
            )))])
            .slack_icon(SlackIcon::new("s"))
            .subtext(TextObject::from(PlainText::new("s"))),
        r#"{"type": "card", "block_id": "s", "hero_image": {"type": "image", "alt_text": "s", "image_url": "s"}, "icon": {"type": "image", "alt_text": "s", "image_url": "s"}, "title": {"type": "plain_text", "text": "s"}, "subtitle": {"type": "plain_text", "text": "s"}, "body": {"type": "plain_text", "text": "s"}, "actions": [{"type": "button", "text": {"type": "plain_text", "text": "s"}}], "slack_icon": {"type": "icon", "name": "s"}, "subtext": {"type": "plain_text", "text": "s"}}"#,
    );
}

#[test]
fn carousel_block() {
    assert_json(
        &CarouselBlock::new(vec![CardBlock::new()]),
        r#"{"type": "carousel", "elements": [{"type": "card"}]}"#,
    );
    assert_json(
        &CarouselBlock::new(vec![CardBlock::new()]).block_id("s"),
        r#"{"type": "carousel", "elements": [{"type": "card"}], "block_id": "s"}"#,
    );
}

#[test]
fn container_block() {
    assert_json(
        &ContainerBlock::new(
            TextObject::from(PlainText::new("s")),
            vec![Block::from(ActionsBlock::new(vec![ActionsElement::from(
                ButtonElement::new(TextObject::from(PlainText::new("s"))),
            )]))],
        ),
        r#"{"type": "container", "title": {"type": "plain_text", "text": "s"}, "child_blocks": [{"type": "actions", "elements": [{"type": "button", "text": {"type": "plain_text", "text": "s"}}]}]}"#,
    );
    assert_json(
        &ContainerBlock::new(
            TextObject::from(PlainText::new("s")),
            vec![Block::from(ActionsBlock::new(vec![ActionsElement::from(
                ButtonElement::new(TextObject::from(PlainText::new("s"))),
            )]))],
        )
        .rich_text_title(RichTextBlock::new(vec![RichTextObject::from(
            RichTextSection::new(vec![RichTextElement::from(AttachmentMentionElement::new(
                "s",
            ))]),
        )]))
        .subtitle(TextObject::from(PlainText::new("s")))
        .block_id("s")
        .width(ContainerWidth::Narrow)
        .icon(ImageElement::new("s", "s"))
        .is_collapsible(true)
        .default_collapsed(true)
        .has_header_divider(true),
        r#"{"type": "container", "title": {"type": "plain_text", "text": "s"}, "child_blocks": [{"type": "actions", "elements": [{"type": "button", "text": {"type": "plain_text", "text": "s"}}]}], "rich_text_title": {"type": "rich_text", "elements": [{"type": "rich_text_section", "elements": [{"type": "attachment_mention", "url": "s"}]}]}, "subtitle": {"type": "plain_text", "text": "s"}, "block_id": "s", "width": "narrow", "icon": {"type": "image", "alt_text": "s", "image_url": "s"}, "is_collapsible": true, "default_collapsed": true, "has_header_divider": true}"#,
    );
}

#[test]
fn context_block() {
    assert_json(
        &ContextBlock::new(vec![ContextElement::from(ImageElement::new("s", "s"))]),
        r#"{"type": "context", "elements": [{"type": "image", "alt_text": "s", "image_url": "s"}]}"#,
    );
    assert_json(
        &ContextBlock::new(vec![ContextElement::from(ImageElement::new("s", "s"))]).block_id("s"),
        r#"{"type": "context", "elements": [{"type": "image", "alt_text": "s", "image_url": "s"}], "block_id": "s"}"#,
    );
}

#[test]
fn context_actions_block() {
    assert_json(
        &ContextActionsBlock::new(vec![ContextActionsElement::from(
            FeedbackButtonsElement::new(
                FeedbackButton::new(TextObject::from(PlainText::new("s")), "s"),
                FeedbackButton::new(TextObject::from(PlainText::new("s")), "s"),
            ),
        )]),
        r#"{"type": "context_actions", "elements": [{"type": "feedback_buttons", "positive_button": {"text": {"type": "plain_text", "text": "s"}, "value": "s"}, "negative_button": {"text": {"type": "plain_text", "text": "s"}, "value": "s"}}]}"#,
    );
    assert_json(
        &ContextActionsBlock::new(vec![ContextActionsElement::from(
            FeedbackButtonsElement::new(
                FeedbackButton::new(TextObject::from(PlainText::new("s")), "s"),
                FeedbackButton::new(TextObject::from(PlainText::new("s")), "s"),
            ),
        )])
        .block_id("s"),
        r#"{"type": "context_actions", "elements": [{"type": "feedback_buttons", "positive_button": {"text": {"type": "plain_text", "text": "s"}, "value": "s"}, "negative_button": {"text": {"type": "plain_text", "text": "s"}, "value": "s"}}], "block_id": "s"}"#,
    );
}

#[test]
fn divider_block() {
    assert_json(&DividerBlock::new(), r#"{"type": "divider"}"#);
    assert_json(
        &DividerBlock::new().block_id("s"),
        r#"{"type": "divider", "block_id": "s"}"#,
    );
}

#[test]
fn file_block() {
    assert_json(
        &FileBlock::new("s", "s"),
        r#"{"type": "file", "external_id": "s", "source": "s"}"#,
    );
    assert_json(
        &FileBlock::new("s", "s").block_id("s"),
        r#"{"type": "file", "external_id": "s", "source": "s", "block_id": "s"}"#,
    );
}

#[test]
fn header_block() {
    assert_json(
        &HeaderBlock::new(TextObject::from(PlainText::new("s"))),
        r#"{"type": "header", "text": {"type": "plain_text", "text": "s"}}"#,
    );
    assert_json(
        &HeaderBlock::new(TextObject::from(PlainText::new("s")))
            .block_id("s")
            .level(1),
        r#"{"type": "header", "text": {"type": "plain_text", "text": "s"}, "block_id": "s", "level": 1}"#,
    );
}

#[test]
fn image_block() {
    assert_json(
        &ImageBlock::new("s", "s"),
        r#"{"type": "image", "alt_text": "s", "image_url": "s"}"#,
    );
    assert_json(
        &ImageBlock::new("s", "s")
            .image_url("s")
            .slack_file(SlackFile::from_id("s"))
            .title(TextObject::from(PlainText::new("s")))
            .block_id("s"),
        r#"{"type": "image", "alt_text": "s", "image_url": "s", "slack_file": {"id": "s"}, "title": {"type": "plain_text", "text": "s"}, "block_id": "s"}"#,
    );
}

#[test]
fn input_block() {
    assert_json(
        &InputBlock::new(
            TextObject::from(PlainText::new("s")),
            InputElement::from(CheckboxesElement::new(vec![OptionObject::new(
                TextObject::from(PlainText::new("s")),
                "s",
            )])),
        ),
        r#"{"type": "input", "label": {"type": "plain_text", "text": "s"}, "element": {"type": "checkboxes", "options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}]}}"#,
    );
    assert_json(
        &InputBlock::new(
            TextObject::from(PlainText::new("s")),
            InputElement::from(CheckboxesElement::new(vec![OptionObject::new(
                TextObject::from(PlainText::new("s")),
                "s",
            )])),
        )
        .dispatch_action(true)
        .block_id("s")
        .hint(TextObject::from(PlainText::new("s")))
        .optional(true),
        r#"{"type": "input", "label": {"type": "plain_text", "text": "s"}, "element": {"type": "checkboxes", "options": [{"text": {"type": "plain_text", "text": "s"}, "value": "s"}]}, "dispatch_action": true, "block_id": "s", "hint": {"type": "plain_text", "text": "s"}, "optional": true}"#,
    );
}

#[test]
fn markdown_block() {
    assert_json(
        &MarkdownBlock::new("s"),
        r#"{"type": "markdown", "text": "s"}"#,
    );
    assert_json(
        &MarkdownBlock::new("s").block_id("s"),
        r#"{"type": "markdown", "text": "s", "block_id": "s"}"#,
    );
}

#[test]
fn plan_block() {
    assert_json(
        &PlanBlock::new("s", vec![PlanTask::new("s", "s", TaskStatus::Pending)]),
        r#"{"type": "plan", "title": "s", "tasks": [{"task_id": "s", "title": "s", "status": "pending"}]}"#,
    );
    assert_json(
        &PlanBlock::new("s", vec![PlanTask::new("s", "s", TaskStatus::Pending)]).block_id("s"),
        r#"{"type": "plan", "title": "s", "tasks": [{"task_id": "s", "title": "s", "status": "pending"}], "block_id": "s"}"#,
    );
}

#[test]
fn plan_task() {
    assert_json(
        &PlanTask::new("s", "s", TaskStatus::Pending),
        r#"{"task_id": "s", "title": "s", "status": "pending"}"#,
    );
    assert_json(
        &PlanTask::new("s", "s", TaskStatus::Pending)
            .details(RichTextBlock::new(vec![RichTextObject::from(
                RichTextSection::new(vec![RichTextElement::from(AttachmentMentionElement::new(
                    "s",
                ))]),
            )]))
            .output(RichTextBlock::new(vec![RichTextObject::from(
                RichTextSection::new(vec![RichTextElement::from(AttachmentMentionElement::new(
                    "s",
                ))]),
            )]))
            .sources(vec![UrlSourceElement::new("s", "s")]),
        r#"{"task_id": "s", "title": "s", "status": "pending", "details": {"type": "rich_text", "elements": [{"type": "rich_text_section", "elements": [{"type": "attachment_mention", "url": "s"}]}]}, "output": {"type": "rich_text", "elements": [{"type": "rich_text_section", "elements": [{"type": "attachment_mention", "url": "s"}]}]}, "sources": [{"type": "url", "url": "s", "text": "s"}]}"#,
    );
}

#[test]
fn section_block() {
    assert_json(&SectionBlock::new(), r#"{"type": "section"}"#);
    assert_json(
        &SectionBlock::new()
            .text(TextObject::from(PlainText::new("s")))
            .block_id("s")
            .fields(vec![TextObject::from(PlainText::new("s"))])
            .accessory(SectionAccessory::from(ButtonElement::new(
                TextObject::from(PlainText::new("s")),
            )))
            .expand(true),
        r#"{"type": "section", "text": {"type": "plain_text", "text": "s"}, "block_id": "s", "fields": [{"type": "plain_text", "text": "s"}], "accessory": {"type": "button", "text": {"type": "plain_text", "text": "s"}}, "expand": true}"#,
    );
}

#[test]
fn task_card_block() {
    assert_json(
        &TaskCardBlock::new("s", "s", TaskStatus::Pending),
        r#"{"type": "task_card", "task_id": "s", "title": "s", "status": "pending"}"#,
    );
    assert_json(
        &TaskCardBlock::new("s", "s", TaskStatus::Pending)
            .details(RichTextBlock::new(vec![RichTextObject::from(
                RichTextSection::new(vec![RichTextElement::from(AttachmentMentionElement::new(
                    "s",
                ))]),
            )]))
            .output(RichTextBlock::new(vec![RichTextObject::from(
                RichTextSection::new(vec![RichTextElement::from(AttachmentMentionElement::new(
                    "s",
                ))]),
            )]))
            .sources(vec![UrlSourceElement::new("s", "s")])
            .block_id("s")
            .icon(SlackIcon::new("s"))
            .hide_title(true),
        r#"{"type": "task_card", "task_id": "s", "title": "s", "status": "pending", "details": {"type": "rich_text", "elements": [{"type": "rich_text_section", "elements": [{"type": "attachment_mention", "url": "s"}]}]}, "output": {"type": "rich_text", "elements": [{"type": "rich_text_section", "elements": [{"type": "attachment_mention", "url": "s"}]}]}, "sources": [{"type": "url", "url": "s", "text": "s"}], "block_id": "s", "icon": {"type": "icon", "name": "s"}, "hide_title": true}"#,
    );
}

#[test]
fn video_block() {
    assert_json(
        &VideoBlock::new("s", TextObject::from(PlainText::new("s")), "s", "s"),
        r#"{"type": "video", "alt_text": "s", "title": {"type": "plain_text", "text": "s"}, "thumbnail_url": "s", "video_url": "s"}"#,
    );
    assert_json(
        &VideoBlock::new("s", TextObject::from(PlainText::new("s")), "s", "s")
            .author_name("s")
            .block_id("s")
            .description(TextObject::from(PlainText::new("s")))
            .provider_icon_url("s")
            .provider_name("s")
            .title_url("s"),
        r#"{"type": "video", "alt_text": "s", "title": {"type": "plain_text", "text": "s"}, "thumbnail_url": "s", "video_url": "s", "author_name": "s", "block_id": "s", "description": {"type": "plain_text", "text": "s"}, "provider_icon_url": "s", "provider_name": "s", "title_url": "s"}"#,
    );
}

#[test]
fn table_block() {
    assert_json(
        &TableBlock::new(vec![vec![TableCell::from(RawTextCell::new("s"))]]),
        r#"{"type": "table", "rows": [[{"type": "raw_text", "text": "s"}]]}"#,
    );
    assert_json(
        &TableBlock::new(vec![vec![TableCell::from(RawTextCell::new("s"))]])
            .block_id("s")
            .column_settings(vec![Some(ColumnSetting::new())]),
        r#"{"type": "table", "rows": [[{"type": "raw_text", "text": "s"}]], "block_id": "s", "column_settings": [{}]}"#,
    );
}

#[test]
fn column_setting() {
    assert_json(&ColumnSetting::new(), r#"{}"#);
    assert_json(
        &ColumnSetting::new()
            .align(ColumnAlign::Left)
            .is_wrapped(true),
        r#"{"align": "left", "is_wrapped": true}"#,
    );
}

#[test]
fn data_table_block() {
    assert_json(
        &DataTableBlock::new(vec![vec![DataTableCell::from(RawTextCell::new("s"))]], "s"),
        r#"{"type": "data_table", "rows": [[{"type": "raw_text", "text": "s"}]], "caption": "s"}"#,
    );
    assert_json(
        &DataTableBlock::new(vec![vec![DataTableCell::from(RawTextCell::new("s"))]], "s")
            .block_id("s")
            .page_size(1)
            .row_header_column_index(1),
        r#"{"type": "data_table", "rows": [[{"type": "raw_text", "text": "s"}]], "caption": "s", "block_id": "s", "page_size": 1, "row_header_column_index": 1}"#,
    );
}

#[test]
fn raw_text_cell() {
    assert_json(
        &RawTextCell::new("s"),
        r#"{"type": "raw_text", "text": "s"}"#,
    );
}

#[test]
fn raw_number_cell() {
    assert_json(
        &RawNumberCell::new(1.5),
        r#"{"type": "raw_number", "value": 1.5}"#,
    );
    assert_json(
        &RawNumberCell::new(1.5).text("s"),
        r#"{"type": "raw_number", "value": 1.5, "text": "s"}"#,
    );
}

#[test]
fn action_cell() {
    assert_json(
        &ActionCell::new(ButtonElement::new(TextObject::from(PlainText::new("s")))),
        r#"{"type": "action_cell", "element": {"type": "button", "text": {"type": "plain_text", "text": "s"}}}"#,
    );
    assert_json(
        &ActionCell::new(ButtonElement::new(TextObject::from(PlainText::new("s"))))
            .fallback(ActionCellFallback::from(RawTextCell::new("s"))),
        r#"{"type": "action_cell", "element": {"type": "button", "text": {"type": "plain_text", "text": "s"}}, "fallback": {"type": "raw_text", "text": "s"}}"#,
    );
}

#[test]
fn data_visualization_block() {
    assert_json(
        &DataVisualizationBlock::new(
            "s",
            Chart::from(PieChart::new(vec![Segment::new("s", 1.5)])),
        ),
        r#"{"type": "data_visualization", "title": "s", "chart": {"type": "pie", "segments": [{"label": "s", "value": 1.5}]}}"#,
    );
    assert_json(
        &DataVisualizationBlock::new(
            "s",
            Chart::from(PieChart::new(vec![Segment::new("s", 1.5)])),
        )
        .block_id("s"),
        r#"{"type": "data_visualization", "title": "s", "chart": {"type": "pie", "segments": [{"label": "s", "value": 1.5}]}, "block_id": "s"}"#,
    );
}

#[test]
fn pie_chart() {
    assert_json(
        &PieChart::new(vec![Segment::new("s", 1.5)]),
        r#"{"type": "pie", "segments": [{"label": "s", "value": 1.5}]}"#,
    );
}

#[test]
fn bar_chart() {
    assert_json(
        &BarChart::new(
            vec![DataSeries::new("s", vec![DataPoint::new("s", 1.5)])],
            AxisConfig::new(vec!["s".to_string()]),
        ),
        r#"{"type": "bar", "series": [{"name": "s", "data": [{"label": "s", "value": 1.5}]}], "axis_config": {"categories": ["s"]}}"#,
    );
}

#[test]
fn area_chart() {
    assert_json(
        &AreaChart::new(
            vec![DataSeries::new("s", vec![DataPoint::new("s", 1.5)])],
            AxisConfig::new(vec!["s".to_string()]),
        ),
        r#"{"type": "area", "series": [{"name": "s", "data": [{"label": "s", "value": 1.5}]}], "axis_config": {"categories": ["s"]}}"#,
    );
}

#[test]
fn line_chart() {
    assert_json(
        &LineChart::new(
            vec![DataSeries::new("s", vec![DataPoint::new("s", 1.5)])],
            AxisConfig::new(vec!["s".to_string()]),
        ),
        r#"{"type": "line", "series": [{"name": "s", "data": [{"label": "s", "value": 1.5}]}], "axis_config": {"categories": ["s"]}}"#,
    );
}

#[test]
fn segment() {
    assert_json(&Segment::new("s", 1.5), r#"{"label": "s", "value": 1.5}"#);
}

#[test]
fn data_series() {
    assert_json(
        &DataSeries::new("s", vec![DataPoint::new("s", 1.5)]),
        r#"{"name": "s", "data": [{"label": "s", "value": 1.5}]}"#,
    );
}

#[test]
fn data_point() {
    assert_json(&DataPoint::new("s", 1.5), r#"{"label": "s", "value": 1.5}"#);
}

#[test]
fn axis_config() {
    assert_json(
        &AxisConfig::new(vec!["s".to_string()]),
        r#"{"categories": ["s"]}"#,
    );
    assert_json(
        &AxisConfig::new(vec!["s".to_string()])
            .x_label("s")
            .y_label("s"),
        r#"{"categories": ["s"], "x_label": "s", "y_label": "s"}"#,
    );
}

#[test]
fn attachment() {
    assert_json(&Attachment::new(), r#"{}"#);
    assert_json(
        &Attachment::new()
            .id(1)
            .fallback("s")
            .color("s")
            .pretext("s")
            .author_name("s")
            .author_link("s")
            .author_icon("s")
            .title("s")
            .title_link("s")
            .text("s")
            .fields(vec![AttachmentField::new("s", "s")])
            .image_url("s")
            .thumb_url("s")
            .thumb_width(1)
            .thumb_height(1)
            .service_name("s")
            .footer("s")
            .footer_icon("s")
            .ts(AttachmentTs::Number(1.into()))
            .mrkdwn_in(vec!["s".to_string()])
            .blocks(vec![Block::from(ActionsBlock::new(vec![
                ActionsElement::from(ButtonElement::new(TextObject::from(PlainText::new("s")))),
            ]))]),
        r#"{"id": 1, "fallback": "s", "color": "s", "pretext": "s", "author_name": "s", "author_link": "s", "author_icon": "s", "title": "s", "title_link": "s", "text": "s", "fields": [{"title": "s", "value": "s"}], "image_url": "s", "thumb_url": "s", "thumb_width": 1, "thumb_height": 1, "service_name": "s", "footer": "s", "footer_icon": "s", "ts": 1, "mrkdwn_in": ["s"], "blocks": [{"type": "actions", "elements": [{"type": "button", "text": {"type": "plain_text", "text": "s"}}]}]}"#,
    );
}

#[test]
fn attachment_field() {
    assert_json(
        &AttachmentField::new("s", "s"),
        r#"{"title": "s", "value": "s"}"#,
    );
    assert_json(
        &AttachmentField::new("s", "s").short(true),
        r#"{"title": "s", "value": "s", "short": true}"#,
    );
}

#[test]
fn view() {
    assert_json(&View::home(Vec::new()), r#"{"type": "home", "blocks": []}"#);
    assert_json(
        &View::home(Vec::new())
            .title(TextObject::from(PlainText::new("s")))
            .close(TextObject::from(PlainText::new("s")))
            .submit(TextObject::from(PlainText::new("s")))
            .private_metadata("s")
            .callback_id("s")
            .clear_on_close(true)
            .notify_on_close(true)
            .external_id("s")
            .submit_disabled(true),
        r#"{"type": "home", "blocks": [], "title": {"type": "plain_text", "text": "s"}, "close": {"type": "plain_text", "text": "s"}, "submit": {"type": "plain_text", "text": "s"}, "private_metadata": "s", "callback_id": "s", "clear_on_close": true, "notify_on_close": true, "external_id": "s", "submit_disabled": true}"#,
    );
}