Repository navigation
Add expand to the section block #480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package com.hubspot.slack.client.models.blocks; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.hubspot.slack.client.jackson.ObjectMapperUtils; | ||
| import com.hubspot.slack.client.models.blocks.objects.Text; | ||
| import com.hubspot.slack.client.models.blocks.objects.TextType; | ||
| import java.io.IOException; | ||
| import org.junit.Test; | ||
|
|
||
| public class SectionBlockTest { | ||
|
|
||
| private static final ObjectMapper MAPPER = ObjectMapperUtils.mapper(); | ||
| private static final String SECTION_TEXT = "A long section that should never collapse"; | ||
|
|
||
| @Test | ||
| public void itSerializesExpandWhenSet() { | ||
| Section section = Section | ||
| .builder() | ||
| .setText(Text.of(TextType.MARKDOWN, SECTION_TEXT)) | ||
| .setExpand(true) | ||
| .build(); | ||
|
|
||
| JsonNode json = MAPPER.valueToTree(section); | ||
|
|
||
| assertThat(json.get("expand").asBoolean()).isTrue(); | ||
| } | ||
|
|
||
| @Test | ||
| public void itSerializesExpandFalseWhenSet() { | ||
| Section section = Section | ||
| .builder() | ||
| .setText(Text.of(TextType.MARKDOWN, SECTION_TEXT)) | ||
| .setExpand(false) | ||
| .build(); | ||
|
|
||
| JsonNode json = MAPPER.valueToTree(section); | ||
|
|
||
| assertThat(json.has("expand")).isTrue(); | ||
| assertThat(json.get("expand").isBoolean()).isTrue(); | ||
| assertThat(json.get("expand").booleanValue()).isFalse(); | ||
| } | ||
|
|
||
| @Test | ||
| public void itOmitsExpandWhenNotSet() { | ||
| Section section = Section.of(Text.of(TextType.MARKDOWN, SECTION_TEXT)); | ||
|
|
||
| JsonNode json = MAPPER.valueToTree(section); | ||
|
|
||
| assertThat(json.has("expand")).isFalse(); | ||
| } | ||
|
|
||
| @Test | ||
| public void itDeserializesExpand() throws IOException { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't cover expand(false). Optional.of(false) should serialize as "expand": false, not be dropped, but nothing asserts it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
| String rawJson = | ||
| "{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"" + | ||
| SECTION_TEXT + | ||
| "\"},\"expand\":true}"; | ||
|
|
||
| Block block = MAPPER.readValue(rawJson, Block.class); | ||
|
|
||
| assertThat(block) | ||
| .isInstanceOfSatisfying( | ||
| Section.class, | ||
| section -> assertThat(section.getExpand()).hasValue(true) | ||
| ); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please leave the link to Slack API documentation about this element: https://docs.slack.dev/reference/block-kit/blocks/section-block?
Like it's done for the other elements, like TaskCardBlockIF, MarkdownBlockIF, this makes it easier to check the parameters and structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the link to the section block docs on
SectionIFin 834446b, following the same pattern asTaskCardBlockIFandMarkdownBlockIF.