Skip to content

Commit

Permalink
morph method (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-yin authored Aug 1, 2024
1 parent 861d1e0 commit 6c800ec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
1 change: 0 additions & 1 deletion docs/source/turbo_stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Turbo Stream built-in actions are all supported in syntax `turbo_stream.xxx`:
- remove
- before
- after
- morph

### TurboStreamResponse

Expand Down
10 changes: 0 additions & 10 deletions src/turbo_helper/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ def update(target, content=None, **kwargs):
return turbo_stream.action("update", target, content, **kwargs)


@register_turbo_stream_action("morph")
def morph(target, content=None, **kwargs):
return turbo_stream.action("morph", target, content, **kwargs)


################################################################################


Expand Down Expand Up @@ -171,8 +166,3 @@ def replace_all(targets, content=None, **kwargs):
@register_turbo_stream_action("update_all")
def update_all(targets, content=None, **kwargs):
return turbo_stream.action_all("update", targets, content, **kwargs)


@register_turbo_stream_action("morph_all")
def morph_all(targets, content=None, **kwargs):
return turbo_stream.action_all("morph_all", targets, content, **kwargs)
31 changes: 18 additions & 13 deletions tests/test_stream.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.http import HttpRequest
from django.utils.safestring import mark_safe

from tests.test_tags import render
from tests.utils import assert_dom_equal
from turbo_helper import turbo_stream
from turbo_helper.constants import TURBO_STREAM_MIME_TYPE
Expand Down Expand Up @@ -101,22 +102,26 @@ def test_response(self, rf):
)


class TestMorph:
def test_morph(self):
stream = '<turbo-stream target="#input" action="morph"><template><p>Morph</p></template></turbo-stream>'
class TestMorphMethod:
def test_update_morph_method(self):
stream = '<turbo-stream target="#input" action="update" method="morph"><template><p>Morph</p></template></turbo-stream>'
assert_dom_equal(
stream, turbo_stream.morph("#input", mark_safe("<p>Morph</p>"))
)

def test_morph_with_targets_as_positional_arg_and_html_as_kwarg(self):
stream = '<turbo-stream targets=".test" action="morph_all"><template><p>Morph</p></template></turbo-stream>'
assert_dom_equal(
stream, turbo_stream.morph_all(".test", mark_safe("<p>Morph</p>"))
stream,
turbo_stream.update("#input", mark_safe("<p>Morph</p>"), method="morph"),
)

def test_morph_with_additional_arguments(self):
stream = '<turbo-stream target="#input" action="morph" something="else"><template><p>Morph</p></template></turbo-stream>'
def test_replace_morph_method(self):
stream = '<turbo-stream target="#input" action="replace" method="morph"><template><p>Morph</p></template></turbo-stream>'
assert_dom_equal(
stream,
turbo_stream.morph("#input", mark_safe("<p>Morph</p>"), something="else"),
turbo_stream.replace("#input", mark_safe("<p>Morph</p>"), method="morph"),
)

def test_tag(self, register_toast_action):
template = """
{% load turbo_helper %}
{% turbo_stream "update" dom_id method="morph" %}{% endturbo_stream %}
"""
output = render(template, {"dom_id": "test"}).strip()
assert '<turbo-stream action="update" target="test" method="morph">' in output

0 comments on commit 6c800ec

Please sign in to comment.