@@ -44,6 +44,11 @@ def profile_page(browser, live_server: str, _register_profile_user):
4444 context .close ()
4545
4646
47+ # Generous bound for htmx round trips under CI load; the assertions below
48+ # still fail fast on a genuinely broken swap since they poll, not sleep.
49+ HTMX_SWAP_TIMEOUT_MS = 10_000
50+
51+
4752def test_edit_profile_swap_cycle (profile_page : Page ):
4853 """Clicking Edit fetches the form via hx-get; submitting swaps back to display."""
4954 page = profile_page
@@ -53,16 +58,27 @@ def test_edit_profile_swap_cycle(profile_page: Page):
5358 expect (card .locator ("button:has-text('Edit')" )).to_be_visible ()
5459 expect (card .locator ("form" )).to_have_count (0 )
5560
56- # Click Edit — fetches form partial via hx-get
57- card .locator ("button:has-text('Edit')" ).click ()
58- expect (card .locator ('button:has-text("Save Changes")' )).to_be_visible (timeout = 5_000 )
61+ # Click Edit — fetches form partial via hx-get. Wait for the response
62+ # itself (not just the eventual DOM state) so a slow server round trip
63+ # produces a clear network-timeout failure rather than a flaky locator
64+ # mismatch.
65+ with page .expect_response ("**/user/edit-form" ):
66+ card .locator ("button:has-text('Edit')" ).click ()
67+ expect (card .locator ('button:has-text("Save Changes")' )).to_be_visible (
68+ timeout = HTMX_SWAP_TIMEOUT_MS
69+ )
5970
6071 # Submit the form
61- card .locator ('button[type="submit"]' ).click ()
72+ with page .expect_response ("**/user/update" ):
73+ card .locator ('button[type="submit"]' ).click ()
6274
6375 # Should swap back to display mode
64- expect (card .locator ("button:has-text('Edit')" )).to_be_visible (timeout = 5_000 )
65- expect (card .locator ('button[type="submit"]' )).to_have_count (0 , timeout = 5_000 )
76+ expect (card .locator ("button:has-text('Edit')" )).to_be_visible (
77+ timeout = HTMX_SWAP_TIMEOUT_MS
78+ )
79+ expect (card .locator ('button[type="submit"]' )).to_have_count (
80+ 0 , timeout = HTMX_SWAP_TIMEOUT_MS
81+ )
6682
6783
6884def test_edit_profile_cancel (profile_page : Page ):
@@ -71,15 +87,23 @@ def test_edit_profile_cancel(profile_page: Page):
7187 card = page .locator ("#profile-card" )
7288
7389 # Click Edit
74- card .locator ("button:has-text('Edit')" ).click ()
75- expect (card .locator ('button:has-text("Save Changes")' )).to_be_visible (timeout = 5_000 )
90+ with page .expect_response ("**/user/edit-form" ):
91+ card .locator ("button:has-text('Edit')" ).click ()
92+ expect (card .locator ('button:has-text("Save Changes")' )).to_be_visible (
93+ timeout = HTMX_SWAP_TIMEOUT_MS
94+ )
7695
7796 # Click Cancel
78- card .locator ("button:has-text('Cancel')" ).click ()
97+ with page .expect_response ("**/user/profile-display" ):
98+ card .locator ("button:has-text('Cancel')" ).click ()
7999
80100 # Should swap back to display mode
81- expect (card .locator ("button:has-text('Edit')" )).to_be_visible (timeout = 5_000 )
82- expect (card .locator ('button[type="submit"]' )).to_have_count (0 , timeout = 5_000 )
101+ expect (card .locator ("button:has-text('Edit')" )).to_be_visible (
102+ timeout = HTMX_SWAP_TIMEOUT_MS
103+ )
104+ expect (card .locator ('button[type="submit"]' )).to_have_count (
105+ 0 , timeout = HTMX_SWAP_TIMEOUT_MS
106+ )
83107
84108
85109def test_add_email_form_resets_after_submit (profile_page : Page ):
@@ -94,7 +118,8 @@ def test_add_email_form_resets_after_submit(profile_page: Page):
94118 email_input .fill ("new-browser-test@example.com" )
95119 assert email_input .input_value () == "new-browser-test@example.com"
96120
97- page .click ('form:has(input[name="new_email"]) button[type="submit"]' )
121+ with page .expect_response ("**/account/emails/add" ):
122+ page .click ('form:has(input[name="new_email"]) button[type="submit"]' )
98123
99124 # hx-on::after-settle resets the form after the swap completes
100- expect (email_input ).to_have_value ("" , timeout = 5_000 )
125+ expect (email_input ).to_have_value ("" , timeout = HTMX_SWAP_TIMEOUT_MS )
0 commit comments