Skip to content

Commit

Permalink
Fix #1517 initial_value for RichTextInputElement should also accept t…
Browse files Browse the repository at this point in the history
…ype RichTextBlock (#1572)
  • Loading branch information
seratch authored Oct 10, 2024
1 parent a966e34 commit 3727ab4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
5 changes: 3 additions & 2 deletions slack_sdk/models/blocks/block_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -1352,12 +1352,13 @@ def attributes(self) -> Set[str]:
}
)

def __init__(
def __init__( # type: ignore
self,
*,
action_id: Optional[str] = None,
placeholder: Optional[Union[str, dict, TextObject]] = None,
initial_value: Optional[Dict[str, Any]] = None, # TODO: Add rich_text block class and its element classes
# To avoid circular imports, the RichTextBlock type here is intentionally a string
initial_value: Optional[Union[Dict[str, Any], "RichTextBlock"]] = None, # noqa: F821
dispatch_action_config: Optional[Union[dict, DispatchActionConfig]] = None,
focus_on_load: Optional[bool] = None,
**others: dict,
Expand Down
40 changes: 40 additions & 0 deletions tests/slack_sdk/models/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
InputInteractiveElement,
InteractiveElement,
PlainTextObject,
RichTextBlock,
)
from slack_sdk.models.blocks.basic_components import SlackFile
from slack_sdk.models.blocks.block_elements import (
Expand All @@ -37,6 +38,8 @@
WorkflowButtonElement,
RichTextInputElement,
FileInputElement,
RichTextSectionElement,
RichTextElementParts,
)
from . import STRING_3001_CHARS, STRING_301_CHARS

Expand Down Expand Up @@ -1069,6 +1072,43 @@ def test_document(self):
}
self.assertDictEqual(input, RichTextInputElement(**input).to_dict())

def test_issue_1571(self):
self.assertDictEqual(
RichTextInputElement(
action_id="contents",
initial_value=RichTextBlock(
elements=[
RichTextSectionElement(
elements=[
RichTextElementParts.Text(text="Hey, "),
RichTextElementParts.Text(text="this", style={"italic": True}),
RichTextElementParts.Text(text="is what you should be looking at. "),
RichTextElementParts.Text(text="Please", style={"bold": True}),
]
)
],
),
).to_dict(),
{
"action_id": "contents",
"initial_value": {
"elements": [
{
"elements": [
{"text": "Hey, ", "type": "text"},
{"style": {"italic": True}, "text": "this", "type": "text"},
{"text": "is what you should be looking at. ", "type": "text"},
{"style": {"bold": True}, "text": "Please", "type": "text"},
],
"type": "rich_text_section",
}
],
"type": "rich_text",
},
"type": "rich_text_input",
},
)


class PlainTextInputElementTests(unittest.TestCase):
def test_document_1(self):
Expand Down

0 comments on commit 3727ab4

Please sign in to comment.