From e565002244d30d51b960d297f8bd4ee75870a3c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Tue, 12 May 2026 10:21:33 +0200 Subject: [PATCH] Add simple table rendering tests --- tests/test_components.py | 181 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) 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")[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()