/slack-api-model/src/test/java/test_locally/api/model/ModelsTest.java

https://github.com/seratch/jslack · Java · 250 lines · 197 code · 53 blank · 0 comment · 0 complexity · 23dc1189d4595d58615c91d94f1b8a72 MD5 · raw file

  1. package test_locally.api.model;
  2. import com.slack.api.model.*;
  3. import com.slack.api.model.block.ActionsBlock;
  4. import com.slack.api.model.block.ContextBlock;
  5. import com.slack.api.model.block.DividerBlock;
  6. import com.slack.api.model.block.composition.*;
  7. import com.slack.api.model.block.element.*;
  8. import com.slack.api.model.dialog.DialogSubType;
  9. import com.slack.api.model.event.MessageBotEvent;
  10. import com.slack.api.model.event.MessageEvent;
  11. import com.slack.api.model.view.ViewState;
  12. import org.junit.Test;
  13. import java.util.Arrays;
  14. import java.util.HashMap;
  15. import java.util.List;
  16. import java.util.Map;
  17. import static com.slack.api.model.Attachments.attachmentMetadata;
  18. import static com.slack.api.model.block.Blocks.*;
  19. import static com.slack.api.model.block.composition.BlockCompositions.*;
  20. import static com.slack.api.model.block.element.BlockElements.*;
  21. import static com.slack.api.model.view.Views.viewState;
  22. import static org.junit.Assert.*;
  23. public class ModelsTest {
  24. @Test
  25. public void dialogSubTypes() {
  26. assertEquals("number", DialogSubType.NUMBER.value());
  27. }
  28. @Test
  29. public void actionTypes() {
  30. assertEquals("button", Action.Type.BUTTON.value());
  31. assertEquals("select", Action.Type.SELECT.value());
  32. }
  33. @Test
  34. public void attachment() {
  35. {
  36. Attachment attachment = new Attachment();
  37. assertNull(attachment.isIndent());
  38. attachment.setIndent(true);
  39. assertTrue(attachment.isIndent());
  40. }
  41. {
  42. Attachment attachment = new Attachment();
  43. assertNull(attachment.isMsgUnfurl());
  44. attachment.setMsgUnfurl(true);
  45. assertTrue(attachment.isMsgUnfurl());
  46. }
  47. {
  48. Attachment attachment = new Attachment();
  49. assertNull(attachment.isReplyUnfurl());
  50. attachment.setReplyUnfurl(true);
  51. assertTrue(attachment.isReplyUnfurl());
  52. }
  53. {
  54. Attachment attachment = new Attachment();
  55. assertNull(attachment.isAppUnfurl());
  56. attachment.setAppUnfurl(true);
  57. assertTrue(attachment.isAppUnfurl());
  58. }
  59. {
  60. Attachment attachment = new Attachment();
  61. assertNull(attachment.isThreadRootUnfurl());
  62. attachment.setThreadRootUnfurl(true);
  63. assertTrue(attachment.isThreadRootUnfurl());
  64. }
  65. }
  66. @Test
  67. public void attachments() {
  68. Attachment.AttachmentMetadata metadata = attachmentMetadata(r -> r.originalHeight(123).originalWidth(234));
  69. assertNotNull(metadata);
  70. }
  71. @Test
  72. public void file() {
  73. File file = new File();
  74. assertFalse(file.isPublic());
  75. file.setPublic(true);
  76. assertTrue(file.isPublic());
  77. }
  78. @Test
  79. public void matchedItem() {
  80. MatchedItem item = new MatchedItem();
  81. assertFalse(item.isPublic());
  82. item.setPublic(true);
  83. assertTrue(item.isPublic());
  84. }
  85. @Test
  86. public void messageItem() {
  87. Message.MessageItem item = new Message.MessageItem();
  88. assertFalse(item.isPublic());
  89. item.setPublic(true);
  90. assertTrue(item.isPublic());
  91. }
  92. @Test
  93. public void teamProfileOptions() {
  94. Team.ProfileOptions item = new Team.ProfileOptions();
  95. assertFalse(item.isProtected());
  96. item.setProtected(true);
  97. assertTrue(item.isProtected());
  98. }
  99. @Test
  100. public void event() {
  101. MessageEvent event = new MessageEvent();
  102. assertNull(event.getSubtype());
  103. MessageBotEvent messageBotEvent = new MessageBotEvent();
  104. assertEquals("bot_message", messageBotEvent.getSubtype());
  105. }
  106. @Test
  107. public void views() {
  108. Map<String, Map<String, ViewState.Value>> values = new HashMap<>();
  109. Map<String, ViewState.Value> block = new HashMap<>();
  110. ViewState.Value value = new ViewState.Value();
  111. value.setValue("something");
  112. block.put("action", value);
  113. values.put("block", block);
  114. ViewState state = viewState(r -> r.values(values));
  115. assertNotNull(state);
  116. assertNotNull(state.getValues());
  117. assertEquals("something", state.getValues().get("block").get("action").getValue());
  118. }
  119. @Test
  120. public void blocks() {
  121. ActionsBlock actions = actions(r -> r.blockId("block"));
  122. assertNotNull(actions);
  123. ContextBlock context = context(r -> r.blockId("block"));
  124. assertNotNull(context);
  125. DividerBlock divider = divider();
  126. assertNotNull(divider);
  127. DividerBlock divider2 = divider(r -> r.blockId("block"));
  128. assertNotNull(divider2);
  129. }
  130. @Test
  131. public void blockElements() {
  132. List<RichTextElement> richTextElements = asRichTextElements();
  133. assertNotNull(richTextElements);
  134. OverflowMenuElement overflowMenu = overflowMenu(r -> r.actionId("action"));
  135. assertNotNull(overflowMenu);
  136. PlainTextInputElement textInput = plainTextInput(r -> r.actionId("action"));
  137. assertNotNull(textInput);
  138. DatePickerElement datePicker = datePicker(r -> r.actionId("action"));
  139. assertNotNull(datePicker);
  140. RadioButtonsElement radioButtons = radioButtons(r -> r.actionId("action"));
  141. assertNotNull(radioButtons);
  142. ChannelsSelectElement channelsSelect = channelsSelect(r -> r.actionId("action"));
  143. assertNotNull(channelsSelect);
  144. ConversationsSelectElement conversationsSelect = conversationsSelect(r -> r.actionId("action"));
  145. assertNotNull(conversationsSelect);
  146. ExternalSelectElement externalSelect = externalSelect(r -> r.actionId("action"));
  147. assertNotNull(externalSelect);
  148. StaticSelectElement staticSelect = staticSelect(r -> r.actionId("action"));
  149. assertNotNull(staticSelect);
  150. UsersSelectElement usersSelect = usersSelect(r -> r.actionId("action"));
  151. assertNotNull(usersSelect);
  152. MultiChannelsSelectElement multiChannelsSelect = multiChannelsSelect(r -> r.actionId("action"));
  153. assertNotNull(multiChannelsSelect);
  154. MultiConversationsSelectElement multiConversationsSelect = multiConversationsSelect(r -> r.actionId("action"));
  155. assertNotNull(multiConversationsSelect);
  156. MultiExternalSelectElement multiExternalSelect = multiExternalSelect(r -> r.actionId("action"));
  157. assertNotNull(multiExternalSelect);
  158. MultiStaticSelectElement multiStaticSelect = multiStaticSelect(r -> r.actionId("action"));
  159. assertNotNull(multiStaticSelect);
  160. MultiUsersSelectElement multiUsersSelect = multiUsersSelect(r -> r.actionId("action"));
  161. assertNotNull(multiUsersSelect);
  162. RichTextListElement richTextList = richTextList(r -> r.style("link"));
  163. assertNotNull(richTextList);
  164. RichTextPreformattedElement richTextPreformatted = richTextPreformatted(r -> r);
  165. assertNotNull(richTextPreformatted);
  166. RichTextQuoteElement richTextQuote = richTextQuote(r -> r);
  167. assertNotNull(richTextQuote);
  168. RichTextSectionElement richTextSection = richTextSection(r -> r);
  169. assertNotNull(richTextSection);
  170. }
  171. @Test
  172. public void blockCompositions() {
  173. PlainTextObject pto = plainText("text", false);
  174. assertNotNull(pto);
  175. MarkdownTextObject mto = markdownText(r -> r.text("foo").verbatim(false));
  176. assertNotNull(mto);
  177. OptionObject opt = option(plainText("text"), "value");
  178. assertNotNull(opt);
  179. List<OptionGroupObject> optionGroups = asOptionGroups(BlockCompositions.optionGroup(r -> r.label(plainText("hi"))));
  180. assertNotNull(optionGroups);
  181. List<OptionObject> options = asOptions(BlockCompositions.option(r -> r.text(plainText("foo")).value("bar")));
  182. assertNotNull(options);
  183. ConfirmationDialogObject confirmationDialog = confirmationDialog(r -> r.text(markdownText("foo")));
  184. assertNotNull(confirmationDialog);
  185. }
  186. @Test
  187. public void blockCompositions_radio_buttons_checkboxes() {
  188. MarkdownTextObject mto = markdownText(r -> r.text("foo").verbatim(false));
  189. assertNotNull(mto);
  190. OptionObject opt = option(mto, "value");
  191. assertNotNull(opt);
  192. RadioButtonsElement radioButtons = radioButtons(r -> r.actionId("a").initialOption(opt).options(Arrays.asList(opt)));
  193. assertNotNull(radioButtons);
  194. CheckboxesElement checkboxes = checkboxes(r -> r.actionId("a").initialOptions(Arrays.asList(opt)).options(Arrays.asList(opt)));
  195. assertNotNull(checkboxes);
  196. }
  197. }