from dataclasses import replace from datetime import date, datetime from html import escape from zoneinfo import ZoneInfo import pytest from test_shift_report_pdf import material_report from production_analytics.presentation.shift_report import MaterialPieBlock, present_report from production_analytics.presentation.shift_report_html import render_page SHIFT_TIMEZONE = ZoneInfo("Europe/Berlin") def page(value): return render_page( machines={value.machine_name: None}, labels={"early": "Frühschicht"}, day=date(2026, 10, 14), shift="early", machine=value.machine_name, report=value, generated_at=datetime.now(SHIFT_TIMEZONE), error=None, ) def test_multiple_materials_chart_and_table(): html = page(material_report((10, 30))) assert '
' in html assert 'Materialname' in html assert "Material-0" in html and "30,00 kg" in html def test_zero_entries_omitted_and_one_material_supported(): value = material_report((0, 12, 0)) html = page(value) assert "Material-0" not in html and "Material-2" not in html assert "Material-1: 12,00 kg (100,00 %)" in html assert html.count("' not in html assert "" not in html and "" not in html assert escape(name + " (M0)") in html assert escape(name + " (M1)") in html assert "" + escape(name) + "" in html @pytest.mark.parametrize("machine", ["B1", "E1", "K7"]) def test_chart_uses_shared_consolidated_material_totals(machine): value = material_report((10, 20, 30)) items = tuple( replace( item, material_name="Harz", material_number="M1", production_order=f"order-{index}", erp_booking_share=0.5 if machine == "K7" else None, ) for index, item in enumerate(value.materials.items) ) value = replace(value, machine_name=machine, materials=replace(value.materials, items=items)) html = page(value) assert "Harz: 60,00 kg (100,00 %)" in html assert html.count("order-{index}" in html assert "ERP-Anteil" in html