{{ comment.body }}
- {% include "comments/_reactions.html" with comment=comment counts=comment.reaction_counts user_reacted=comment.user_reacted %} -{{ reply.body }}
+ +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'
{{ comment.body }}
- {% include "comments/_reactions.html" with comment=comment counts=comment.reaction_counts user_reacted=comment.user_reacted %} -{{ reply.body }}
+ +
Post a Comment
- {% if success_message %} -{{ error }}
{% endfor %} - {% for field in comment_form %}{% for error in field.errors %}{{ field.label }}: {{ error }}
{% endfor %}{% endfor %} -