#!/usr/bin/env python3 """Integration test for cron.html page.""" import subprocess, sys, json, re def curl(path): r = subprocess.run(["curl", "-s", "http://127.0.0.1:5000" + path], capture_output=True, text=True, timeout=10) return r.returncode, r.stdout passed = 0 failed = 0 def test(name, condition, detail=""): global passed, failed if condition: passed += 1 print(f" PASS: {name}") else: failed += 1 print(f" FAIL: {name} {detail}") print("\n=== S2: Cron Page Integration Tests ===\n") # ── Test 1: Page loads ── code, html = curl("/cron") test("GET /cron returns 200", code == 0 and "cron" in html.lower(), f"code={code}") # ── Test 2: Key JS functions exist ── test("loadJobs function exists", 'loadJobs' in html, "JS function not found") test("loadLogs function exists", 'loadLogs' in html, "JS function not found") test("switchTab function exists", 'switchTab' in html, "JS function not found") test("escHtml used (from base)", 'escHtml' in html, "escHtml not referenced") # ── Test 3: JS escaping checks ── test("No style=backslash bug", 'style=\\' not in html, "STYLE BACKSLASH found") test("No triple escape bug", '\\\\\\\\\\\\\\\"' not in html, "TRIPLE ESCAPE found") # ── Test 4: Key DOM elements ── test("Tab config container exists", 'id="tab-config"' in html, "tab-config not found") test("Tab logs container exists", 'id="tab-logs"' in html, "tab-logs not found") test("Job selector exists", 'id="job-select"' in html, "job-select not found") # ── Test 5: API call patterns ── test("Fetches /api/cron/list", '/api/cron/list' in html, "API path not found") test("Fetches /api/cron/logs/", '/api/cron/logs/' in html, "API path not found") # ── Test 6: Auto-refresh ── test("Has setInterval for auto-refresh", 'setInterval' in html, "No auto-refresh") # ── Test 7: Tab switch buttons ── test("Tab-config button exists", 'id="btn-tab-config"' in html, "btn-tab-config not found") test("Tab-logs button exists", 'id="btn-tab-logs"' in html, "btn-tab-logs not found") print(f"\n=== Result: {passed} passed, {failed} failed ===") sys.exit(0 if failed == 0 else 1)