diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index 94958370..4b2ddd76 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -888,7 +888,9 @@ U.PathMixin = { const other = new (this instanceof U.Polyline ? U.Polyline : U.Polygon)( this.map, shape, - { geojson: { properties: properties } } + { + geojson: { properties }, + } ) this.datalayer.addLayer(other) other.edit() diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index b4df88cf..7383f74c 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -974,6 +974,8 @@ U.Map = L.Map.extend({ formData.append('settings', JSON.stringify(geojson)) const uri = this.urls.get('map_save', { map_id: this.options.umap_id }) const [data, response, error] = await this.server.post(uri, {}, formData) + // FIXME: login_required response will not be an error, so it will not + // stop code while it should if (!error) { let duration = 3000, alert = { content: L._('Map has been saved!'), level: 'info' } diff --git a/umap/static/umap/test/Choropleth.js b/umap/static/umap/test/Choropleth.js deleted file mode 100644 index de479af3..00000000 --- a/umap/static/umap/test/Choropleth.js +++ /dev/null @@ -1,245 +0,0 @@ -const POLYGONS = { - _umap_options: defaultDatalayerData(), - type: 'FeatureCollection', - features: [ - { - type: 'Feature', - properties: { - name: 'number 1', - value: 45, - }, - geometry: { - type: 'Polygon', - coordinates: [ - [ - [0, 49], - [-2, 47], - [1, 46], - [3, 47], - [0, 49], - ], - ], - }, - }, - { - type: 'Feature', - properties: { - name: 'number 2', - value: 87, - }, - geometry: { - type: 'Polygon', - coordinates: [ - [ - [0, 49], - [2, 50], - [6, 49], - [4, 47], - [0, 49], - ], - ], - }, - }, - { - type: 'Feature', - properties: { - name: 'number 3', - value: 673, - }, - geometry: { - type: 'Polygon', - coordinates: [ - [ - [4, 47], - [6, 49], - [11, 47], - [9, 45], - [4, 47], - ], - ], - }, - }, - { - type: 'Feature', - properties: { - name: 'number 4', - value: 674, - }, - geometry: { - type: 'Polygon', - coordinates: [ - [ - [2, 46], - [4, 47], - [8, 45], - [6, 43], - [2, 46], - ], - ], - }, - }, - { - type: 'Feature', - properties: { - name: 'number 5', - value: 839, - }, - geometry: { - type: 'Polygon', - coordinates: [ - [ - [-2, 47], - [1, 46], - [0, 44], - [-4, 45], - [-2, 47], - ], - ], - }, - }, - { - type: 'Feature', - properties: { - name: 'number 6', - value: 3829, - }, - geometry: { - type: 'Polygon', - coordinates: [ - [ - [1, 45], - [5, 43], - [4, 42], - [0, 44], - [1, 45], - ], - ], - }, - }, - { - type: 'Feature', - properties: { - name: 'number 7', - value: 4900, - }, - geometry: { - type: 'Polygon', - coordinates: [ - [ - [9, 45], - [12, 47], - [15, 45], - [13, 43], - [9, 45], - ], - ], - }, - }, - { - type: 'Feature', - properties: { - name: 'number 8', - value: 4988, - }, - geometry: { - type: 'Polygon', - coordinates: [ - [ - [7, 43], - [9, 45], - [12, 43], - [10, 42], - [7, 43], - ], - ], - }, - }, - { - type: 'Feature', - properties: { - name: 'number 9', - value: 9898, - }, - geometry: { - type: 'Polygon', - coordinates: [ - [ - [4, 42], - [6, 43], - [9, 41], - [7, 40], - [4, 42], - ], - ], - }, - }, - ], -} - -describe('U.Choropleth', () => { - let path = '/map/99/datalayer/edit/62/', - poly1, - poly4, - poly9, - map, - datalayer - - before(async () => { - fetchMock.mock(/\/datalayer\/62\/\?.*/, JSON.stringify(POLYGONS)) - map = initMap({ umap_id: 99 }) - const datalayer_options = defaultDatalayerData() - await map.initDataLayers([datalayer_options]) - datalayer = map.getDataLayerByUmapId(62) - datalayer.options.type = 'Choropleth' - datalayer.options.choropleth = { - property: 'value', - } - enableEdit() - datalayer.eachLayer(function (layer) { - if (layer.properties.name === 'number 1') { - poly1 = layer - } else if (layer.properties.name === 'number 4') { - poly4 = layer - } else if (layer.properties.name === 'number 9') { - poly9 = layer - } - }) - }) - after(() => { - fetchMock.restore() - resetMap() - }) - - describe('#init()', () => { - it('datalayer should have 9 features', () => { - assert.equal(datalayer._index.length, 9) - }) - }) - describe('#compute()', () => { - it('choropleth should compute default colors', () => { - datalayer.resetLayer(true) - assert.deepEqual( - datalayer.layer.options.breaks, - [45, 673, 3829, 4900, 9898, 9898] - ) - assert.equal(poly1._path.attributes.fill.value, '#eff3ff') - assert.equal(poly4._path.attributes.fill.value, '#bdd7e7') - assert.equal(poly9._path.attributes.fill.value, '#3182bd') - }) - it('can change brewer scheme', () => { - datalayer.options.choropleth.brewer = 'Reds' - datalayer.resetLayer(true) - assert.equal(poly1._path.attributes.fill.value, '#fee5d9') - assert.equal(poly4._path.attributes.fill.value, '#fcae91') - assert.equal(poly9._path.attributes.fill.value, '#de2d26') - }) - it('choropleth should allow to change steps', () => { - datalayer.options.choropleth.brewer = 'Blues' - datalayer.options.choropleth.classes = 6 - datalayer.resetLayer(true) - assert.equal(poly1._path.attributes.fill.value, '#eff3ff') - assert.equal(poly4._path.attributes.fill.value, '#c6dbef') - assert.equal(poly9._path.attributes.fill.value, '#3182bd') - }) - }) -}) diff --git a/umap/static/umap/test/Permissions.js b/umap/static/umap/test/Permissions.js deleted file mode 100644 index 979dcd03..00000000 --- a/umap/static/umap/test/Permissions.js +++ /dev/null @@ -1,74 +0,0 @@ -describe('L.Permissions', function () { - var path = '/map/99/datalayer/edit/62/' - - before(function () { - this.server = sinon.fakeServer.create() - this.server.respondWith( - /\/datalayer\/62\/\?.*/, - JSON.stringify(RESPONSES.datalayer62_GET) - ) - this.map = initMap({ umap_id: 99 }) - this.datalayer = this.map.getDataLayerByUmapId(62) - this.server.respond() - enableEdit() - }) - after(function () { - clickCancel() - this.server.restore() - resetMap() - }) - - describe('#open()', function () { - var button - - it('should exist update permissions link', function () { - button = qs('a.update-map-permissions') - expect(button).to.be.ok - }) - - it('should open table button click', function () { - happen.click(button) - expect(qs('.permissions-panel')).to.be.ok - }) - }) - describe('#anonymous with cookie', function () { - var button - - it('should not allow share_status nor owner', function () { - this.map.permissions.options.anonymous_edit_url = 'http://anonymous.url' - delete this.map.options.permissions.owner - button = qs('a.update-map-permissions') - happen.click(button) - expect(qs('select[name="share_status"]')).not.to.be.ok - expect(qs('input.edit-owner')).not.to.be.ok - }) - }) - - describe('#editor', function () { - var button - - it('should only allow editors', function () { - this.map.options.permissions.owner = { id: 1, url: '/url', name: 'jojo' } - delete this.map.options.permissions.anonymous_edit_url - delete this.map.options.user - button = qs('a.update-map-permissions') - happen.click(button) - expect(qs('select[name="share_status"]')).not.to.be.ok - expect(qs('input.edit-owner')).not.to.be.ok - expect(qs('input.edit-editors')).to.be.ok - }) - }) - - describe('#owner', function () { - var button - - it('should allow everything', function () { - this.map.permissions.options.owner = { id: 1, url: '/url', name: 'jojo' } - this.map.options.user = { id: 1, url: '/url', name: 'jojo' } - button = qs('a.update-map-permissions') - happen.click(button) - expect(qs('input.edit-owner')).to.be.ok - expect(qs('input.edit-editors')).to.be.ok - }) - }) -}) diff --git a/umap/static/umap/test/Polygon.js b/umap/static/umap/test/Polygon.js index f0c1124c..d0860167 100644 --- a/umap/static/umap/test/Polygon.js +++ b/umap/static/umap/test/Polygon.js @@ -108,260 +108,4 @@ describe('U.Polygon', function () { }) }) - describe('#contextmenu', function () { - afterEach(function () { - // Make sure contextmenu is hidden - happen.once(document, { type: 'keydown', keyCode: 27 }) - }) - - describe('#in edit mode', function () { - it('should allow to remove shape when multi', function () { - var latlngs = [ - [[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]], - [[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]], - ], - layer = new U.Polygon(map, latlngs, { - datalayer: datalayer, - }).addTo(datalayer) - happen.once(layer._path, { type: 'contextmenu' }) - assert.equal(qst('Remove shape from the multi'), 1) - }) - - it('should not allow to remove shape when not multi', function () { - var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]], - layer = new U.Polygon(map, latlngs, { - datalayer: datalayer, - }).addTo(datalayer) - happen.once(layer._path, { type: 'contextmenu' }) - assert.notOk(qst('Remove shape from the multi')) - }) - - it('should not allow to isolate shape when not multi', function () { - var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]], - layer = new U.Polygon(map, latlngs, { - datalayer: datalayer, - }).addTo(datalayer) - happen.once(layer._path, { type: 'contextmenu' }) - assert.notOk(qst('Extract shape to separate feature')) - }) - - it('should allow to isolate shape when multi', function () { - var latlngs = [ - [[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]], - [[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]], - ], - layer = new U.Polygon(map, latlngs, { - datalayer: datalayer, - }).addTo(datalayer) - happen.once(layer._path, { type: 'contextmenu' }) - assert.ok(qst('Extract shape to separate feature')) - }) - - it('should not allow to transform to lines when multi', function () { - var latlngs = [ - [[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]], - [[p2ll(300, 350), p2ll(350, 400), p2ll(400, 300)]], - ], - layer = new U.Polygon(map, latlngs, { - datalayer: datalayer, - }).addTo(datalayer) - happen.once(layer._path, { type: 'contextmenu' }) - assert.notOk(qst('Transform to lines')) - }) - - it('should not allow to transform to lines when hole', function () { - var latlngs = [ - [ - [p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)], - [p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)], - ], - ], - layer = new U.Polygon(map, latlngs, { - datalayer: datalayer, - }).addTo(datalayer) - happen.once(layer._path, { type: 'contextmenu' }) - assert.notOk(qst('Transform to lines')) - }) - - it('should allow to transform to lines when not multi', function () { - var latlngs = [[[p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)]]] - new U.Polygon(map, latlngs, { datalayer: datalayer }).addTo( - datalayer - ) - happen.at('contextmenu', 150, 150) - assert.equal(qst('Transform to lines'), 1) - }) - - it('should not allow to transfer shape when not editedFeature', function () { - new U.Polygon(map, [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)], { - datalayer: datalayer, - }).addTo(datalayer) - happen.at('contextmenu', 110, 160) - assert.equal(qst('Delete this feature'), 1) // Make sure we have right clicked on the polygon. - assert.notOk(qst('Transfer shape to edited feature')) - }) - - it('should not allow to transfer shape when editedFeature is not a polygon', function () { - var layer = new U.Polygon( - map, - [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)], - { datalayer: datalayer } - ).addTo(datalayer), - other = new U.Polyline(map, [p2ll(200, 250), p2ll(200, 300)], { - datalayer: datalayer, - }).addTo(datalayer) - other.edit() - happen.once(layer._path, { type: 'contextmenu' }) - assert.equal(qst('Delete this feature'), 1) // Make sure we have right clicked on the polygon. - assert.notOk(qst('Transfer shape to edited feature')) - }) - - it('should allow to transfer shape when another polygon is edited', function () { - datalayer.empty() - var layer = new U.Polygon( - map, - [p2ll(200, 300), p2ll(300, 200), p2ll(200, 100)], - { datalayer: datalayer } - ).addTo(datalayer) - layer.edit() // This moves the map to put "other" at the center. - var other = new U.Polygon( - map, - [p2ll(100, 150), p2ll(100, 200), p2ll(200, 150)], - { datalayer: datalayer } - ).addTo(datalayer) - happen.once(other._path, { type: 'contextmenu' }) - assert.equal(qst('Transfer shape to edited feature'), 1) - layer.remove() - }) - }) - }) - - describe('#addShape', function () { - it('"add shape" control should not be visible by default', function () { - assert.notOk(qs('.umap-draw-polygon-multi')) - }) - - it('"add shape" control should be visible when editing a Polygon', function () { - var layer = new U.Polygon(map, [p2ll(100, 100), p2ll(100, 200)], { - datalayer: datalayer, - }).addTo(datalayer) - layer.edit() - assert.ok(qs('.umap-draw-polygon-multi')) - }) - - it('"add shape" control should extend the same multi', function () { - var layer = new U.Polygon( - map, - [p2ll(100, 150), p2ll(150, 200), p2ll(200, 100)], - { datalayer: datalayer } - ).addTo(datalayer) - layer.edit() - assert.notOk(layer.isMulti()) - happen.click(qs('.umap-draw-polygon-multi')) - happen.at('mousemove', 300, 300) - happen.at('click', 300, 300) - happen.at('mousemove', 350, 300) - happen.at('click', 350, 300) - happen.at('click', 350, 300) - assert.ok(layer.isMulti()) - assert.equal(datalayer._index.length, 1) - }) - }) - - describe('#transferShape', function () { - it('should transfer simple polygon shape to another polygon', function () { - var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], - layer = new U.Polygon(map, latlngs, { datalayer: datalayer }).addTo( - datalayer - ), - other = new U.Polygon( - map, - [p2ll(200, 350), p2ll(200, 300), p2ll(300, 200)], - { datalayer: datalayer } - ).addTo(datalayer) - assert.ok(map.hasLayer(layer)) - layer.transferShape(p2ll(150, 150), other) - assert.equal(other._latlngs.length, 2) - assert.deepEqual(other._latlngs[1][0], latlngs) - assert.notOk(map.hasLayer(layer)) - }) - - it('should transfer multipolygon shape to another polygon', function () { - var latlngs = [ - [ - [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], - [p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)], - ], - [[p2ll(200, 300), p2ll(300, 200)]], - ], - layer = new U.Polygon(map, latlngs, { datalayer: datalayer }).addTo( - datalayer - ), - other = new U.Polygon( - map, - [p2ll(200, 350), p2ll(200, 300), p2ll(300, 200)], - { datalayer: datalayer } - ).addTo(datalayer) - assert.ok(map.hasLayer(layer)) - layer.transferShape(p2ll(150, 150), other) - assert.equal(other._latlngs.length, 2) - assert.deepEqual(other._latlngs[1][0], latlngs[0][0]) - assert.ok(map.hasLayer(layer)) - assert.equal(layer._latlngs.length, 1) - }) - }) - - describe('#isolateShape', function () { - it('should not allow to isolate simple polygon', function () { - var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], - layer = new U.Polygon(map, latlngs, { datalayer: datalayer }).addTo( - datalayer - ) - assert.equal(datalayer._index.length, 1) - assert.ok(map.hasLayer(layer)) - layer.isolateShape(p2ll(150, 150)) - assert.equal(layer._latlngs[0].length, 3) - assert.equal(datalayer._index.length, 1) - }) - - it('should isolate multipolygon shape', function () { - var latlngs = [ - [ - [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], - [p2ll(120, 150), p2ll(150, 180), p2ll(180, 120)], - ], - [[p2ll(200, 300), p2ll(300, 200)]], - ], - layer = new U.Polygon(map, latlngs, { datalayer: datalayer }).addTo( - datalayer - ) - assert.equal(datalayer._index.length, 1) - assert.ok(map.hasLayer(layer)) - var other = layer.isolateShape(p2ll(150, 150)) - assert.equal(datalayer._index.length, 2) - assert.equal(other._latlngs.length, 2) - assert.deepEqual(other._latlngs[0], latlngs[0][0]) - assert.ok(map.hasLayer(layer)) - assert.ok(map.hasLayer(other)) - assert.equal(layer._latlngs.length, 1) - other.remove() - }) - }) - - describe('#clone', function () { - it('should clone polygon', function () { - var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], - layer = new U.Polygon(map, latlngs, { datalayer: datalayer }).addTo( - datalayer - ) - assert.equal(datalayer._index.length, 1) - other = layer.clone() - assert.ok(map.hasLayer(other)) - assert.equal(datalayer._index.length, 2) - // Must not be the same reference - assert.notEqual(layer._latlngs, other._latlngs) - assert.equal(L.Util.formatNum(layer._latlngs[0][0].lat), other._latlngs[0][0].lat) - assert.equal(L.Util.formatNum(layer._latlngs[0][0].lng), other._latlngs[0][0].lng) - }) - }) }) diff --git a/umap/static/umap/test/Polyline.js b/umap/static/umap/test/Polyline.js index 41b6e16c..06f5ee08 100644 --- a/umap/static/umap/test/Polyline.js +++ b/umap/static/umap/test/Polyline.js @@ -234,72 +234,6 @@ describe('U.Polyline', function () { }) }) - describe('#addShape', function () { - it('"add shape" control should not be visible by default', function () { - assert.notOk(qs('.umap-draw-polyline-multi')) - }) - - it('"add shape" control should be visible when editing a Polyline', function () { - var layer = new U.Polyline(this.map, [p2ll(100, 100), p2ll(100, 200)], { - datalayer: this.datalayer, - }).addTo(this.datalayer) - layer.edit() - assert.ok(qs('.umap-draw-polyline-multi')) - }) - - it('"add shape" control should extend the same multi', function () { - var layer = new U.Polyline(this.map, [p2ll(100, 100), p2ll(100, 200)], { - datalayer: this.datalayer, - }).addTo(this.datalayer) - layer.edit() - assert.notOk(layer.isMulti()) - happen.click(qs('.umap-draw-polyline-multi')) - happen.at('mousemove', 300, 300) - happen.at('click', 300, 300) - happen.at('mousemove', 350, 300) - happen.at('click', 350, 300) - happen.at('click', 350, 300) - assert.ok(layer.isMulti()) - assert.equal(this.datalayer._index.length, 1) - }) - }) - - describe('#transferShape', function () { - it('should transfer simple line shape to another line', function () { - var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], - layer = new U.Polyline(this.map, latlngs, { - datalayer: this.datalayer, - }).addTo(this.datalayer), - other = new U.Polyline(this.map, [p2ll(200, 300), p2ll(300, 200)], { - datalayer: this.datalayer, - }).addTo(this.datalayer) - assert.ok(this.map.hasLayer(layer)) - layer.transferShape(p2ll(150, 150), other) - assert.equal(other._latlngs.length, 2) - assert.deepEqual(other._latlngs[1], latlngs) - assert.notOk(this.map.hasLayer(layer)) - }) - - it('should transfer multi line shape to another line', function () { - var latlngs = [ - [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], - [p2ll(200, 300), p2ll(300, 200)], - ], - layer = new U.Polyline(this.map, latlngs, { - datalayer: this.datalayer, - }).addTo(this.datalayer), - other = new U.Polyline(this.map, [p2ll(250, 300), p2ll(350, 200)], { - datalayer: this.datalayer, - }).addTo(this.datalayer) - assert.ok(this.map.hasLayer(layer)) - layer.transferShape(p2ll(150, 150), other) - assert.equal(other._latlngs.length, 2) - assert.deepEqual(other._latlngs[1], latlngs[0]) - assert.ok(this.map.hasLayer(layer)) - assert.equal(layer._latlngs.length, 1) - }) - }) - describe('#mergeShapes', function () { it('should remove duplicated join point when merging', function () { var latlngs = [ @@ -349,54 +283,4 @@ describe('U.Polyline', function () { }) }) - describe('#isolateShape', function () { - it('should not allow to isolate simple line', function () { - var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], - layer = new U.Polyline(this.map, latlngs, { - datalayer: this.datalayer, - }).addTo(this.datalayer) - assert.equal(this.datalayer._index.length, 1) - assert.ok(this.map.hasLayer(layer)) - layer.isolateShape(p2ll(150, 150)) - assert.equal(layer._latlngs.length, 3) - assert.equal(this.datalayer._index.length, 1) - }) - - it('should isolate multipolyline shape', function () { - var latlngs = [ - [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], - [[p2ll(200, 300), p2ll(300, 200)]], - ], - layer = new U.Polyline(this.map, latlngs, { - datalayer: this.datalayer, - }).addTo(this.datalayer) - assert.equal(this.datalayer._index.length, 1) - assert.ok(this.map.hasLayer(layer)) - var other = layer.isolateShape(p2ll(150, 150)) - assert.equal(this.datalayer._index.length, 2) - assert.equal(other._latlngs.length, 3) - assert.deepEqual(other._latlngs, latlngs[0]) - assert.ok(this.map.hasLayer(layer)) - assert.ok(this.map.hasLayer(other)) - assert.equal(layer._latlngs.length, 1) - other.remove() - }) - }) - - describe('#clone', function () { - it('should clone polyline', function () { - var latlngs = [p2ll(100, 150), p2ll(100, 200), p2ll(200, 100)], - layer = new U.Polyline(this.map, latlngs, { - datalayer: this.datalayer, - }).addTo(this.datalayer) - assert.equal(this.datalayer._index.length, 1) - other = layer.clone() - assert.ok(this.map.hasLayer(other)) - assert.equal(this.datalayer._index.length, 2) - // Must not be the same reference - assert.notEqual(layer._latlngs, other._latlngs) - assert.equal(L.Util.formatNum(layer._latlngs[0].lat), other._latlngs[0].lat) - assert.equal(L.Util.formatNum(layer._latlngs[0].lng), other._latlngs[0].lng) - }) - }) }) diff --git a/umap/static/umap/test/index.html b/umap/static/umap/test/index.html index 254728ce..8ab2c567 100644 --- a/umap/static/umap/test/index.html +++ b/umap/static/umap/test/index.html @@ -95,8 +95,6 @@ - -