From d61eedce7fa3d5985c6b31363fe178a83bbf1910 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Tue, 8 Sep 2026 16:15:17 -0700 Subject: [PATCH] refactor(block-kit): remove nested rich_text block example in favor of standalone elements The rich_text block example (blocks/rich_text) duplicated the standalone rich-text element examples (elements/rich_text_*), which the docs reference pages now pin to directly. Every nested exampleNN is reproduced by a standalone element example, so this is pure deduplication with no loss of demonstrated coverage: - example01 -> rich_text_section - example02/03 -> rich_text_list - example04 -> rich_text_preformatted - example05 -> rich_text_quote - example06-13 (broadcast/color/channel/date/emoji/link/user/usergroup) -> the respective standalone element examples The rich-text-block reference page is prose-only and references no example file, so removing this changes no docs reference. Co-Authored-By: Claude --- block-kit/README.md | 1 - block-kit/src/main/java/blocks/RichText.java | 284 ---------- .../src/test/java/blocks/RichTextTest.java | 525 ------------------ 3 files changed, 810 deletions(-) delete mode 100644 block-kit/src/main/java/blocks/RichText.java delete mode 100644 block-kit/src/test/java/blocks/RichTextTest.java diff --git a/block-kit/README.md b/block-kit/README.md index 0ccfb5d..51c096c 100644 --- a/block-kit/README.md +++ b/block-kit/README.md @@ -19,7 +19,6 @@ Read the [docs](https://docs.slack.dev/block-kit/) to learn concepts behind thes - **[Image](https://docs.slack.dev/reference/block-kit/blocks/image-block)**: Displays an image. [Implementation](./src/main/java/blocks/Image.java). - **[Input](https://docs.slack.dev/reference/block-kit/blocks/input-block)**: Collects information from users via elements. [Implementation](./src/main/java/blocks/Input.java). - **[Markdown](https://docs.slack.dev/reference/block-kit/blocks/markdown-block)**: Displays formatted markdown. [Implementation](./src/main/java/blocks/Markdown.java). -- **[Rich text](https://docs.slack.dev/reference/block-kit/blocks/rich-text-block)**: Displays formatted, structured representation of text. [Implementation](./src/main/java/blocks/RichText.java). - **[Section](https://docs.slack.dev/reference/block-kit/blocks/section-block)**: Displays text, possibly alongside elements. [Implementation](./src/main/java/blocks/Section.java). - **[Video](https://docs.slack.dev/reference/block-kit/blocks/video-block)**: Displays an embedded video player. [Implementation](./src/main/java/blocks/Video.java). diff --git a/block-kit/src/main/java/blocks/RichText.java b/block-kit/src/main/java/blocks/RichText.java deleted file mode 100644 index 63e9944..0000000 --- a/block-kit/src/main/java/blocks/RichText.java +++ /dev/null @@ -1,284 +0,0 @@ -package blocks; - -import com.slack.api.model.block.Blocks; -import com.slack.api.model.block.RichTextBlock; -import com.slack.api.model.block.element.RichTextListElement; -import com.slack.api.model.block.element.RichTextPreformattedElement; -import com.slack.api.model.block.element.RichTextQuoteElement; -import com.slack.api.model.block.element.RichTextSectionElement; -import com.slack.api.model.block.element.RichTextSectionElement.TextStyle; -import java.util.List; - -/** - * Displays formatted, structured representation of text. - * {@link https://docs.slack.dev/reference/block-kit/blocks/rich-text-block/} - */ -public class RichText { - /** - * Four basic rich text section examples (basic, bold, italic, strikethrough). - */ - public static List example01() { - List blocks = List.of( - Blocks.richText(rt -> rt.elements(List.of(RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.Text.builder() - .text("Hello there, I am a basic rich text block!") - .build())) - .build()))), - Blocks.richText(rt -> rt.elements(List.of(RichTextSectionElement.builder() - .elements(List.of( - RichTextSectionElement.Text.builder() - .text("Hello there, ") - .build(), - RichTextSectionElement.Text.builder() - .text("I am a bold rich text block!") - .style(TextStyle.builder().bold(true).build()) - .build())) - .build()))), - Blocks.richText(rt -> rt.elements(List.of(RichTextSectionElement.builder() - .elements(List.of( - RichTextSectionElement.Text.builder() - .text("Hello there, ") - .build(), - RichTextSectionElement.Text.builder() - .text("I am an italic rich text block!") - .style(TextStyle.builder().italic(true).build()) - .build())) - .build()))), - Blocks.richText(rt -> rt.elements(List.of(RichTextSectionElement.builder() - .elements(List.of( - RichTextSectionElement.Text.builder() - .text("Hello there, ") - .build(), - RichTextSectionElement.Text.builder() - .text("I am a strikethrough rich text block!") - .style(TextStyle.builder().strike(true).build()) - .build())) - .build())))); - return blocks; - } - - /** - * A rich text block with a bullet list. - */ - public static RichTextBlock example02() { - RichTextBlock block = Blocks.richText(rt -> rt.blockId("block1") - .elements(List.of( - RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.Text.builder() - .text("My favorite Slack features (in no particular order):") - .build())) - .build(), - RichTextListElement.builder() - .style("bullet") - .indent(0) - .border(1) - .elements(List.of( - RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.Text.builder() - .text("Huddles") - .build())) - .build(), - RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.Text.builder() - .text("Canvas") - .build())) - .build(), - RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.Text.builder() - .text("Developing with Block Kit") - .build())) - .build())) - .build()))); - return block; - } - - /** - * A rich text block with a nested bullet list. - */ - public static RichTextBlock example03() { - RichTextBlock block = Blocks.richText(rt -> rt.blockId("block1") - .elements(List.of( - RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.Text.builder() - .text("Breakfast foods I enjoy:") - .build())) - .build(), - RichTextListElement.builder() - .style("bullet") - .elements(List.of( - RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.Text.builder() - .text("Hashbrowns") - .build())) - .build(), - RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.Text.builder() - .text("Eggs") - .build())) - .build())) - .build(), - RichTextListElement.builder() - .style("bullet") - .indent(1) - .elements(List.of( - RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.Text.builder() - .text("Scrambled") - .build())) - .build(), - RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.Text.builder() - .text("Over easy") - .build())) - .build())) - .build(), - RichTextListElement.builder() - .style("bullet") - .elements(List.of(RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.Text.builder() - .text("Pancakes, extra syrup") - .build())) - .build())) - .build()))); - return block; - } - - /** - * A rich text block with preformatted code. - */ - public static RichTextBlock example04() { - RichTextBlock block = Blocks.richText(rt -> rt.elements(List.of(RichTextPreformattedElement.builder() - .border(0) - .elements(List.of(RichTextSectionElement.Text.builder() - .text( - "{\n \"object\": {\n \"description\": \"this is an example of a json object\"\n }\n}") - .build())) - .build()))); - return block; - } - - /** - * A rich text block with a quote. - */ - public static RichTextBlock example05() { - RichTextBlock block = Blocks.richText(rt -> rt.blockId("Vrzsu") - .elements(List.of( - RichTextQuoteElement.builder() - .elements(List.of(RichTextSectionElement.Text.builder() - .text("What we need is good examples in our documentation.") - .build())) - .build(), - RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.Text.builder() - .text("Yes - I completely agree, Luke!") - .build())) - .build()))); - return block; - } - - /** - * A rich text block with a broadcast element. - */ - public static RichTextBlock example06() { - RichTextBlock block = Blocks.richText(rt -> rt.elements(List.of(RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.Broadcast.builder() - .range("everyone") - .build())) - .build()))); - return block; - } - - /** - * A rich text block with a color element. - */ - public static RichTextBlock example07() { - RichTextBlock block = Blocks.richText(rt -> rt.elements(List.of(RichTextSectionElement.builder() - .elements(List.of( - RichTextSectionElement.Color.builder().value("#F405B3").build())) - .build()))); - return block; - } - - /** - * A rich text block with a channel element. - */ - public static RichTextBlock example08() { - RichTextBlock block = Blocks.richText(rt -> rt.elements(List.of(RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.Channel.builder() - .channelId("C123ABC456") - .build())) - .build()))); - return block; - } - - /** - * A rich text block with a date element. - */ - public static RichTextBlock example09() { - RichTextBlock block = Blocks.richText(rt -> rt.elements(List.of(RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.Date.builder() - .timestamp(1720710212) - .format("{date_num} at {time}") - .fallback("timey") - .build())) - .build()))); - return block; - } - - /** - * A rich text block with emoji elements. - */ - public static RichTextBlock example10() { - RichTextBlock block = Blocks.richText(rt -> rt.elements(List.of(RichTextSectionElement.builder() - .elements(List.of( - RichTextSectionElement.Emoji.builder() - .name("basketball") - .build(), - RichTextSectionElement.Text.builder().text(" ").build(), - RichTextSectionElement.Emoji.builder() - .name("snowboarder") - .build(), - RichTextSectionElement.Text.builder().text(" ").build(), - RichTextSectionElement.Emoji.builder() - .name("checkered_flag") - .build())) - .build()))); - return block; - } - - /** - * A rich text block with a link element. - */ - public static RichTextBlock example11() { - RichTextBlock block = Blocks.richText(rt -> rt.elements(List.of(RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.Link.builder() - .url("https://api.slack.com") - .build())) - .build()))); - return block; - } - - /** - * A rich text block with a user mention element. - */ - public static RichTextBlock example12() { - RichTextBlock block = Blocks.richText(rt -> rt.elements(List.of(RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.User.builder() - .userId("U123ABC456") - .build())) - .build()))); - return block; - } - - /** - * A rich text block with a usergroup mention element. - */ - public static RichTextBlock example13() { - RichTextBlock block = Blocks.richText(rt -> rt.elements(List.of(RichTextSectionElement.builder() - .elements(List.of(RichTextSectionElement.UserGroup.builder() - .usergroupId("G123ABC456") - .build())) - .build()))); - return block; - } -} diff --git a/block-kit/src/test/java/blocks/RichTextTest.java b/block-kit/src/test/java/blocks/RichTextTest.java deleted file mode 100644 index c67af51..0000000 --- a/block-kit/src/test/java/blocks/RichTextTest.java +++ /dev/null @@ -1,525 +0,0 @@ -package blocks; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.google.gson.JsonParser; -import com.slack.api.model.block.RichTextBlock; -import com.slack.api.util.json.GsonFactory; -import org.junit.jupiter.api.Test; - -public class RichTextTest { - @Test - public void testExample01() { - java.util.List blocks = RichText.example01(); - String actual = GsonFactory.createSnakeCase().toJson(blocks); - String expected = """ - [ - { - "type": "rich_text", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "text", - "text": "Hello there, I am a basic rich text block!" - } - ] - } - ] - }, - { - "type": "rich_text", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "text", - "text": "Hello there, " - }, - { - "type": "text", - "text": "I am a bold rich text block!", - "style": { - "bold": true, - "italic": false, - "strike": false, - "highlight": false, - "client_highlight": false, - "underline": false, - "unlink": false, - "code": false - } - } - ] - } - ] - }, - { - "type": "rich_text", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "text", - "text": "Hello there, " - }, - { - "type": "text", - "text": "I am an italic rich text block!", - "style": { - "bold": false, - "italic": true, - "strike": false, - "highlight": false, - "client_highlight": false, - "underline": false, - "unlink": false, - "code": false - } - } - ] - } - ] - }, - { - "type": "rich_text", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "text", - "text": "Hello there, " - }, - { - "type": "text", - "text": "I am a strikethrough rich text block!", - "style": { - "bold": false, - "italic": false, - "strike": true, - "highlight": false, - "client_highlight": false, - "underline": false, - "unlink": false, - "code": false - } - } - ] - } - ] - } - ] - """; - assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual)); - } - - @Test - public void testExample02() { - RichTextBlock block = RichText.example02(); - String actual = GsonFactory.createSnakeCase().toJson(block); - String expected = """ - { - "type": "rich_text", - "block_id": "block1", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "text", - "text": "My favorite Slack features (in no particular order):" - } - ] - }, - { - "type": "rich_text_list", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "text", - "text": "Huddles" - } - ] - }, - { - "type": "rich_text_section", - "elements": [ - { - "type": "text", - "text": "Canvas" - } - ] - }, - { - "type": "rich_text_section", - "elements": [ - { - "type": "text", - "text": "Developing with Block Kit" - } - ] - } - ], - "style": "bullet", - "indent": 0, - "border": 1 - } - ] - } - """; - assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual)); - } - - @Test - public void testExample03() { - RichTextBlock block = RichText.example03(); - String actual = GsonFactory.createSnakeCase().toJson(block); - String expected = """ - { - "type": "rich_text", - "block_id": "block1", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "text", - "text": "Breakfast foods I enjoy:" - } - ] - }, - { - "type": "rich_text_list", - "style": "bullet", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "text", - "text": "Hashbrowns" - } - ] - }, - { - "type": "rich_text_section", - "elements": [ - { - "type": "text", - "text": "Eggs" - } - ] - } - ] - }, - { - "type": "rich_text_list", - "style": "bullet", - "indent": 1, - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "text", - "text": "Scrambled" - } - ] - }, - { - "type": "rich_text_section", - "elements": [ - { - "type": "text", - "text": "Over easy" - } - ] - } - ] - }, - { - "type": "rich_text_list", - "style": "bullet", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "text", - "text": "Pancakes, extra syrup" - } - ] - } - ] - } - ] - } - """; - assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual)); - } - - @Test - public void testExample04() { - RichTextBlock block = RichText.example04(); - String actual = GsonFactory.createSnakeCase().toJson(block); - String expected = """ - { - "type": "rich_text", - "elements": [ - { - "type": "rich_text_preformatted", - "elements": [ - { - "type": "text", - "text": "{\\n \\"object\\": {\\n \\"description\\": \\"this is an example of a json object\\"\\n }\\n}" - } - ], - "border": 0 - } - ] - } - """; - assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual)); - } - - @Test - public void testExample05() { - RichTextBlock block = RichText.example05(); - String actual = GsonFactory.createSnakeCase().toJson(block); - String expected = """ - { - "type": "rich_text", - "block_id": "Vrzsu", - "elements": [ - { - "type": "rich_text_quote", - "elements": [ - { - "type": "text", - "text": "What we need is good examples in our documentation." - } - ] - }, - { - "type": "rich_text_section", - "elements": [ - { - "type": "text", - "text": "Yes - I completely agree, Luke!" - } - ] - } - ] - } - """; - assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual)); - } - - @Test - public void testExample06() { - RichTextBlock block = RichText.example06(); - String actual = GsonFactory.createSnakeCase().toJson(block); - String expected = """ - { - "type": "rich_text", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "broadcast", - "range": "everyone" - } - ] - } - ] - } - """; - assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual)); - } - - @Test - public void testExample07() { - RichTextBlock block = RichText.example07(); - String actual = GsonFactory.createSnakeCase().toJson(block); - String expected = """ - { - "type": "rich_text", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "color", - "value": "#F405B3" - } - ] - } - ] - } - """; - assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual)); - } - - @Test - public void testExample08() { - RichTextBlock block = RichText.example08(); - String actual = GsonFactory.createSnakeCase().toJson(block); - String expected = """ - { - "type": "rich_text", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "channel", - "channel_id": "C123ABC456" - } - ] - } - ] - } - """; - assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual)); - } - - @Test - public void testExample09() { - RichTextBlock block = RichText.example09(); - String actual = GsonFactory.createSnakeCase().toJson(block); - String expected = """ - { - "type": "rich_text", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "date", - "timestamp": 1720710212, - "format": "{date_num} at {time}", - "fallback": "timey" - } - ] - } - ] - } - """; - assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual)); - } - - @Test - public void testExample10() { - RichTextBlock block = RichText.example10(); - String actual = GsonFactory.createSnakeCase().toJson(block); - String expected = """ - { - "type": "rich_text", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "emoji", - "name": "basketball" - }, - { - "type": "text", - "text": " " - }, - { - "type": "emoji", - "name": "snowboarder" - }, - { - "type": "text", - "text": " " - }, - { - "type": "emoji", - "name": "checkered_flag" - } - ] - } - ] - } - """; - assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual)); - } - - @Test - public void testExample11() { - RichTextBlock block = RichText.example11(); - String actual = GsonFactory.createSnakeCase().toJson(block); - String expected = """ - { - "type": "rich_text", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "link", - "url": "https://api.slack.com" - } - ] - } - ] - } - """; - assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual)); - } - - @Test - public void testExample12() { - RichTextBlock block = RichText.example12(); - String actual = GsonFactory.createSnakeCase().toJson(block); - String expected = """ - { - "type": "rich_text", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "user", - "user_id": "U123ABC456" - } - ] - } - ] - } - """; - assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual)); - } - - @Test - public void testExample13() { - RichTextBlock block = RichText.example13(); - String actual = GsonFactory.createSnakeCase().toJson(block); - String expected = """ - { - "type": "rich_text", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "usergroup", - "usergroup_id": "G123ABC456" - } - ] - } - ] - } - """; - assertEquals(JsonParser.parseString(expected), JsonParser.parseString(actual)); - } -}