# -*- coding: utf-8 -*-
"""
Test FastMarkerCluster
------------------
"""

from jinja2 import Template
import numpy as np

import folium
from folium import plugins


def test_fast_marker_cluster():
    n = 100
    np.random.seed(seed=26082009)
    data = np.array([
        np.random.uniform(low=35, high=60, size=n),   # Random latitudes.
        np.random.uniform(low=-12, high=30, size=n),  # Random longitudes.
        range(n),                                     # Popups.
    ]).tolist()
    m = folium.Map([45., 3.], zoom_start=4)
    mc = plugins.FastMarkerCluster(data, callback=None)
    m.add_children(mc)
    m._repr_html_()

    out = m._parent.render()

    # We verify that imports
    assert ('<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.'
            'markercluster/0.4.0/leaflet.markercluster.js"></script>') in out
    assert ('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/'
            'libs/leaflet.markercluster/0.4.0/MarkerCluster.css" />') in out
    assert ('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/'
            'libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css" />'
            ) in out

    # Verify the script part is okay.
    tmpl = Template("""
        {% macro script(this, kwargs) %}
        (function() {
            var data = {{this._data}};
            var map = {{this._parent.get_name()}};
            var cluster = L.markerClusterGroup();
            {{this._callback}}

            for (var i = 0; i < data.length; i++) {
                var row = data[i];
                var marker = callback(row, popup='names');
                marker.addTo(cluster);
            }

            cluster.addTo(map);
        })();
        {% endmacro %}
    """)

    assert ''.join(tmpl.render(this=mc).split()) in ''.join(out.split())

# -*- coding: utf-8 -*-
"""
Test FastMarkerCluster
------------------
"""

from jinja2 import Template
import numpy as np

import folium
from folium import plugins


def test_fast_marker_cluster():
    n = 100
    np.random.seed(seed=26082009)
    data = np.array([
        np.random.uniform(low=35, high=60, size=n),   # Random latitudes.
        np.random.uniform(low=-12, high=30, size=n),  # Random longitudes.
        range(n),                                     # Popups.
    ]).tolist()
    m = folium.Map([45., 3.], zoom_start=4)
    mc = plugins.FastMarkerCluster(data, callback=None)
    m.add_child(mc)
    m._repr_html_()

    out = m._parent.render()

    # We verify that imports
    assert ('<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.'
            'markercluster/0.4.0/leaflet.markercluster.js"></script>') in out
    assert ('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/'
            'libs/leaflet.markercluster/0.4.0/MarkerCluster.css" />') in out
    assert ('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/'
            'libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css" />'
            ) in out

    # Verify the script part is okay.
    tmpl = Template("""
        {% macro script(this, kwargs) %}
        (function() {
            var data = {{this._data}};
            var map = {{this._parent.get_name()}};
            var cluster = L.markerClusterGroup();
            {{this._callback}}

            for (var i = 0; i < data.length; i++) {
                var row = data[i];
                var marker = callback(row, popup='names');
                marker.addTo(cluster);
            }

            cluster.addTo(map);
        })();
        {% endmacro %}
    """)

    assert ''.join(tmpl.render(this=mc).split()) in ''.join(out.split())

Remove deprecated add_children method call