11package test_locally.block
22
33import com.google.gson.JsonElement
4+ import com.slack.api.model.kotlin_extension.block.element.ButtonStyle
45import com.slack.api.model.kotlin_extension.block.withBlocks
56import com.slack.api.util.json.GsonFactory
67import org.junit.Test
@@ -12,7 +13,7 @@ class HomeTemplateTest {
1213 val gson = GsonFactory .createSnakeCase()
1314
1415 @Test
15- fun projetTracker () {
16+ fun projectTracker () {
1617 val blocks = withBlocks {
1718 section {
1819 markdownText(" *Here's what you can do with Project Tracker:*" )
@@ -196,4 +197,380 @@ class HomeTemplateTest {
196197 assertEquals(expected, actual, " \n " + expected.toString() + " \n " + actual.toString())
197198 }
198199
200+ @Test
201+ fun calendar () {
202+ val blocks = withBlocks {
203+ section {
204+ markdownText(" *Today, 22 October*" )
205+ accessory {
206+ button {
207+ text(" Manage App Settings" , emoji = true )
208+ value(" settings" )
209+ }
210+ }
211+ }
212+ actions {
213+ elements {
214+ datePicker {
215+ initialDate(" 2019-10-22" )
216+ placeholder(" Select a date" , emoji = true )
217+ }
218+ }
219+ }
220+ divider()
221+ section {
222+ markdownText(" *<fakelink.toUrl.com|Marketing weekly sync>*\n 11:30am — 12:30pm | SF500 · 7F · Saturn (5)\n Status: ✅ Going" )
223+ accessory {
224+ overflowMenu {
225+ options {
226+ option {
227+ plainText(" View Event Details" , emoji = true )
228+ value(" view_event_details" )
229+ }
230+ option {
231+ plainText(" Change Response" , emoji = true )
232+ value(" change_response" )
233+ }
234+ }
235+ }
236+ }
237+ }
238+ actions {
239+ elements {
240+ button {
241+ text(" Join Video Call" , emoji = true )
242+ style(ButtonStyle .PRIMARY )
243+ value(" join" )
244+ }
245+ }
246+ }
247+ divider()
248+ section {
249+ markdownText(" *<fakelink.toUrl.com|Design review w/ Platform leads>*\n 1:30pm — 2:00pm | SF500 · 4F · Finch (4)" )
250+ accessory {
251+ overflowMenu {
252+ options {
253+ option {
254+ plainText(" View Event Details" , emoji = true )
255+ value(" view_event_details" )
256+ }
257+ option {
258+ plainText(" Change Response" , emoji = true )
259+ value(" change_response" )
260+ }
261+ }
262+ }
263+ }
264+ }
265+ actions {
266+ elements {
267+ staticSelect {
268+ placeholder(" Going?" , emoji = true )
269+ options {
270+ option {
271+ plainText(" Going" , emoji = true )
272+ value(" going" )
273+ }
274+ option {
275+ plainText(" Maybe" , emoji = true )
276+ value(" maybe" )
277+ }
278+ option {
279+ plainText(" Not going" , emoji = true )
280+ value(" decline" )
281+ }
282+ }
283+ }
284+ }
285+ }
286+ divider()
287+ section {
288+ markdownText(" *<fakelink.toUrl.com|Presentation write-up>*\n 4:00pm — 5:30pm | SF500 · 7F · Saturn (5)\n Status: ✅ Going" )
289+ accessory {
290+ overflowMenu {
291+ options {
292+ option {
293+ plainText(" View Event Details" , emoji = true )
294+ value(" view_event_details" )
295+ }
296+ option {
297+ plainText(" Change Response" , emoji = true )
298+ value(" change_response" )
299+ }
300+ }
301+ }
302+ }
303+ }
304+ actions {
305+ elements {
306+ button {
307+ text(" Join Video Call" , emoji = true )
308+ style(ButtonStyle .PRIMARY )
309+ value(" join" )
310+ }
311+ }
312+ }
313+ divider()
314+ context {
315+ elements {
316+ image(" https://api.slack.com/img/blocks/bkb_template_images/placeholder.png" , altText = " placeholder" )
317+ }
318+ }
319+ context {
320+ elements {
321+ markdownText(" Past events" )
322+ }
323+ }
324+ section {
325+ markdownText(" *Marketing team breakfast*\n 8:30am — 9:30am | SF500 · 7F · Saturn (5)" )
326+ }
327+ divider()
328+ section {
329+ markdownText(" *Coffee chat w/ candidate*\n 10:30am — 11:00am | SF500 · 10F · Cafe" )
330+ }
331+ }
332+ val original = """
333+ {
334+ "type": "home",
335+ "blocks": [
336+ {
337+ "type": "section",
338+ "text": {
339+ "type": "mrkdwn",
340+ "text": "*Today, 22 October*"
341+ },
342+ "accessory": {
343+ "type": "button",
344+ "text": {
345+ "type": "plain_text",
346+ "text": "Manage App Settings",
347+ "emoji": true
348+ },
349+ "value": "settings"
350+ }
351+ },
352+ {
353+ "type": "actions",
354+ "elements": [
355+ {
356+ "type": "datepicker",
357+ "initial_date": "2019-10-22",
358+ "placeholder": {
359+ "type": "plain_text",
360+ "text": "Select a date",
361+ "emoji": true
362+ }
363+ }
364+ ]
365+ },
366+ {
367+ "type": "divider"
368+ },
369+ {
370+ "type": "section",
371+ "text": {
372+ "type": "mrkdwn",
373+ "text": "*<fakelink.toUrl.com|Marketing weekly sync>*\n11:30am — 12:30pm | SF500 · 7F · Saturn (5)\nStatus: ✅ Going"
374+ },
375+ "accessory": {
376+ "type": "overflow",
377+ "options": [
378+ {
379+ "text": {
380+ "type": "plain_text",
381+ "text": "View Event Details",
382+ "emoji": true
383+ },
384+ "value": "view_event_details"
385+ },
386+ {
387+ "text": {
388+ "type": "plain_text",
389+ "text": "Change Response",
390+ "emoji": true
391+ },
392+ "value": "change_response"
393+ }
394+ ]
395+ }
396+ },
397+ {
398+ "type": "actions",
399+ "elements": [
400+ {
401+ "type": "button",
402+ "text": {
403+ "type": "plain_text",
404+ "text": "Join Video Call",
405+ "emoji": true
406+ },
407+ "style": "primary",
408+ "value": "join"
409+ }
410+ ]
411+ },
412+ {
413+ "type": "divider"
414+ },
415+ {
416+ "type": "section",
417+ "text": {
418+ "type": "mrkdwn",
419+ "text": "*<fakelink.toUrl.com|Design review w/ Platform leads>*\n1:30pm — 2:00pm | SF500 · 4F · Finch (4)"
420+ },
421+ "accessory": {
422+ "type": "overflow",
423+ "options": [
424+ {
425+ "text": {
426+ "type": "plain_text",
427+ "text": "View Event Details",
428+ "emoji": true
429+ },
430+ "value": "view_event_details"
431+ },
432+ {
433+ "text": {
434+ "type": "plain_text",
435+ "text": "Change Response",
436+ "emoji": true
437+ },
438+ "value": "change_response"
439+ }
440+ ]
441+ }
442+ },
443+ {
444+ "type": "actions",
445+ "elements": [
446+ {
447+ "type": "static_select",
448+ "placeholder": {
449+ "type": "plain_text",
450+ "text": "Going?",
451+ "emoji": true
452+ },
453+ "options": [
454+ {
455+ "text": {
456+ "type": "plain_text",
457+ "text": "Going",
458+ "emoji": true
459+ },
460+ "value": "going"
461+ },
462+ {
463+ "text": {
464+ "type": "plain_text",
465+ "text": "Maybe",
466+ "emoji": true
467+ },
468+ "value": "maybe"
469+ },
470+ {
471+ "text": {
472+ "type": "plain_text",
473+ "text": "Not going",
474+ "emoji": true
475+ },
476+ "value": "decline"
477+ }
478+ ]
479+ }
480+ ]
481+ },
482+ {
483+ "type": "divider"
484+ },
485+ {
486+ "type": "section",
487+ "text": {
488+ "type": "mrkdwn",
489+ "text": "*<fakelink.toUrl.com|Presentation write-up>*\n4:00pm — 5:30pm | SF500 · 7F · Saturn (5)\nStatus: ✅ Going"
490+ },
491+ "accessory": {
492+ "type": "overflow",
493+ "options": [
494+ {
495+ "text": {
496+ "type": "plain_text",
497+ "text": "View Event Details",
498+ "emoji": true
499+ },
500+ "value": "view_event_details"
501+ },
502+ {
503+ "text": {
504+ "type": "plain_text",
505+ "text": "Change Response",
506+ "emoji": true
507+ },
508+ "value": "change_response"
509+ }
510+ ]
511+ }
512+ },
513+ {
514+ "type": "actions",
515+ "elements": [
516+ {
517+ "type": "button",
518+ "text": {
519+ "type": "plain_text",
520+ "text": "Join Video Call",
521+ "emoji": true
522+ },
523+ "style": "primary",
524+ "value": "join"
525+ }
526+ ]
527+ },
528+ {
529+ "type": "divider"
530+ },
531+ {
532+ "type": "context",
533+ "elements": [
534+ {
535+ "type": "image",
536+ "image_url": "https://api.slack.com/img/blocks/bkb_template_images/placeholder.png",
537+ "alt_text": "placeholder"
538+ }
539+ ]
540+ },
541+ {
542+ "type": "context",
543+ "elements": [
544+ {
545+ "type": "mrkdwn",
546+ "text": "Past events"
547+ }
548+ ]
549+ },
550+ {
551+ "type": "section",
552+ "text": {
553+ "type": "mrkdwn",
554+ "text": "*Marketing team breakfast*\n8:30am — 9:30am | SF500 · 7F · Saturn (5)"
555+ }
556+ },
557+ {
558+ "type": "divider"
559+ },
560+ {
561+ "type": "section",
562+ "text": {
563+ "type": "mrkdwn",
564+ "text": "*Coffee chat w/ candidate*\n10:30am — 11:00am | SF500 · 10F · Cafe"
565+ }
566+ }
567+ ]
568+ }
569+ """ .trimIndent()
570+ val json = gson.fromJson(original, JsonElement ::class .java)
571+ val expected = json.asJsonObject[" blocks" ]
572+ val actual = gson.toJsonTree(blocks)
573+ assertEquals(expected, actual, " \n " + expected.toString() + " \n " + actual.toString())
574+ }
575+
199576}
0 commit comments