@@ -219,6 +219,7 @@ class RichTextBlockTest {
219
219
fun richTextObjects () {
220
220
val blocks = withBlocks {
221
221
richText {
222
+ blockId(" rich-text-block" )
222
223
richTextList {
223
224
style(ListStyle .BULLET )
224
225
indent(0 )
@@ -233,9 +234,7 @@ class RichTextBlockTest {
233
234
broadcast(BroadcastRange .EVERYONE )
234
235
}
235
236
}
236
- }
237
237
238
- richText {
239
238
richTextList {
240
239
style(ListStyle .BULLET )
241
240
indent(1 )
@@ -244,9 +243,7 @@ class RichTextBlockTest {
244
243
color(" #C0FFEE" )
245
244
}
246
245
}
247
- }
248
246
249
- richText {
250
247
richTextList {
251
248
style(ListStyle .ORDERED )
252
249
indent(0 )
@@ -259,25 +256,23 @@ class RichTextBlockTest {
259
256
LimitedTextStyle .builder().bold(true ).italic(true ).clientHighlight(true ).build())
260
257
}
261
258
}
262
- }
263
259
264
- richText {
265
- richTextSection {
266
- date(1720710212 , " {date_num} at {time}" , fallback = " timey" )
260
+ richTextList {
261
+ style(ListStyle .BULLET )
262
+ offset(0 )
263
+ richTextSection {
264
+ date(1720710212 , " {date_num} at {time}" , fallback = " timey" )
265
+ }
267
266
}
268
- }
269
267
270
- richText {
271
268
richTextSection {
272
269
emoji(" basketball" )
273
270
text(" " )
274
271
emoji(" snowboarder" )
275
272
text(" " )
276
273
emoji(" checkered_flag" )
277
274
}
278
- }
279
275
280
- richText {
281
276
richTextQuote {
282
277
border(1 )
283
278
link(" https://api.slack.com" )
@@ -289,25 +284,27 @@ class RichTextBlockTest {
289
284
link(" https://api.slack.com" , " Slack API" ,
290
285
style = TextStyle .builder().strike(true ).code(true ).clientHighlight(true ).build())
291
286
}
292
- }
293
287
294
- richText {
295
288
richTextSection {
296
289
user(" U12345678" )
297
290
}
298
- }
299
291
300
- richText {
301
292
richTextSection {
302
293
usergroup(" S0123456789" )
303
294
}
295
+
296
+ richTextPreformatted {
297
+ border(1 )
298
+ text(" preformatted" )
299
+ }
304
300
}
305
301
}
306
302
val original = """
307
303
{
308
304
"blocks": [
309
305
{
310
306
"type": "rich_text",
307
+ "block_id": "rich-text-block",
311
308
"elements": [
312
309
{
313
310
"type": "rich_text_list",
@@ -343,12 +340,7 @@ class RichTextBlockTest {
343
340
"style": "bullet",
344
341
"indent": 0,
345
342
"border": 0
346
- }
347
- ]
348
- },
349
- {
350
- "type": "rich_text",
351
- "elements": [
343
+ },
352
344
{
353
345
"type": "rich_text_list",
354
346
"elements": [
@@ -365,12 +357,7 @@ class RichTextBlockTest {
365
357
"style": "bullet",
366
358
"indent": 1,
367
359
"border": 0
368
- }
369
- ]
370
- },
371
- {
372
- "type": "rich_text",
373
- "elements": [
360
+ },
374
361
{
375
362
"type": "rich_text_list",
376
363
"elements": [
@@ -404,28 +391,25 @@ class RichTextBlockTest {
404
391
"style": "ordered",
405
392
"indent": 0,
406
393
"border": 1
407
- }
408
- ]
409
- },
410
- {
411
- "type": "rich_text",
412
- "elements": [
394
+ },
413
395
{
414
- "type": "rich_text_section ",
396
+ "type": "rich_text_list ",
415
397
"elements": [
416
398
{
417
- "type": "date",
418
- "timestamp": 1720710212,
419
- "format": "{date_num} at {time}",
420
- "fallback": "timey"
399
+ "type": "rich_text_section",
400
+ "elements": [
401
+ {
402
+ "type": "date",
403
+ "timestamp": 1720710212,
404
+ "format": "{date_num} at {time}",
405
+ "fallback": "timey"
406
+ }
407
+ ]
421
408
}
422
- ]
423
- }
424
- ]
425
- },
426
- {
427
- "type": "rich_text",
428
- "elements": [
409
+ ],
410
+ "style": "bullet",
411
+ "offset": 0
412
+ },
429
413
{
430
414
"type": "rich_text_section",
431
415
"elements": [
@@ -450,12 +434,7 @@ class RichTextBlockTest {
450
434
"name": "checkered_flag"
451
435
}
452
436
]
453
- }
454
- ]
455
- },
456
- {
457
- "type": "rich_text",
458
- "elements": [
437
+ },
459
438
{
460
439
"type": "rich_text_quote",
461
440
"elements": [
@@ -501,12 +480,7 @@ class RichTextBlockTest {
501
480
}
502
481
],
503
482
"border": 1
504
- }
505
- ]
506
- },
507
- {
508
- "type": "rich_text",
509
- "elements": [
483
+ },
510
484
{
511
485
"type": "rich_text_section",
512
486
"elements": [
@@ -515,12 +489,7 @@ class RichTextBlockTest {
515
489
"user_id": "U12345678"
516
490
}
517
491
]
518
- }
519
- ]
520
- },
521
- {
522
- "type": "rich_text",
523
- "elements": [
492
+ },
524
493
{
525
494
"type": "rich_text_section",
526
495
"elements": [
@@ -529,6 +498,16 @@ class RichTextBlockTest {
529
498
"usergroup_id": "S0123456789"
530
499
}
531
500
]
501
+ },
502
+ {
503
+ "type": "rich_text_preformatted",
504
+ "elements": [
505
+ {
506
+ "type": "text",
507
+ "text": "preformatted"
508
+ }
509
+ ],
510
+ "border": 1
532
511
}
533
512
]
534
513
}
@@ -541,4 +520,61 @@ class RichTextBlockTest {
541
520
assertEquals(expected, actual, " \n " + expected.toString() + " \n " + actual.toString())
542
521
}
543
522
523
+ @Test
524
+ fun dslWithElements () {
525
+ val blocksWithElements = withBlocks {
526
+ richText {
527
+ elements {
528
+ richTextSection {
529
+ elements {
530
+ text(" section" )
531
+ }
532
+ }
533
+ richTextList {
534
+ style(ListStyle .BULLET )
535
+ elements {
536
+ richTextSection {
537
+ elements {
538
+ text(" list" )
539
+ }
540
+ }
541
+ }
542
+ }
543
+ richTextPreformatted {
544
+ elements {
545
+ text(" preformatted" )
546
+ }
547
+ }
548
+ richTextQuote {
549
+ elements {
550
+ text(" quote" )
551
+ }
552
+ }
553
+ }
554
+ }
555
+ }
556
+ val original = withBlocks {
557
+ richText {
558
+ richTextSection {
559
+ text(" section" )
560
+ }
561
+ richTextList {
562
+ style(ListStyle .BULLET )
563
+ richTextSection {
564
+ text(" list" )
565
+ }
566
+ }
567
+ richTextPreformatted {
568
+ text(" preformatted" )
569
+ }
570
+ richTextQuote {
571
+ text(" quote" )
572
+ }
573
+ }
574
+ }
575
+ val expected = gson.toJsonTree(original)
576
+ val actual = gson.toJsonTree(blocksWithElements)
577
+ assertEquals(expected, actual, " \n " + expected.toString() + " \n " + actual.toString())
578
+ }
579
+
544
580
}
0 commit comments