diff --git a/tests/test_components.py b/tests/test_components.py
index b33ee97..262c555 100644
--- a/tests/test_components.py
+++ b/tests/test_components.py
@@ -906,5 +906,186 @@ class ResolveNameWithIconTest(unittest.TestCase):
self.assertFalse(emulated)
+class SimpleTableRenderingTest(unittest.TestCase):
+ """Test that c-simple-table renders rows correctly."""
+
+ def setUp(self):
+ components.enable_cache()
+ components._render_cached.cache_clear()
+
+ def tearDown(self):
+ components._render_cached = components._render_cached_impl
+
+ def test_simple_table_renders_list_rows(self):
+ """Verify list-style rows render as
with | + | ."""
+ from django.template.loader import render_to_string
+ result = render_to_string(
+ "cotton/simple_table.html",
+ {
+ "columns": ["Game", "Started", "Ended"],
+ "rows": [["Game1", "2025-01-01", "2025-03-01"]],
+ "header_action": None,
+ "page_obj": None,
+ "elided_page_range": None,
+ },
+ )
+ # body rows (not thead)
+ tbody = result.split(" |
")[0]
+ self.assertIn("
+ self.assertIn("th scope=\"row\"", tbody)
+ # subsequent cells are |
+ self.assertIn(" | ."""
+ from django.template.loader import render_to_string
+ result = render_to_string(
+ "cotton/simple_table.html",
+ {
+ "columns": ["Game", "Started"],
+ "rows": [],
+ "header_action": None,
+ "page_obj": None,
+ "elided_page_range": None,
+ },
+ )
+ self.assertIn(" |
")[0]
+ self.assertNotIn("")[0]
+ self.assertIn("GameA", tbody)
+ self.assertIn("GameB", tbody)
+ self.assertIn("
elements
+ self.assertEqual(tbody.count("
")[0]
+ self.assertIn('id="session-row-1"', tbody)
+ self.assertIn("device-changed", tbody)
+ self.assertIn("th scope=\"row\"", tbody)
+ self.assertIn("Game1", tbody)
+ self.assertIn("2025-01-01", tbody)
+ self.assertIn("2025-03-01", result)
+
+ def test_simple_table_empty_rows(self):
+ """Verify empty rows list renders empty
."""
+ from django.template.loader import render_to_string
+ result = render_to_string(
+ "cotton/simple_table.html",
+ {
+ "columns": ["Game", "Started"],
+ "rows": [],
+ "header_action": None,
+ "page_obj": None,
+ "elided_page_range": None,
+ },
+ )
+ self.assertIn("")[0]
+ self.assertNotIn("")[0]
+ self.assertIn("GameA", tbody)
+ self.assertIn("GameB", tbody)
+ self.assertIn("
."""
+ from django.template.loader import render_to_string
+ from django.utils.safestring import mark_safe
+ result = render_to_string(
+ "cotton/simple_table.html",
+ {
+ "columns": ["Game", "Started"],
+ "rows": [["Game1", "2025-01-01"]],
+ "header_action": mark_safe('Add'),
+ "page_obj": None,
+ "elided_page_range": None,
+ },
+ )
+ self.assertIn("Add", result)
+
+ def test_simple_table_dict_rows_with_cell_data(self):
+ """Verify dict-style rows with row_id and cell_data render correctly."""
+ from django.template.loader import render_to_string
+ result = render_to_string(
+ "cotton/simple_table.html",
+ {
+ "columns": ["Name", "Date"],
+ "rows": [
+ {
+ "row_id": "session-row-1",
+ "hx_trigger": "device-changed",
+ "cell_data": ["Game1", "2025-01-01"],
+ }
+ ],
+ "header_action": None,
+ "page_obj": None,
+ "elided_page_range": None,
+ },
+ )
+ tbody = result.split("
")[0]
+ self.assertIn('id="session-row-1"', tbody)
+ self.assertIn("device-changed", tbody)
+ self.assertIn("th scope=\"row\"", tbody)
+ self.assertIn("Game1", tbody)
+ self.assertIn("2025-01-01", tbody)
+
+
if __name__ == "__main__":
unittest.main()