feat(11-01): UIE-02 — dedicated Add Printer page at GET /printers/new
- Create imptune/templates/printers_new.html: full page extending base.html
with plain <form action="/printers" method="post"> (no HTMX, browser follows 303)
and inline driver upload sub-form
- Update imptune/templates/printers.html: remove inline Add Printer form,
add <a href="/printers/new" role="button">Add Printer</a> link
- Add GET /printers/new route in imptune/api/pages.py (placed before /{printer_id})
- Change POST /printers to always return RedirectResponse(url='/printers', status_code=303)
- Update existing POST /printers tests to assert 303 + follow_redirects=False
- Update test_printer_form.py to check /printers/new instead of /printers (UIE-02 arch)
- UIE-02 tests GREEN; UIE-01/03 scaffolds remain RED (expected — not yet implemented)
This commit is contained in:
+16
-21
@@ -3,44 +3,39 @@ from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
def test_printer_form_has_inline_driver_upload(client: TestClient) -> None:
|
||||
"""GET /printers renders printer form with:
|
||||
"""GET /printers/new renders printer form with:
|
||||
- Driver <select> with stable id="printer-form-driver-select"
|
||||
- Inline upload form with caller=printer_form hidden field
|
||||
- hx-post="/drivers/upload" NOT nested inside the printer <form>
|
||||
- hx-post="/drivers/upload" for the driver upload sub-form
|
||||
- Plain <form action="/printers" method="post"> for the printer (no HTMX on main form)
|
||||
|
||||
Updated in 11-01: form moved from /printers to /printers/new (UIE-02).
|
||||
"""
|
||||
resp = client.get("/printers")
|
||||
resp = client.get("/printers/new")
|
||||
assert resp.status_code == 200
|
||||
html = resp.text
|
||||
|
||||
# Driver select has stable id for OOB swap target
|
||||
assert 'id="printer-form-driver-select"' in html, (
|
||||
"Printer form driver <select> must have id=\"printer-form-driver-select\" "
|
||||
'Printer form driver <select> 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 '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 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\""
|
||||
'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 </form>.
|
||||
printer_form_start = html.find('hx-post="/printers"')
|
||||
assert printer_form_start != -1, "Printer form hx-post not found — template changed?"
|
||||
|
||||
# Find the first </form> after the printer form opening tag
|
||||
printer_form_end = html.find("</form>", printer_form_start)
|
||||
assert printer_form_end != -1, "Printer form closing </form> 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 <form> — "
|
||||
"HTML forbids nested forms and browsers silently ignore the inner one"
|
||||
# Main printer form uses plain POST (no HTMX) so browser follows 303 redirect
|
||||
assert 'action="/printers"' in html, (
|
||||
'Printer form must use action="/printers" (plain HTML form, not hx-post)'
|
||||
)
|
||||
assert 'method="post"' in html, (
|
||||
'Printer form must use method="post"'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user