From 72c6a985787bdb12332c1adf47280d2acbd0b414 Mon Sep 17 00:00:00 2001 From: Kawa Date: Mon, 13 Apr 2026 10:51:46 +0200 Subject: [PATCH] feat(09-01): add inline driver upload to printer form with OOB refresh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add id="printer-form-driver-select" to driver sentinel triggers OOB path - Add hidden
anchor for HTMX outerHTML swap target - Create tests/test_printer_form.py with test_printer_form_has_inline_driver_upload asserting stable select id, caller sentinel, and non-nested upload form Full non-e2e suite: 112 passed. --- imptune/templates/partials/printer_form.html | 15 ++++++- tests/test_printer_form.py | 46 ++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/test_printer_form.py diff --git a/imptune/templates/partials/printer_form.html b/imptune/templates/partials/printer_form.html index e0dde80..1a833b1 100644 --- a/imptune/templates/partials/printer_form.html +++ b/imptune/templates/partials/printer_form.html @@ -27,7 +27,7 @@
diff --git a/tests/test_printer_form.py b/tests/test_printer_form.py new file mode 100644 index 0000000..d88253a --- /dev/null +++ b/tests/test_printer_form.py @@ -0,0 +1,46 @@ +"""Tests for printer form template wiring — inline driver upload + OOB select.""" +from fastapi.testclient import TestClient + + +def test_printer_form_has_inline_driver_upload(client: TestClient) -> None: + """GET /printers renders printer form with: + - Driver must have id=\"printer-form-driver-select\" " + "for HTMX OOB swap to work" + ) + + # Inline upload form posts caller=printer_form sentinel + assert 'name="caller"' in html, "Inline upload form missing name=\"caller\" field" + assert 'value="printer_form"' in html, ( + "Inline upload form missing value=\"printer_form\" sentinel" + ) + + # Inline upload form targets /drivers/upload + assert 'hx-post="/drivers/upload"' in html, ( + "Inline upload form missing hx-post=\"/drivers/upload\"" + ) + + # CRITICAL: hx-post="/drivers/upload" must NOT be nested inside the printer form. + # Split on the printer form boundary and verify the upload endpoint is not inside it. + # The printer form always starts with hx-post="/printers" and ends at its . + printer_form_start = html.find('hx-post="/printers"') + assert printer_form_start != -1, "Printer form hx-post not found — template changed?" + + # Find the first after the printer form opening tag + printer_form_end = html.find("", printer_form_start) + assert printer_form_end != -1, "Printer form closing not found" + + printer_form_chunk = html[printer_form_start:printer_form_end] + assert 'hx-post="/drivers/upload"' not in printer_form_chunk, ( + "hx-post=\"/drivers/upload\" must NOT be nested inside the printer
— " + "HTML forbids nested forms and browsers silently ignore the inner one" + )