From b2ea693d9d69719c44605d7e3a2261e45f6d7354 Mon Sep 17 00:00:00 2001 From: Mark <162816078+markashton480@users.noreply.github.com> Date: Wed, 4 Mar 2026 10:54:25 +0000 Subject: [PATCH] fix: resolve review blockers for comments redesign - Fix context key mismatch in _render_htmx_success ('reply' vs 'comment') - Update OOB swap selector to match new sibling relationship for replies container - Update HTMX reply tests to verify correct OOB selector and content rendering - Fix variable naming in _reply.html to match parent context --- apps/comments/tests/test_v2.py | 11 ++++++----- apps/comments/views.py | 8 ++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/comments/tests/test_v2.py b/apps/comments/tests/test_v2.py index 883be34..7f964ca 100644 --- a/apps/comments/tests/test_v2.py +++ b/apps/comments/tests/test_v2.py @@ -132,12 +132,13 @@ def test_htmx_reply_returns_oob_reply_when_approved(client, _article, approved_c ) content = resp.content.decode() assert resp.status_code == 200 - # OOB targets the parent's replies-container - assert f"#comment-{approved_comment.id}" in content - assert "hx-swap-oob" in content - # Reply uses compact markup (no nested reply form) - assert "Reply posted!" in content + # OOB targets the sibling .replies-container of the parent comment article + assert f'hx-swap-oob="beforeend:#comment-{approved_comment.id} ~ .replies-container"' in content + # Verify content is rendered (not empty due to context mismatch) + assert "Replier" in content + assert "Nice reply" in content reply = Comment.objects.exclude(pk=approved_comment.pk).get() + assert f"comment-{reply.id}" in content assert reply.parent_id == approved_comment.id assert reply.is_approved is True diff --git a/apps/comments/views.py b/apps/comments/views.py index cc3675c..228f3ff 100644 --- a/apps/comments/views.py +++ b/apps/comments/views.py @@ -148,10 +148,14 @@ class CommentCreateView(View): if comment.is_approved: ctx = _comment_template_context(comment, article, request) if comment.parent_id: - comment_html = render_to_string("comments/_reply.html", ctx, request) + # _reply.html expects 'reply' context key + reply_ctx = ctx.copy() + reply_ctx["reply"] = reply_ctx.pop("comment") + comment_html = render_to_string("comments/_reply.html", reply_ctx, request) + # .replies-container is now a sibling of #comment-{id} oob_html = ( f'