Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
python-visualization
GitHub Repository: python-visualization/folium
Path: blob/main/tests/plugins/test_scroll_zoom_toggler.py
1601 views
1
"""
2
Test ScrollZoomToggler
3
----------------------
4
"""
5
6
import folium
7
from folium import plugins
8
from folium.template import Template
9
from folium.utilities import normalize
10
11
12
def test_scroll_zoom_toggler():
13
m = folium.Map([45.0, 3.0], zoom_start=4)
14
szt = plugins.ScrollZoomToggler()
15
m.add_child(szt)
16
17
out = normalize(m._parent.render())
18
19
# Verify that the div has been created.
20
tmpl = Template(
21
"""
22
<img id="{{this.get_name()}}" alt="scroll"
23
src="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/png/512/arrow-move.png"
24
style="z-index: 999999"
25
onclick="{{this._parent.get_name()}}.toggleScroll()"></img>
26
"""
27
)
28
assert "".join(tmpl.render(this=szt).split()) in "".join(out.split())
29
30
# Verify that the style has been created
31
tmpl = Template(
32
"""
33
<style>
34
#{{this.get_name()}} {
35
position:absolute;
36
width:35px;
37
bottom:10px;
38
height:35px;
39
left:10px;
40
background-color:#fff;
41
text-align:center;
42
line-height:35px;
43
vertical-align: middle;
44
}
45
</style>
46
"""
47
)
48
expected = normalize(tmpl.render(this=szt))
49
assert expected in out
50
51
# Verify that the script is okay.
52
tmpl = Template(
53
"""
54
{{this._parent.get_name()}}.scrollEnabled = true;
55
56
{{this._parent.get_name()}}.toggleScroll = function() {
57
if (this.scrollEnabled) {
58
this.scrollEnabled = false;
59
this.scrollWheelZoom.disable();
60
} else {
61
this.scrollEnabled = true;
62
this.scrollWheelZoom.enable();
63
}
64
};
65
66
{{this._parent.get_name()}}.toggleScroll();
67
"""
68
)
69
expected = normalize(tmpl.render(this=szt))
70
assert expected in out
71
72
bounds = m.get_bounds()
73
assert bounds == [[None, None], [None, None]], bounds
74
75