Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
janbaykara committed Sep 14, 2022
1 parent c871717 commit d74ea7c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
9 changes: 5 additions & 4 deletions groundwork/geo/templates/groundwork/geo/components/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
{% for key, val in values %}
{% if val %}data-map-{{key}}-value="{{val}}"{% endif %}
{% endfor %}
data-controller="map"
>
data-controller="map">
{{slots}}
{% if in_place != True %}
{% include "groundwork/geo/components/map_canvas.html" %}
{% if in_place is False %}
{% comment %}It's up to the developer to place the map canvas{% endcomment %}
{% else %}
{% include "groundwork/geo/components/map_canvas.html" only %}
{% endif %}
</{{element}}>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<{{element}}
<{% firstof element "div" %}
{% for key, val in attrs %}
{% if val %}{{key}}="{{val}}"{% endif %}
{% endfor %}
data-map-target="canvas">
</{{element}}>
data-map-target="canvas"
>
</{% firstof element "div" %}>
2 changes: 2 additions & 0 deletions groundwork/geo/templatetags/groundwork_geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def map(
api_key: Optional[str] = None,
center: Any = None,
zoom: Optional[int] = None,
in_place: Optional[bool] = True,
children: Optional[template.NodeList] = None,
**attrs: Dict[str, str],
) -> template.Node:
Expand All @@ -36,6 +37,7 @@ def map(
return MAP_TEMPLATE.render(
{
"element": element,
"in_place": in_place,
"values": (
("api-key", api_key),
("center", center),
Expand Down
28 changes: 28 additions & 0 deletions test/geo/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,34 @@ def test_renders_map(self):
html,
)

def test_renders_map_in_place_false_without_canvas(self):
html = render_template(
"{% load groundwork_geo %}"
'{% map in_place=False class="w-100" zoom=9 %}'
"{% endmap %}"
)

self.assertInHTML(
'<div class="w-100" data-controller="map" data-map-zoom-value="9" data-map-api-key-value="dummy">'
"</div>",
html,
)

def test_renders_map_in_place_false_with_canvas(self):
html = render_template(
"{% load groundwork_geo %}"
'{% map in_place=False class="w-100" zoom=9 %}'
'{% map_canvas class="w-50" %}'
"{% endmap %}"
)

self.assertInHTML(
'<div class="w-100" data-controller="map" data-map-zoom-value="9" data-map-api-key-value="dummy">'
'<div class="w-50" data-map-target="canvas"></div>'
"</div>",
html,
)


def render_template(content: str) -> Any:
context = Context()
Expand Down

0 comments on commit d74ea7c

Please sign in to comment.