Skip to content

Commit 757234a

Browse files
authored
Merge branch 'master' into add-two-apis-2020-06
2 parents 9d790e0 + b0443a1 commit 757234a

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
}

0 commit comments

Comments
 (0)