|
35 | 35 | SectionBlock, |
36 | 36 | StaticSelectElement, |
37 | 37 | TableBlock, |
| 38 | + TableBlockColumnSettings, |
38 | 39 | TaskCardBlock, |
39 | 40 | VideoBlock, |
40 | 41 | ) |
41 | 42 | from slack_sdk.models.blocks.basic_components import FeedbackButtonObject, SlackFile |
42 | | -from slack_sdk.models.blocks.block_elements import FeedbackButtonsElement, IconButtonElement, ImageElement |
| 43 | +from slack_sdk.models.blocks.block_elements import FeedbackButtonsElement, IconButtonElement |
43 | 44 |
|
44 | 45 | from . import STRING_3001_CHARS |
45 | 46 |
|
@@ -1462,6 +1463,74 @@ def test_with_block_id(self): |
1462 | 1463 | } |
1463 | 1464 | self.assertDictEqual(input, TableBlock(**input).to_dict()) |
1464 | 1465 |
|
| 1466 | + def test_with_column_settings_objects(self): |
| 1467 | + """Test table using typed TableBlockColumnSettings objects""" |
| 1468 | + block = TableBlock( |
| 1469 | + rows=[[{"type": "raw_text", "text": "A"}, {"type": "raw_text", "text": "B"}]], |
| 1470 | + column_settings=[ |
| 1471 | + TableBlockColumnSettings(align="right", is_wrapped=True), |
| 1472 | + TableBlockColumnSettings(align="left"), |
| 1473 | + ], |
| 1474 | + ) |
| 1475 | + expected = { |
| 1476 | + "type": "table", |
| 1477 | + "column_settings": [{"align": "right", "is_wrapped": True}, {"align": "left"}], |
| 1478 | + "rows": [[{"type": "raw_text", "text": "A"}, {"type": "raw_text", "text": "B"}]], |
| 1479 | + } |
| 1480 | + self.assertDictEqual(expected, block.to_dict()) |
| 1481 | + |
| 1482 | + def test_with_rich_text_cell_objects(self): |
| 1483 | + """Test table using typed RichTextBlock objects""" |
| 1484 | + cell = RichTextBlock( |
| 1485 | + elements=[RichTextSectionElement(elements=[RichTextElementParts.Text(text="Hello")])] |
| 1486 | + ) |
| 1487 | + block = TableBlock( |
| 1488 | + rows=[ |
| 1489 | + [RawTextObject(text="Header"), cell], |
| 1490 | + ], |
| 1491 | + ) |
| 1492 | + expected = { |
| 1493 | + "type": "table", |
| 1494 | + "rows": [ |
| 1495 | + [ |
| 1496 | + {"type": "raw_text", "text": "Header"}, |
| 1497 | + { |
| 1498 | + "type": "rich_text", |
| 1499 | + "elements": [{"type": "rich_text_section", "elements": [{"type": "text", "text": "Hello"}]}], |
| 1500 | + }, |
| 1501 | + ] |
| 1502 | + ], |
| 1503 | + } |
| 1504 | + self.assertDictEqual(expected, block.to_dict()) |
| 1505 | + |
| 1506 | + def test_mixed_typed_and_dict_cells(self): |
| 1507 | + """Test table accepts a mix of typed objects and plain dicts""" |
| 1508 | + block = TableBlock( |
| 1509 | + rows=[ |
| 1510 | + [RawTextObject(text="Col A"), RawTextObject(text="Col B")], |
| 1511 | + [ |
| 1512 | + {"type": "raw_text", "text": "Data"}, |
| 1513 | + RichTextBlock(elements=[{"type": "rich_text_section", "elements": [{"type": "text", "text": "rich"}]}]), |
| 1514 | + ], |
| 1515 | + ], |
| 1516 | + column_settings=[TableBlockColumnSettings(align="left"), {"align": "right"}], |
| 1517 | + ) |
| 1518 | + expected = { |
| 1519 | + "type": "table", |
| 1520 | + "column_settings": [{"align": "left"}, {"align": "right"}], |
| 1521 | + "rows": [ |
| 1522 | + [{"type": "raw_text", "text": "Col A"}, {"type": "raw_text", "text": "Col B"}], |
| 1523 | + [ |
| 1524 | + {"type": "raw_text", "text": "Data"}, |
| 1525 | + { |
| 1526 | + "type": "rich_text", |
| 1527 | + "elements": [{"type": "rich_text_section", "elements": [{"type": "text", "text": "rich"}]}], |
| 1528 | + }, |
| 1529 | + ], |
| 1530 | + ], |
| 1531 | + } |
| 1532 | + self.assertDictEqual(expected, block.to_dict()) |
| 1533 | + |
1465 | 1534 | def test_column_settings_variations(self): |
1466 | 1535 | """Test various column_settings configurations""" |
1467 | 1536 | # Left align |
|
0 commit comments