Skip to content

Commit d74ea7c

Browse files
committed
Fix tests
1 parent c871717 commit d74ea7c

4 files changed

Lines changed: 39 additions & 7 deletions

File tree

groundwork/geo/templates/groundwork/geo/components/map.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
{% for key, val in values %}
66
{% if val %}data-map-{{key}}-value="{{val}}"{% endif %}
77
{% endfor %}
8-
data-controller="map"
9-
>
8+
data-controller="map">
109
{{slots}}
11-
{% if in_place != True %}
12-
{% include "groundwork/geo/components/map_canvas.html" %}
10+
{% if in_place is False %}
11+
{% comment %}It's up to the developer to place the map canvas{% endcomment %}
12+
{% else %}
13+
{% include "groundwork/geo/components/map_canvas.html" only %}
1314
{% endif %}
1415
</{{element}}>
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
<{{element}}
1+
<{% firstof element "div" %}
22
{% for key, val in attrs %}
33
{% if val %}{{key}}="{{val}}"{% endif %}
44
{% endfor %}
5-
data-map-target="canvas">
6-
</{{element}}>
5+
data-map-target="canvas"
6+
>
7+
</{% firstof element "div" %}>

groundwork/geo/templatetags/groundwork_geo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def map(
2424
api_key: Optional[str] = None,
2525
center: Any = None,
2626
zoom: Optional[int] = None,
27+
in_place: Optional[bool] = True,
2728
children: Optional[template.NodeList] = None,
2829
**attrs: Dict[str, str],
2930
) -> template.Node:
@@ -36,6 +37,7 @@ def map(
3637
return MAP_TEMPLATE.render(
3738
{
3839
"element": element,
40+
"in_place": in_place,
3941
"values": (
4042
("api-key", api_key),
4143
("center", center),

test/geo/test_tags.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,34 @@ def test_renders_map(self):
1818
html,
1919
)
2020

21+
def test_renders_map_in_place_false_without_canvas(self):
22+
html = render_template(
23+
"{% load groundwork_geo %}"
24+
'{% map in_place=False class="w-100" zoom=9 %}'
25+
"{% endmap %}"
26+
)
27+
28+
self.assertInHTML(
29+
'<div class="w-100" data-controller="map" data-map-zoom-value="9" data-map-api-key-value="dummy">'
30+
"</div>",
31+
html,
32+
)
33+
34+
def test_renders_map_in_place_false_with_canvas(self):
35+
html = render_template(
36+
"{% load groundwork_geo %}"
37+
'{% map in_place=False class="w-100" zoom=9 %}'
38+
'{% map_canvas class="w-50" %}'
39+
"{% endmap %}"
40+
)
41+
42+
self.assertInHTML(
43+
'<div class="w-100" data-controller="map" data-map-zoom-value="9" data-map-api-key-value="dummy">'
44+
'<div class="w-50" data-map-target="canvas"></div>'
45+
"</div>",
46+
html,
47+
)
48+
2149

2250
def render_template(content: str) -> Any:
2351
context = Context()

0 commit comments

Comments
 (0)