Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1517 initial_value for RichTextInputElement should also accept type RichTextBlock #1572

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading