Skip to content

Commit 3727ab4

Browse files
authored
Fix #1517 initial_value for RichTextInputElement should also accept type RichTextBlock (#1572)
1 parent a966e34 commit 3727ab4

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

slack_sdk/models/blocks/block_elements.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,12 +1352,13 @@ def attributes(self) -> Set[str]:
13521352
}
13531353
)
13541354

1355-
def __init__(
1355+
def __init__( # type: ignore
13561356
self,
13571357
*,
13581358
action_id: Optional[str] = None,
13591359
placeholder: Optional[Union[str, dict, TextObject]] = None,
1360-
initial_value: Optional[Dict[str, Any]] = None, # TODO: Add rich_text block class and its element classes
1360+
# To avoid circular imports, the RichTextBlock type here is intentionally a string
1361+
initial_value: Optional[Union[Dict[str, Any], "RichTextBlock"]] = None, # noqa: F821
13611362
dispatch_action_config: Optional[Union[dict, DispatchActionConfig]] = None,
13621363
focus_on_load: Optional[bool] = None,
13631364
**others: dict,

tests/slack_sdk/models/test_elements.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
InputInteractiveElement,
2828
InteractiveElement,
2929
PlainTextObject,
30+
RichTextBlock,
3031
)
3132
from slack_sdk.models.blocks.basic_components import SlackFile
3233
from slack_sdk.models.blocks.block_elements import (
@@ -37,6 +38,8 @@
3738
WorkflowButtonElement,
3839
RichTextInputElement,
3940
FileInputElement,
41+
RichTextSectionElement,
42+
RichTextElementParts,
4043
)
4144
from . import STRING_3001_CHARS, STRING_301_CHARS
4245

@@ -1069,6 +1072,43 @@ def test_document(self):
10691072
}
10701073
self.assertDictEqual(input, RichTextInputElement(**input).to_dict())
10711074

1075+
def test_issue_1571(self):
1076+
self.assertDictEqual(
1077+
RichTextInputElement(
1078+
action_id="contents",
1079+
initial_value=RichTextBlock(
1080+
elements=[
1081+
RichTextSectionElement(
1082+
elements=[
1083+
RichTextElementParts.Text(text="Hey, "),
1084+
RichTextElementParts.Text(text="this", style={"italic": True}),
1085+
RichTextElementParts.Text(text="is what you should be looking at. "),
1086+
RichTextElementParts.Text(text="Please", style={"bold": True}),
1087+
]
1088+
)
1089+
],
1090+
),
1091+
).to_dict(),
1092+
{
1093+
"action_id": "contents",
1094+
"initial_value": {
1095+
"elements": [
1096+
{
1097+
"elements": [
1098+
{"text": "Hey, ", "type": "text"},
1099+
{"style": {"italic": True}, "text": "this", "type": "text"},
1100+
{"text": "is what you should be looking at. ", "type": "text"},
1101+
{"style": {"bold": True}, "text": "Please", "type": "text"},
1102+
],
1103+
"type": "rich_text_section",
1104+
}
1105+
],
1106+
"type": "rich_text",
1107+
},
1108+
"type": "rich_text_input",
1109+
},
1110+
)
1111+
10721112

10731113
class PlainTextInputElementTests(unittest.TestCase):
10741114
def test_document_1(self):

0 commit comments

Comments
 (0)