Path: blob/main/tests/plugins/test_timeline.py
1601 views
"""1Test Timeline2-----------------------34"""56import json78import folium9from folium import plugins10from folium.features import GeoJsonPopup11from folium.template import Template12from folium.utilities import normalize131415def test_timeline():16m = folium.Map()1718data = json.load(open("./examples/data/historical_country_borders.json"))19timeline = plugins.Timeline(20data,21).add_to(m)22GeoJsonPopup(fields=["name"], labels=True).add_to(timeline)23slider = (24plugins.TimelineSlider(25auto_play=False,26show_ticks=True,27enable_keyboard_controls=True,28playback_duration=30000,29)30.add_timelines(timeline)31.add_to(m)32)3334out = normalize(m._parent.render())3536# Verify the imports.37assert (38'<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.timeline.min.js"></script>'39in out40)41assert (42'<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>'43in out44)4546# Verify that the script is okay.47tmpl = Template(48"""49{% macro header(this,kwargs) %}50<style>51.leaflet-bottom.leaflet-left {52width: 100%;53}54.leaflet-control-container .leaflet-timeline-controls {55box-sizing: border-box;56width: 100%;57margin: 0;58margin-bottom: 15px;59}60</style>61{% endmacro %}6263{% macro script(this, kwargs) %}64var {{ this.get_name() }}_options = {{ this.options|tojavascript }};65{% for key, value in this.functions.items() %}66{{ this.get_name() }}_options["{{key}}"] = {{ value }};67{% endfor %}6869var {{ this.get_name() }} = L.timelineSliderControl(70{{ this.get_name() }}_options71);72{{ this.get_name() }}.addTo({{ this._parent.get_name() }});7374{% for timeline in this.timelines %}75{{ this.get_name() }}.addTimelines({{ timeline.get_name() }});76{% endfor %}7778{% endmacro %}79"""80) # noqa81expected = normalize(tmpl.render(this=slider))82assert expected in out838485