From 7a7dcedcb77064ee23217d87d2b93e58128864e5 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 14 Apr 2026 07:51:16 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Add=20test=20for=20year-by-year?= =?UTF-8?q?=20impact=20log=20toggle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: singhaditya21 <53948039+singhaditya21@users.noreply.github.com> --- tests/test_script.py | 81 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/test_script.py diff --git a/tests/test_script.py b/tests/test_script.py new file mode 100644 index 0000000..0cd8bf1 --- /dev/null +++ b/tests/test_script.py @@ -0,0 +1,81 @@ +import unittest +import os +from playwright.sync_api import sync_playwright + +class TestYearCardToggle(unittest.TestCase): + def setUp(self): + # We need absolute path for the script.js since we might run from another dir + base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + self.script_path = os.path.join(base_dir, 'script.js') + + def test_toggle_expanded_class(self): + """ + Tests that the 'expanded' class is correctly toggled on '.year-card' + elements when their '.year-card-header' is clicked. + Also verifies the first '.year-card' is expanded by default. + """ + with sync_playwright() as p: + browser = p.chromium.launch(headless=True) + page = browser.new_page() + + with open(self.script_path, "r") as f: + js_content = f.read() + + # Mocked DOM + html_content = f""" + + + + +
+
2023
+
Content 2023
+
+
+
2022
+
Content 2022
+
+ +
+ No header here +
+ + + + """ + + page.set_content(html_content) + + card1 = page.locator('#card1') + header1 = card1.locator('.year-card-header') + + card2 = page.locator('#card2') + header2 = card2.locator('.year-card-header') + + # card1 should be expanded by default (script.js adds 'expanded' to the first .year-card) + self.assertIn("expanded", card1.get_attribute("class") or "") + + # card2 should not be expanded initially + self.assertNotIn("expanded", card2.get_attribute("class") or "") + + # Action: Toggle card1 + header1.click() + # Verification: card1 should no longer be expanded + self.assertNotIn("expanded", card1.get_attribute("class") or "") + + # Action: Toggle card2 + header2.click() + # Verification: card2 should now be expanded + self.assertIn("expanded", card2.get_attribute("class") or "") + + # Action: Toggle card1 back + header1.click() + # Verification: card1 should be expanded again + self.assertIn("expanded", card1.get_attribute("class") or "") + + browser.close() + +if __name__ == '__main__': + unittest.main()