Files
RollCalcPython/tests/test_template_integration.py

56 lines
2.5 KiB
Python

from pathlib import Path
import unittest
PROJECT_ROOT = Path(__file__).resolve().parents[1]
class TemplatePdfIntegrationTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.template = (PROJECT_ROOT / "templates" / "roll_calculator.html").read_text(
encoding="utf-8"
)
cls.pdf_report = (PROJECT_ROOT / "pdf_report.py").read_text(encoding="utf-8")
def test_ui_uses_the_headless_calculation_result(self):
self.assertIn("fetch('/api/calculations/roll'", self.template)
self.assertIn("calculation.average_diameter_mm", self.template)
self.assertIn("calculation.effective_roll_length_m", self.template)
def test_product_length_ui_uses_the_shared_domain_endpoint(self):
self.assertIn("fetch('/api/calculations/product-length'", self.template)
self.assertIn("calculation.average_product_length_m", self.template)
self.assertNotIn("const L_calc = (Math.PI / (4 * t))", self.template)
self.assertNotIn("function calculateDiameterResult", self.template)
def test_optional_weight_requires_both_weight_inputs(self):
self.assertIn(
"include_roll_weight: width !== null && areaWeight !== null",
self.template,
)
def test_pdf_action_starts_disabled_and_posts_structured_result(self):
self.assertIn('id="d-pdf" type="button" disabled', self.template)
self.assertIn("body: JSON.stringify(window.CURRENT_ROLL_REQUEST)", self.template)
self.assertIn("function invalidatePdfReport()", self.template)
def test_pdf_layout_uses_four_primary_result_cards(self):
self.assertIn('"CALCULATION RESULTS"', self.pdf_report)
self.assertIn('(("ROLL", "LENGTH"), report["roll_length"]["display"])', self.pdf_report)
def test_direct_forklift_display_consumes_service_warning_or_note(self):
self.assertIn("renderAuthoritativeForkliftResult(authoritativeResult)", self.template)
self.assertIn("const warning = result.warnings?.[0]", self.template)
self.assertIn("const note = result.notes?.[0]", self.template)
def test_transport_ui_uses_shared_api_without_a_browser_capacity_calculator(self):
self.assertIn("fetch('/api/calculations/transport'", self.template)
self.assertIn("this.showResults(payload.analysis)", self.template)
self.assertNotIn("calculateLoadUtilization", self.template)
self.assertNotIn("class LoadOptimizer {", self.template)
if __name__ == "__main__":
unittest.main()