mirror of
https://github.com/django-components/django-components.git
synced 2025-09-19 20:29:44 +00:00
Merge 1671b625a3
into 8a6215b9cd
This commit is contained in:
commit
c5392d38d3
2 changed files with 77 additions and 0 deletions
|
@ -28,6 +28,17 @@ ProvideNode.register(register)
|
|||
SlotNode.register(register)
|
||||
|
||||
|
||||
@register.inclusion_tag('component_inside_include_sub.html')
|
||||
def inclusion_tag():
|
||||
return {}
|
||||
|
||||
|
||||
@register.inclusion_tag('component_inside_include_sub.html')
|
||||
def inclusion_tag_working():
|
||||
# DJC_DEPS_STRATEGY = ignore fixes the expected behavior.
|
||||
return {"DJC_DEPS_STRATEGY": 'ignore'}
|
||||
|
||||
|
||||
# For an intuitive use via Python imports, the tags are aliased to the function name.
|
||||
# E.g. so if the tag name is `slot`, one can also do:
|
||||
# `from django_components.templatetags.component_tags import slot`
|
||||
|
|
|
@ -631,3 +631,69 @@ class TestDependencyRendering:
|
|||
<div data-djc-id-ca1bc44>Another</div>
|
||||
""",
|
||||
)
|
||||
|
||||
def test_dependencies_with_component_in_inclusion_tag(self):
|
||||
registry.register(name="test_component", component=OtherComponent)
|
||||
|
||||
template_str: types.django_html = """
|
||||
{% load component_tags %}
|
||||
{% component_js_dependencies %}
|
||||
{% component_css_dependencies %}
|
||||
{% inclusion_tag %}
|
||||
"""
|
||||
template = Template(template_str)
|
||||
rendered: str = template.render(Context({}))
|
||||
|
||||
# Dependency manager script
|
||||
assertInHTML('<script src="django_components/django_components.min.js"></script>', rendered, count=1)
|
||||
assertInHTML(
|
||||
"""
|
||||
<script src="xyz1.js"></script>
|
||||
""",
|
||||
rendered,
|
||||
count=1,
|
||||
)
|
||||
assertInHTML(
|
||||
"""
|
||||
<link href="xyz1.css" media="all" rel="stylesheet">
|
||||
""",
|
||||
rendered,
|
||||
count=1,
|
||||
)
|
||||
|
||||
assert rendered.count("<script") == 4 # manager + loader + 2 OtherComponent
|
||||
assert rendered.count("<link") == 1 # 1 OtherComponent
|
||||
assert rendered.count("<style") == 1 # 1 Style
|
||||
|
||||
def test_dependencies_with_component_in_inclusion_tag_working(self):
|
||||
registry.register(name="test_component", component=OtherComponent)
|
||||
|
||||
template_str: types.django_html = """
|
||||
{% load component_tags %}
|
||||
{% component_js_dependencies %}
|
||||
{% component_css_dependencies %}
|
||||
{% inclusion_tag_working %}
|
||||
"""
|
||||
template = Template(template_str)
|
||||
rendered: str = template.render(Context({}))
|
||||
|
||||
# Dependency manager script
|
||||
assertInHTML('<script src="django_components/django_components.min.js"></script>', rendered, count=1)
|
||||
assertInHTML(
|
||||
"""
|
||||
<script src="xyz1.js"></script>
|
||||
""",
|
||||
rendered,
|
||||
count=1,
|
||||
)
|
||||
assertInHTML(
|
||||
"""
|
||||
<link href="xyz1.css" media="all" rel="stylesheet">
|
||||
""",
|
||||
rendered,
|
||||
count=1,
|
||||
)
|
||||
|
||||
assert rendered.count("<script") == 4 # manager + loader + 2 OtherComponent
|
||||
assert rendered.count("<link") == 1 # 1 OtherComponent
|
||||
assert rendered.count("<style") == 1 # 1 Style
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue