diff --git a/umap/static/umap/test/Map.Export.js b/umap/static/umap/test/Map.Export.js
deleted file mode 100644
index 006cedef..00000000
--- a/umap/static/umap/test/Map.Export.js
+++ /dev/null
@@ -1,106 +0,0 @@
-describe('U.Map.Export', function () {
- let map
- before(async () => {
- await fetchMock.mock(
- /\/datalayer\/62\/\?.*/,
- JSON.stringify(RESPONSES.datalayer62_GET)
- )
- this.options = {
- umap_id: 99,
- }
- map = initMap({ umap_id: 99 })
- const datalayer_options = defaultDatalayerData()
- await map.initDataLayers([datalayer_options])
- })
- after(function () {
- fetchMock.restore()
- clickCancel()
- resetMap()
- })
-
- describe('#formatters()', function () {
- it('should export to geojson', function () {
- const { content, filetype, filename } = map.share.format('geojson')
- assert.equal(filetype, 'application/json')
- assert.equal(filename, 'name_of_the_map.geojson')
- assert.deepEqual(JSON.parse(content), {
- type: 'FeatureCollection',
- features: [
- {
- type: 'Feature',
- properties: {
- name: 'name poly',
- },
- geometry: {
- type: 'Polygon',
- coordinates: [
- [
- [11.25, 53.585984],
- [10.151367, 52.975108],
- [12.689209, 52.167194],
- [14.084473, 53.199452],
- [12.634277, 53.618579],
- [11.25, 53.585984],
- [11.25, 53.585984],
- ],
- ],
- },
- },
- {
- type: 'Feature',
- properties: {
- _umap_options: {
- color: 'OliveDrab',
- },
- name: 'test',
- },
- geometry: {
- type: 'Point',
- coordinates: [-0.274658, 52.57635],
- },
- },
- {
- type: 'Feature',
- properties: {
- _umap_options: {
- fill: false,
- opacity: 0.6,
- },
- name: 'test',
- },
- geometry: {
- type: 'LineString',
- coordinates: [
- [-0.571289, 54.476422],
- [0.439453, 54.610255],
- [1.724854, 53.448807],
- [4.163818, 53.988395],
- [5.306396, 53.533778],
- [6.591797, 53.709714],
- [7.042236, 53.350551],
- ],
- },
- },
- ],
- })
- })
-
- it('should export to gpx', function () {
- const { content, filetype, filename } = map.share.format('gpx')
- assert.equal(filetype, 'application/gpx+xml')
- assert.equal(filename, 'name_of_the_map.gpx')
- const expected =
- 'testname=testname polyname=name polytestname=test'
- assert.equal(content, expected)
- })
-
- it('should export to kml', function () {
- const { content, filetype, filename } = map.share.format('kml')
- assert.equal(filetype, 'application/vnd.google-earth.kml+xml')
- assert.equal(filename, 'name_of_the_map.kml')
- const expected =
- 'name polyname poly11.25,53.585984 10.151367,52.975108 12.689209,52.167194 14.084473,53.199452 12.634277,53.618579 11.25,53.585984 11.25,53.585984test[object Object]test-0.274658,52.57635test[object Object]test-0.571289,54.476422 0.439453,54.610255 1.724854,53.448807 4.163818,53.988395 5.306396,53.533778 6.591797,53.709714 7.042236,53.350551'
- assert.equal(content, expected)
- })
- })
-})
diff --git a/umap/static/umap/test/index.html b/umap/static/umap/test/index.html
index e01794a3..254728ce 100644
--- a/umap/static/umap/test/index.html
+++ b/umap/static/umap/test/index.html
@@ -88,7 +88,6 @@
-
diff --git a/umap/tests/integration/test_export_map.py b/umap/tests/integration/test_export_map.py
index 69599dde..1f65d46f 100644
--- a/umap/tests/integration/test_export_map.py
+++ b/umap/tests/integration/test_export_map.py
@@ -4,10 +4,84 @@ from pathlib import Path
import pytest
from playwright.sync_api import expect
+from ..base import DataLayerFactory
+
pytestmark = pytest.mark.django_db
+DATALAYER_DATA = {
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "properties": {
+ "name": "name poly",
+ },
+ "id": "gyNzM",
+ "geometry": {
+ "type": "Polygon",
+ "coordinates": [
+ [
+ [11.25, 53.585984],
+ [10.151367, 52.975108],
+ [12.689209, 52.167194],
+ [14.084473, 53.199452],
+ [12.634277, 53.618579],
+ [11.25, 53.585984],
+ [11.25, 53.585984],
+ ],
+ ],
+ },
+ },
+ {
+ "type": "Feature",
+ "properties": {
+ "_umap_options": {
+ "color": "OliveDrab",
+ },
+ "name": "test",
+ "description": "Some description",
+ },
+ "id": "QwNjg",
+ "geometry": {
+ "type": "Point",
+ "coordinates": [-0.274658, 52.57635],
+ },
+ },
+ {
+ "type": "Feature",
+ "properties": {
+ "_umap_options": {
+ "fill": False,
+ "opacity": 0.6,
+ },
+ "name": "test",
+ },
+ "id": "YwMTM",
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [-0.571289, 54.476422],
+ [0.439453, 54.610255],
+ [1.724854, 53.448807],
+ [4.163818, 53.988395],
+ [5.306396, 53.533778],
+ [6.591797, 53.709714],
+ [7.042236, 53.350551],
+ ],
+ },
+ },
+ ],
+}
-def test_umap_export(map, live_server, datalayer, page):
+
+@pytest.fixture
+def bootstrap(map, live_server):
+ map.settings["properties"]["onLoadPanel"] = "databrowser"
+ map.save()
+ DataLayerFactory(map=map, data=DATALAYER_DATA)
+
+
+def test_umap_export(map, live_server, bootstrap, page):
page.goto(f"{live_server.url}{map.get_absolute_url()}?share")
link = page.get_by_role("link", name="full backup")
expect(link).to_be_visible()
@@ -34,16 +108,56 @@ def test_umap_export(map, live_server, datalayer, page):
"features": [
{
"geometry": {
- "coordinates": [14.68896484375, 48.55297816440071],
+ "coordinates": [
+ [
+ [11.25, 53.585984],
+ [10.151367, 52.975108],
+ [12.689209, 52.167194],
+ [14.084473, 53.199452],
+ [12.634277, 53.618579],
+ [11.25, 53.585984],
+ [11.25, 53.585984],
+ ]
+ ],
+ "type": "Polygon",
+ },
+ "id": "gyNzM",
+ "properties": {"name": "name poly"},
+ "type": "Feature",
+ },
+ {
+ "geometry": {
+ "coordinates": [-0.274658, 52.57635],
"type": "Point",
},
+ "id": "QwNjg",
"properties": {
- "_umap_options": {"color": "DarkCyan", "iconClass": "Ball"},
- "description": "Da place anonymous " "again 755",
- "name": "Here",
+ "_umap_options": {"color": "OliveDrab"},
+ "name": "test",
+ "description": "Some description",
},
"type": "Feature",
- }
+ },
+ {
+ "geometry": {
+ "coordinates": [
+ [-0.571289, 54.476422],
+ [0.439453, 54.610255],
+ [1.724854, 53.448807],
+ [4.163818, 53.988395],
+ [5.306396, 53.533778],
+ [6.591797, 53.709714],
+ [7.042236, 53.350551],
+ ],
+ "type": "LineString",
+ },
+ "id": "YwMTM",
+ "properties": {
+ "_umap_options": {"fill": False, "opacity": 0.6},
+ "name": "test",
+ },
+ "type": "Feature",
+ },
],
"type": "FeatureCollection",
}
@@ -66,12 +180,13 @@ def test_umap_export(map, live_server, datalayer, page):
"tilelayersControl": True,
"zoom": 7,
"zoomControl": True,
+ "onLoadPanel": "databrowser",
},
"type": "umap",
}
-def test_csv_export(map, live_server, datalayer, page):
+def test_csv_export(map, live_server, bootstrap, page):
page.goto(f"{live_server.url}{map.get_absolute_url()}?share")
button = page.get_by_role("button", name="csv")
expect(button).to_be_visible()
@@ -83,6 +198,108 @@ def test_csv_export(map, live_server, datalayer, page):
download.save_as(path)
assert (
path.read_text()
- == """name,description,Latitude,Longitude
-Here,Da place anonymous again 755,48.55297816440071,14.68896484375"""
+ == """name,Latitude,Longitude,description
+name poly,53.0072070131872,12.182431646910137,
+test,52.57635,-0.274658,Some description
+test,53.725145179688646,2.9700064980570517,"""
)
+
+
+def test_gpx_export(map, live_server, bootstrap, page):
+ page.goto(f"{live_server.url}{map.get_absolute_url()}?share")
+ button = page.get_by_role("button", name="gpx")
+ expect(button).to_be_visible()
+ with page.expect_download() as download_info:
+ button.click()
+ download = download_info.value
+ # FIXME assert mimetype (find no way to access it throught PW)
+ assert download.suggested_filename == "test_map.gpx"
+ path = Path("/tmp/") / download.suggested_filename
+ download.save_as(path)
+ assert (
+ path.read_text()
+ == """testname=test
+description=Some descriptionname polyname=name polytestname=test"""
+ )
+
+
+def test_kml_export(map, live_server, bootstrap, page):
+ page.goto(f"{live_server.url}{map.get_absolute_url()}?share")
+ button = page.get_by_role("button", name="kml")
+ expect(button).to_be_visible()
+ with page.expect_download() as download_info:
+ button.click()
+ download = download_info.value
+ assert download.suggested_filename == "test_map.kml"
+ path = Path("/tmp/") / download.suggested_filename
+ download.save_as(path)
+ assert (
+ path.read_text()
+ == """name polyname poly11.25,53.585984 10.151367,52.975108 12.689209,52.167194 14.084473,53.199452 12.634277,53.618579 11.25,53.585984 11.25,53.585984testSome description[object Object]testSome description-0.274658,52.57635test[object Object]test-0.571289,54.476422 0.439453,54.610255 1.724854,53.448807 4.163818,53.988395 5.306396,53.533778 6.591797,53.709714 7.042236,53.350551"""
+ )
+
+
+def test_geojson_export(map, live_server, bootstrap, page):
+ page.goto(f"{live_server.url}{map.get_absolute_url()}?share")
+ button = page.get_by_role("button", name="geojson")
+ expect(button).to_be_visible()
+ with page.expect_download() as download_info:
+ button.click()
+ download = download_info.value
+ assert download.suggested_filename == "test_map.geojson"
+ path = Path("/tmp/") / download.suggested_filename
+ download.save_as(path)
+ assert json.loads(path.read_text()) == {
+ "features": [
+ {
+ "geometry": {
+ "coordinates": [
+ [
+ [11.25, 53.585984],
+ [10.151367, 52.975108],
+ [12.689209, 52.167194],
+ [14.084473, 53.199452],
+ [12.634277, 53.618579],
+ [11.25, 53.585984],
+ [11.25, 53.585984],
+ ]
+ ],
+ "type": "Polygon",
+ },
+ "id": "gyNzM",
+ "properties": {"name": "name poly"},
+ "type": "Feature",
+ },
+ {
+ "geometry": {"coordinates": [-0.274658, 52.57635], "type": "Point"},
+ "id": "QwNjg",
+ "properties": {
+ "_umap_options": {"color": "OliveDrab"},
+ "name": "test",
+ "description": "Some description",
+ },
+ "type": "Feature",
+ },
+ {
+ "geometry": {
+ "coordinates": [
+ [-0.571289, 54.476422],
+ [0.439453, 54.610255],
+ [1.724854, 53.448807],
+ [4.163818, 53.988395],
+ [5.306396, 53.533778],
+ [6.591797, 53.709714],
+ [7.042236, 53.350551],
+ ],
+ "type": "LineString",
+ },
+ "id": "YwMTM",
+ "properties": {
+ "_umap_options": {"fill": False, "opacity": 0.6},
+ "name": "test",
+ },
+ "type": "Feature",
+ },
+ ],
+ "type": "FeatureCollection",
+ }