|
26 | 26 | OverflowMenuElement, |
27 | 27 | PlainTextObject, |
28 | 28 | PlanBlock, |
| 29 | + RawNumberObject, |
29 | 30 | RawTextObject, |
30 | 31 | RichTextBlock, |
31 | 32 | RichTextElementParts, |
@@ -1358,6 +1359,40 @@ def test_parsing_empty_block_elements(self): |
1358 | 1359 | self.assertIsNotNone(block_dict["elements"][3].get("elements")) |
1359 | 1360 |
|
1360 | 1361 |
|
| 1362 | +# ---------------------------------------------- |
| 1363 | +# RawNumberObject |
| 1364 | +# ---------------------------------------------- |
| 1365 | + |
| 1366 | + |
| 1367 | +class RawNumberObjectTests(unittest.TestCase): |
| 1368 | + def test_basic_creation(self): |
| 1369 | + """Test basic RawNumberObject creation""" |
| 1370 | + obj = RawNumberObject(value=42, text="42") |
| 1371 | + expected = {"type": "raw_number", "value": 42, "text": "42"} |
| 1372 | + self.assertDictEqual(expected, obj.to_dict()) |
| 1373 | + |
| 1374 | + def test_float_value(self): |
| 1375 | + """Test RawNumberObject accepts a float value""" |
| 1376 | + obj = RawNumberObject(value=3.14, text="3.14") |
| 1377 | + expected = {"type": "raw_number", "value": 3.14, "text": "3.14"} |
| 1378 | + self.assertDictEqual(expected, obj.to_dict()) |
| 1379 | + |
| 1380 | + def test_text_length_validation_min(self): |
| 1381 | + """Test that empty text fails validation""" |
| 1382 | + with self.assertRaises(SlackObjectFormationError): |
| 1383 | + RawNumberObject(value=0, text="").to_dict() |
| 1384 | + |
| 1385 | + def test_text_length_validation_at_min(self): |
| 1386 | + """Test that text with 1 character passes validation""" |
| 1387 | + obj = RawNumberObject(value=1, text="1") |
| 1388 | + obj.to_dict() # Should not raise |
| 1389 | + |
| 1390 | + def test_attributes(self): |
| 1391 | + """Test that RawNumberObject only has value, text, and type attributes""" |
| 1392 | + obj = RawNumberObject(value=42, text="42") |
| 1393 | + self.assertEqual(obj.attributes, {"value", "text", "type"}) |
| 1394 | + |
| 1395 | + |
1361 | 1396 | # ---------------------------------------------- |
1362 | 1397 | # RawTextObject |
1363 | 1398 | # ---------------------------------------------- |
@@ -1444,6 +1479,35 @@ def test_with_rich_text(self): |
1444 | 1479 | self.assertDictEqual(input, TableBlock(**input).to_dict()) |
1445 | 1480 | self.assertDictEqual(input, Block.parse(input).to_dict()) |
1446 | 1481 |
|
| 1482 | + def test_with_raw_number(self): |
| 1483 | + """Test table block with raw_number cells""" |
| 1484 | + input = { |
| 1485 | + "type": "table", |
| 1486 | + "rows": [ |
| 1487 | + [{"type": "raw_text", "text": "Widgets"}, {"type": "raw_number", "value": 42, "text": "42"}], |
| 1488 | + [ |
| 1489 | + { |
| 1490 | + "type": "rich_text", |
| 1491 | + "elements": [{"type": "rich_text_section", "elements": [{"type": "text", "text": "Gadgets"}]}], |
| 1492 | + }, |
| 1493 | + {"type": "raw_number", "value": 7, "text": "7"}, |
| 1494 | + ], |
| 1495 | + ], |
| 1496 | + } |
| 1497 | + self.assertDictEqual(input, TableBlock(**input).to_dict()) |
| 1498 | + self.assertDictEqual(input, Block.parse(input).to_dict()) |
| 1499 | + |
| 1500 | + def test_with_raw_number_cell_objects(self): |
| 1501 | + """Test table using typed RawNumberObject cells""" |
| 1502 | + block = TableBlock( |
| 1503 | + rows=[[RawTextObject(text="Count"), RawNumberObject(value=42, text="42")]], |
| 1504 | + ) |
| 1505 | + expected = { |
| 1506 | + "type": "table", |
| 1507 | + "rows": [[{"type": "raw_text", "text": "Count"}, {"type": "raw_number", "value": 42, "text": "42"}]], |
| 1508 | + } |
| 1509 | + self.assertDictEqual(expected, block.to_dict()) |
| 1510 | + |
1447 | 1511 | def test_minimal_table(self): |
1448 | 1512 | """Test table with only required fields""" |
1449 | 1513 | input = { |
|
0 commit comments