Test `PolygonFromEncoded` plugin. The test ensures: - The original JS script is present in the HTML file. - The rendering from `PolygonFromEncoded` and the original plugin gives the same output.
()
| 44 | |
| 45 | |
| 46 | def test_polygon_from_encoded(): |
| 47 | """Test `PolygonFromEncoded` plugin. |
| 48 | |
| 49 | The test ensures: |
| 50 | - The original JS script is present in the HTML file. |
| 51 | - The rendering from `PolygonFromEncoded` and the original plugin gives the |
| 52 | same output. |
| 53 | """ |
| 54 | |
| 55 | m = Map([40.0, -80.0], zoom_start=3) |
| 56 | |
| 57 | encoded = r"w`j~FpxivO}jz@qnnCd}~Bsa{@~f`C`lkH" |
| 58 | polygon = PolygonFromEncoded(encoded=encoded, kwargs={}) |
| 59 | |
| 60 | polygon.add_to(m) |
| 61 | |
| 62 | out = normalize(m._parent.render()) |
| 63 | |
| 64 | script = '<script src="https://cdn.jsdelivr.net/npm/polyline-encoded@0.0.9/Polyline.encoded.js"></script>' |
| 65 | assert script in out |
| 66 | |
| 67 | tmpl = Template( |
| 68 | """ |
| 69 | var {{this.get_name()}} = L.Polygon.fromEncoded( |
| 70 | {{ this.encoded|tojson }}, |
| 71 | {{ this.options|tojavascript }} |
| 72 | ) |
| 73 | .addTo({{this._parent.get_name()}}); |
| 74 | """ |
| 75 | ) |
| 76 | |
| 77 | expected_render = tmpl.render(this=polygon) |
| 78 | |
| 79 | actual_render = polygon._template.module.script(polygon) |
| 80 | |
| 81 | assert normalize(expected_render) == normalize(actual_render) |