Test `PolyLineFromEncoded` plugin. The test ensures: - The original JS script is present in the HTML file. - The rendering from `PolyLineFromEncoded` and the original plugin gives the same output.
()
| 7 | |
| 8 | |
| 9 | def test_polyline_from_encoded(): |
| 10 | """Test `PolyLineFromEncoded` plugin. |
| 11 | |
| 12 | The test ensures: |
| 13 | - The original JS script is present in the HTML file. |
| 14 | - The rendering from `PolyLineFromEncoded` and the original plugin gives the |
| 15 | same output. |
| 16 | """ |
| 17 | |
| 18 | m = Map([35.0, -120.0], zoom_start=3) |
| 19 | |
| 20 | encoded = r"_p~iF~cn~U_ulLn{vA_mqNvxq`@" |
| 21 | kwargs = {"color": "green"} |
| 22 | polyline = PolyLineFromEncoded(encoded=encoded, **kwargs) |
| 23 | |
| 24 | polyline.add_to(m) |
| 25 | |
| 26 | out = normalize(m._parent.render()) |
| 27 | |
| 28 | script = '<script src="https://cdn.jsdelivr.net/npm/polyline-encoded@0.0.9/Polyline.encoded.js"></script>' |
| 29 | assert script in out |
| 30 | |
| 31 | tmpl = Template( |
| 32 | """ |
| 33 | var {{this.get_name()}} = L.Polyline.fromEncoded( |
| 34 | {{ this.encoded|tojson }}, |
| 35 | {{ this.options|tojavascript }} |
| 36 | ).addTo({{this._parent.get_name()}}); |
| 37 | """ |
| 38 | ) |
| 39 | |
| 40 | expected_render = tmpl.render(this=polyline) |
| 41 | actual_render = polyline._template.module.script(polyline) |
| 42 | |
| 43 | assert normalize(expected_render) == normalize(actual_render) |
| 44 | |
| 45 | |
| 46 | def test_polygon_from_encoded(): |