File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed
slack-api-model-kotlin-extension/src
main/kotlin/com/slack/api/model/kotlin_extension/view
test/kotlin/test_locally/view Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ package com.slack.api.model.kotlin_extension.view
2+
3+ import com.slack.api.model.kotlin_extension.block.dsl.LayoutBlockDsl
4+ import com.slack.api.model.kotlin_extension.block.withBlocks
5+ import com.slack.api.model.view.View.ViewBuilder
6+
7+ fun ViewBuilder.blocks (builder : LayoutBlockDsl .() -> Unit ): ViewBuilder {
8+ return this .blocks(withBlocks(builder))
9+ }
Original file line number Diff line number Diff line change 1+ package test_locally.view
2+
3+ import com.slack.api.model.block.Blocks.*
4+ import com.slack.api.model.block.composition.BlockCompositions.*
5+ import com.slack.api.model.kotlin_extension.view.blocks
6+ import com.slack.api.model.view.Views.view
7+ import org.junit.Test
8+ import kotlin.test.assertEquals
9+
10+ class ViewBuilderExtensionTest {
11+ @Test
12+ fun `View builder extension works` () {
13+ val view = view {
14+ it.type(" home" )
15+ .blocks {
16+ section {
17+ markdownText(" **Welcome to your home screen!**" )
18+ }
19+ divider()
20+ section {
21+ markdownText(" :clock3: Your next event starts in **10** minutes." )
22+ fields {
23+ plainText(" :pushpin: Location: Large Conference Room" , emoji = true )
24+ plainText(" :hourglass_flowing_sand: Duration: 30 minutes" , emoji = true )
25+ }
26+ }
27+ }
28+ }
29+
30+ val expected = view {
31+ it.type(" home" )
32+ .blocks(asBlocks(
33+ section { thisSection ->
34+ thisSection.text(markdownText { mt -> mt.text(" **Welcome to your home screen!**" )})
35+ },
36+ divider(),
37+ section { thisSection ->
38+ thisSection.text(markdownText { mt -> mt.text(" :clock3: Your next event starts in **10** minutes." ) })
39+ .fields(asSectionFields(
40+ plainText { pt -> pt.text(" :pushpin: Location: Large Conference Room" ).emoji(true ) },
41+ plainText { pt -> pt.text(" :hourglass_flowing_sand: Duration: 30 minutes" ).emoji(true ) }
42+ ))
43+ }
44+ ))
45+ }
46+
47+ assertEquals(expected.toString(), view.toString(), " $expected \n $view " )
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments